Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: move $ERRNO to the system module



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) <S>)(
-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) <S>)(
 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




Messages sorted by: Reverse Date, Date, Thread, Author