zsh-workers
 help / color / Atom feed
* [PATCH] find RLIM_NLIMITS correctly on Cygwin
@ 2020-01-08 10:39 Jun T
  2020-01-08 21:33 ` Daniel Shahaf
  0 siblings, 1 reply; 38+ messages in thread
From: Jun T @ 2020-01-08 10:39 UTC (permalink / raw)
  To: zsh-workers

On Cygwin, <sys/resource.h> has lines like:

#define RLIMIT_NLIMITS  7       /* upper bound of RLIMIT_* defines */
#define RLIM_NLIMITS    RLIMIT_NLIMITS

but rlimits.awk fails to find the value of RLIM_NLIMITS
(and sets ZSH_NLIMITS to zero).



diff --git a/Src/Builtins/rlimits.awk b/Src/Builtins/rlimits.awk
index e9c576c66..4cf960314 100644
--- a/Src/Builtins/rlimits.awk
+++ b/Src/Builtins/rlimits.awk
@@ -79,6 +79,12 @@ BEGIN {limidx = 0}
     split(limtail, tmp)
     nlimits = tmp[2]
 }
+# for Cygwin
+/^[\t ]*#[\t ]*define[\t ]*RLIM_NLIMITS[\t ]*RLIMIT_NLIMITS/ {
+    if (!nlimits && limrev["NLIMITS"]) {
+      nlimits = limrev["NLIMITS"]
+    }
+}
 
 END {
     if (limrev["MEMLOCK"] != "") {



^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-01-08 10:39 [PATCH] find RLIM_NLIMITS correctly on Cygwin Jun T
@ 2020-01-08 21:33 ` Daniel Shahaf
  2020-01-09 10:32   ` Jun T
  0 siblings, 1 reply; 38+ messages in thread
From: Daniel Shahaf @ 2020-01-08 21:33 UTC (permalink / raw)
  To: Jun T, zsh-workers

Jun T wrote on Wed, 08 Jan 2020 10:39 +00:00:
> On Cygwin, <sys/resource.h> has lines like:
> 
> #define RLIMIT_NLIMITS  7       /* upper bound of RLIMIT_* defines */
> #define RLIM_NLIMITS    RLIMIT_NLIMITS
> 
> but rlimits.awk fails to find the value of RLIM_NLIMITS
> (and sets ZSH_NLIMITS to zero).

I don't object to the patch, but we should think about actually using
a C preprocessor to parse header files, otherwise we'd just be playing
whack-a-mole as OS's use more features of C syntax in their header files.

Actually, looking at the generated $builddir/Src/Builtins/rlimits.h file,
couldn't we move the entire thing into Src/Builtins/rlimits.c?  Instead of
«recs[lim]» we could have «recs(lim)», using the following function:

static inline const char *recs(int lim)
{
    if (lim == RLIMIT_AIO_MEM) return "aiomemorylocked";
    if (lim == RLIMIT_AIO_OPS) return "aiooperations";
    ⋮
}

And then another such function for «limtype», replace the «for(i = 0; i <
ZSH_NLIMITS; i++)» loops by looping on all RLIMIT_* macros that are
#define'd by the OS, and good riddance to the awk script…

Cheers,

Daniel

> 
> diff --git a/Src/Builtins/rlimits.awk b/Src/Builtins/rlimits.awk
> index e9c576c66..4cf960314 100644
> --- a/Src/Builtins/rlimits.awk
> +++ b/Src/Builtins/rlimits.awk
> @@ -79,6 +79,12 @@ BEGIN {limidx = 0}
>      split(limtail, tmp)
>      nlimits = tmp[2]
>  }
> +# for Cygwin
> +/^[\t ]*#[\t ]*define[\t ]*RLIM_NLIMITS[\t ]*RLIMIT_NLIMITS/ {
> +    if (!nlimits && limrev["NLIMITS"]) {
> +      nlimits = limrev["NLIMITS"]
> +    }
> +}
>  
>  END {
>      if (limrev["MEMLOCK"] != "") {
> 
> 
>

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-01-08 21:33 ` Daniel Shahaf
@ 2020-01-09 10:32   ` Jun T
  2020-01-09 13:15     ` Daniel Shahaf
  0 siblings, 1 reply; 38+ messages in thread
From: Jun T @ 2020-01-09 10:32 UTC (permalink / raw)
  To: zsh-workers


> 2020/01/09 6:33, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> 
> I don't object to the patch, but we should think about actually using
> a C preprocessor to parse header files, otherwise we'd just be playing
> whack-a-mole as OS's use more features of C syntax in their header files.

Yes, but ...

When rlimits.awk finds an unknown macro RLIMIT_???, for example

#define RLIMIT_FOO	8

then it sets recs[8]="FOO", and this enables the limit builtin to print
the resource name as "FOO". *If* we need this feature, it would not be
easy to achieve by using C preprocessor alone.

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-01-09 10:32   ` Jun T
@ 2020-01-09 13:15     ` Daniel Shahaf
  2020-01-10 10:24       ` Jun T
  0 siblings, 1 reply; 38+ messages in thread
From: Daniel Shahaf @ 2020-01-09 13:15 UTC (permalink / raw)
  To: zsh-workers

Jun T wrote on Thu, Jan 09, 2020 at 19:32:17 +0900:
> 
> > 2020/01/09 6:33, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > 
> > I don't object to the patch, but we should think about actually using
> > a C preprocessor to parse header files, otherwise we'd just be playing
> > whack-a-mole as OS's use more features of C syntax in their header files.
> 
> Yes, but ...
> 
> When rlimits.awk finds an unknown macro RLIMIT_???, for example
> 
> #define RLIMIT_FOO	8
> 
> then it sets recs[8]="FOO", and this enables the limit builtin to print
> the resource name as "FOO". *If* we need this feature, it would not be
> easy to achieve by using C preprocessor alone.

Yeah, the C preprocessor can't discover RLIMIT_* macros we don't know about in
advance, I agree.  For that we'd need awk(1) or similar (maybe just «grep -o
'RLIMIT_[^ ]*'»).  Maybe something along these lines:

[[[
static const struct {
    const char *symbol;
    const char *name;
    int type;
    int value;
} rlimits[] = {
#ifdef RLIMIT_CPU
    { "CPU", "cputime", ZLIMTYPE_TIME, RLIMIT_CPU },
#endif
#ifdef RLIMIT_DATA
    { "DATA", "datasize", ZLIMTYPE_MEMORY, RLIMIT_DATA },
#endif
#include "unknown-limits.h"
    { NULL }
};
]]]

where unknown-limits.h is generated (by awk(1)) as:

[[[
#ifdef RLIMIT_FOO
    { "FOO", "FOO", ZLIMTYPE_UNKNOWN, RLIMIT_FOO },
#endif
#ifdef RLIMIT_BAR
    { "BAR", "BAR", ZLIMTYPE_UNKNOWN, RLIMIT_BAR },
#endif
]]]

All limits we know about will be in the first file; any limits we don't know
about will be in the second file

This way the numerical calculations would be done by the preprocessor, and we'd
not be assuming that the integer values of RLIMIT_* macros are sequential and
start from zero.  (Though apparently that assumption happens to be true on
current OS's)

Cheers,

Daniel

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-01-09 13:15     ` Daniel Shahaf
@ 2020-01-10 10:24       ` Jun T
  2020-01-11 20:15         ` Daniel Shahaf
  0 siblings, 1 reply; 38+ messages in thread
From: Jun T @ 2020-01-10 10:24 UTC (permalink / raw)
  To: zsh-workers


> 2020/01/09 22:15, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> 
> Yeah, the C preprocessor can't discover RLIMIT_* macros we don't know about in
> advance, I agree.  For that we'd need awk(1) or similar (maybe just «grep -o
> 'RLIMIT_[^ ]*'»).  Maybe something along these lines:

Thanks.
But I've started thinking that we can just use a resource name such as
"unknown8" (instead of "FOO") for unknown resource. Then rlimits.awk can
be removed as you have suggested originally.

Of cause there is a chance that the tail part of the macro name ("FOO") may
give some hint for users, but it is far from satisfactory anyway.
If users find "unknown8" in the output of the limit builtin, then *hopefully*
they report it to zsh/workers; then we can add it to the list of known
resources easily.



^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-01-10 10:24       ` Jun T
@ 2020-01-11 20:15         ` Daniel Shahaf
  2020-01-13 11:00           ` Jun T
  0 siblings, 1 reply; 38+ messages in thread
From: Daniel Shahaf @ 2020-01-11 20:15 UTC (permalink / raw)
  To: zsh-workers

Jun T wrote on Fri, Jan 10, 2020 at 19:24:49 +0900:
> 
> > 2020/01/09 22:15, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > 
> > Yeah, the C preprocessor can't discover RLIMIT_* macros we don't know about in
> > advance, I agree.  For that we'd need awk(1) or similar (maybe just «grep -o
> > 'RLIMIT_[^ ]*'»).  Maybe something along these lines:
> 
> Thanks.
> But I've started thinking that we can just use a resource name such as
> "unknown8" (instead of "FOO") for unknown resource. Then rlimits.awk can
> be removed as you have suggested originally.
> 
> Of cause there is a chance that the tail part of the macro name ("FOO") may
> give some hint for users, but it is far from satisfactory anyway.
> If users find "unknown8" in the output of the limit builtin, then *hopefully*
> they report it to zsh/workers; then we can add it to the list of known
> resources easily.

I've thought about it and I think I agree.  There could be RLIMIT_* macros that
aren't valid as arguments to getrlimit(2); assuming otherwise is a bit too
hacky, and the alternative — the limit being settable numerically — isn't that
bad.

We could even add a test that runs «ulimit -a | grep '^-N'» and, if that has
any output, prints a warning to stderr (without failing the test run).

The part that's not clear to me is how we'd even know that «8» is a valid value for
the first actual argument to getrlimit().  Currently, the code assumes that the
values of RLIMIT_* macros are consecutive small integers, but that is not guaranteed
by any standard, is it?

Cheers,

Daniel

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-01-11 20:15         ` Daniel Shahaf
@ 2020-01-13 11:00           ` Jun T
  2020-01-13 16:42             ` Daniel Shahaf
  0 siblings, 1 reply; 38+ messages in thread
From: Jun T @ 2020-01-13 11:00 UTC (permalink / raw)
  To: zsh-workers



> 2020/01/12 5:15, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> 
> The part that's not clear to me is how we'd even know that «8» is a valid value for
> the first actual argument to getrlimit().  Currently, the code assumes that the
> values of RLIMIT_* macros are consecutive small integers, but that is not guaranteed
> by any standard, is it?

There is no guarantee, but current version of ulimit builtin accepts any number
for -N (and output error). limit builtin accepts only the resource name,
and maybe we accept "unknonw8" only for getrlimit() but not for setrlimit()?


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-01-13 11:00           ` Jun T
@ 2020-01-13 16:42             ` Daniel Shahaf
  2020-01-14  4:44               ` Jun T
  0 siblings, 1 reply; 38+ messages in thread
From: Daniel Shahaf @ 2020-01-13 16:42 UTC (permalink / raw)
  To: zsh-workers

Jun T wrote on Mon, 13 Jan 2020 11:00 +00:00:
> 
> 
> > 2020/01/12 5:15, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > 
> > The part that's not clear to me is how we'd even know that «8» is a valid value for
> > the first actual argument to getrlimit().  Currently, the code assumes that the
> > values of RLIMIT_* macros are consecutive small integers, but that is not guaranteed
> > by any standard, is it?
> 
> There is no guarantee, but current version of ulimit builtin accepts any number
> for -N (and output error). limit builtin accepts only the resource name,
> and maybe we accept "unknonw8" only for getrlimit() but not for setrlimit()?

Sorry, I don't follow.  Why shouldn't we accept "unknown8" in the limit-setting syntaxes?

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-01-13 16:42             ` Daniel Shahaf
@ 2020-01-14  4:44               ` Jun T
  2020-01-14 16:25                 ` Daniel Shahaf
  0 siblings, 1 reply; 38+ messages in thread
From: Jun T @ 2020-01-14  4:44 UTC (permalink / raw)
  To: zsh-workers


> 2020/01/14 1:42, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> 
> Jun T wrote on Mon, 13 Jan 2020 11:00 +00:00:
>> 
>>> 2020/01/12 5:15, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
>>> 
>>> The part that's not clear to me is how we'd even know that «8» is a valid value for
>>> the first actual argument to getrlimit().  Currently, the code assumes that the
>>> values of RLIMIT_* macros are consecutive small integers, but that is not guaranteed
>>> by any standard, is it?
>> 
>> There is no guarantee, but current version of ulimit builtin accepts any number
>> for -N (and output error). limit builtin accepts only the resource name,
>> and maybe we accept "unknonw8" only for getrlimit() but not for setrlimit()?
> 
> Sorry, I don't follow.  Why shouldn't we accept "unknown8" in the limit-setting syntaxes?

Sorry for my unclear English.

Why do you think that knowing "8" is a valid resource number is important?

I think we can just call {get, set}rlimit() with any resource number, but if you
think it better to avoid using questionable resource number, then we can avoid
calling setrlimit() that may actually change the limit of "unknown" resource.
But ulimit -N 8 can change the limit anyway, so I think we can call {get, set}rlimit()
with any resource number specified by the user.

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-01-14  4:44               ` Jun T
@ 2020-01-14 16:25                 ` Daniel Shahaf
  2020-02-25  9:38                   ` Jun T
  0 siblings, 1 reply; 38+ messages in thread
From: Daniel Shahaf @ 2020-01-14 16:25 UTC (permalink / raw)
  To: zsh-workers

Jun T wrote on Tue, 14 Jan 2020 04:44 +00:00:
> 
> > 2020/01/14 1:42, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > 
> > Jun T wrote on Mon, 13 Jan 2020 11:00 +00:00:
> >> 
> >>> 2020/01/12 5:15, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> >>> 
> >>> The part that's not clear to me is how we'd even know that «8» is a valid value for
> >>> the first actual argument to getrlimit().  Currently, the code assumes that the
> >>> values of RLIMIT_* macros are consecutive small integers, but that is not guaranteed
> >>> by any standard, is it?
> >> 
> >> There is no guarantee, but current version of ulimit builtin accepts any number
> >> for -N (and output error). limit builtin accepts only the resource name,
> >> and maybe we accept "unknonw8" only for getrlimit() but not for setrlimit()?
> > 
> > Sorry, I don't follow.  Why shouldn't we accept "unknown8" in the limit-setting syntaxes?
> 
> Sorry for my unclear English.
> 
> Why do you think that knowing "8" is a valid resource number is important?

I don't think that.  I was asking a rhetorical question, the implication
being that we _should_ allow setting limits by number even when that
number was not determined to be known-good at build time.

> I think we can just call {get, set}rlimit() with any resource number,
> but if you think it better to avoid using questionable resource
> number, then we can avoid calling setrlimit() that may actually change
> the limit of "unknown" resource. But ulimit -N 8 can change the limit
> anyway, so I think we can call {get, set}rlimit() with any resource
> number specified by the user.

+1, agreed.

Cheers,

Daniel

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-01-14 16:25                 ` Daniel Shahaf
@ 2020-02-25  9:38                   ` Jun T
  2020-02-27 13:22                     ` Daniel Shahaf
  2020-03-20 19:18                     ` Daniel Shahaf
  0 siblings, 2 replies; 38+ messages in thread
From: Jun T @ 2020-02-25  9:38 UTC (permalink / raw)
  To: zsh-workers

Sorry for a *very* slow response; I've been quite busy these days.
Finally I found some time to work on this.

The patch below removes rlimits.{awk,h} and introduces a table of
known resources in rlimits.c. All the "#ifdef HAVE_RLIMIT_XXX"s
are now in the initialization of this table.

But removing rlimits.awk has one drawback:
Before the patch, unknown resource can be detected in the build
time (by the special make rule defined in rlimits.mdd).
With the patch, we can notice unknown resouce(s) only when running
the limit (or ulimit) builtin. We may hope that a user who sees
UNKNOWN in the output of limit/ulimit will report it to us, or
add a simple test like

limit | grep UNKNOWN || print OK

somewhere in the test (but in which .ztst file?).


 .gitignore               |   1 -
 Src/Builtins/rlimits.awk | 116 --------
 Src/Builtins/rlimits.c   | 692 ++++++++++++++++++-----------------------------
 Src/Builtins/rlimits.mdd |  15 -
 configure.ac             |   1 +
 5 files changed, 264 insertions(+), 561 deletions(-)


diff --git a/.gitignore b/.gitignore
index e46f8517e..ec2f56642 100644
--- a/.gitignore
+++ b/.gitignore
@@ -123,7 +123,6 @@ Src/Builtins/*.mdh
 Src/Builtins/*.mdhi
 Src/Builtins/*.mdhs
 Src/Builtins/*.mdh.tmp
-Src/Builtins/rlimits.h
 
 Src/Modules/Makefile.in
 Src/Modules/*.export
diff --git a/Src/Builtins/rlimits.awk b/Src/Builtins/rlimits.awk
deleted file mode 100644
index e9c576c66..000000000
--- a/Src/Builtins/rlimits.awk
+++ /dev/null
@@ -1,116 +0,0 @@
-#
-# rlimits.awk: {g,n}awk script to generate rlimits.h
-#
-# NB: On SunOS 4.1.3 - user-functions don't work properly, also \" problems
-# Without 0 + hacks some nawks compare numbers as strings
-#
-BEGIN {limidx = 0}
-
-/^[\t ]*(#[\t ]*define[\t _]*RLIMIT_[A-Z_]*[\t ]*[0-9][0-9]*|RLIMIT_[A-Z_]*,[\t ]*|_*RLIMIT_[A-Z_]*[\t ]*=[\t ]*[0-9][0-9]*,[\t ]*)/ {
-    limindex = index($0, "RLIMIT_")
-    limtail = substr($0, limindex, 80)
-    split(limtail, tmp)
-    limnam = substr(tmp[1], 8, 20)
-    limnum = tmp[2]
-    # in this case I assume GNU libc resourcebits.h
-    if (limnum == "") {
-	limnum = limidx++
-	limindex = index($0, ",")
-	limnam = substr(limnam, 1, limindex-1)
-    }
-    if (limnum == "=") {
-	if (tmp[3] ~ /^[0-9]/) {
-	    limnum = tmp[3] + 0
-	} else {
-	    limnum = limidx++
-	}
-	limindex = index($0, ",")
-	limnam = substr(limnam, 1, limindex-1)
-    }
-    limrev[limnam] = limnum
-    if (lim[limnum] == "") {
-	lim[limnum] = limnam
-	if (limnum ~ /^[0-9]*$/) {
-	    if (limnam == "AIO_MEM") { msg[limnum] = "Maiomemorylocked" }
-	    if (limnam == "AIO_OPS") { msg[limnum] = "Naiooperations" }
-	    if (limnam == "AS")      { msg[limnum] = "Maddressspace" }
-	    if (limnam == "CORE")    { msg[limnum] = "Mcoredumpsize" }
-	    if (limnam == "CPU")     { msg[limnum] = "Tcputime" }
-	    if (limnam == "DATA")    { msg[limnum] = "Mdatasize" }
-	    if (limnam == "FSIZE")   { msg[limnum] = "Mfilesize" }
-	    if (limnam == "LOCKS")   { msg[limnum] = "Nmaxfilelocks" }
-	    if (limnam == "MEMLOCK") { msg[limnum] = "Mmemorylocked" }
-	    if (limnam == "NOFILE")  { msg[limnum] = "Ndescriptors" }
-	    if (limnam == "NPROC")   { msg[limnum] = "Nmaxproc" }
-	    if (limnam == "NTHR")    { msg[limnum] = "Nmaxpthreads" }
-	    if (limnam == "OFILE")   { msg[limnum] = "Ndescriptors" }
-	    if (limnam == "PTHREAD") { msg[limnum] = "Nmaxpthreads" }
-	    if (limnam == "RSS")     { msg[limnum] = "Mresident" }
-	    if (limnam == "SBSIZE")  { msg[limnum] = "Msockbufsize" }
-	    if (limnam == "STACK")   { msg[limnum] = "Mstacksize" }
-	    if (limnam == "TCACHE")  { msg[limnum] = "Ncachedthreads" }
-	    if (limnam == "VMEM")    { msg[limnum] = "Mvmemorysize" }
-	    if (limnam == "SIGPENDING") { msg[limnum] = "Nsigpending" }
-	    if (limnam == "MSGQUEUE") { msg[limnum] = "Nmsgqueue" }
-	    if (limnam == "NICE") { msg[limnum] = "Nnice" }
-	    if (limnam == "RTPRIO") { msg[limnum] = "Nrt_priority" }
-	    if (limnam == "RTTIME") { msg[limnum] = "Urt_time" }
-	    if (limnam == "POSIXLOCKS") { msg[limnum] = "Nposixlocks" }
-	    if (limnam == "NPTS")    { msg[limnum] = "Npseudoterminals" }
-	    if (limnam == "SWAP")    { msg[limnum] = "Mswapsize" }
-	    if (limnam == "KQUEUES") { msg[limnum] = "Nkqueues" }
-	    if (limnam == "UMTXP")   { msg[limnum] = "Numtxp" }
-        }
-    }
-}
-/^[\t ]*#[\t ]*define[\t _]*RLIM_NLIMITS[\t ]*[0-9][0-9]*/ {
-    limindex = index($0, "RLIM_")
-    limtail = substr($0, limindex, 80)
-    split(limtail, tmp)
-    nlimits = tmp[2]
-}
-# in case of GNU libc
-/^[\t ]*RLIM_NLIMITS[\t ]*=[\t ]*RLIMIT_NLIMITS/ {
-    if(!nlimits) { nlimits = limidx }
-}
-/^[\t _]*RLIM(IT)?_NLIMITS[\t ]*=[\t ]*[0-9][0-9]*/ {
-    limindex = index($0, "=")
-    limtail = substr($0, limindex, 80)
-    split(limtail, tmp)
-    nlimits = tmp[2]
-}
-
-END {
-    if (limrev["MEMLOCK"] != "") {
-        irss = limrev["RSS"]
-        msg[irss] = "Mmemoryuse"
-    }
-    ps = "%s"
-
-    printf("%s\n%s\n\n", "/** rlimits.h                              **/", "/** architecture-customized limits for zsh **/")
-    printf("#define ZSH_NLIMITS %d\n\nstatic char const *recs[ZSH_NLIMITS] = {\n", 0 + nlimits)
-
-    for (i = 0; i < 0 + nlimits; i++)
-	if (msg[i] == "")
-            printf("\t%c%s%c,\n", 34, lim[i], 34)
-	else
-	    printf("\t%c%s%c,\n", 34, substr(msg[i], 2, 30), 34)
-    print "};"
-    print ""
-    print "static int limtype[ZSH_NLIMITS] = {"
-    for (i = 0; i < 0 + nlimits; i++) {
-	if (msg[i] == "")
-	    limtype = "UNKNOWN"
-	else {
-	    limtype = substr(msg[i], 1, 1)
-	    if(limtype == "M") { limtype = "MEMORY" }
-	    if(limtype == "N") { limtype = "NUMBER" }
-	    if(limtype == "T") { limtype = "TIME" }
-	    if(limtype == "U") { limtype = "MICROSECONDS" }
-	}
-	printf("\tZLIMTYPE_%s,\n", limtype)
-    }
-    print "};"
-
-    exit(0)
-}
diff --git a/Src/Builtins/rlimits.c b/Src/Builtins/rlimits.c
index 6b552f3a9..e9fa77152 100644
--- a/Src/Builtins/rlimits.c
+++ b/Src/Builtins/rlimits.c
@@ -32,20 +32,7 @@
 
 #if defined(HAVE_GETRLIMIT) && defined(RLIM_INFINITY)
 
-#if defined(HAVE_RLIMIT_POSIXLOCKS) && !defined(HAVE_RLIMIT_LOCKS)
-#  define RLIMIT_LOCKS		RLIMIT_POSIXLOCKS
-#  define HAVE_RLIMIT_LOCKS     1
-#endif
-
-#if defined(HAVE_RLIMIT_NTHR) && !defined(HAVE_RLIMIT_PTHREAD)
-#  define RLIMIT_PTHREAD	RLIMIT_NTHR
-#  define HAVE_RLIMIT_PTHREAD   1
-#  define THREAD_FMT            "-T: threads                         "
-#else
-#  define THREAD_FMT            "-T: threads per process             "
-#endif
-
-enum {
+enum zlimtype {
     ZLIMTYPE_MEMORY,
     ZLIMTYPE_NUMBER,
     ZLIMTYPE_TIME,
@@ -53,11 +40,214 @@ enum {
     ZLIMTYPE_UNKNOWN
 };
 
-/* Generated rec array containing limits required for the limit builtin.     *
- * They must appear in this array in numerical order of the RLIMIT_* macros. */
+typedef struct {
+    int	res;		/* RLIMIT_XXX */
+    char* name;		/* used by limit builtin */
+    enum zlimtype type;
+    int unit;		/* 1, 512, or 1024 */
+    char opt;		/* option character */
+    char* descr;	/* used by ulimit builtin */
+} resinfo_t;
+
+/* table of known resources */
+static resinfo_t known_resources[] = {
+    {RLIMIT_CPU, "cputime", ZLIMTYPE_TIME, 1,
+		't', "cpu time (seconds)"},
+    {RLIMIT_FSIZE, "filesize", ZLIMTYPE_MEMORY, 512,
+		'f', "file size (blocks)"},
+    {RLIMIT_DATA, "datasize", ZLIMTYPE_MEMORY, 1024,
+		'd', "data seg size (kbytes)"},
+    {RLIMIT_STACK, "stacksize", ZLIMTYPE_MEMORY, 1024,
+		's', "stack size (kbytes)"},
+    {RLIMIT_CORE, "coredumpsize", ZLIMTYPE_MEMORY, 512,
+		'c', "core file size (blocks)"},
+# ifdef HAVE_RLIMIT_NOFILE
+    {RLIMIT_NOFILE, "descriptors", ZLIMTYPE_NUMBER, 1,
+		'n', "file descriptors"},
+# endif
+# if defined(HAVE_RLIMIT_AS) && !defined(RLIMIT_VMEM_IS_AS)
+    {RLIMIT_AS, "addressspace", ZLIMTYPE_MEMORY, 1024,
+		'v', "address space (kbytes)"},
+# endif
+# if defined(HAVE_RLIMIT_RSS) && !defined(RLIMIT_VMEM_IS_RSS) && !defined(RLIMIT_RSS_IS_AS)
+    {RLIMIT_RSS, "resident", ZLIMTYPE_MEMORY, 1024,
+		'm', "resident set size (kbytes)"},
+# endif
+# if defined(HAVE_RLIMIT_VMEM)
+    {RLIMIT_VMEM,
+#  if defined(RLIMIT_VMEM_IS_RSS)
+		 "resident", ZLIMTYPE_MEMORY, 1024,
+		 'm', "memory size (kbytes)"},
+#  else
+		 "vmemorysize", ZLIMTYPE_MEMORY, 1024,
+		 'v', "virtual memory size (kbytes)"},
+#  endif
+# endif
+# ifdef HAVE_RLIMIT_NPROC
+    {RLIMIT_NPROC, "maxproc", ZLIMTYPE_NUMBER, 1,
+		'u', "processes"},
+# endif
+# ifdef HAVE_RLIMIT_MEMLOCK
+    {RLIMIT_MEMLOCK, "memorylocked", ZLIMTYPE_MEMORY, 1024,
+		'l', "locked-in-memory size (kbytes)"},
+# endif
+    /* Linux */
+# ifdef HAVE_RLIMIT_LOCKS
+    {RLIMIT_LOCKS, "maxfilelocks", ZLIMTYPE_NUMBER, 1,
+		'x', "file locks"},
+# endif
+# ifdef HAVE_RLIMIT_SIGPENDING
+    {RLIMIT_SIGPENDING, "sigpending", ZLIMTYPE_NUMBER, 1,
+		'i', "pending signals"},
+# endif
+# ifdef HAVE_RLIMIT_MSGQUEUE
+    {RLIMIT_MSGQUEUE, "msgqueue", ZLIMTYPE_NUMBER, 1,
+		'q', "bytes in POSIX msg queues"},
+# endif
+# ifdef HAVE_RLIMIT_NICE
+    {RLIMIT_NICE, "nice", ZLIMTYPE_NUMBER, 1,
+		'e', "max nice"},
+# endif
+# ifdef HAVE_RLIMIT_RTPRIO
+    {RLIMIT_RTPRIO, "rt_priority", ZLIMTYPE_NUMBER, 1,
+		'r', "max rt priority"},
+# endif
+# ifdef HAVE_RLIMIT_RTTIME
+    {RLIMIT_RTTIME, "rt_time", ZLIMTYPE_MICROSECONDS, 1,
+		'N', "rt cpu time (microseconds)"},
+# endif
+    /* BSD */
+# ifdef HAVE_RLIMIT_SBSIZE
+    {RLIMIT_SBSIZE, "sockbufsize", ZLIMTYPE_MEMORY, 1,
+		'b', "socket buffer size (bytes)"},
+# endif
+# ifdef HAVE_RLIMIT_KQUEUES /* FreeBSD */
+    {RLIMIT_KQUEUES, "kqueues", ZLIMTYPE_NUMBER, 1,
+		'k', "kqueues"},
+# endif
+# ifdef HAVE_RLIMIT_NPTS    /* FreeBSD */
+    {RLIMIT_NPTS, "pseudoterminals", ZLIMTYPE_NUMBER, 1,
+		'p', "pseudo-terminals"},
+# endif
+# ifdef HAVE_RLIMIT_SWAP    /* FreeBSD */
+    {RLIMIT_SWAP, "swapsize", ZLIMTYPE_MEMORY, 1024,
+		'w', "swap size (kbytes)"},
+# endif
+# ifdef HAVE_RLIMIT_UMTXP   /* FreeBSD */
+    {RLIMIT_UMTXP, "umtxp", ZLIMTYPE_NUMBER, 1,
+		'o', "umtx shared locks"},
+# endif
+
+# ifdef HAVE_RLIMIT_POSIXLOCKS	/* DragonFly */
+    {RLIMIT_POSIXLOCKS, "posixlocks", ZLIMTYPE_NUMBER, 1,
+		'x', "number of POSIX locks"},
+# endif
+# if defined(HAVE_RLIMIT_NTHR) && !defined(HAVE_RLIMIT_RTPRIO) /* Net/OpenBSD */
+    {RLIMIT_NTHR, "maxpthreads", ZLIMTYPE_NUMBER, 1,
+		'r', "threads"},
+# endif
+    /* others */
+# if defined(HAVE_RLIMIT_PTHREAD) && !defined(HAVE_RLIMIT_NTHR)	/* IRIX ? */
+    {RLIMIT_PTHREAD, "maxpthreads", ZLIMTYPE_NUMBER, 1,
+		'T', "threads per process"},
+# endif
+# ifdef HAVE_RLIMIT_AIO_MEM /* HP-UX ? */
+    {RLIMIT_AIO_MEM, "aiomemorylocked", ZLIMTYPE_MEMORY, 1024,
+		'N', "AIO locked-in-memory (kbytes)"},
+# endif
+# ifdef HAVE_RLIMIT_AIO_OPS /* HP-UX ? */
+    {RLIMIT_AIO_OPS, "aiooperations", ZLIMTYPE_NUMBER, 1,
+		'N', "AIO operations"},
+# endif
+# ifdef HAVE_RLIMIT_TCACHE  /* HP-UX ? */
+    {RLIMIT_TCACHE, "cachedthreads", ZLIMTYPE_NUMBER, 1,
+		'N', "cached threads"},
+# endif
+};
 
-# include "rlimits.h"
+/* resinfo[RLIMIT_XXX] points to the corresponding entry
+ * in known_resources[] */
+static resinfo_t **resinfo;
 
+/**/
+static void
+set_resinfo(void)
+{
+    int i;
+
+    resinfo = (resinfo_t **)zshcalloc(RLIM_NLIMITS*sizeof(resinfo_t *));
+
+    for (i=0; i<sizeof(known_resources)/sizeof(resinfo_t); ++i) {
+	resinfo[known_resources[i].res] = &known_resources[i];
+    }
+    for (i=0; i<RLIM_NLIMITS; ++i) {
+	if (!resinfo[i]) {
+	    /* unknown resource */
+	    resinfo_t *info = (resinfo_t *)zshcalloc(sizeof(resinfo_t));
+	    char *buf = (char *)zalloc(12);
+	    snprintf(buf, 12, "UNKNOWN-%d", i);
+	    info->res = - 1;	/* negative value indicates "unknown" */
+	    info->name = buf;
+	    info->type = ZLIMTYPE_UNKNOWN;
+	    info->unit = 1;
+	    info->opt = 'N';
+	    info->descr = buf;
+	    resinfo[i] = info;
+	}
+    }
+}
+
+/**/
+static void
+free_resinfo(void)
+{
+    int i;
+    for (i=0; i<RLIM_NLIMITS; ++i) {
+	if (resinfo[i]->res < 0) {  /* unknown resource */
+	    free(resinfo[i]->name);
+	    free(resinfo[i]);
+	}
+    }
+    free(resinfo);
+    resinfo = NULL;
+}
+
+/* Find resource by its option character */
+
+/**/
+static int
+find_resource(char c)
+{
+    int i;
+    for (i=0; i<RLIM_NLIMITS; ++i) {
+	if (resinfo[i]->opt == c)
+	    return i;
+    }
+    return -1;
+}
+
+/* Print a value of type rlim_t */
+
+/**/
+static void
+printrlim(rlim_t val, const char *unit)
+{
+# ifdef RLIM_T_IS_QUAD_T
+	printf("%qd%s", val, unit);
+# else
+#  ifdef RLIM_T_IS_LONG_LONG
+	printf("%lld%s", val, unit);
+#  else
+#   ifdef RLIM_T_IS_UNSIGNED
+	printf("%lu%s", (unsigned long)val, unit);
+#   else
+	printf("%ld%s", (long)val, unit);
+#   endif /* RLIM_T_IS_UNSIGNED */
+#  endif /* RLIM_T_IS_LONG_LONG */
+# endif /* RLIM_T_IS_QUAD_T */
+}
+
+/**/
 static rlim_t
 zstrtorlimt(const char *s, char **t, int base)
 {
@@ -97,8 +287,8 @@ static void
 showlimitvalue(int lim, rlim_t val)
 {
     /* display limit for resource number lim */
-    if (lim < ZSH_NLIMITS)
-	printf("%-16s", recs[lim]);
+    if (lim < RLIM_NLIMITS)
+	printf("%-16s", resinfo[lim]->name);
     else
     {
 	/* Unknown limit, hence unknown units. */
@@ -106,81 +296,25 @@ showlimitvalue(int lim, rlim_t val)
     }
     if (val == RLIM_INFINITY)
 	printf("unlimited\n");
-    else if (lim >= ZSH_NLIMITS)
-    {
-# ifdef RLIM_T_IS_QUAD_T
-	printf("%qd\n", val);
-# else
-#  ifdef RLIM_T_IS_LONG_LONG
-	printf("%lld\n", val);
-#  else
-#   ifdef RLIM_T_IS_UNSIGNED
-	printf("%lu\n", (unsigned long)val);
-#   else
-	printf("%ld\n", (long)val);
-#   endif /* RLIM_T_IS_UNSIGNED */
-#  endif /* RLIM_T_IS_LONG_LONG */
-# endif /* RLIM_T_IS_QUAD_T */
-    }
-    else if (limtype[lim] == ZLIMTYPE_TIME) {
+    else if (lim >= RLIM_NLIMITS)
+	printrlim(val, "\n");
+    else if (resinfo[lim]->type == ZLIMTYPE_TIME) {
 	/* time-type resource -- display as hours, minutes and
 	   seconds. */
 	printf("%d:%02d:%02d\n", (int)(val / 3600),
 	       (int)(val / 60) % 60, (int)(val % 60));
-    } else if (limtype[lim] == ZLIMTYPE_MICROSECONDS) {
-	/* microseconds */
-# ifdef RLIM_T_IS_QUAD_T
-	printf("%qdus\n", val);
-# else
-#  ifdef RLIM_T_IS_LONG_LONG
-	printf("%lldus\n", val);
-#  else
-#   ifdef RLIM_T_IS_UNSIGNED
-	printf("%luus\n", (unsigned long)val);
-#   else
-	printf("%ldus\n", (long)val);
-#   endif /* RLIM_T_IS_UNSIGNED */
-#  endif /* RLIM_T_IS_LONG_LONG */
-# endif /* RLIM_T_IS_QUAD_T */
-    } else if (limtype[lim] == ZLIMTYPE_NUMBER ||
-	       limtype[lim] == ZLIMTYPE_UNKNOWN) {
-	/* pure numeric resource */
-# ifdef RLIM_T_IS_QUAD_T
-	printf("%qd\n", val);
-# else
-#  ifdef RLIM_T_IS_LONG_LONG
-	printf("%lld\n", val);
-#  else
-#   ifdef RLIM_T_IS_UNSIGNED
-	printf("%lu\n", (unsigned long)val);
-#   else
-	printf("%ld\n", (long)val);
-#   endif /* RLIM_T_IS_UNSIGNED */
-#  endif /* RLIM_T_IS_LONG_LONG */
-# endif /* RLIM_T_IS_QUAD_T */
-    } else if (val >= 1024L * 1024L)
-	/* memory resource -- display with `K' or `M' modifier */
-# ifdef RLIM_T_IS_QUAD_T
-	printf("%qdMB\n", val / (1024L * 1024L));
-    else
-	printf("%qdkB\n", val / 1024L);
-# else
-#  ifdef RLIM_T_IS_LONG_LONG
-	printf("%lldMB\n", val / (1024L * 1024L));
-    else
-	printf("%lldkB\n", val / 1024L);
-#  else
-#   ifdef RLIM_T_IS_UNSIGNED
-    printf("%luMB\n", (unsigned long)(val / (1024L * 1024L)));
-    else
-	printf("%lukB\n", (unsigned long)(val / 1024L));
-#   else
-    printf("%ldMB\n", (long)val / (1024L * 1024L));
-    else
-	printf("%ldkB\n", (long)val / 1024L);
-#   endif /* RLIM_T_IS_UNSIGNED */
-#  endif /* RLIM_T_IS_LONG_LONG */
-# endif /* RLIM_T_IS_QUAD_T */
+    } else if (resinfo[lim]->type == ZLIMTYPE_MICROSECONDS)
+	printrlim(val, "us\n");	/* microseconds */
+    else if (resinfo[lim]->type == ZLIMTYPE_NUMBER ||
+	       resinfo[lim]->type == ZLIMTYPE_UNKNOWN)
+	printrlim(val, "\n");	/* pure numeric resource */
+    else {
+	/* memory resource -- display with `k' or `M' modifier */
+	if (val >= 1024L * 1024L)
+	    printrlim(val/(1024L * 1024L), "MB\n");
+	else
+	    printrlim(val/1024L, "kB\n");
+    }
 }
 
 /* Display resource limits.  hard indicates whether `hard' or `soft'  *
@@ -193,7 +327,7 @@ showlimits(char *nam, int hard, int lim)
 {
     int rt;
 
-    if (lim >= ZSH_NLIMITS)
+    if (lim >= RLIM_NLIMITS)
     {
 	/*
 	 * Not configured into the shell.  Ask the OS
@@ -215,7 +349,7 @@ showlimits(char *nam, int hard, int lim)
     else
     {
 	/* main loop over resource types */
-	for (rt = 0; rt != ZSH_NLIMITS; rt++)
+	for (rt = 0; rt != RLIM_NLIMITS; rt++)
 	    showlimitvalue(rt, (hard) ? limits[rt].rlim_max :
 			   limits[rt].rlim_cur);
     }
@@ -234,7 +368,7 @@ printulimit(char *nam, int lim, int hard, int head)
     rlim_t limit;
 
     /* get the limit in question */
-    if (lim >= ZSH_NLIMITS)
+    if (lim >= RLIM_NLIMITS)
     {
 	struct rlimit vals;
 
@@ -248,199 +382,25 @@ printulimit(char *nam, int lim, int hard, int head)
     else
 	limit = (hard) ? limits[lim].rlim_max : limits[lim].rlim_cur;
     /* display the appropriate heading */
-    switch (lim) {
-    case RLIMIT_CORE:
-	if (head)
-	    printf("-c: core file size (blocks)         ");
-	if (limit != RLIM_INFINITY)
-	    limit /= 512;
-	break;
-    case RLIMIT_DATA:
-	if (head)
-	    printf("-d: data seg size (kbytes)          ");
-	if (limit != RLIM_INFINITY)
-	    limit /= 1024;
-	break;
-    case RLIMIT_FSIZE:
-	if (head)
-	    printf("-f: file size (blocks)              ");
-	if (limit != RLIM_INFINITY)
-	    limit /= 512;
-	break;
-# ifdef HAVE_RLIMIT_SIGPENDING
-    case RLIMIT_SIGPENDING:
-	if (head)
-	    printf("-i: pending signals                 ");
-	break;
-# endif
-# ifdef HAVE_RLIMIT_MEMLOCK
-    case RLIMIT_MEMLOCK:
-	if (head)
-	    printf("-l: locked-in-memory size (kbytes)  ");
-	if (limit != RLIM_INFINITY)
-	    limit /= 1024;
-	break;
-# endif /* HAVE_RLIMIT_MEMLOCK */
-/* If RLIMIT_VMEM and RLIMIT_RSS are defined and equal, avoid *
- * duplicate case statement.  Observed on QNX Neutrino 6.1.0. */
-# if defined(HAVE_RLIMIT_RSS) && !defined(RLIMIT_VMEM_IS_RSS) && !defined(RLIMIT_RSS_IS_AS)
-    case RLIMIT_RSS:
-	if (head)
-	    printf("-m: resident set size (kbytes)      ");
-	if (limit != RLIM_INFINITY)
-	    limit /= 1024;
-	break;
-# endif /* HAVE_RLIMIT_RSS */
-# if defined(HAVE_RLIMIT_VMEM) && defined(HAVE_RLIMIT_RSS) && defined(RLIMIT_VMEM_IS_RSS)
-    case RLIMIT_VMEM:
-	if (head)
-	    printf("-m: memory size (kbytes)            ");
-	if (limit != RLIM_INFINITY)
-	    limit /= 1024;
-	break;
-# endif /* HAVE_RLIMIT_VMEM */
-# ifdef HAVE_RLIMIT_NOFILE
-    case RLIMIT_NOFILE:
-	if (head)
-	    printf("-n: file descriptors                ");
-	break;
-# endif /* HAVE_RLIMIT_NOFILE */
-# ifdef HAVE_RLIMIT_MSGQUEUE
-    case RLIMIT_MSGQUEUE:
-	if (head)
-	    printf("-q: bytes in POSIX msg queues       ");
-	break;
-# endif
-    case RLIMIT_STACK:
-	if (head)
-	    printf("-s: stack size (kbytes)             ");
-	if (limit != RLIM_INFINITY)
-	    limit /= 1024;
-	break;
-    case RLIMIT_CPU:
-	if (head)
-	    printf("-t: cpu time (seconds)              ");
-	break;
-# ifdef HAVE_RLIMIT_NPROC
-    case RLIMIT_NPROC:
-	if (head)
-	    printf("-u: processes                       ");
-	break;
-# endif /* HAVE_RLIMIT_NPROC */
-# if defined(HAVE_RLIMIT_VMEM) && (!defined(HAVE_RLIMIT_RSS) || !defined(RLIMIT_VMEM_IS_RSS))
-    case RLIMIT_VMEM:
-	if (head)
-	    printf("-v: virtual memory size (kbytes)    ");
-	if (limit != RLIM_INFINITY)
-	    limit /= 1024;
-	break;
-# endif /* HAVE_RLIMIT_VMEM */
-# if defined HAVE_RLIMIT_AS && !defined(RLIMIT_VMEM_IS_AS)
-    case RLIMIT_AS:
-	if (head)
-	    printf("-v: address space (kbytes)          ");
-	if (limit != RLIM_INFINITY)
-	    limit /= 1024;
-	break;
-# endif /* HAVE_RLIMIT_AS */
-# ifdef HAVE_RLIMIT_LOCKS
-    case RLIMIT_LOCKS:
-	if (head)
-	    printf("-x: file locks                      ");
-	break;
-# endif /* HAVE_RLIMIT_LOCKS */
-# ifdef HAVE_RLIMIT_AIO_MEM
-    case RLIMIT_AIO_MEM:
-	if (head)
-	    printf("-N %2d: AIO locked-in-memory (kbytes)", RLIMIT_AIO_MEM);
-	if (limit != RLIM_INFINITY)
-	    limit /= 1024;
-	break;
-# endif /* HAVE_RLIMIT_AIO_MEM */
-# ifdef HAVE_RLIMIT_AIO_OPS
-    case RLIMIT_AIO_OPS:
-	if (head)
-	    printf("-N %2d: AIO operations               ", RLIMIT_AIO_OPS);
-	break;
-# endif /* HAVE_RLIMIT_AIO_OPS */
-# ifdef HAVE_RLIMIT_TCACHE
-    case RLIMIT_TCACHE:
-	if (head)
-	    printf("-N %2d: cached threads               ", RLIMIT_TCACHE);
-	break;
-# endif /* HAVE_RLIMIT_TCACHE */
-# ifdef HAVE_RLIMIT_SBSIZE
-    case RLIMIT_SBSIZE:
-	if (head)
-	    printf("-b: socket buffer size (bytes)      ");
-	break;
-# endif /* HAVE_RLIMIT_SBSIZE */
-# ifdef HAVE_RLIMIT_PTHREAD
-    case RLIMIT_PTHREAD:
-	if (head)
-	    printf("%s", THREAD_FMT);
-	break;
-# endif /* HAVE_RLIMIT_PTHREAD */
-# ifdef HAVE_RLIMIT_NICE
-    case RLIMIT_NICE:
-	if (head)
-	    printf("-e: max nice                        ");
-	break;
-# endif /* HAVE_RLIMIT_NICE */
-# ifdef HAVE_RLIMIT_RTPRIO
-    case RLIMIT_RTPRIO:
-	if (head)
-	    printf("-r: max rt priority                 ");
-	break;
-# endif /* HAVE_RLIMIT_RTPRIO */
-# ifdef HAVE_RLIMIT_NPTS
-    case RLIMIT_NPTS:
-	if (head)
-	    printf("-p: pseudo-terminals                ");
-	break;
-# endif /* HAVE_RLIMIT_NPTS */
-# ifdef HAVE_RLIMIT_SWAP
-    case RLIMIT_SWAP:
-	if (head)
-	    printf("-w: swap size (kbytes)              ");
-	if (limit != RLIM_INFINITY)
-	    limit /= 1024;
-	break;
-# endif /* HAVE_RLIMIT_SWAP */
-# ifdef HAVE_RLIMIT_KQUEUES
-    case RLIMIT_KQUEUES:
-	if (head)
-	    printf("-k: kqueues                         ");
-	break;
-# endif /* HAVE_RLIMIT_KQUEUES */
-# ifdef HAVE_RLIMIT_UMTXP
-    case RLIMIT_UMTXP:
-	if (head)
-	    printf("-o: umtx shared locks               ");
-	break;
-# endif /* HAVE_RLIMIT_UMTXP */
-    default:
-	if (head)
-	    printf("-N %2d:                              ", lim);
-	break;
+    if (head) {
+	if (lim < RLIM_NLIMITS) {
+	    resinfo_t *info = resinfo[lim];
+	    if (info->opt == 'N')
+		printf("-N %2d: %-29s", lim, info->descr);
+	    else
+		printf("-%c: %-32s", info->opt, info->descr);
+	}
+	else
+	    printf("-N %2d: %-29s", lim, "");
     }
     /* display the limit */
     if (limit == RLIM_INFINITY)
 	printf("unlimited\n");
     else {
-# ifdef RLIM_T_IS_QUAD_T
-	printf("%qd\n", limit);
-# else
-#  ifdef RLIM_T_IS_LONG_LONG
-	printf("%lld\n", limit);
-#  else
-#   ifdef RLIM_T_IS_UNSIGNED
-	printf("%lu\n", (unsigned long)limit);
-#   else
-	printf("%ld\n", (long)limit);
-#   endif /* RLIM_T_IS_UNSIGNED */
-#  endif /* RLIM_T_IS_LONG_LONG */
-# endif /* RLIM_T_IS_QUAD_T */
+	if (lim < RLIM_NLIMITS)
+	    printrlim(limit/resinfo[lim]->unit, "\n");
+	else
+	    printrlim(limit, "\n");
     }
 
     return 0;
@@ -450,7 +410,7 @@ printulimit(char *nam, int lim, int hard, int head)
 static int
 do_limit(char *nam, int lim, rlim_t val, int hard, int soft, int set)
 {
-    if (lim >= ZSH_NLIMITS) {
+    if (lim >= RLIM_NLIMITS) {
 	struct rlimit vals;
 	if (getrlimit(lim, &vals) < 0)
 	{
@@ -558,8 +518,8 @@ bin_limit(char *nam, char **argv, Options ops, UNUSED(int func))
 	    lim = (int)zstrtol(s, NULL, 10);
 	}
 	else
-	    for (lim = -1, limnum = 0; limnum < ZSH_NLIMITS; limnum++)
-		if (!strncmp(recs[limnum], s, strlen(s))) {
+	    for (lim = -1, limnum = 0; limnum < RLIM_NLIMITS; limnum++)
+		if (!strncmp(resinfo[limnum]->name, s, strlen(s))) {
 		    if (lim != -1)
 			lim = -2;
 		    else
@@ -576,7 +536,7 @@ bin_limit(char *nam, char **argv, Options ops, UNUSED(int func))
 	/* without value for limit, display the current limit */
 	if (!(s = *argv++))
 	    return showlimits(nam, hard, lim);
-	if (lim >= ZSH_NLIMITS)
+	if (lim >= RLIM_NLIMITS)
 	{
 	    val = zstrtorlimt(s, &s, 10);
 	    if (*s)
@@ -586,7 +546,7 @@ bin_limit(char *nam, char **argv, Options ops, UNUSED(int func))
 		return 1;
 	    }
 	}
-	else if (limtype[lim] == ZLIMTYPE_TIME) {
+	else if (resinfo[lim]->type == ZLIMTYPE_TIME) {
 	    /* time-type resource -- may be specified as seconds, or minutes or *
 	     * hours with the `m' and `h' modifiers, and `:' may be used to add *
 	     * together more than one of these.  It's easier to understand from *
@@ -604,9 +564,9 @@ bin_limit(char *nam, char **argv, Options ops, UNUSED(int func))
 		    return 1;
 		}
 	    }
-	} else if (limtype[lim] == ZLIMTYPE_NUMBER ||
-		   limtype[lim] == ZLIMTYPE_UNKNOWN ||
-		   limtype[lim] == ZLIMTYPE_MICROSECONDS) {
+	} else if (resinfo[lim]->type == ZLIMTYPE_NUMBER ||
+		   resinfo[lim]->type == ZLIMTYPE_UNKNOWN ||
+		   resinfo[lim]->type == ZLIMTYPE_MICROSECONDS) {
 	    /* pure numeric resource -- only a straight decimal number is
 	    permitted. */
 	    char *t = s;
@@ -642,7 +602,7 @@ static int
 do_unlimit(char *nam, int lim, int hard, int soft, int set, int euid)
 {
     /* remove specified limit */
-    if (lim >= ZSH_NLIMITS) {
+    if (lim >= RLIM_NLIMITS) {
 	struct rlimit vals;
 	if (getrlimit(lim, &vals) < 0)
 	{
@@ -718,8 +678,8 @@ bin_unlimit(char *nam, char **argv, Options ops, UNUSED(int func))
 	    if (idigit(**argv)) {
 		lim = (int)zstrtol(*argv, NULL, 10);
 	    } else {
-		for (lim = -1, limnum = 0; limnum < ZSH_NLIMITS; limnum++)
-		    if (!strncmp(recs[limnum], *argv, strlen(*argv))) {
+		for (lim = -1, limnum = 0; limnum < RLIM_NLIMITS; limnum++)
+		    if (!strncmp(resinfo[limnum]->name, *argv, strlen(*argv))) {
 			if (lim != -1)
 			    lim = -2;
 			else
@@ -800,116 +760,14 @@ bin_ulimit(char *name, char **argv, UNUSED(Options ops), UNUSED(int func))
 		    resmask = (1 << RLIM_NLIMITS) - 1;
 		    nres = RLIM_NLIMITS;
 		    continue;
-		case 't':
-		    res = RLIMIT_CPU;
-		    break;
-		case 'f':
-		    res = RLIMIT_FSIZE;
-		    break;
-		case 'd':
-		    res = RLIMIT_DATA;
-		    break;
-		case 's':
-		    res = RLIMIT_STACK;
-		    break;
-		case 'c':
-		    res = RLIMIT_CORE;
-		    break;
-# ifdef HAVE_RLIMIT_SBSIZE
-		case 'b':
-		    res = RLIMIT_SBSIZE;
-		    break;
-# endif /* HAVE_RLIMIT_SBSIZE */
-# ifdef HAVE_RLIMIT_MEMLOCK
-		case 'l':
-		    res = RLIMIT_MEMLOCK;
-		    break;
-# endif /* HAVE_RLIMIT_MEMLOCK */
-# ifdef HAVE_RLIMIT_RSS
-		case 'm':
-		    res = RLIMIT_RSS;
-		    break;
-# endif /* HAVE_RLIMIT_RSS */
-# ifdef HAVE_RLIMIT_NOFILE
-		case 'n':
-		    res = RLIMIT_NOFILE;
-		    break;
-# endif /* HAVE_RLIMIT_NOFILE */
-# ifdef HAVE_RLIMIT_NPROC
-		case 'u':
-		    res = RLIMIT_NPROC;
-		    break;
-# endif /* HAVE_RLIMIT_NPROC */
-# if defined(HAVE_RLIMIT_VMEM) || defined(HAVE_RLIMIT_AS)
-		case 'v':
-#  ifdef HAVE_RLIMIT_VMEM
-		    res = RLIMIT_VMEM;
-#  else
-		    res = RLIMIT_AS;
-#  endif
-		    break;
-# endif /* HAVE_RLIMIT_VMEM */
-# ifdef HAVE_RLIMIT_LOCKS
-		case 'x':
-		    res = RLIMIT_LOCKS;
-		    break;
-# endif
-# ifdef HAVE_RLIMIT_SIGPENDING
-		case 'i':
-		    res = RLIMIT_SIGPENDING;
-		    break;
-# endif
-# ifdef HAVE_RLIMIT_MSGQUEUE
-		case 'q':
-		    res = RLIMIT_MSGQUEUE;
-		    break;
-# endif
-# ifdef HAVE_RLIMIT_NICE
-		case 'e':
-		    res = RLIMIT_NICE;
-		    break;
-# endif
-# ifdef HAVE_RLIMIT_RTPRIO
-		case 'r':
-		    res = RLIMIT_RTPRIO;
-		    break;
-# else
-#  ifdef HAVE_RLIMIT_NTHR
-		    /* For compatibility with sh on NetBSD */
-		case 'r':
-		    res = RLIMIT_NTHR;
-		    break;
-#  endif /* HAVE_RLIMIT_NTHR */
-# endif
-# ifdef HAVE_RLIMIT_NPTS
-		case 'p':
-		    res = RLIMIT_NPTS;
-		    break;
-# endif
-# ifdef HAVE_RLIMIT_SWAP
-		case 'w':
-		    res = RLIMIT_SWAP;
-		    break;
-# endif
-# ifdef HAVE_RLIMIT_KQUEUES
-		case 'k':
-		    res = RLIMIT_KQUEUES;
-		    break;
-# endif
-# ifdef HAVE_RLIMIT_PTHREAD
-		case 'T':
-		    res = RLIMIT_PTHREAD;
-		    break;
-# endif
-# ifdef HAVE_RLIMIT_UMTXP
-		case 'o':
-		    res = RLIMIT_UMTXP;
-		    break;
-# endif
 		default:
-		    /* unrecognised limit */
-		    zwarnnam(name, "bad option: -%c", *options);
-		    return 1;
+		    res = find_resource(*options);
+		    if (res < 0) {
+			/* unrecognised limit */
+			zwarnnam(name, "bad option: -%c", *options);
+			return 1;
+		    }
+		    break;
 		}
 		if (options[1]) {
 		    resmask |= 1 << res;
@@ -961,34 +819,8 @@ bin_ulimit(char *name, char **argv, UNUSED(Options ops), UNUSED(int func))
 		    return 1;
 		}
 		/* scale appropriately */
-		switch (res) {
-		case RLIMIT_FSIZE:
-		case RLIMIT_CORE:
-		    limit *= 512;
-		    break;
-		case RLIMIT_DATA:
-		case RLIMIT_STACK:
-# ifdef HAVE_RLIMIT_RSS
-		case RLIMIT_RSS:
-# endif /* HAVE_RLIMIT_RSS */
-# ifdef HAVE_RLIMIT_MEMLOCK
-		case RLIMIT_MEMLOCK:
-# endif /* HAVE_RLIMIT_MEMLOCK */
-/* If RLIMIT_VMEM and RLIMIT_RSS are defined and equal, avoid *
- * duplicate case statement.  Observed on QNX Neutrino 6.1.0. */
-# if defined(HAVE_RLIMIT_VMEM) && !defined(RLIMIT_VMEM_IS_RSS)
-		case RLIMIT_VMEM:
-# endif /* HAVE_RLIMIT_VMEM */
-/* ditto RLIMIT_VMEM and RLIMIT_AS */
-# if defined(HAVE_RLIMIT_AS) && !defined(RLIMIT_VMEM_IS_AS) && !defined(RLIMIT_RSS_IS_AS)
-		case RLIMIT_AS:
-# endif /* HAVE_RLIMIT_AS */
-# ifdef HAVE_RLIMIT_AIO_MEM
-		case RLIMIT_AIO_MEM:
-# endif /* HAVE_RLIMIT_AIO_MEM */
-		    limit *= 1024;
-		    break;
-		}
+		if (res < RLIM_NLIMITS)
+		    limit *= resinfo[res]->unit;
 	    }
 	    if (do_limit(name, res, limit, hard, soft, 1))
 		ret++;
@@ -1052,6 +884,7 @@ enables_(Module m, int **enables)
 int
 boot_(UNUSED(Module m))
 {
+    set_resinfo();
     return 0;
 }
 
@@ -1059,6 +892,7 @@ boot_(UNUSED(Module m))
 int
 cleanup_(Module m)
 {
+    free_resinfo();
     return setfeatureenables(m, &module_features, NULL);
 }
 
diff --git a/Src/Builtins/rlimits.mdd b/Src/Builtins/rlimits.mdd
index 9e6e9e598..06c9e9c7f 100644
--- a/Src/Builtins/rlimits.mdd
+++ b/Src/Builtins/rlimits.mdd
@@ -6,18 +6,3 @@ autofeatures="b:limit b:ulimit b:unlimit"
 autofeatures_emu="b:ulimit"
 
 objects="rlimits.o"
-
-:<<\Make
-rlimits.o rlimits..o: rlimits.h
-
-# this file will not be made if limits are unavailable
-rlimits.h: rlimits.awk @RLIMITS_INC_H@
-	$(AWK) -f $(sdir)/rlimits.awk @RLIMITS_INC_H@ /dev/null > rlimits.h
-	@if grep ZLIMTYPE_UNKNOWN rlimits.h >/dev/null; then \
-	    echo >&2 WARNING: unknown limits: mail Src/Builtins/rlimits.h to developers; \
-	else :; fi
-
-clean-here: clean.rlimits
-clean.rlimits:
-	rm -f rlimits.h
-Make
diff --git a/configure.ac b/configure.ac
index f2d65ecfc..2f1e0c41e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1928,6 +1928,7 @@ zsh_LIMIT_PRESENT(RLIMIT_SIGPENDING)
 zsh_LIMIT_PRESENT(RLIMIT_MSGQUEUE)
 zsh_LIMIT_PRESENT(RLIMIT_NICE)
 zsh_LIMIT_PRESENT(RLIMIT_RTPRIO)
+zsh_LIMIT_PRESENT(RLIMIT_RTTIME)
 zsh_LIMIT_PRESENT(RLIMIT_POSIXLOCKS)
 zsh_LIMIT_PRESENT(RLIMIT_NPTS)
 zsh_LIMIT_PRESENT(RLIMIT_SWAP)




^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-02-25  9:38                   ` Jun T
@ 2020-02-27 13:22                     ` Daniel Shahaf
  2020-02-27 18:46                       ` Mikael Magnusson
  2020-02-28  8:42                       ` Jun T
  2020-03-20 19:18                     ` Daniel Shahaf
  1 sibling, 2 replies; 38+ messages in thread
From: Daniel Shahaf @ 2020-02-27 13:22 UTC (permalink / raw)
  To: zsh-workers

Jun T wrote on Tue, 25 Feb 2020 18:38 +0900:
> Sorry for a *very* slow response; I've been quite busy these days.
> Finally I found some time to work on this.

No worries; we've all been there.  I'm swamped/backlogged too.

> But removing rlimits.awk has one drawback:
> Before the patch, unknown resource can be detected in the build
> time (by the special make rule defined in rlimits.mdd).
> With the patch, we can notice unknown resouce(s) only when running
> the limit (or ulimit) builtin. We may hope that a user who sees
> UNKNOWN in the output of limit/ulimit will report it to us, or
> add a simple test like
> 
> limit | grep UNKNOWN || print OK
> 
> somewhere in the test (but in which .ztst file?).

I prefer a new test, but to arrange things in such a way that a failure
of the new test won't fail the build or prevent other tests from
running.

So, how about: —

1. Placing the test in a new file, V99nonfatal.ztst; and

2. Using «F:» lines to explain that when the test fails, that shouldn't
be treated as a build breaker and there is no problem to go on and do
«make install».

?

We might even add a new flag, e.g., «ZTST_failure_is_fatal=false», which
would cause «make test» to report the failure on stderr but keep the
exit code as zero: this way, if someone builds zsh 5.8 five years from
now on a 2025-vintage OS, their «make && make check && make install»
wouldn't fail on account of OS API changes between now and then.

A couple of minor issues spotted in read-through:

> --- a/Src/Builtins/rlimits.c
> +++ b/Src/Builtins/rlimits.c
> @@ -53,11 +40,214 @@ enum {
> +typedef struct {

Suggest to name the struct type — «typedef struct resinfo_t { … }
resinfo_t» — as that tends to result in prettier output in the debugger.

> +/* table of known resources */
> +static resinfo_t known_resources[] = {

Suggest to make the variable const.

I haven't had time yet to do a full review or to test this, I'm afraid ☹

Cheers,

Daniel

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-02-27 13:22                     ` Daniel Shahaf
@ 2020-02-27 18:46                       ` Mikael Magnusson
  2020-02-28  8:42                       ` Jun T
  1 sibling, 0 replies; 38+ messages in thread
From: Mikael Magnusson @ 2020-02-27 18:46 UTC (permalink / raw)
  To: zsh-workers

On 2/27/20, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> Jun T wrote on Tue, 25 Feb 2020 18:38 +0900:

> A couple of minor issues spotted in read-through:
>
>> --- a/Src/Builtins/rlimits.c
>> +++ b/Src/Builtins/rlimits.c
>> @@ -53,11 +40,214 @@ enum {
>> +typedef struct {
>
> Suggest to name the struct type — «typedef struct resinfo_t { … }
> resinfo_t» — as that tends to result in prettier output in the debugger.
>
>> +/* table of known resources */
>> +static resinfo_t known_resources[] = {

It shouldn't be named anything_t at all, that suffix is reserved (see
for example the system rlim_t type in the same file). Ref:
https://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html

-- 
Mikael Magnusson

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-02-27 13:22                     ` Daniel Shahaf
  2020-02-27 18:46                       ` Mikael Magnusson
@ 2020-02-28  8:42                       ` Jun T
  2020-02-28 14:19                         ` Daniel Shahaf
  1 sibling, 1 reply; 38+ messages in thread
From: Jun T @ 2020-02-28  8:42 UTC (permalink / raw)
  To: zsh-workers


> 2020/02/27 22:22, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> 
> Jun T wrote on Tue, 25 Feb 2020 18:38 +0900:
>> We may hope that a user who sees
>> UNKNOWN in the output of limit/ulimit will report it to us, or
>> add a simple test like
>> 
>> limit | grep UNKNOWN || print OK
>> 
>> somewhere in the test (but in which .ztst file?).
> 
> I prefer a new test, but to arrange things in such a way that a failure
> of the new test won't fail the build or prevent other tests from
> running.
(snip)
> We might even add a new flag, e.g., «ZTST_failure_is_fatal=false»

Currently each test chunk can have flags 'd' 'D' 'q' and 'f'.
We can add a new flag, say 'n', to make the failure not fatal.


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-02-28  8:42                       ` Jun T
@ 2020-02-28 14:19                         ` Daniel Shahaf
  2020-02-28 14:31                           ` Daniel Shahaf
  2020-03-03  9:23                           ` Jun T
  0 siblings, 2 replies; 38+ messages in thread
From: Daniel Shahaf @ 2020-02-28 14:19 UTC (permalink / raw)
  To: zsh-workers

Jun T wrote on Fri, 28 Feb 2020 17:42 +0900:
> > 2020/02/27 22:22, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > 
> > Jun T wrote on Tue, 25 Feb 2020 18:38 +0900:  
> >> We may hope that a user who sees
> >> UNKNOWN in the output of limit/ulimit will report it to us, or
> >> add a simple test like
> >> 
> >> limit | grep UNKNOWN || print OK
> >> 
> >> somewhere in the test (but in which .ztst file?).  
> > 
> > I prefer a new test, but to arrange things in such a way that a failure
> > of the new test won't fail the build or prevent other tests from
> > running.  
> (snip)
> > We might even add a new flag, e.g., «ZTST_failure_is_fatal=false»  
> 
> Currently each test chunk can have flags 'd' 'D' 'q' and 'f'.
> We can add a new flag, say 'n', to make the failure not fatal.

If we add a new letter flag, we won't be able to make the non-fatalness
specific to only one platform, though.  We a new parameter, we'd be
able to do «[[ $OSTYPE == cygwin* ]] && ZTST_failure_is_fatal=false».

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-02-28 14:19                         ` Daniel Shahaf
@ 2020-02-28 14:31                           ` Daniel Shahaf
  2020-03-03  9:23                           ` Jun T
  1 sibling, 0 replies; 38+ messages in thread
From: Daniel Shahaf @ 2020-02-28 14:31 UTC (permalink / raw)
  To: zsh-workers

Daniel Shahaf wrote on Fri, 28 Feb 2020 14:19 +00:00:
> Jun T wrote on Fri, 28 Feb 2020 17:42 +0900:
> > > 2020/02/27 22:22, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > > 
> > > Jun T wrote on Tue, 25 Feb 2020 18:38 +0900:  
> > >> We may hope that a user who sees
> > >> UNKNOWN in the output of limit/ulimit will report it to us, or
> > >> add a simple test like
> > >> 
> > >> limit | grep UNKNOWN || print OK
> > >> 
> > >> somewhere in the test (but in which .ztst file?).  
> > > 
> > > I prefer a new test, but to arrange things in such a way that a failure
> > > of the new test won't fail the build or prevent other tests from
> > > running.  
> > (snip)
> > > We might even add a new flag, e.g., «ZTST_failure_is_fatal=false»  
> > 
> > Currently each test chunk can have flags 'd' 'D' 'q' and 'f'.
> > We can add a new flag, say 'n', to make the failure not fatal.
> 
> If we add a new letter flag, we won't be able to make the non-fatalness
> specific to only one platform, though.  We a new parameter, we'd be
> able to do «[[ $OSTYPE == cygwin* ]] && ZTST_failure_is_fatal=false».

That was just an example; there's no particular reason to make the
«limit | grep UNKNOWN» test specific to any particular set of
${OSTYPE}s.

Cheers,

Daniel

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-02-28 14:19                         ` Daniel Shahaf
  2020-02-28 14:31                           ` Daniel Shahaf
@ 2020-03-03  9:23                           ` Jun T
  2020-03-04 19:29                             ` Daniel Shahaf
  2020-03-20 17:02                             ` Daniel Shahaf
  1 sibling, 2 replies; 38+ messages in thread
From: Jun T @ 2020-03-03  9:23 UTC (permalink / raw)
  To: zsh-workers


> 2020/02/28 23:19, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> 
> Jun T wrote on Fri, 28 Feb 2020 17:42 +0900:
>> 
>> Currently each test chunk can have flags 'd' 'D' 'q' and 'f'.
>> We can add a new flag, say 'n', to make the failure not fatal.
> 
> If we add a new letter flag, we won't be able to make the non-fatalness
> specific to only one platform, though.  We a new parameter, we'd be
> able to do «[[ $OSTYPE == cygwin* ]] && ZTST_failure_is_fatal=false».

I feel just letting the test fail may be enough,  but if we are going
to add a new parameter/flag to ztst.zsh then it would be something like
the patch below.

BTW, in B01cd.ztst, line 73:

#  . d  Don't diff stdout against the expected stdout.

What does this '.' mean?  Is it just a typo?



 Test/B01cd.ztst    |  7 +++++--
 Test/B12limit.ztst | 10 ++++++++++
 Test/ztst.zsh      | 32 ++++++++++++++++++++++----------
 3 files changed, 37 insertions(+), 12 deletions(-)


diff --git a/Test/B01cd.ztst b/Test/B01cd.ztst
index d903b7462..a91fdd95d 100644
--- a/Test/B01cd.ztst
+++ b/Test/B01cd.ztst
@@ -96,8 +96,9 @@
 # itself.  (The example below isn't particularly useful as errors with
 # `cd' are unusual.)
 #
-# A couple of features aren't used in this file, but are usefuil in cases
-# where features may not be available so should not be tested.  They boh
+# A couple of features aren't used in this file, but are useful in cases
+# where features may not be available so should not be tested, or a
+# failure of a test need not be considered as a fatal error.  They all
 # take the form of variables.  Note that to keep the test framework simple
 # there is no magic in setting the variables: the chunk of code being
 # executed needs to avoid executing any test code by appropriate structure
@@ -107,6 +108,8 @@
 #   is to be skipped.
 # ZTST_skip: Set this in any test case if that single test case is to be
 #   skipped.  Testing resumes at the next test case in the same file.
+# ZTST_not_fatal: Set this in any test case if its failure is not fatal.
+#   The failure is reported but the test case is considered as passed.
 #
 # Syntax highlighting for Vim is available, see Util/ztst-*.vim.
  cd cdtst.tmp/sub/fake &&
diff --git a/Test/B12limit.ztst b/Test/B12limit.ztst
new file mode 100644
index 000000000..2a072da08
--- /dev/null
+++ b/Test/B12limit.ztst
@@ -0,0 +1,10 @@
+# check if there is unknown resouce(s)
+
+%test
+
+ ZTST_not_fatal=1
+ limit | grep UNKNOWN || print OK
+0:Check if there is unknown resouce(s) in the system
+>OK
+F:A failure here just indicates there is a resource in your system that is
+F:unknown to zsh developers. Please report this to zsh-workers mailing list.
diff --git a/Test/ztst.zsh b/Test/ztst.zsh
index 375efd16c..496a5c1bd 100755
--- a/Test/ztst.zsh
+++ b/Test/ztst.zsh
@@ -133,17 +133,22 @@ rm -rf dummy.tmp *.tmp
 
 # Report failure.  Note that all output regarding the tests goes to stdout.
 # That saves an unpleasant mixture of stdout and stderr to sort out.
+# If $2 is given and equal to 1, this faiure is not fatal.
 ZTST_testfailed() {
   print -r "Test $ZTST_testname failed: $1"
   if [[ -n $ZTST_message ]]; then
     print -r "Was testing: $ZTST_message"
   fi
-  print -r "$ZTST_testname: test failed."
+  if (( $2 == 1 )); then
+    print -r "$ZTST_testname: Non-fatal failure."
+  else
+    print -r "$ZTST_testname: test failed."
+    ZTST_testfailed=1
+  fi
   if [[ -n $ZTST_failmsg ]]; then
     print -r "The following may (or may not) help identifying the cause:
 $ZTST_failmsg"
   fi
-  ZTST_testfailed=1
   return 1
 }
 
@@ -365,8 +370,8 @@ ZTST_diff() {
 ZTST_test() {
   local last match mbegin mend found substlines
   local diff_out diff_err
-  local ZTST_skip
-  integer expected_to_fail
+  local ZTST_skip ZTST_not_fatal
+  integer expected_to_fail not_fatal
 
   while true; do
     rm -f $ZTST_in $ZTST_out $ZTST_err
@@ -461,6 +466,13 @@ $ZTST_curline"
 	fi
       fi
 
+      if [[ -n $ZTST_not_fatal ]]; then
+	not_fatal=1
+	ZTST_not_fatal=
+      else
+	not_fatal=0
+      fi
+
       if [[ $ZTST_flags = *f* ]]; then
         expected_to_fail=1
         ZTST_xfail_diff() { ZTST_diff "$@" > /dev/null }
@@ -479,7 +491,7 @@ $ZTST_curline"
 	ZTST_testfailed "bad status $ZTST_status, expected $ZTST_xstatus from:
 $ZTST_code${$(<$ZTST_terr):+
 Error output:
-$(<$ZTST_terr)}"
+$(<$ZTST_terr)}" $not_fatal
 	return 1
       fi
 
@@ -502,8 +514,8 @@ $(<$ZTST_terr)"
 	ZTST_testfailed "output differs from expected as shown above for:
 $ZTST_code${$(<$ZTST_terr):+
 Error output:
-$(<$ZTST_terr)}"
-	return 1
+$(<$ZTST_terr)}" $not_fatal
+	(( not_fatal )) && continue || return 1
       fi
       if [[ $ZTST_flags = *q* && -s $ZTST_err ]]; then
 	substlines="$(<$ZTST_err)"
@@ -516,12 +528,12 @@ $(<$ZTST_terr)}"
           continue
         fi
 	ZTST_testfailed "error output differs from expected as shown above for:
-$ZTST_code"
-	return 1
+$ZTST_code" $not_fatal
+	(( not_fatal )) && continue || return 1
       fi
       if (( expected_to_fail )); then
         ZTST_testfailed "test was expected to fail, but passed."
-        return 1
+	(( not_fatal )) && continue || return 1
       fi
     fi
     ZTST_verbose 1 "Test successful."




^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-03-03  9:23                           ` Jun T
@ 2020-03-04 19:29                             ` Daniel Shahaf
  2020-03-05 10:26                               ` Jun T
  2020-03-20 17:02                             ` Daniel Shahaf
  1 sibling, 1 reply; 38+ messages in thread
From: Daniel Shahaf @ 2020-03-04 19:29 UTC (permalink / raw)
  To: zsh-workers

Jun T wrote on Tue, 03 Mar 2020 09:23 +00:00:
> 
> > 2020/02/28 23:19, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > 
> > Jun T wrote on Fri, 28 Feb 2020 17:42 +0900:
> >> 
> >> Currently each test chunk can have flags 'd' 'D' 'q' and 'f'.
> >> We can add a new flag, say 'n', to make the failure not fatal.
> > 
> > If we add a new letter flag, we won't be able to make the non-fatalness
> > specific to only one platform, though.  We a new parameter, we'd be
> > able to do «[[ $OSTYPE == cygwin* ]] && ZTST_failure_is_fatal=false».
> 
> I feel just letting the test fail may be enough,  but if we are going
> to add a new parameter/flag to ztst.zsh then it would be something like
> the patch below.

In this case, how about letting the test fail, as you say?  If in the
future we change our mind about that, we can add the $ZTST_not_fatal
flag then.

> BTW, in B01cd.ztst, line 73:
> 
> #  . d  Don't diff stdout against the expected stdout.
> 
> What does this '.' mean?  Is it just a typo?
> 

It was added in 08f084ecdeaeb19e595441e3e0203be4562bd285 (no X-Seq) by
pws.  The change isn't mentioned in the log message and broke alignment
of the description column, so I guess it was a typo.

>  Test/B01cd.ztst    |  7 +++++--
>  Test/B12limit.ztst | 10 ++++++++++
>  Test/ztst.zsh      | 32 ++++++++++++++++++++++----------
>  3 files changed, 37 insertions(+), 12 deletions(-)

I reviewed the diff (without out-of-hunk contexts) and have no comments.

Cheers,

Daniel

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-03-04 19:29                             ` Daniel Shahaf
@ 2020-03-05 10:26                               ` Jun T
  2020-03-05 14:58                                 ` Daniel Shahaf
  0 siblings, 1 reply; 38+ messages in thread
From: Jun T @ 2020-03-05 10:26 UTC (permalink / raw)
  To: zsh-workers


> 2020/03/05 4:29, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> 
>> I feel just letting the test fail may be enough,  but if we are going
>> to add a new parameter/flag to ztst.zsh then it would be something like
>> the patch below.
> 
> In this case, how about letting the test fail, as you say?  If in the
> future we change our mind about that, we can add the $ZTST_not_fatal
> flag then.

OK, If users complain that the failure is too stringent then we will make it
not fatal.

> 
>> BTW, in B01cd.ztst, line 73:
>> 
>> #  . d  Don't diff stdout against the expected stdout.
>> 
>> What does this '.' mean?  Is it just a typo?
>> 
> 
> It was added in 08f084ecdeaeb19e595441e3e0203be4562bd285 (no X-Seq) by
> pws.  The change isn't mentioned in the log message and broke alignment
> of the description column, so I guess it was a typo.

Thanks.

> 
>> Test/B01cd.ztst    |  7 +++++--
>> Test/B12limit.ztst | 10 ++++++++++
>> Test/ztst.zsh      | 32 ++++++++++++++++++++++----------
>> 3 files changed, 37 insertions(+), 12 deletions(-)
> 
> I reviewed the diff (without out-of-hunk contexts) and have no comments.

How about the patch for rlimit.c?
If it's OK (other than the constness and name of the structure) I will push
them soon.

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-03-05 10:26                               ` Jun T
@ 2020-03-05 14:58                                 ` Daniel Shahaf
  0 siblings, 0 replies; 38+ messages in thread
From: Daniel Shahaf @ 2020-03-05 14:58 UTC (permalink / raw)
  To: zsh-workers

Jun T wrote on Thu, 05 Mar 2020 10:26 +00:00:
> > 2020/03/05 4:29, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > 
> >> Test/B01cd.ztst    |  7 +++++--
> >> Test/B12limit.ztst | 10 ++++++++++
> >> Test/ztst.zsh      | 32 ++++++++++++++++++++++----------
> >> 3 files changed, 37 insertions(+), 12 deletions(-)
> > 
> > I reviewed the diff (without out-of-hunk contexts) and have no comments.
> 
> How about the patch for rlimit.c?
> If it's OK (other than the constness and name of the structure) I will push
> them soon.

Sure, go ahead.  (I haven't had a chance to look at it yet, I'm afraid,
but I don't see that as a blocker.)

Cheers,

Daniel

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-03-03  9:23                           ` Jun T
  2020-03-04 19:29                             ` Daniel Shahaf
@ 2020-03-20 17:02                             ` Daniel Shahaf
  2020-03-20 17:20                               ` Bart Schaefer
  1 sibling, 1 reply; 38+ messages in thread
From: Daniel Shahaf @ 2020-03-20 17:02 UTC (permalink / raw)
  To: Jun T; +Cc: zsh-workers

Good morning Jun-san,

I've started to review the rlimits patch and have found an issue:

Jun T wrote on Tue, 03 Mar 2020 18:23 +0900:
> diff --git a/Test/B12limit.ztst b/Test/B12limit.ztst
> new file mode 100644
> index 000000000..2a072da08
> --- /dev/null
> +++ b/Test/B12limit.ztst
> @@ -0,0 +1,10 @@
> +# check if there is unknown resouce(s)
> +
> +%test
> +
> + ZTST_not_fatal=1
> + limit | grep UNKNOWN || print OK
> +0:Check if there is unknown resouce(s) in the system
> +>OK  
> +F:A failure here just indicates there is a resource in your system that is
> +F:unknown to zsh developers. Please report this to zsh-workers mailing list.

The "limit" builtin is provided by a module.  As such, it can be
unavailable if the module had been disabled in config.modules prior to
building.

Proposed patch:

[[[
diff --git a/Test/B12limit.ztst b/Test/B12limit.ztst
index 5dd7afdbe..2a4749632 100644
--- a/Test/B12limit.ztst
+++ b/Test/B12limit.ztst
@@ -1,4 +1,12 @@
-# check if there is unknown resouce(s)
+
+%prep
+
+  if grep '^name=zsh/rlimits .* link=no ' $ZTST_testdir/../config.modules >/dev/null
+  then
+    ZTST_unimplemented="the zsh/rlimits module was disabled by configure (see config.modules)"
+    return 0
+  fi
+  zmodload zsh/rlimits
 
 %test
 
]]]

(The %prep block is copied verbatim from V07pcre.ztst.)

With that patch, B12limit.ztst gets skipped if zsh/rlimits is disabled.

Cheers,

Daniel

P.S. Shouldn't the test file should be renamed into the V namespace?

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-03-20 17:02                             ` Daniel Shahaf
@ 2020-03-20 17:20                               ` Bart Schaefer
  2020-03-20 17:39                                 ` Daniel Shahaf
  0 siblings, 1 reply; 38+ messages in thread
From: Bart Schaefer @ 2020-03-20 17:20 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: Jun T, zsh-workers

On Fri, Mar 20, 2020 at 10:03 AM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
>
> The "limit" builtin is provided by a module.  As such, it can be
> unavailable if the module had been disabled in config.modules prior to
> building.
>
> Proposed patch:
>
> +  if grep '^name=zsh/rlimits .* link=no ' $ZTST_testdir/../config.modules >/dev/null

Wouldn't it be better to test this with "zmodload" rather than attempt
to examine the build config?

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-03-20 17:20                               ` Bart Schaefer
@ 2020-03-20 17:39                                 ` Daniel Shahaf
  2020-03-20 18:28                                   ` Daniel Shahaf
  0 siblings, 1 reply; 38+ messages in thread
From: Daniel Shahaf @ 2020-03-20 17:39 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Jun T, zsh-workers

Bart Schaefer wrote on Fri, 20 Mar 2020 10:20 -0700:
> On Fri, Mar 20, 2020 at 10:03 AM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> >
> > The "limit" builtin is provided by a module.  As such, it can be
> > unavailable if the module had been disabled in config.modules prior to
> > building.
> >
> > Proposed patch:
> >
> > +  if grep '^name=zsh/rlimits .* link=no ' $ZTST_testdir/../config.modules >/dev/null  
> 
> Wouldn't it be better to test this with "zmodload" rather than attempt
> to examine the build config?

That was my first instinct too, but I just copied what V07pcre.ztst
did.  If using zmodload is better, then that file should probably be
updated to that approach too.

Cheers,

Daniel

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-03-20 17:39                                 ` Daniel Shahaf
@ 2020-03-20 18:28                                   ` Daniel Shahaf
  2020-03-20 18:36                                     ` Bart Schaefer
  2020-03-20 18:39                                     ` Bart Schaefer
  0 siblings, 2 replies; 38+ messages in thread
From: Daniel Shahaf @ 2020-03-20 18:28 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Jun T, zsh-workers

Daniel Shahaf wrote on Fri, 20 Mar 2020 17:39 +0000:
> Bart Schaefer wrote on Fri, 20 Mar 2020 10:20 -0700:
> > On Fri, Mar 20, 2020 at 10:03 AM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:  
> > >
> > > The "limit" builtin is provided by a module.  As such, it can be
> > > unavailable if the module had been disabled in config.modules prior to
> > > building.
> > >
> > > Proposed patch:
> > >
> > > +  if grep '^name=zsh/rlimits .* link=no ' $ZTST_testdir/../config.modules >/dev/null    
> > 
> > Wouldn't it be better to test this with "zmodload" rather than attempt
> > to examine the build config?  
> 
> That was my first instinct too, but I just copied what V07pcre.ztst
> did.  If using zmodload is better, then that file should probably be
> updated to that approach too.

Ah, I see.  I think the reason for checking config.modules is because
we need to distinguish between "module had been disabled" and "module
was enabled, but failed to load due to a bug".  That is, we want the
test suite to fail if the module failed to load even though it was
enabled in config.modules.

However, most Test/V*.ztst files use a simple «if ! zmodload zsh/foo; …»
check.

So, I think we should write a ZTST_* helper function that encapsulates
the config.modules check, and then call it as «ZTST_load_or_skip zsh/foo || return $?»
to make sure that V${N}foo.ztst fails if «zmodload zsh/foo» unexpectedly failed.

Makes sense?

Cheers,

Daniel

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-03-20 18:28                                   ` Daniel Shahaf
@ 2020-03-20 18:36                                     ` Bart Schaefer
  2020-03-20 19:38                                       ` Daniel Shahaf
  2020-03-20 18:39                                     ` Bart Schaefer
  1 sibling, 1 reply; 38+ messages in thread
From: Bart Schaefer @ 2020-03-20 18:36 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: Jun T, zsh-workers

On Fri, Mar 20, 2020 at 11:28 AM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
>
> Ah, I see.  I think the reason for checking config.modules is because
> we need to distinguish between "module had been disabled" and "module
> was enabled, but failed to load due to a bug".

I was about to ask whether that seemed to be the purpose of checking the config.

> So, I think we should write a ZTST_* helper function that encapsulates
> the config.modules check

Seems reasonable.  It does presume that "make check" is always
preceded by "make", but I suppose that's true most of the time.

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-03-20 18:28                                   ` Daniel Shahaf
  2020-03-20 18:36                                     ` Bart Schaefer
@ 2020-03-20 18:39                                     ` Bart Schaefer
  2020-03-20 19:32                                       ` Daniel Shahaf
  1 sibling, 1 reply; 38+ messages in thread
From: Bart Schaefer @ 2020-03-20 18:39 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: Jun T, zsh-workers

On Fri, Mar 20, 2020 at 11:28 AM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
>
> That is, we want the
> test suite to fail if the module failed to load even though it was
> enabled in config.modules.

An alternate approach (and maybe one that the suite already supports,
Test/V01zmodload.ztst?) is to separate the test for module loading
bugs from the tests for module feature bugs.

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-02-25  9:38                   ` Jun T
  2020-02-27 13:22                     ` Daniel Shahaf
@ 2020-03-20 19:18                     ` Daniel Shahaf
  2020-03-23  5:31                       ` Jun T
  2020-03-23  5:41                       ` Jun T
  1 sibling, 2 replies; 38+ messages in thread
From: Daniel Shahaf @ 2020-03-20 19:18 UTC (permalink / raw)
  To: Jun T; +Cc: zsh-workers


[-- Attachment #1: Type: text/plain, Size: 2489 bytes --]

Continuing my review:

Jun T wrote on Tue, 25 Feb 2020 18:38 +0900:
> --- a/Src/Builtins/rlimits.awk
> +++ /dev/null
> @@ -1,116 +0,0 @@
> -#
> -# rlimits.awk: {g,n}awk script to generate rlimits.h
> -#
> -# NB: On SunOS 4.1.3 - user-functions don't work properly, also \" problems
> -# Without 0 + hacks some nawks compare numbers as strings
> -#
> -BEGIN {limidx = 0}
> -
> -/^[\t ]*(#[\t ]*define[\t _]*RLIMIT_[A-Z_]*[\t ]*[0-9][0-9]*|RLIMIT_[A-Z_]*,[\t ]*|_*RLIMIT_[A-Z_]*[\t ]*=[\t ]*[0-9][0-9]*,[\t ]*)/ {
> -	    if (limnam == "RSS")     { msg[limnum] = "Mresident" }
> -END {
> -    if (limrev["MEMLOCK"] != "") {
> -        irss = limrev["RSS"]
> -        msg[irss] = "Mmemoryuse"
> -    }  

Question.  I compared the output before and after the patch and I see
the following difference:

    % diff -U0 =(zsh-5.7.1 -fc 'limit') =(limit)
    --- /tmp/zshZXxkUD      2020-03-20 18:00:04.239999929 +0000
    +++ /tmp/zshxTTscg      2020-03-20 18:00:04.239999929 +0000
    @@ -6 +6 @@
    -memoryuse       unlimited
    +resident        unlimited
    zsh: exit 1     diff -U0 =(zsh-5.7.1 -fc 'limit') =(limit)

It seems to be caused by the C implementation not having an equivalent
of the above piece of code. this difference intentional?

> +++ b/Src/Builtins/rlimits.c
> @@ -53,11 +40,214 @@ enum {
> +/* table of known resources */
> +static resinfo_t known_resources[] = {
> +    {RLIMIT_CPU, "cputime", ZLIMTYPE_TIME, 1,
> +		't', "cpu time (seconds)"},
> +    {RLIMIT_FSIZE, "filesize", ZLIMTYPE_MEMORY, 512,
> +		'f', "file size (blocks)"},
> ⋮

What will happen if two different elements of this array have the same
option letter?

When I simulate that (by manually changing the «'f'» to «'t'»), I get
output such as:
.
    % b/Src/zsh -fc 'ulimit -a'
    -t: cpu time (seconds)              unlimited
    ⋮
    -t: file size (blocks)              unlimited
.
Given this output, people are liable to invoke «ulimit -t» in an
attempt to change the file size limit.

Currently, each of the letters [mrvx] is used by two different elements.
I haven't checked whether both elements of any of these pairs can be
present on a single system, but in any case, more collisions may be
added in the future.

Therefore, I was wondering if we should have a test for this situation,
or possibly a runtime check; see the attached series for example.

Sorry for my slow response.

Cheers,

Daniel

[-- Attachment #2: 0001-zsh-rlimits-Make-known_resources-const-in-set_re.patch.txt --]
[-- Type: text/plain, Size: 2039 bytes --]

From 0f3dc2ee15c6bb1a005728d3d1107cd4da6e0c7f Mon Sep 17 00:00:00 2001
From: Daniel Shahaf <d.s@daniel.shahaf.name>
Date: Fri, 20 Mar 2020 18:48:28 +0000
Subject: [PATCH 1/2] zsh/rlimits: Make known_resources const in set_resinfo()
 but not elsewhere.

---
 Src/Builtins/rlimits.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/Src/Builtins/rlimits.c b/Src/Builtins/rlimits.c
index aa9b9dd48..c3c031fff 100644
--- a/Src/Builtins/rlimits.c
+++ b/Src/Builtins/rlimits.c
@@ -49,8 +49,13 @@ typedef struct resinfo_T {
     char* descr;	/* used by ulimit builtin */
 } resinfo_T;
 
-/* table of known resources */
-static const resinfo_T known_resources[] = {
+/* table of known resources
+ *
+ * Not const since set_resinfo() may change some of the letters to 'N' in case
+ * of collisions.  However, all access should be through the "resinfo" global,
+ * which exposes this as a const array.
+ */
+static resinfo_T known_resources[] = {
     {RLIMIT_CPU, "cputime", ZLIMTYPE_TIME, 1,
 		't', "cpu time (seconds)"},
     {RLIMIT_FSIZE, "filesize", ZLIMTYPE_MEMORY, 512,
@@ -175,14 +180,15 @@ static void
 set_resinfo(void)
 {
     int i;
+    resinfo_T **resinfo_mutable;
 
-    resinfo = (const resinfo_T **)zshcalloc(RLIM_NLIMITS*sizeof(resinfo_T *));
+    resinfo_mutable = (resinfo_T **)zshcalloc(RLIM_NLIMITS*sizeof(resinfo_T *));
 
     for (i=0; i<sizeof(known_resources)/sizeof(resinfo_T); ++i) {
-	resinfo[known_resources[i].res] = &known_resources[i];
+	resinfo_mutable[known_resources[i].res] = &known_resources[i];
     }
     for (i=0; i<RLIM_NLIMITS; ++i) {
-	if (!resinfo[i]) {
+	if (!resinfo_mutable[i]) {
 	    /* unknown resource */
 	    resinfo_T *info = (resinfo_T *)zshcalloc(sizeof(resinfo_T));
 	    char *buf = (char *)zalloc(12);
@@ -193,9 +199,11 @@ set_resinfo(void)
 	    info->unit = 1;
 	    info->opt = 'N';
 	    info->descr = buf;
-	    resinfo[i] = info;
+	    resinfo_mutable[i] = info;
 	}
     }
+
+    resinfo = (const resinfo_T **) resinfo_mutable;
 }
 
 /**/

[-- Attachment #3: 0002-zsh-rlimits-Ensure-option-letters-are-unambiguou.patch.txt --]
[-- Type: text/plain, Size: 2001 bytes --]

From 5ffb506e43cd8dd5ecd1945a93e854f1b735cfd5 Mon Sep 17 00:00:00 2001
From: Daniel Shahaf <d.s@daniel.shahaf.name>
Date: Fri, 20 Mar 2020 18:49:42 +0000
Subject: [PATCH 2/2] zsh/rlimits: Ensure option letters are unambiguous at
 runtime.

---
 Src/Builtins/rlimits.c | 15 +++++++++++++++
 Test/B12limit.ztst     | 10 ++++++++++
 2 files changed, 25 insertions(+)

diff --git a/Src/Builtins/rlimits.c b/Src/Builtins/rlimits.c
index c3c031fff..5c260e7db 100644
--- a/Src/Builtins/rlimits.c
+++ b/Src/Builtins/rlimits.c
@@ -181,11 +181,26 @@ set_resinfo(void)
 {
     int i;
     resinfo_T **resinfo_mutable;
+    char seen_letters[sizeof(known_resources)/sizeof(resinfo_T) + 1] = {0};
+    char *seen_p = seen_letters;
 
     resinfo_mutable = (resinfo_T **)zshcalloc(RLIM_NLIMITS*sizeof(resinfo_T *));
 
     for (i=0; i<sizeof(known_resources)/sizeof(resinfo_T); ++i) {
 	resinfo_mutable[known_resources[i].res] = &known_resources[i];
+
+	/* 
+	 * If this resource's option letter is already used, change its option
+	 * letter to 'N'.
+	 */
+	{
+	    char *current_letter = &known_resources[i].opt;
+	    if (*current_letter != 'N' && strchr(seen_letters, *current_letter)) {
+		DPUTS1(1, "duplicate ulimit option letter: %c", *current_letter);
+		*current_letter = 'N';
+	    }
+	    *seen_p++ = *current_letter;
+	}
     }
     for (i=0; i<RLIM_NLIMITS; ++i) {
 	if (!resinfo_mutable[i]) {
diff --git a/Test/B12limit.ztst b/Test/B12limit.ztst
index 5dd7afdbe..922751369 100644
--- a/Test/B12limit.ztst
+++ b/Test/B12limit.ztst
@@ -8,3 +8,13 @@
 F:A failure here does not indicate any error in zsh. It just means there
 F:is a resource in your system that is unknown to zsh developers. Please
 F:report this to zsh-workers mailing list.
+
+  () {
+    set -- ${(f)"$(ulimit -a)"}
+    set -- ${@%%:*}
+    typeset -aU unique_options=( "$@" )
+    # The value of $unique_options is, e.g., ( -t -f '-N 2' -s ... ).
+    (( $# == $#unique_options ))
+  }
+0:check if limit option letters are unique
+

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-03-20 18:39                                     ` Bart Schaefer
@ 2020-03-20 19:32                                       ` Daniel Shahaf
  0 siblings, 0 replies; 38+ messages in thread
From: Daniel Shahaf @ 2020-03-20 19:32 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Jun T, zsh-workers

Bart Schaefer wrote on Fri, 20 Mar 2020 11:39 -0700:
> On Fri, Mar 20, 2020 at 11:28 AM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> >
> > That is, we want the
> > test suite to fail if the module failed to load even though it was
> > enabled in config.modules.  
> 
> An alternate approach (and maybe one that the suite already supports,
> Test/V01zmodload.ztst?) is to separate the test for module loading
> bugs from the tests for module feature bugs.

I think that'd be just this? —

diff --git a/Test/V01zmodload.ztst b/Test/V01zmodload.ztst
index 0a7fbb651..daf49cd72 100644
--- a/Test/V01zmodload.ztst
+++ b/Test/V01zmodload.ztst
@@ -64,7 +64,7 @@
 
  for m in $mods
  do
-   zmodload $m || mods[(r)$m]=()
+   zmodload $m || return $?
  done
 0d:Test loading of all compiled modules
 
diff --git a/Test/V07pcre.ztst b/Test/V07pcre.ztst
index 1c2a5a4df..15a0982c8 100644
--- a/Test/V07pcre.ztst
+++ b/Test/V07pcre.ztst
@@ -1,11 +1,10 @@
 %prep
 
-  if grep '^name=zsh/pcre .* link=no ' $ZTST_testdir/../config.modules >/dev/null
+  if ! zmodload zsh/pcre 2>/dev/null; then
   then
     ZTST_unimplemented="the zsh/pcre module was disabled by configure (see config.modules)"
     return 0
   fi
-  zmodload zsh/pcre || return $?
   setopt rematch_pcre
 # Find a UTF-8 locale.
   setopt multibyte

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-03-20 18:36                                     ` Bart Schaefer
@ 2020-03-20 19:38                                       ` Daniel Shahaf
  0 siblings, 0 replies; 38+ messages in thread
From: Daniel Shahaf @ 2020-03-20 19:38 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Jun T, zsh-workers

Bart Schaefer wrote on Fri, 20 Mar 2020 11:36 -0700:
> On Fri, Mar 20, 2020 at 11:28 AM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > So, I think we should write a ZTST_* helper function that encapsulates
> > the config.modules check  
> 
> Seems reasonable.  It does presume that "make check" is always
> preceded by "make", but I suppose that's true most of the time.

Actually, «make check» implicitly builds modules before running the
tests.  For example, «make && rm Src/Modules/zutil.so && make check»
will re-build zutil.so before running tests.

However, «make check» doesn't build Src/zsh. ☹

Cheers,

Daniel

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-03-20 19:18                     ` Daniel Shahaf
@ 2020-03-23  5:31                       ` Jun T
  2020-03-24  2:08                         ` Daniel Shahaf
  2020-03-23  5:41                       ` Jun T
  1 sibling, 1 reply; 38+ messages in thread
From: Jun T @ 2020-03-23  5:31 UTC (permalink / raw)
  To: zsh-workers

reply 1/2 to workers/45590⁩
> 2020/03/21 4:18, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> 
> Continuing my review:
> 
> Jun T wrote on Tue, 25 Feb 2020 18:38 +0900:
>> 
>> -END {
>> -    if (limrev["MEMLOCK"] != "") {
>> -        irss = limrev["RSS"]
>> -        msg[irss] = "Mmemoryuse"
>> -    }  
> 
> Question.  I compared the output before and after the patch and I see
> the following difference:
> 
>    % diff -U0 =(zsh-5.7.1 -fc 'limit') =(limit)
>    --- /tmp/zshZXxkUD      2020-03-20 18:00:04.239999929 +0000
>    +++ /tmp/zshxTTscg      2020-03-20 18:00:04.239999929 +0000
>    @@ -6 +6 @@
>    -memoryuse       unlimited
>    +resident        unlimited
>    zsh: exit 1     diff -U0 =(zsh-5.7.1 -fc 'limit') =(limit)
> 
> It seems to be caused by the C implementation not having an equivalent
> of the above piece of code. this difference intentional?

Sorry, I just lazily ignored that part of rlimits.awk because:
I didn't understand why existence of RLIMIT_MEMLOCK affects the name
of RLIMIT_RSS, and,
on Linux ulimit prints it as "resident set size", and,
RLIMIT_RSS is used only in kernel 2.4.29 or earlier (on Linux).

# bash's builtin ulimit prints it as "max memory size" on Linux.

If compatibility with the previous version of zsh is important
we may use the patch below.

zshbuiltin man page also needs be updated. Do we need to list all the
known resources? Or just list most common resources and mention that,
for example, exact list of resources supported on your system can
be shown by running 'limit' or 'ulimit -a'?


diff --git a/Src/Builtins/rlimits.c b/Src/Builtins/rlimits.c
index aa9b9dd48..8f1d4b306 100644
--- a/Src/Builtins/rlimits.c
+++ b/Src/Builtins/rlimits.c
@@ -65,18 +65,23 @@ static const resinfo_T known_resources[] = {
     {RLIMIT_NOFILE, "descriptors", ZLIMTYPE_NUMBER, 1,
 		'n', "file descriptors"},
 # endif
+# ifdef HAVE_RLIMIT_MEMLOCK
+#  define RSS_NAME "memoryuse"
+# else
+#  define RSS_NAME "resident"
+# endif
 # if defined(HAVE_RLIMIT_AS) && !defined(RLIMIT_VMEM_IS_AS)
     {RLIMIT_AS, "addressspace", ZLIMTYPE_MEMORY, 1024,
 		'v', "address space (kbytes)"},
 # endif
 # if defined(HAVE_RLIMIT_RSS) && !defined(RLIMIT_VMEM_IS_RSS) && !defined(RLIMIT_RSS_IS_AS)
-    {RLIMIT_RSS, "resident", ZLIMTYPE_MEMORY, 1024,
+    {RLIMIT_RSS, RSS_NAME, ZLIMTYPE_MEMORY, 1024,
 		'm', "resident set size (kbytes)"},
 # endif
 # if defined(HAVE_RLIMIT_VMEM)
     {RLIMIT_VMEM,
 #  if defined(RLIMIT_VMEM_IS_RSS)
-		 "resident", ZLIMTYPE_MEMORY, 1024,
+		 RSS_NAME, ZLIMTYPE_MEMORY, 1024,
 		 'm', "memory size (kbytes)"
 #  else
 		 "vmemorysize", ZLIMTYPE_MEMORY, 1024,









^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-03-20 19:18                     ` Daniel Shahaf
  2020-03-23  5:31                       ` Jun T
@ 2020-03-23  5:41                       ` Jun T
  2020-03-24  1:33                         ` Jun T
  2020-03-24  2:34                         ` [PATCH] find RLIM_NLIMITS correctly on Cygwin Daniel Shahaf
  1 sibling, 2 replies; 38+ messages in thread
From: Jun T @ 2020-03-23  5:41 UTC (permalink / raw)
  To: zsh-workers

reply 2/2 to workers/45590⁩

> 2020/03/21 4:18, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> 
> Jun T wrote on Tue, 25 Feb 2020 18:38 +0900:
> 
>> +++ b/Src/Builtins/rlimits.c
>> @@ -53,11 +40,214 @@ enum {
>> +/* table of known resources */
>> +static resinfo_t known_resources[] = {
>> +    {RLIMIT_CPU, "cputime", ZLIMTYPE_TIME, 1,
>> +		't', "cpu time (seconds)"},
>> +    {RLIMIT_FSIZE, "filesize", ZLIMTYPE_MEMORY, 512,
>> +		'f', "file size (blocks)"},
>> ⋮
> 
> What will happen if two different elements of this array have the same
> option letter?
(snip)
> Currently, each of the letters [mrvx] is used by two different elements.
> I haven't checked whether both elements of any of these pairs can be
> present on a single system, but in any case, more collisions may be
> added in the future.

I believe *currently* there is no conflict. I was just hoping that
if someone add a new resource (with a new option letter) in the future
they will be sure to test it (by running 'ulimit-a') and notice the
conflict if any. But I agree this is too optimistic.

> Therefore, I was wondering if we should have a test for this situation,
> or possibly a runtime check; see the attached series for example.

Thank you for the patches.
Personally I feel only adding a test (B12limit.zsh) is enough for now, but
have no objection to adding a runtime check in rlimits.c.

Do we really need resinfo_mutable?
Changes to the data in known_resouces is done via the pointer current_letter:
char *current_letter = &known_resources[i].opt;
Constness of resinfo does not interfere with this.

# and the data for unknown resource (if any) is setup using the pointer
# resinfo_T *info = (resinfo_T *)zshcalloc(sizeof(resinfo_T));
# and the assignment "resinfo[i] = info" does not conflict with the
# constness of resinfo.

Using resinfo instead of resinfo_mutable gives no warning for me
(gcc on Linux and clang on macOS).


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-03-23  5:41                       ` Jun T
@ 2020-03-24  1:33                         ` Jun T
  2020-03-24  2:43                           ` Daniel Shahaf
  2020-03-24  2:34                         ` [PATCH] find RLIM_NLIMITS correctly on Cygwin Daniel Shahaf
  1 sibling, 1 reply; 38+ messages in thread
From: Jun T @ 2020-03-24  1:33 UTC (permalink / raw)
  To: zsh-workers


> 2020/03/23 14:41, I wrote:
> 
> Personally I feel only adding a test (B12limit.zsh) is enough for now, but
> have no objection to adding a runtime check in rlimits.c.

If I add the runtime check, and if there is a duplicated option letter,
I get the error message 'duplicate ulimit option letter' every time
I start zsh. This may be quite annoying for ordinary users.

B12limit.ztst (limit| grep UNKNOWN || print OK) fails due to the error
message; I think it's OK. But V01zmodload.ztst also fails due to the
message, and other tests would fail if they use the rlimits module.

So I think just adding a test for duplicated option letter is enough.
If someone add a new resource then it is their responsibility to
confirm that all the tests pass. I think ordinary users need not see
the error message.

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-03-23  5:31                       ` Jun T
@ 2020-03-24  2:08                         ` Daniel Shahaf
  0 siblings, 0 replies; 38+ messages in thread
From: Daniel Shahaf @ 2020-03-24  2:08 UTC (permalink / raw)
  To: Jun T; +Cc: zsh-workers

Jun T wrote on Mon, 23 Mar 2020 14:31 +0900:
> reply 1/2 to workers/45590⁩
> > 2020/03/21 4:18, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > 
> > Continuing my review:
> > 
> > Jun T wrote on Tue, 25 Feb 2020 18:38 +0900:  
> >> 
> >> -END {
> >> -    if (limrev["MEMLOCK"] != "") {
> >> -        irss = limrev["RSS"]
> >> -        msg[irss] = "Mmemoryuse"  
> >> -    }    
> > 
> > Question.  I compared the output before and after the patch and I see
> > the following difference:
> > 
> >    % diff -U0 =(zsh-5.7.1 -fc 'limit') =(limit)
> >    --- /tmp/zshZXxkUD      2020-03-20 18:00:04.239999929 +0000
> >    +++ /tmp/zshxTTscg      2020-03-20 18:00:04.239999929 +0000
> >    @@ -6 +6 @@
> >    -memoryuse       unlimited
> >    +resident        unlimited
> >    zsh: exit 1     diff -U0 =(zsh-5.7.1 -fc 'limit') =(limit)
> > 
> > It seems to be caused by the C implementation not having an equivalent
> > of the above piece of code. this difference intentional?  
> 
> Sorry, I just lazily ignored that part of rlimits.awk because:
> I didn't understand why existence of RLIMIT_MEMLOCK affects the name
> of RLIMIT_RSS, and,
> on Linux ulimit prints it as "resident set size", and,
> RLIMIT_RSS is used only in kernel 2.4.29 or earlier (on Linux).
> 
> # bash's builtin ulimit prints it as "max memory size" on Linux.
> 
> If compatibility with the previous version of zsh is important
> we may use the patch below.

I don't know what the rationale/purpose of that awk snippet was, so
I'll leave this to your judgement.  (The awk check has been there since
before the first git revision.)

> zshbuiltin man page also needs be updated. Do we need to list all the
> known resources? Or just list most common resources and mention that,
> for example, exact list of resources supported on your system can
> be shown by running 'limit' or 'ulimit -a'?

I'd vote for the latter.

Cheers,

Daniel

> +++ b/Src/Builtins/rlimits.c
> @@ -65,18 +65,23 @@ static const resinfo_T known_resources[] = {


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-03-23  5:41                       ` Jun T
  2020-03-24  1:33                         ` Jun T
@ 2020-03-24  2:34                         ` Daniel Shahaf
  1 sibling, 0 replies; 38+ messages in thread
From: Daniel Shahaf @ 2020-03-24  2:34 UTC (permalink / raw)
  To: Jun T; +Cc: zsh-workers

Jun T wrote on Mon, 23 Mar 2020 14:41 +0900:
> Changes to the data in known_resouces is done via the pointer current_letter:
> char *current_letter = &known_resources[i].opt;
> Constness of resinfo does not interfere with this.

Right.

> # and the data for unknown resource (if any) is setup using the pointer
> # resinfo_T *info = (resinfo_T *)zshcalloc(sizeof(resinfo_T));
> # and the assignment "resinfo[i] = info" does not conflict with the
> # constness of resinfo.

I agree about the assignment, but that allocation won't run for the case
at hand, will it?  In the second for loop, «resinfo[i]» (in the 'if'
condition) will be non-NULL; it will point to an element of
«known_resources» whose «opt» member will have been changed to 'N' by
the first for loop.

> Using resinfo instead of resinfo_mutable gives no warning for me
> (gcc on Linux and clang on macOS).
> 
> Do we really need resinfo_mutable?

I guess not.  That must be a relic from an earlier draft of that patch.
I will fix it if we decide to add the runtime verification.  Thanks for
the review. :-)

Cheers,

Daniel

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-03-24  1:33                         ` Jun T
@ 2020-03-24  2:43                           ` Daniel Shahaf
  2020-03-25  0:16                             ` Jun T
  0 siblings, 1 reply; 38+ messages in thread
From: Daniel Shahaf @ 2020-03-24  2:43 UTC (permalink / raw)
  To: Jun T; +Cc: zsh-workers

Jun T wrote on Tue, 24 Mar 2020 10:33 +0900:
> > 2020/03/23 14:41, I wrote:
> > 
> > Personally I feel only adding a test (B12limit.zsh) is enough for now, but
> > have no objection to adding a runtime check in rlimits.c.  
> 
> If I add the runtime check, and if there is a duplicated option letter,
> I get the error message 'duplicate ulimit option letter' every time
> I start zsh. This may be quite annoying for ordinary users.

That message is printed by the DPUTS1() macro.  That macro expands to
nothing unless the «DEBUG» preprocessor symbol is defined, which
happens if one runs configure with --enable-zsh-debug.  Ordinary users
shouldn't see that.

> B12limit.ztst (limit| grep UNKNOWN || print OK) fails due to the error
> message; I think it's OK. But V01zmodload.ztst also fails due to the
> message, and other tests would fail if they use the rlimits module.
> 

Only in --enable-zsh-debug mode, and the fix is trivial: edit
known_resources and change one of the two colliding resources' letter
to 'N'.  Does this address your concerns, or would you prefer something
more?  We could even remove the DPUTS1() call entirely.

> So I think just adding a test for duplicated option letter is enough.
> If someone add a new resource then it is their responsibility to
> confirm that all the tests pass. I think ordinary users need not see
> the error message.

They won't, unless they configure with --enable-zsh-debug.

Cheers,

Daniel

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-03-24  2:43                           ` Daniel Shahaf
@ 2020-03-25  0:16                             ` Jun T
  2020-03-25 22:04                               ` Daniel Shahaf
  0 siblings, 1 reply; 38+ messages in thread
From: Jun T @ 2020-03-25  0:16 UTC (permalink / raw)
  To: zsh-workers


> 2020/03/24 11:43, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> 
> Jun T wrote on Tue, 24 Mar 2020 10:33 +0900:
>> 
>> I get the error message 'duplicate ulimit option letter' every time
>> I start zsh. This may be quite annoying for ordinary users.
> 
> That message is printed by the DPUTS1() macro.

Whoops, sorry.

I think only someone here (zsh-workers) will add a new resource, and
I believe they will run the tests (but not sure they use
 --enable-zsh-debug). So just adding a test is sufficient, I think.

# Typical use of DPUTS() is to find a not-easy-to-find bug (corner cases
# etc.) which can be detected only by running zsh under various situations.
# Duplicated option letter should/can be detected more earlier.

As for the test:

> 2020/03/21 2:02, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> 
>> + limit | grep UNKNOWN || print OK
> 
> The "limit" builtin is provided by a module.  As such, it can be
> unavailable if the module had been disabled in config.modules prior to
> building.

So what the fix for this? Is it enough to skip the tests if loading
rlimits module fails (because we are testing module features, not
module loading)?

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin
  2020-03-25  0:16                             ` Jun T
@ 2020-03-25 22:04                               ` Daniel Shahaf
  2020-03-25 23:42                                 ` [PATCH] find RLIM_NLIMITS correctly on CygwinjL Daniel Shahaf
  0 siblings, 1 reply; 38+ messages in thread
From: Daniel Shahaf @ 2020-03-25 22:04 UTC (permalink / raw)
  To: Jun T; +Cc: zsh-workers

Jun T wrote on Wed, 25 Mar 2020 09:16 +0900:
> > 2020/03/24 11:43, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > 
> > Jun T wrote on Tue, 24 Mar 2020 10:33 +0900:  
> >> 
> >> I get the error message 'duplicate ulimit option letter' every time
> >> I start zsh. This may be quite annoying for ordinary users.  
> > 
> > That message is printed by the DPUTS1() macro.  
> 
> Whoops, sorry.
> 
> I think only someone here (zsh-workers) will add a new resource, and
> I believe they will run the tests (but not sure they use
>  --enable-zsh-debug). So just adding a test is sufficient, I think.
> 

Okay, I'll commit the test from 45590, then, and leave the rest out.

> > 2020/03/21 2:02, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> >   
> >> + limit | grep UNKNOWN || print OK  
> > 
> > The "limit" builtin is provided by a module.  As such, it can be
> > unavailable if the module had been disabled in config.modules prior to
> > building.  
> 
> So what the fix for this? Is it enough to skip the tests if loading
> rlimits module fails (because we are testing module features, not
> module loading)?

Yes, I think so.  The patch in 45591 will take care of testing that
zmodload succeeds.  With that patch, B12limit.ztst can just do
«if ! zmodload …; ZTST_unimplemented=…» like all other V*ztst files:
zmodload errors will be caught by 45591.

Cheers,

Daniel

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH] find RLIM_NLIMITS correctly on CygwinjL
  2020-03-25 22:04                               ` Daniel Shahaf
@ 2020-03-25 23:42                                 ` Daniel Shahaf
  0 siblings, 0 replies; 38+ messages in thread
From: Daniel Shahaf @ 2020-03-25 23:42 UTC (permalink / raw)
  To: Jun T; +Cc: zsh-workers

Daniel Shahaf wrote on Wed, 25 Mar 2020 22:04 +0000:
> Jun T wrote on Wed, 25 Mar 2020 09:16 +0900:
> > > 2020/03/24 11:43, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > > 2020/03/21 2:02, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > >     
> > >> + limit | grep UNKNOWN || print OK    
> > > 
> > > The "limit" builtin is provided by a module.  As such, it can be
> > > unavailable if the module had been disabled in config.modules prior to
> > > building.    
> > 
> > So what the fix for this? Is it enough to skip the tests if loading
> > rlimits module fails (because we are testing module features, not
> > module loading)?  
> 
> Yes, I think so.  The patch in 45591 will take care of testing that
> zmodload succeeds.  With that patch, B12limit.ztst can just do
> «if ! zmodload …; ZTST_unimplemented=…» like all other V*ztst files:
> zmodload errors will be caught by 45591.

So, to be concrete, how about the following? —

workers/45591 (with conflicts fixed):

[[[
diff --git a/Test/V01zmodload.ztst b/Test/V01zmodload.ztst
index 0a7fbb651..daf49cd72 100644
--- a/Test/V01zmodload.ztst
+++ b/Test/V01zmodload.ztst
@@ -64,7 +64,7 @@
 
  for m in $mods
  do
-   zmodload $m || mods[(r)$m]=()
+   zmodload $m || return $?
  done
 0d:Test loading of all compiled modules
 
diff --git a/Test/V07pcre.ztst b/Test/V07pcre.ztst
index ab67f3d80..15a0982c8 100644
--- a/Test/V07pcre.ztst
+++ b/Test/V07pcre.ztst
@@ -1,11 +1,10 @@
 %prep
 
-  if grep '^name=zsh/pcre .* link=no ' $ZTST_testdir/../config.modules >/dev/null
+  if ! zmodload zsh/pcre 2>/dev/null; then
   then
     ZTST_unimplemented="the zsh/pcre module was disabled by configure (see config.modules)"
     return 0
   fi
-  zmodload zsh/pcre
   setopt rematch_pcre
 # Find a UTF-8 locale.
   setopt multibyte
]]]

Followed by 45584, adjusted for the above:

[[[
diff --git a/Test/B12limit.ztst b/Test/B12limit.ztst
index 922751369..48d33e6e3 100644
--- a/Test/B12limit.ztst
+++ b/Test/B12limit.ztst
@@ -1,4 +1,12 @@
-# check if there is unknown resouce(s)
+
+%prep
+
+  if ! zmodload zsh/rlimits 2>/dev/null
+  then
+    ZTST_unimplemented="the zsh/rlimits module was disabled by configure (see config.modules)"
+    return 0
+  fi
+  zmodload zsh/rlimits
 
 %test
]]]

Cheers,

Daniel

^ permalink raw reply	[flat|nested] 38+ messages in thread

end of thread, back to index

Thread overview: 38+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-08 10:39 [PATCH] find RLIM_NLIMITS correctly on Cygwin Jun T
2020-01-08 21:33 ` Daniel Shahaf
2020-01-09 10:32   ` Jun T
2020-01-09 13:15     ` Daniel Shahaf
2020-01-10 10:24       ` Jun T
2020-01-11 20:15         ` Daniel Shahaf
2020-01-13 11:00           ` Jun T
2020-01-13 16:42             ` Daniel Shahaf
2020-01-14  4:44               ` Jun T
2020-01-14 16:25                 ` Daniel Shahaf
2020-02-25  9:38                   ` Jun T
2020-02-27 13:22                     ` Daniel Shahaf
2020-02-27 18:46                       ` Mikael Magnusson
2020-02-28  8:42                       ` Jun T
2020-02-28 14:19                         ` Daniel Shahaf
2020-02-28 14:31                           ` Daniel Shahaf
2020-03-03  9:23                           ` Jun T
2020-03-04 19:29                             ` Daniel Shahaf
2020-03-05 10:26                               ` Jun T
2020-03-05 14:58                                 ` Daniel Shahaf
2020-03-20 17:02                             ` Daniel Shahaf
2020-03-20 17:20                               ` Bart Schaefer
2020-03-20 17:39                                 ` Daniel Shahaf
2020-03-20 18:28                                   ` Daniel Shahaf
2020-03-20 18:36                                     ` Bart Schaefer
2020-03-20 19:38                                       ` Daniel Shahaf
2020-03-20 18:39                                     ` Bart Schaefer
2020-03-20 19:32                                       ` Daniel Shahaf
2020-03-20 19:18                     ` Daniel Shahaf
2020-03-23  5:31                       ` Jun T
2020-03-24  2:08                         ` Daniel Shahaf
2020-03-23  5:41                       ` Jun T
2020-03-24  1:33                         ` Jun T
2020-03-24  2:43                           ` Daniel Shahaf
2020-03-25  0:16                             ` Jun T
2020-03-25 22:04                               ` Daniel Shahaf
2020-03-25 23:42                                 ` [PATCH] find RLIM_NLIMITS correctly on CygwinjL Daniel Shahaf
2020-03-24  2:34                         ` [PATCH] find RLIM_NLIMITS correctly on Cygwin Daniel Shahaf

zsh-workers

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-workers

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git