From nobody Wed Nov 27 18:39:00 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Xz7WS44R5z5fbc6; Wed, 27 Nov 2024 18:39:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Xz7WS3XbQz46Qx; Wed, 27 Nov 2024 18:39:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732732740; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mbWwGnMzu9TSyh1mVVXBPGEYSYdlkKOxFDCZJwePwwo=; b=A/EFwO4EKaGV43NWcRM6d+oVdJzwEIoH2LlTJsOLMn/faE6ZpQXCFmd57SNcLjdVQlWHEo F4E3Lyo/YG5iwHC130JYOXm6ZFmEG2Khf5AK5Xvk7eTGN9J91RURjrpXt090C/AwSy5I0E MyGWcmaFDTeQarn68YLiJOPjGLatpFnPGTQS6/h9yqp5janfFzDzivvnG8FyWWEvKyd0O5 Tn+Aj7H9GYpWV6qUrsogF0lD1vNpCWXr/P8UeR2KubP9/enOtNYA2yxTDGne81u0Y5Ymbk ZCpVB9HzC4CpJNDFkA8CPUJdxkF42/qwEEqHV2jKz1WgtvGIEpUCErTr5ceexw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732732740; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mbWwGnMzu9TSyh1mVVXBPGEYSYdlkKOxFDCZJwePwwo=; b=gpptCrvGy/zV/1qI/xzbGKMLHu9lu1P9C8aAA4z4Z1gz10WK8vii6vRXhJ6WCvMGb36F2L RhNQwscqCb0zHoJs9txWiJ0ztySaaOQ3EPeuwP63NB/A+fHKGHAz6FbrfvD0VlEdXz/hhb QS/SVe06UGaUgl5/bhCoy3bzf5m1a1aPyAH/oPg+hempjsHqbkpv87T6Zc7MXrhGzyFhOo Hxpf9JZz+HIOsZlbkbG9mRCk+s1A3MP3HTvL6xl+m8z/ccFefkJ2NcBhl5odRyn0a5Xyih cyWMTqg0Sm40zsPjNQUgtjG7a6TcOdtTBUY9HpeL2ZV2YtVfuM5xdjJccyIcRA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1732732740; a=rsa-sha256; cv=none; b=okN2QfbvoYv51IF/DQI/Yszeno4Fb5qC6kg8eQpA0wI3OxsmD8TNr8jgbKWM55dIVfsgRb Gdy5oMIw31i5hIOA72I519PyEAMJpw/yp1FOZyi9/bAEiFBQdorgqMM2qLHfL4KRG8CcEM o3ECLcAvVf8ctydq9A7EwndXpyr5wKbc9CX33EDZurdAu8TGaN9GQz7pnH9DUYkfGqr8q+ JhtDNbs8kpvYYJcn3g3dD6/9Z92Ashk/F1D20+OZxvdX8e5SAg1Zuzg1XRkb1N334IWw0m C7maF0bKAWWUlmZRrOLkwTXGCKK90h4EPHdFKtgU7t52PzPlqER+Z6YE2anf5g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Xz7WS37hnz1LKL; Wed, 27 Nov 2024 18:39:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4ARId03W098266; Wed, 27 Nov 2024 18:39:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4ARId03h098263; Wed, 27 Nov 2024 18:39:00 GMT (envelope-from git) Date: Wed, 27 Nov 2024 18:39:00 GMT Message-Id: <202411271839.4ARId03h098263@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Brooks Davis Subject: git: 06a98fefd3d3 - main - nvi: Replace Clang-only __builtin_is_aligned with C code (#124) List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: brooks X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 06a98fefd3d3ff42b7e7832af6c0736b98f167ac Auto-Submitted: auto-generated The branch main has been updated by brooks: URL: https://cgit.FreeBSD.org/src/commit/?id=06a98fefd3d3ff42b7e7832af6c0736b98f167ac commit 06a98fefd3d3ff42b7e7832af6c0736b98f167ac Author: Zhihao Yuan AuthorDate: 2024-11-27 18:30:46 +0000 Commit: Brooks Davis CommitDate: 2024-11-27 18:35:10 +0000 nvi: Replace Clang-only __builtin_is_aligned with C code (#124) We should use alignof in the future. Obtained from: https://github.com/lichray/nvi2/commit/25c4d7db4ea638a31ac458b733a3b67b0a0ff634 --- contrib/nvi/common/log.c | 2 +- contrib/nvi/common/mem.h | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/contrib/nvi/common/log.c b/contrib/nvi/common/log.c index d9b142b16d01..d1a1bc6f704a 100644 --- a/contrib/nvi/common/log.c +++ b/contrib/nvi/common/log.c @@ -709,7 +709,7 @@ apply_with(int (*db_func)(SCR *, recno_t, CHAR_T *, size_t), SCR *sp, static size_t blen; static u_char *bp; - if (!__builtin_is_aligned(p, sizeof(unsigned long))) { + if (!is_aligned(p, sizeof(unsigned long))) { if (len > blen) { blen = p2roundup(MAX(len, 512)); REALLOC(sp, bp, u_char *, blen); diff --git a/contrib/nvi/common/mem.h b/contrib/nvi/common/mem.h index d24ec0b50b09..0c83b70dec2f 100644 --- a/contrib/nvi/common/mem.h +++ b/contrib/nvi/common/mem.h @@ -212,6 +212,18 @@ p2roundup(size_t n) return (n); } +/* + * is_aligned -- + * Determine whether the program can safely read an object with an + * alignment requirement from ptr. + * + * See also: https://clang.llvm.org/docs/LanguageExtensions.html#alignment-builtins + */ +static __inline int +is_aligned(void *ptr, size_t alignment) { + return ((uintptr_t)ptr % alignment) == 0; +} + /* Additional TAILQ helper. */ #define TAILQ_ENTRY_ISVALID(elm, field) \ ((elm)->field.tqe_prev != NULL)