From nobody Thu Sep 11 18:50:22 2025 X-Original-To: dev-commits-src-all@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 4cN67f6Y4vz67Hnk; Thu, 11 Sep 2025 18:50:22 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cN67f5Z58z3h4j; Thu, 11 Sep 2025 18:50:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1757616622; 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=Fn28Odag4c+dItmtvcwT9sa38mLimXw9cne/BUkwkAQ=; b=GHVY6T2IwSOrfrKhBtcrmuGZNSZjxpA2l6ji733ItGCaxQ96wAoa17ynImxkMPiO+Mb//I IzTH081ASKaG2D3pcbjeTo1X2kccrRhwpjfkorlOfaFcL5gVC5ND1WYPl4GrXZSIGR//O0 WeaSa3INztKLKdKFLj6C99yH90r2EgiCWnDPY2ZAB0ZZ3nnysCGzw96MLnbBb1dudGBe1t oVH272q8iMNFYOYp8Ds1icSep6f6BrvBC+xOKy+qtuaA5ULiHmseRDejUBtmPG3psSglqW iWCipeJ/I/uxL9ogZnBrBpvjOfqVslRpfZSGBhnTsayy//SOWukJeD4lNhr1cQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1757616622; 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=Fn28Odag4c+dItmtvcwT9sa38mLimXw9cne/BUkwkAQ=; b=xfblhhqBam+o6kvETpV1JC1/yZXbqJUZiAM0wdZi+rmM3/w3ShdHFZ1ke8zj3bk6BAUXGv 7DD37PnMzxj8Yjx6g3ppK3sSHj/ug3XRV0d7NE1jtseD8SwdWVveKURPCz/4h2lio5nEIv SJvC6wkoK96Rm5cwrBXpddlnowpf6wJynPE6XS5z0zscdqm8Z7EiEIEr0Lj2jj0s9OJvY4 b0xtGSYpLMfeDO0NhP3HpC5E7XobFaysUHHupVM6W3xRX+B7+2UlijkMGTLlac9UNh3awk Lmt06Qx93jcuEkaCjntAiaVSitdDG3r4JfDOoQgAUhpReOHJvOJSk9/5DyzXGA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1757616622; a=rsa-sha256; cv=none; b=ohoitQP2CnDGE3/9owO2yjNjj6fCk2/nmFzdVveqbLXbD40KhlCCIwMWMr8m072k8yRyf3 TsKKs+cQrScsBVoGmZWI9tpFyUAf5NAqcP0E5R2bamWCVEnoy2RsMXZkiL/LWYSmVyugyx y3A3dbGweO6qRJRFlSvcBwoE6OW3GUSC4DdsosGCqDJbaFnUAPsDt6sJMUNWMQUXHH9Roc PZiofQzMpsa57lB2oT/oaTjWlqn5PLlRKXaTO4wct/y13Iu/yg9dkcVsNpp4PQboPaAIk/ ZbfL05Ev62LLWmzOpOZeYSbGfLqyq8s/9ep1fQPd9SM+mM3l9FPLTd/7H1wtYA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4cN67f4qP5z4DH; Thu, 11 Sep 2025 18:50:22 +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 58BIoMsF092903; Thu, 11 Sep 2025 18:50:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58BIoMG3092900; Thu, 11 Sep 2025 18:50:22 GMT (envelope-from git) Date: Thu, 11 Sep 2025 18:50:22 GMT Message-Id: <202509111850.58BIoMG3092900@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: f56402485dd5 - stable/14 - lposix: Clean up the posix namespace definitions List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: f56402485dd54c7a2d88cb145864bba59b8d4532 Auto-Submitted: auto-generated The branch stable/14 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=f56402485dd54c7a2d88cb145864bba59b8d4532 commit f56402485dd54c7a2d88cb145864bba59b8d4532 Author: Mark Johnston AuthorDate: 2025-07-07 15:43:27 +0000 Commit: Ed Maste CommitDate: 2025-09-11 15:09:58 +0000 lposix: Clean up the posix namespace definitions The posix module is subdivided according to C headers; for instance, posix.unistd contains routines available from unistd.h, such as chown(2). A quirk of our implementation is that each of the modules is a direct entry in the global table. That is, there is no "posix" table. Instead, "posix.foo" and "posix.bar.baz" are both top-level tables. This is surprising and goes against Lua's shorthand of using "." to access keys in a table. lua-posix also doesn't work this way. Rework things so that "posix" and "posix.sys" are proper tables. Existing flua code which uses require() to bind posix submodules to a name will be unaffected. Code which accesses them directly using something like _G["posix.sys.utsname"].uname() will be broken, but I don't think anything like that exists. In particular, it is now possible to call posix.sys.utsname.uname() without any require statements. Reviewed by: imp, bapt MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D51158 (cherry picked from commit eda96744b434325c475dce449744f2268f1033e8) --- libexec/flua/linit_flua.c | 10 +-------- libexec/flua/modules/lposix.c | 51 +++++++++++++++++++++++++++++++++---------- libexec/flua/modules/lposix.h | 8 +------ 3 files changed, 42 insertions(+), 27 deletions(-) diff --git a/libexec/flua/linit_flua.c b/libexec/flua/linit_flua.c index 8eaa4af1ffca..b466b7872158 100644 --- a/libexec/flua/linit_flua.c +++ b/libexec/flua/linit_flua.c @@ -57,18 +57,11 @@ static const luaL_Reg loadedlibs[] = { #endif /* FreeBSD Extensions */ {"lfs", luaopen_lfs}, - {"posix.fnmatch", luaopen_posix_fnmatch}, - {"posix.libgen", luaopen_posix_libgen}, - {"posix.stdlib", luaopen_posix_stdlib}, - {"posix.sys.stat", luaopen_posix_sys_stat}, - {"posix.sys.utsname", luaopen_posix_sys_utsname}, - {"posix.sys.wait", luaopen_posix_sys_wait}, - {"posix.unistd", luaopen_posix_unistd}, + {"posix", luaopen_posix}, {"fbsd", luaopen_fbsd}, {NULL, NULL} }; - LUALIB_API void luaL_openlibs (lua_State *L) { const luaL_Reg *lib; /* "require" functions from 'loadedlibs' and set results to global table */ @@ -77,4 +70,3 @@ LUALIB_API void luaL_openlibs (lua_State *L) { lua_pop(L, 1); /* remove lib */ } } - diff --git a/libexec/flua/modules/lposix.c b/libexec/flua/modules/lposix.c index 43b9ee83673c..4ccfcdaa46e7 100644 --- a/libexec/flua/modules/lposix.c +++ b/libexec/flua/modules/lposix.c @@ -533,21 +533,21 @@ static const struct luaL_Reg unistdlib[] = { #undef REG_SIMPLE #undef REG_DEF -int +static int luaopen_posix_libgen(lua_State *L) { luaL_newlib(L, libgenlib); return (1); } -int +static int luaopen_posix_stdlib(lua_State *L) { luaL_newlib(L, stdliblib); return (1); } -int +static int luaopen_posix_fnmatch(lua_State *L) { luaL_newlib(L, fnmatchlib); @@ -565,14 +565,21 @@ luaopen_posix_fnmatch(lua_State *L) return 1; } -int +static int luaopen_posix_sys_stat(lua_State *L) { luaL_newlib(L, sys_statlib); return (1); } -int +static int +luaopen_posix_sys_utsname(lua_State *L) +{ + luaL_newlib(L, sys_utsnamelib); + return 1; +} + +static int luaopen_posix_sys_wait(lua_State *L) { luaL_newlib(L, sys_waitlib); @@ -598,16 +605,38 @@ luaopen_posix_sys_wait(lua_State *L) return (1); } -int -luaopen_posix_sys_utsname(lua_State *L) +static int +luaopen_posix_unistd(lua_State *L) { - luaL_newlib(L, sys_utsnamelib); - return 1; + luaL_newlib(L, unistdlib); + return (1); } int -luaopen_posix_unistd(lua_State *L) +luaopen_posix(lua_State *L) { - luaL_newlib(L, unistdlib); + lua_newtable(L); /* posix */ + + luaL_requiref(L, "posix.fnmatch", luaopen_posix_fnmatch, 0); + lua_setfield(L, -2, "fnmatch"); + + luaL_requiref(L, "posix.libgen", luaopen_posix_libgen, 0); + lua_setfield(L, -2, "libgen"); + + luaL_requiref(L, "posix.stdlib", luaopen_posix_stdlib, 0); + lua_setfield(L, -2, "stdlib"); + + lua_newtable(L); /* posix.sys */ + luaL_requiref(L, "posix.sys.stat", luaopen_posix_sys_stat, 0); + lua_setfield(L, -2, "stat"); + luaL_requiref(L, "posix.sys.utsname", luaopen_posix_sys_utsname, 0); + lua_setfield(L, -2, "utsname"); + luaL_requiref(L, "posix.sys.wait", luaopen_posix_sys_wait, 0); + lua_setfield(L, -2, "wait"); + lua_setfield(L, -2, "sys"); + + luaL_requiref(L, "posix.unistd", luaopen_posix_unistd, 0); + lua_setfield(L, -2, "unistd"); + return (1); } diff --git a/libexec/flua/modules/lposix.h b/libexec/flua/modules/lposix.h index da7079056826..1aa33f042571 100644 --- a/libexec/flua/modules/lposix.h +++ b/libexec/flua/modules/lposix.h @@ -7,10 +7,4 @@ #include -int luaopen_posix_fnmatch(lua_State *L); -int luaopen_posix_libgen(lua_State *L); -int luaopen_posix_stdlib(lua_State *L); -int luaopen_posix_sys_stat(lua_State *L); -int luaopen_posix_sys_utsname(lua_State *L); -int luaopen_posix_sys_wait(lua_State *L); -int luaopen_posix_unistd(lua_State *L); +int luaopen_posix(lua_State *L);