Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCHv2 2/2] [long] improvements to limit/ulimit API and doc (the rest)
- X-seq: zsh-workers 47665
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: [PATCHv2 2/2] [long] improvements to limit/ulimit API and doc (the rest)
- Date: Fri, 27 Nov 2020 16:39:49 +0000
- Archived-at: <https://zsh.org/workers/47665>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2020-11/20201127163949.GD26720%40tarpaulin.shahaf.local2>
- Authentication-results: zsh.org; iprev=pass (out3-smtp.messagingengine.com) smtp.remote-ip=66.111.4.27; dkim=pass header.d=daniel.shahaf.name header.s=fm2 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm1 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:to:subject:message-id:references :mime-version:content-type:content-transfer-encoding :in-reply-to; s=fm2; bh=HrTTQYBC7Acn6yXU5p8A1YFD6Afi2un/hb6i2rAk EqI=; b=fbNE6Z6FDdUNN9zzS/+3OAZqfeOcD4VSPTQO2nRjqCmKAvDxIKxNpQYw pUC2hPwKb+QHodbFUD6J94Wn0RXsAF1C6uOZvU0rZ/teemZTHQvZrZ7YgybwkifA BgbWQK0AZW2nM/MHv5HRhAfCgc/cRh8BGCOTAAFaQ2x7P0yuedGpzi6Q9emAgETE ra/11gpOIUaOQpxYuR23fV9nO8jBj8T6gAJH8bGdkz3dY4hy2rcp/8K2c5tnzY8H +O8t2toipRUNz8scluuergmOKG8U8CT7ChMT27G6rhPV1L6PS3VGLfDcjqLUlygS Vrzpi+7UFJb/cYUKXG+nyFWXgVRlcg==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=HrTTQYBC7Acn6yXU5p8A1YFD6Afi2un/hb6i2rAkE qI=; b=XUcawYhYkh3Sa5PKfmTbddb1gcTgIhR7Xsb7hZUbSoh5wmX0Uu95ntCdm VGj65ffYa7OsFY9oYRtTaNMBxdoUPKSBETEbsY+7xCmnlU5qXAU8Rk6hR840xOlz 0Mz+MhrEHX28CIHj4zxTWOsv8+grYX3fhRoKOi3ytivVKveFiSNplZtd+QUZ0BuG k+Xlen7LUs8HKxQbYqsHbcWy8zleO4fE4oCwOqzwpl2bIiI173CCTghjtoPNUwOn YFax1jCVno/JJHls8RIBt+0mwZm783DB5giynMkhGedYGKeyRhMxrMGRstBPgqjq p/n7w073HayV3Av0Oq1GjTfBNuprQ==
- In-reply-to: <20201126205819.dbncs24ppnw3pdny@chazelas.org>
- List-archive: <http://www.zsh.org/sympa/arc/zsh-workers>
- List-help: <mailto:sympa@zsh.org?subject=help>
- List-id: <zsh-workers.zsh.org>
- List-owner: <mailto:zsh-workers-request@zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-subscribe: <mailto:sympa@zsh.org?subject=subscribe%20zsh-workers>
- List-unsubscribe: <mailto:sympa@zsh.org?subject=unsubscribe%20zsh-workers>
- References: <20201123214942.hi2rx7n3jk25ucmd@chazelas.org> <74327-1606347813.918593@HxCz.NV4p.AwzH> <20201126205819.dbncs24ppnw3pdny@chazelas.org>
- Sender: zsh-workers-request@xxxxxxx
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)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author