From nobody Thu Jun 12 18:17:24 2025 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 4bJ9jc5Mg1z5yBsD; Thu, 12 Jun 2025 18:17:24 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bJ9jc4L4Dz3RW3; Thu, 12 Jun 2025 18:17:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1749752244; 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=0KK0H61LS5WEEkeNcwXbKRw6KVuPxDPsk8OJshjjxv8=; b=Pj+t0mgvaNfQB67D4H2cAgfCbL8xt28s7q0Nt6IaCDOh/NLAhno50J/Sy2Nvzi9xti1kN/ 1KNZtk3lTaBwqQbz3j2k7fmovxaKc7QqQGVUypImeqmKNH0nGO/Yt9Qz8hx5N2YQTFRaN+ gZmF4cOJJPu/7fcdl8Si74HkYJgQ9xL+xSNc21hCOTDJsWHjEnztRfMfEmJW8ITEmumYNp DgR0+/TnNeP9d6AKC5jO4eMpVaiLxREtlsh0ud3GmAZrdkDsDnlGpER3jOI+IUHWjm4XOR RqGvN81ZJ3y7cZIYiZI3wskkqoUBeJ6CJM/EQ0Wh+WqPj/bmIFUjB97AYh8v8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1749752244; 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=0KK0H61LS5WEEkeNcwXbKRw6KVuPxDPsk8OJshjjxv8=; b=CDeOdxwdJEoJ/+BsnDwS6LMX7+P4SzPlVpsl+eBhh+dm32s0tEko5FqDusbbE6ySAKT4b2 8oDnlwKIS5756DYnR2SysjbDSGXXZosWUWK9nJGweFNKwr9sjqQRL/Z5AK7bvXSWKEMvzT t5+xYw+XM7ct7tR1f6H9MEP/1SD2ITROWydIbmJJvyyHJQPPvDcCGc0kYmkXer0ZsgoPHN s8lPlD6npJfuz5Bd+SYe/lhndrXsfxHVCGE2GA7YhFUmgmkwANqKjpiyxpjyHhGMpY1Xfa Qc2FdTgVqA7f8H6vAdf7HZ2KaRLqzVNnmfxfaMSmIhoid8nnMpZsC9UpXKMOPw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1749752244; a=rsa-sha256; cv=none; b=Ro8vu5DV8qB8gBw3RNpRJ3DqDOAbzQhQvhgSWksuvlwz1KdVYeggkbIh83pgAvxU0YGxky X8S/7SYlPl5G3QMIEhDT/L0kvCIT9AuCbBRWMbft43e6l9Sk8rW+MmUyjDJEhF8gRyqVmw 78MUn3Iy6orO68qOR4XMJ4oC25v5V17+E7Lc/3WJaqnz+Nb3pvmmOH8g4nqCP1u3lzkV9M SdOvf+QiRTm2Q8UYNljOqkElRq2PTG9J+egvoKMjbV3tMqUiXl9IW7NAZpyI8TBWlOoloj TcFakHZXooAUttcyX0udBkg+GoxyQBwg20H5CvngCW5KN2EufivwhxYVdZ+1tg== 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 4bJ9jc3Q3Zz6yD; Thu, 12 Jun 2025 18:17:24 +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 55CIHOFh087677; Thu, 12 Jun 2025 18:17:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 55CIHO5l087674; Thu, 12 Jun 2025 18:17:24 GMT (envelope-from git) Date: Thu, 12 Jun 2025 18:17:24 GMT Message-Id: <202506121817.55CIHO5l087674@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Hiroki Sato Subject: git: 6501b68ffba7 - main - libcasper: Use __VA_ARGS__ for function-like macros 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: hrs X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6501b68ffba7f4414b3818fcc3ee945e70918772 Auto-Submitted: auto-generated The branch main has been updated by hrs: URL: https://cgit.FreeBSD.org/src/commit/?id=6501b68ffba7f4414b3818fcc3ee945e70918772 commit 6501b68ffba7f4414b3818fcc3ee945e70918772 Author: Hiroki Sato AuthorDate: 2025-06-12 18:04:21 +0000 Commit: Hiroki Sato CommitDate: 2025-06-12 18:04:21 +0000 libcasper: Use __VA_ARGS__ for function-like macros cap_net.h uses "#define cap_f(chan, a) f(a)" to call the conventional service function with the first argument of cap_f() dropped for compatibility with the environment where the casper service is unavailable. However, this function-like macro does not work when the arguments contains C99 compound literals, such as f(chan, (int[]){1,2,3}). The following is a typical example: error = cap_getaddrinfo(capnet, "192.168.0.1", "100", &(struct addrinfo){ .ai_family = AF_INET, .ai_flags = AI_NUMERICHOST }, &res); Using cap_f(chan, ...) and __VA_ARGS__ in C99 seems a reasonable solution for this problem. While there is a workaround using parenthesis around the compound literal like f(chan, ((int[]){1,2,3})), it is not intuitive and the above example works when the cap_net is available and f() is defined as a function. A possible moot point is that __VA_ARGS__ cannot control how many arguments are passed at the macro level, and "chan" is not protected. However, "chan" is less likely to be written in compound literal, and the function prototype should check the remaining arguments. Reviewed by: oshogbo Differential Revision: https://reviews.freebsd.org/D45858 --- lib/libcasper/services/cap_net/cap_net.h | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/libcasper/services/cap_net/cap_net.h b/lib/libcasper/services/cap_net/cap_net.h index 1e9a6021d240..75f936954199 100644 --- a/lib/libcasper/services/cap_net/cap_net.h +++ b/lib/libcasper/services/cap_net/cap_net.h @@ -93,18 +93,14 @@ struct hostent *cap_gethostbyaddr(cap_channel_t *chan, const void *addr, socklen_t len, int af); #else /* Capability functions. */ -#define cap_bind(chan, s, addr, addrlen) \ - bind(s, addr, addrlen) -#define cap_connect(chan, s, name, namelen) \ - connect(s, name, namelen) -#define cap_getaddrinfo(chan, hostname, servname, hints, res) \ - getaddrinfo(hostname, servname, hints, res) -#define cap_getnameinfo(chan, sa, salen, host, hostlen, serv, servlen, flags) \ - getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) +#define cap_bind(chan, ...) bind(__VA_ARGS__) +#define cap_connect(chan, ...) connect(__VA_ARGS__) +#define cap_getaddrinfo(chan, ...) getaddrinfo(__VA_ARGS__) +#define cap_getnameinfo(chan, ...) getnameinfo(__VA_ARGS__) /* Limit functions. */ -#define cap_net_limit_init(chan, mode) ((cap_net_limit_t *)malloc(8)) -#define cap_net_free(limit) free(limit) +#define cap_net_limit_init(chan, ...) ((cap_net_limit_t *)malloc(8)) +#define cap_net_free(...) free(__VA_ARGS__) static inline int cap_net_limit(cap_net_limit_t *limit) { @@ -155,9 +151,9 @@ cap_net_limit_bind(cap_net_limit_t *limit, } /* Deprecated functions. */ -#define cap_gethostbyname(chan, name) gethostbyname(name) -#define cap_gethostbyname2(chan, name, type) gethostbyname2(name, type) -#define cap_gethostbyaddr(chan, addr, len, type) gethostbyaddr(addr, len, type) +#define cap_gethostbyname(chan, ...) gethostbyname(__VA_ARGS__) +#define cap_gethostbyname2(chan, ...) gethostbyname2(__VA_ARGS__) +#define cap_gethostbyaddr(chan, ...) gethostbyaddr(__VA_ARGS__) #endif #endif /* !_CAP_NETWORK_H_ */