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

Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin



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"] != "") {
> 
> 
>



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