zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [PATCHv2 2/2] [long] improvements to limit/ulimit API and doc (the rest)
Date: Fri, 27 Nov 2020 16:39:49 +0000	[thread overview]
Message-ID: <20201127163949.GD26720@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <20201126205819.dbncs24ppnw3pdny@chazelas.org>

Stephane Chazelas wrote on Thu, Nov 26, 2020 at 20:58:19 +0000:
> +++ b/Src/Builtins/rlimits.c
> @@ -255,38 +267,204 @@ printrlim(rlim_t val, const char *unit)
>  # endif /* RLIM_T_IS_QUAD_T */
>  }
>  
> +/*
> + * Parse a string into the corresponding value based on the limit type
> + *
> + *   ZLIMTYPE_UNKNOWN / ZLIMTYPE_NUMBER:
> + *     decimal integer without sign only: raw value
> + *
> + *   ZLIMTYPE_TIME / ZLIMTYPE_MICROSECONDS:
> + *     <decimal> only gives seconds or microseconds depending on type
> + *     or:
> + *     [[hour:]min:]sec[.usec]
> + *     or:
> + *     <decimal> with h (hour), m (min), s (sec), ms, us suffix.
> + *
> + *   ZLIMTYPE_MEMORY:
> + *     <decimal> without suffix interpreted as KiB by "limit" (except for
> + *     RLIMIT_MSGQUEUE, see below) and based on resinfo.unit by "ulimit".
> + *
> + *     K/M/G/T/P/E suffix and same with iB suffix use 1024 factor
> + *     KB/MB/GB... use 1000 factor.
> + *
> + *     B for bytes (avoids that mess about default units).
> + *
> + * All suffixes are case insensitive.
> + *
> + */
> +
>  /**/
>  static rlim_t
> -zstrtorlimt(const char *s, char **t, int base)
> +zstrtorlimt(const char *s, int lim, int ulimit, char **err)

Please specify in the docstring the types, values, and meanings of the
formal parameters.

>  {
>      rlim_t ret = 0;
> +    const char *orig = s;
> +    enum zlimtype type = resinfo[lim]->type;
> +    *err = NULL;
> +    else if (type == ZLIMTYPE_TIME ||
> +	     type == ZLIMTYPE_MICROSECONDS) {
> +	    default:
> +		*err = "invalid time specification";

Could you arrange for the invalid value to be included in the error
message, as in «zwarnnam(nam, "invalid time specification: %s", foo)»?
That tends to be more user-friendly, particularly when the call stack is
deep.

> +		return 0;
> +	    }
> +
> +	    if (*s) {
> +		*err = "invalid time specification";
> +		return 0;
> +	    }
> +
> +	    ret *= factor;
> +	    if (type == ZLIMTYPE_MICROSECONDS)
> +		ret *= 1000000 / divisor;
> +	    else
> +		ret /= divisor;
> +	}
> +    }
> @@ -543,61 +763,12 @@ bin_limit(char *nam, char **argv, Options ops, UNUSED(int func))
> +	val = zstrtorlimt(s, lim, 0, &err);
> +	if (err) {
> +	    zwarnnam(nam, err);

This should be zwarnnam(nam, "%s", err), otherwise any percent signs in
«err» would cause breakage.

> +	    return 1;
>  	}
>  	if (do_limit(nam, lim, val, hard, !hard, OPT_ISSET(ops, 's')))
>  	    ret++;

Cheers,

Daniel
(haven't done a full review; just ran into thils in skimming)



  reply	other threads:[~2020-11-27 16:40 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-23 21:49 [PATCHv1] [long] improvements to limit/ulimit API and doc Stephane Chazelas
2020-11-25  0:35 ` Daniel Shahaf
2020-11-25  6:44   ` Stephane Chazelas
2020-11-27 17:16     ` Daniel Shahaf
2020-11-26  6:57   ` [PATCHv2 1/2] [long] improvements to limit/ulimit API and doc ((un)limit in csh emulation) Stephane Chazelas
2020-11-25 23:43 ` [PATCHv1] [long] improvements to limit/ulimit API and doc Oliver Kiddle
2020-11-26 20:14   ` [PATCH] ulimit option completions using ulimit -a output Stephane Chazelas
2020-11-27  7:13     ` Stephane Chazelas
2020-11-27  8:15       ` Felipe Contreras
2020-11-27 12:19       ` Oliver Kiddle
2021-03-27 21:25         ` Lawrence Velázquez
2021-04-03 14:57           ` Lawrence Velázquez
2021-04-10 20:11             ` Lawrence Velázquez
2021-04-13 14:35     ` Daniel Shahaf
2021-05-09 20:37       ` Lawrence Velázquez
2021-05-11 19:05         ` Stephane Chazelas
2020-11-26 20:58   ` [PATCHv2 2/2] [long] improvements to limit/ulimit API and doc (the rest) Stephane Chazelas
2020-11-27 16:39     ` Daniel Shahaf [this message]
2020-11-27 20:13       ` Stephane Chazelas
2020-11-27 20:36         ` Daniel Shahaf
2020-11-28  6:52           ` zsh coding style (was about a limit patch review) Stephane Chazelas
2020-12-01 16:47             ` Daniel Shahaf
2020-11-28  8:16         ` [PATCHv3 2/2] [long] improvements to limit/ulimit API and doc (the rest) Stephane Chazelas
2021-03-27 21:21           ` Lawrence Velázquez
2021-03-31 18:06             ` Stephane Chazelas
2020-11-26 11:19 ` [PATCHv1] [long] improvements to limit/ulimit API and doc Jun T
2020-11-26 13:55   ` Stephane Chazelas
2020-11-26 15:22     ` Jun. T
2020-11-26 17:23       ` Stephane Chazelas
2020-11-27 18:24         ` Jun. T
2020-11-27 18:34           ` Daniel Shahaf
2020-11-27 20:46           ` Stephane Chazelas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201127163949.GD26720@tarpaulin.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).