From: Stephen Boyd <bebarino@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Johannes Sixt <j.sixt@viscovery.net>
Subject: Re: [PATCHv3 2/2] read-tree: migrate to parse-options
Date: Fri, 26 Jun 2009 19:00:17 -0700 [thread overview]
Message-ID: <4A457D31.9030407@gmail.com> (raw)
In-Reply-To: <7vab3uucxi.fsf@alter.siamese.dyndns.org>
Junio C Hamano wrote:
>
> 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.
>
> 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.
prev parent reply other threads:[~2009-06-27 2:00 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-24 4:27 [PATCH 1/2] read-tree: convert unhelpful usage()'s to helpful die()'s Stephen Boyd
2009-06-24 4:27 ` [PATCH 2/2] read-tree: migrate to parse-options Stephen Boyd
2009-06-24 5:08 ` Junio C Hamano
2009-06-25 1:36 ` Stephen Boyd
2009-06-25 5:06 ` [PATCHv2 " Stephen Boyd
2009-06-25 6:55 ` Johannes Sixt
2009-06-26 3:15 ` Stephen Boyd
2009-06-26 5:14 ` [PATCHv3 1/2] read-tree: convert unhelpful usage()'s to helpful die()'s Stephen Boyd
2009-06-26 5:14 ` [PATCHv3 2/2] read-tree: migrate to parse-options Stephen Boyd
2009-06-26 5:29 ` Stephen Boyd
2009-06-26 17:23 ` Junio C Hamano
2009-06-27 2:00 ` Stephen Boyd [this message]
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A457D31.9030407@gmail.com \
--to=bebarino@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j.sixt@viscovery.net \
/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://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).