From nobody Mon Jul 7 15:44:00 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 4bbT745b46z6211k; Mon, 07 Jul 2025 15:44: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 4bbT744s5Zz4G6h; Mon, 07 Jul 2025 15:44:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1751903040; 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=hl09G+V9B5axLtWjIG/NV0Rhcwh2iIgYqGorQUORNi0=; b=V8dh714hQIvN4xMy+ONbQuzlrC8cKqjwFDyLWrR3UQ0sZWoYOBUKJlE6E7m8Tjqh4YCC20 OILQFPCHjj4PhmgqmGjZDBki3siAbkoJfkGqn1PaaA23PUHaGWtC5mBq28oQrW2uLYSjDx 8rR6er7UbYm43E1noHbIJk4FeoawVw+AAMv24a0WZV0zFJNsqHN5OPUfnELgI7xafk4+q0 GZridzOcz1jY/ZFO14JbzH1uu9w1+dLpp29NM8GSnaUXAjjUzdnOTjybtUYKO/ftjWO/Ko jRm3gEBeY06ANnYGVnOSIztKuOQMIUyiGENF/yYu6KfTOVFTQlfYMol1yyJ6Kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1751903040; 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=hl09G+V9B5axLtWjIG/NV0Rhcwh2iIgYqGorQUORNi0=; b=YOWPo0MH6wAOTOCPCMGgTr5IRwn9cKJKP/xcbxr9NfG4nFofHROlM76KxDG0Hh6apDtku7 ydbx6G7cvyGaOkLpYtf3wDMH/iSlY8tNnP/hzbM2CBYenlPAnuvsurxV0Sf0W0IyAU92KF pE+LyZDXhNBGVW/TfEHNOR5aIhWnpJsYsok2vM8wCsJYx6TowTmd7Re7GXZqcHXyMujsmq ViyEvfcqkFGeG4jt9arWXlVes+PCZIiT8iguesWSs4pS5MR8qrxnrbfLAPWChlT/Y0+200 D8Jjtkbxf0ysFvnj7MNKxlpmbwuEGHuhpAjVLHV6uRvq8/9pJPF1B7CDM9hS9g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1751903040; a=rsa-sha256; cv=none; b=S5mlqqTayWVe2ZX6+nfElH5RMK0VGLVWlOuXWU5FhMNmXYsKqiaRPlmXeXygIzEwB7Auqh aRvL9atCV9SfQ3efXEqu21AhE6T3aO7YoppCs8e3fNVnp95esaxY6xpN275VGHFioPyzEH 7arWUddsXMEszJtJ7XiijlMXVDeNcPNym8GlwK9JykKnJPjGY/kZdYB7JtixdNH4xfhAg/ e7YVhqXcvkP4Tj2u53kekVmCzkd2QjPDS/XXTb3fsbijvkuPjQ1yRXhzDjg7E/8kQND+Ps HpRNmW1O9t78oZdJIyiaDyXvfM5TQXMsvzdZa/yk+XcFThuChoh1NL9if76lQA== 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 4bbT744RGYzxCl; Mon, 07 Jul 2025 15:44: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 567Fi0EY092404; Mon, 7 Jul 2025 15:44:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 567Fi0ZJ092401; Mon, 7 Jul 2025 15:44:00 GMT (envelope-from git) Date: Mon, 7 Jul 2025 15:44:00 GMT Message-Id: <202507071544.567Fi0ZJ092401@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: eda96744b434 - main - lposix: Clean up the posix namespace definitions 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: eda96744b434325c475dce449744f2268f1033e8 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=eda96744b434325c475dce449744f2268f1033e8 commit eda96744b434325c475dce449744f2268f1033e8 Author: Mark Johnston AuthorDate: 2025-07-07 15:43:27 +0000 Commit: Mark Johnston CommitDate: 2025-07-07 15:43:27 +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 --- 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 9edc7e687786..75cdd345aeaa 100644 --- a/libexec/flua/modules/lposix.c +++ b/libexec/flua/modules/lposix.c @@ -590,21 +590,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); @@ -622,14 +622,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); @@ -655,16 +662,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);