From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 30668 invoked from network); 11 Jan 2023 23:30:14 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 11 Jan 2023 23:30:14 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date:Content-ID: Content-Type:MIME-Version:Subject:To:From:Reply-To:Cc: Content-Transfer-Encoding:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=JofWARJ7CgEp8mUPgwSgcVbZ33vjedJuWG1JZypoy6E=; b=mRkj18bsb5dxx3ptoBTO34J8dx AfCSR+iEPGR6R30am22G6aiuraMwEia52cKuCA3KWtAEIJScYfj3NNRLswN07os751vs48HLqdTf3 VK+f1qpkkdPmUt3Mjb1FfkmPbbGZEn2AmSYgP2wvxryCyjdvsIJ3PMQcRG+HtoqFOIQ3OYAm82WlG axGTiU3/Jk5ew4UMtSUlDeSwSzXG5T6lkc53tP7ZAMuIAILGb7AMrd8H5YBQVXYpJk46RfPiFoEhG QsXJrsU7w/TkGu7nOl6FzVepc3xqgYZnAjg7ybEiI00x162VDCJ8Zmxyb4abS1RZgGruQocrp9nZa AlelkUFg==; Received: by zero.zsh.org with local id 1pFkXs-0005YL-KB; Wed, 11 Jan 2023 23:30:12 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1pFkNp-000511-Gv; Wed, 11 Jan 2023 23:19:49 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.95) (envelope-from ) id 1pFkNo-000GaN-IS for zsh-workers@zsh.org; Thu, 12 Jan 2023 00:19:48 +0100 From: Oliver Kiddle To: Zsh workers Subject: PATCH: move $ERRNO to the system module MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <63757.1673479188.1@hydra> Date: Thu, 12 Jan 2023 00:19:48 +0100 Message-ID: <63758-1673479188.568367@mRHO.g-Av.gAfN> X-Seq: 51299 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: This would not be a strictly backward-compatible change. My justification is that, given how close it is to the system, any reliance on it is already liable to break just because we might reorder or add system calls. ERRNO is not especially portable, either. ERRNO predates the system module, and loadable modules in general. I had even forgotten it existed until it was mentioned recently. I doubt it's especially widely used. system.mdd does specify load=no so there would be no automatic loading. The trick with defining it as PM_UNSET doesn't appear to work from a module. But that's less necessary if the variable is in a module. I'll allow plenty of time for dissenting opinions on this but it'd also be good to hear if anyone agrees. Oliver diff --git a/Doc/Zsh/mod_system.yo b/Doc/Zsh/mod_system.yo index e25201faa..88bc5ee9b 100644 --- a/Doc/Zsh/mod_system.yo +++ b/Doc/Zsh/mod_system.yo @@ -252,6 +252,13 @@ enditem() subsect(Parameters) startitem() +vindex(ERRNO) +item(tt(ERRNO))( +The value of tt(errno) (see manref(errno)(3)) +as set by the most recently failed system call. +This value is system dependent and is intended for debugging +purposes. +) vindex(errnos) item(tt(errnos))( A readonly array of the names of errors defined on the system. These diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index 2a30085a8..a7863a136 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -743,17 +743,6 @@ effective user ID by `tt(LPAR()EUID=)var(uid)tt(; command+RPAR())' If this is made local, it is not implicitly set to 0, but may be explicitly set locally. ) -vindex(ERRNO) -item(tt(ERRNO) )( -The value of tt(errno) (see manref(errno)(3)) -as set by the most recently failed system call. -This value is system dependent and is intended for debugging -purposes. It is also useful with the tt(zsh/system) module which -allows the number to be turned into a name or message. - -To use this parameter, it must first be assigned a value (typically -0 (zero)). It is initially unset for scripting compatibility. -) vindex(FUNCNEST) item(tt(FUNCNEST) )( Integer. If greater than or equal to zero, the maximum nesting depth of diff --git a/Src/Modules/system.c b/Src/Modules/system.c index 929a8b002..8ee1e6258 100644 --- a/Src/Modules/system.c +++ b/Src/Modules/system.c @@ -835,9 +835,30 @@ errnosgetfn(UNUSED(Param pm)) return arrdup((char **)sys_errnames); } +/* Function to set value for special parameter `ERRNO' */ + +/**/ +void +errnosetfn(UNUSED(Param pm), zlong x) +{ + errno = (int)x; + if ((zlong)errno != x) + zwarn("errno truncated on assignment"); +} + +/* Function to get value for special parameter `ERRNO' */ + +/**/ +zlong +errnogetfn(UNUSED(Param pm)) +{ + return errno; +} + static const struct gsu_array errnos_gsu = { errnosgetfn, arrsetfn, stdunsetfn }; - +static const struct gsu_integer errno_gsu = +{ errnogetfn, errnosetfn, stdunsetfn }; /* Functions for the sysparams special parameter. */ @@ -899,6 +920,7 @@ static struct mathfunc mftab[] = { }; static struct paramdef partab[] = { + PARAMDEF("ERRNO", PM_INTEGER, NULL, &errno_gsu), SPECIALPMDEF("errnos", PM_ARRAY|PM_READONLY, &errnos_gsu, NULL, NULL), SPECIALPMDEF("sysparams", PM_READONLY, diff --git a/Src/Modules/system.mdd b/Src/Modules/system.mdd index 00a3e7896..1ee6ba140 100644 --- a/Src/Modules/system.mdd +++ b/Src/Modules/system.mdd @@ -2,7 +2,7 @@ name=zsh/system link=dynamic load=no -autofeatures="b:sysread b:syswrite b:sysopen b:sysseek b:syserror p:errnos f:systell" +autofeatures="b:sysread b:syswrite b:sysopen b:sysseek b:syserror p:ERRNO p:errnos f:systell" objects="system.o errnames.o" diff --git a/Src/params.c b/Src/params.c index 2e4a6eae2..3bc5a0d80 100644 --- a/Src/params.c +++ b/Src/params.c @@ -201,8 +201,6 @@ mod_export const struct gsu_scalar colonarr_gsu = /* Non standard methods (not exported) */ static const struct gsu_integer pound_gsu = { poundgetfn, nullintsetfn, stdunsetfn }; -static const struct gsu_integer errno_gsu = -{ errnogetfn, errnosetfn, stdunsetfn }; static const struct gsu_integer gid_gsu = { gidgetfn, gidsetfn, stdunsetfn }; static const struct gsu_integer egid_gsu = @@ -297,7 +295,6 @@ static initparam special_params[] ={ #define NULL_GSU BR((GsuScalar)(void *)NULL) #define IPDEF1(A,B,C) {{NULL,A,PM_INTEGER|PM_SPECIAL|C},BR(NULL),GSU(B),10,0,NULL,NULL,NULL,0} IPDEF1("#", pound_gsu, PM_READONLY_SPECIAL), -IPDEF1("ERRNO", errno_gsu, PM_UNSET), IPDEF1("GID", gid_gsu, PM_DONTIMPORT | PM_RESTRICTED), IPDEF1("EGID", egid_gsu, PM_DONTIMPORT | PM_RESTRICTED), IPDEF1("HISTSIZE", histsize_gsu, PM_RESTRICTED), @@ -4771,26 +4768,6 @@ savehistsizesetfn(UNUSED(Param pm), zlong v) savehistsiz = 0; } -/* Function to set value for special parameter `ERRNO' */ - -/**/ -void -errnosetfn(UNUSED(Param pm), zlong x) -{ - errno = (int)x; - if ((zlong)errno != x) - zwarn("errno truncated on assignment"); -} - -/* Function to get value for special parameter `ERRNO' */ - -/**/ -zlong -errnogetfn(UNUSED(Param pm)) -{ - return errno; -} - /* Function to get value for special parameter `KEYBOARD_HACK' */ /**/ diff --git a/Test/V01zmodload.ztst b/Test/V01zmodload.ztst index daf49cd72..52cba69e9 100644 --- a/Test/V01zmodload.ztst +++ b/Test/V01zmodload.ztst @@ -293,6 +293,7 @@ >+b:sysseek >+b:zsystem >+f:systell +>+p:ERRNO >+p:errnos >+p:sysparams >0 @@ -303,6 +304,7 @@ >+b:sysseek >+b:zsystem >+f:systell +>+p:ERRNO >-p:errnos >+p:sysparams >1 @@ -313,6 +315,7 @@ >+b:sysseek >+b:zsystem >+f:systell +>+p:ERRNO >+p:errnos >+p:sysparams @@ -334,6 +337,7 @@ >+b:sysseek >+b:zsystem >-f:systell +>+p:ERRNO >+p:errnos >+p:sysparams >+b:syserror @@ -343,6 +347,7 @@ >+b:sysseek >+b:zsystem >+f:systell +>+p:ERRNO >+p:errnos >+p:sysparams ?(eval):6: unknown function: systell