public inbox for linux-rt-users@vger.kernel.org
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Crystal Wood <crwood@redhat.com>
Cc: Costa Shulyupin <costa.shul@redhat.com>,
	linux-rt-users <linux-rt-users@vger.kernel.org>,
	John Kacur <jkacur@redhat.com>, Tomas Glozar <tglozar@redhat.com>
Subject: Re: [PATCH v1] cyclictest: Generate optstring dynamically from long_options
Date: Tue, 13 Jan 2026 09:13:00 +0100	[thread overview]
Message-ID: <20260113081300.s3s115wU@linutronix.de> (raw)
In-Reply-To: <e64e7188a920634fce126fc71ccc09696984f42f.camel@redhat.com>

On 2026-01-12 15:13:22 [-0600], Crystal Wood wrote:
> > --- /dev/null
> > +++ b/src/lib/opt.c
> > @@ -0,0 +1,29 @@
> > +// SPDX-License-Identifier: GPL-2.0-or-later
> > +#include <stdlib.h>
> > +
> > +#include "opt.h"
> > +
> > +char *build_optstring(const struct option *long_opts)
> > +{
> > +	char *opts = NULL;
> > +	int n = 0;
> > +
> > +	for (int i = 0; long_opts[i].name; i++) {
> > +		opts = realloc(opts, n + 4);
> 
> I realize this isn't going to be noticeable even if it ends up being a
> copy each time, but linear realloc like this makes me twinge and think
> of how just about every other language in common use would have a
> readily available growable string implementation :-P

and assume you never run out of memory…

> > +
> > +		if (long_opts[i].flag || long_opts[i].val < 32 || long_opts[i].val > 127)
> > +			continue;
> 
> What happens if the OPT enum grows beyond 32 entries?  It's already at
> 16.  Maybe start the enum at 0x100, and print an error if val is less
> than that but not valid for getopt?
> 
> Why is the implementation (slightly) different here versus the rtla
> patch?  We should probably use an enum in rtla instead of '4', '\1',
> etc. as well.

GNU ARGP might be easier to parse and maintain in the long run
especially if 20 other options are added.
	https://www.gnu.org/software/libc/manual/html_node/Argp-Example-4.html

> -Crystal

Sebastian

  reply	other threads:[~2026-01-13  8:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-10 11:37 [PATCH v1] cyclictest: Generate optstring dynamically from long_options Costa Shulyupin
2026-01-12 21:13 ` Crystal Wood
2026-01-13  8:13   ` Sebastian Andrzej Siewior [this message]
2026-01-13 10:00     ` Costa Shulyupin
2026-01-13 11:14       ` Sebastian Andrzej Siewior
2026-01-13 23:41         ` Crystal Wood
2026-01-13 23:34     ` Crystal Wood
2026-01-13 12:45   ` Costa Shulyupin

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=20260113081300.s3s115wU@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=costa.shul@redhat.com \
    --cc=crwood@redhat.com \
    --cc=jkacur@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=tglozar@redhat.com \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox