git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCHv3 2/2] read-tree: migrate to parse-options

From
Stephen Boyd <bebarino@gmail.com>
Date
Jun 27, 2009, 02:00 UTC
Message-ID
<4A457D31.9030407@gmail.com>
In-Reply-To
<7vab3uucxi.fsf@alter.siamese.dyndns.org>
Junio C Hamano wrote:
Show 13 quoted lines
>
> Let's look at this (not this follow-up patch) the other way around.
>
> Six months down the load, somebody may ask you:
>
>     Is there a good reason why many are not bitfields but only selected
>     few are bitfields in this structure?  Most of these can and should be
>     bitfields, as far as I can see, because the code uses them as
>     booleans, and the only breakage it may cause if we change them to
>     bitfields to shrink this structure would be the option parsing code.
>
> What would be your answer?  Doesn't it feel wrong to do such a conversion
> only to work around the current limitation of parseopt?

I understand. It does feel wrong to do this just to workaround parseopts, but I was assuming this wasn't a performance critical struct because Hannes said it wasn't set in stone. Of course, it also feels wrong to have the foo ? 1 : 0, but I think it's less wrong. This is why I had the foo ? 1 : 0 constructs in v2, because I felt that making this more radical change would lead to just this question. As a bonus, having these ugly constructs encourages someone to come up with a way to handle bit fields in parseopts.

Show 24 quoted lines
>
> By the way, has it been verified that all the users of these fields are OK
> with this change when they use these fields?  I am not worried about them
> reading the value command line option parser set, but more worried about
> reading after other codepaths set/modified these fields.  The command line
> parser that uses parseopt may correctly set only 0 or 1 to these fields
> initially and we should be able to verify that from the patch text, but
> there is no guarantee that this conversion is even correct at runtime
> without an audit, no?
>
> The callers have long relied on the fact that reading from these bitfields
> yields either 0 or 1 and never 2 or larger, but they are now widened to
> full-width unsigned.  A pattern like this:
>
> 	uto.field = ~uto.field;
>         if (uto.field == 1) {
>         	field now set;
> 	} else {
>         	field now unset;
> 	}
>
> would be broken by widening "unsigned field:1" to "unsigned field", right?
> I am not saying this is the only pattern that would break, nor I know
> there are codepaths that use this pattern, but I think you got my point.

Yes. I glanced over the users of unpack_trees_options and didn't see anything dangerous like the above example. It wasn't a really thorough audit though because I was hoping that the callers were treating them as booleans, and not bits.

Previous: Junio C Hamano
Message 12 of 12 in “read-tree: convert unhelpful usage()'s to helpful die()'s”
  1. 1/2 read-tree: convert unhelpful usage()'s to helpful die()'sStephen Boyd, Jun 24, 2009
  2. 2/2 read-tree: migrate to parse-optionsStephen Boyd, Jun 24, 2009
  3. Junio C HamanoJun 24, 2009
  4. Stephen BoydJun 25, 2009
  5. 2/2 read-tree: migrate to parse-optionsStephen Boyd, Jun 25, 2009
  6. Johannes SixtJun 25, 2009
  7. Stephen BoydJun 26, 2009
  8. 1/2 read-tree: convert unhelpful usage()'s to helpful die()'sStephen Boyd, Jun 26, 2009
  9. 2/2 read-tree: migrate to parse-optionsStephen Boyd, Jun 26, 2009
  10. Stephen BoydJun 26, 2009
  11. Junio C HamanoJun 26, 2009
  12. Stephen BoydJun 27, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.