git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] GSoC Micoproject: Hunt down signed int flags
@ 2016-02-21 11:13 Saurav Sachidanand
  2016-02-21 23:22 ` Moritz Neeb
  2016-02-22  9:32 ` Duy Nguyen
  0 siblings, 2 replies; 4+ messages in thread
From: Saurav Sachidanand @ 2016-02-21 11:13 UTC (permalink / raw)
  To: git; +Cc: Saurav Sachidanand

This is patch is for a suggested micro project for GSoC 2016; namely,
that of searching for a field of a struct that is of signed integral
type and used as a collection of multiple bits, and converting it to
an unsigned type if the MSB isn’t used in any special way.

Two structs, `pattern` defined in attr.c and `exclude` defined in dir.h,
have a `flags` field of signed int type. The fields of both structs take
on values from the same set of positive integers {1, 4, 8, 16},
enumerated through the marco EXC_FLAG_*. `pattern` is used only in attr.c,
and `exclude` is used only in builtin/check-ignore.c and dir.c, and in
those files, either, the value of `flags` is checked using the `&` operator
(e.g.: flags & EXC_FLAG_NODIR), or the value of `flags` is first set to 0
and then set to any one of {1, 4, 8, 16} using the `|=` operator
(e.g.: flags |= EXC_FLAG_NODIR). And, so it does not appear that the MSB
of `flags` is used in any special way. Therefore, I thought to change the
type of `flags` in the definitions of both structs to `unsigned int`.

Furthermore, `flags` is passed by reference (of `pattern` in attr.c and of
`exclude` in dir.c) to the function `parse_exclude_pattern` defined in
dir.c, that accepts an `int *` type for `flags`. When make was run, it gave
a warning for ‘converting between pointers to integer types of different
sign’, so I changed the type of that respective argument to `unsigned int *`.

In the end, running make to build didn’t produce any more warnings, and
running make in t/ didn’t produce any breakage that wasn’t ‘#TODO known
breakage’.

I also thought it’d be helpful to add the comment /* EXC_FLAG_* */ next
to `flags` of `exclude`, just like it exists for `flags` of `pattern`.

Signed-off-by: Saurav Sachidanand <sauravsachidanand@gmail.com>
---
 attr.c | 2 +-
 dir.c  | 4 ++--
 dir.h  | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/attr.c b/attr.c
index 086c08d..874f726 100644
--- a/attr.c
+++ b/attr.c
@@ -124,7 +124,7 @@ struct pattern {
 	const char *pattern;
 	int patternlen;
 	int nowildcardlen;
-	int flags;		/* EXC_FLAG_* */
+	unsigned int flags;		/* EXC_FLAG_* */
 };
 
 /*
diff --git a/dir.c b/dir.c
index f0b6d0a..2d657e1 100644
--- a/dir.c
+++ b/dir.c
@@ -457,7 +457,7 @@ int no_wildcard(const char *string)
 
 void parse_exclude_pattern(const char **pattern,
 			   int *patternlen,
-			   int *flags,
+			   unsigned int *flags,
 			   int *nowildcardlen)
 {
 	const char *p = *pattern;
@@ -498,7 +498,7 @@ void add_exclude(const char *string, const char *base,
 {
 	struct exclude *x;
 	int patternlen;
-	int flags;
+	unsigned int flags;
 	int nowildcardlen;
 
 	parse_exclude_pattern(&string, &patternlen, &flags, &nowildcardlen);
diff --git a/dir.h b/dir.h
index cd46f30..6d205f0 100644
--- a/dir.h
+++ b/dir.h
@@ -27,7 +27,7 @@ struct exclude {
 	int nowildcardlen;
 	const char *base;
 	int baselen;
-	int flags;
+	unsigned int flags;		/* EXC_FLAG_* */
 
 	/*
 	 * Counting starts from 1 for line numbers in ignore files,
@@ -241,7 +241,7 @@ extern struct exclude_list *add_exclude_list(struct dir_struct *dir,
 extern int add_excludes_from_file_to_list(const char *fname, const char *base, int baselen,
 					  struct exclude_list *el, int check_index);
 extern void add_excludes_from_file(struct dir_struct *, const char *fname);
-extern void parse_exclude_pattern(const char **string, int *patternlen, int *flags, int *nowildcardlen);
+extern void parse_exclude_pattern(const char **string, int *patternlen, unsigned int *flags, int *nowildcardlen);
 extern void add_exclude(const char *string, const char *base,
 			int baselen, struct exclude_list *el, int srcpos);
 extern void clear_exclude_list(struct exclude_list *el);
-- 
2.7.1.339.g0233b80

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] GSoC Micoproject: Hunt down signed int flags
  2016-02-21 11:13 [PATCH] GSoC Micoproject: Hunt down signed int flags Saurav Sachidanand
@ 2016-02-21 23:22 ` Moritz Neeb
  2016-02-22  0:48   ` Eric Sunshine
  2016-02-22  9:32 ` Duy Nguyen
  1 sibling, 1 reply; 4+ messages in thread
From: Moritz Neeb @ 2016-02-21 23:22 UTC (permalink / raw)
  To: Saurav Sachidanand, git

Thanks for your patch. Just to let you know, this will be my first
review, but I hope it will be helpful anyway. I will mostly review your
commit text. First some general remarks:

The text you are submitting with you email is directly used as commit
message (the email subject as well, as the first line). You might want
to take care that the description is useful as a "bit of history", I
will give examples of what I mean below. Some guidelines for that can be
found in "Documentation/SubmittingPatches" section (2).

On 02/21/2016 12:13 PM, Saurav Sachidanand wrote:
> This is patch is for a suggested micro project for GSoC 2016; namely,
> that of searching for a field of a struct that is of signed integral
> type and used as a collection of multiple bits, and converting it to
> an unsigned type if the MSB isn’t used in any special way.

Especially, you might not want to include the fact that this is a GSoC
project. You might want to add this kind of information in the
"notes"-section of your email after the three dashes "---", this will be
skipped when the patch is applied.

> Two structs, `pattern` defined in attr.c and `exclude` defined in dir.h,
> have a `flags` field of signed int type. 

I have never seen the Markdown-style quotes ` in git.git commits. To be
in the same style as previous git (which helps e.g. in readability
because it is homogeneous), you can use the "-quote for code. Or even
leave them out if its clear from context.

> The fields of both structs take
> on values from the same set of positive integers {1, 4, 8, 16},
> enumerated through the marco EXC_FLAG_*.

marco -> macro.

I'd say this is a good observation to state.

Maybe it's also helpful to further explain why the two structs are
logically connected, or if that turns out to be false, to split up you
changes into two commits. I am not fully convinced that it should be one
commit.

>`pattern` is used only in attr.c,
> and `exclude` is used only in builtin/check-ignore.c and dir.c, and in
> those files, either, the value of `flags` is checked using the `&` operator
> (e.g.: flags & EXC_FLAG_NODIR), or the value of `flags` is first set to 0
> and then set to any one of {1, 4, 8, 16} using the `|=` operator
> (e.g.: flags |= EXC_FLAG_NODIR). And, so it does not appear that the MSB
> of `flags` is used in any special way.

This is the conclusion that is needed, but you might want state it more
direct, like "the MSB is not used...".

> Therefore, I thought to change the
> type of `flags` in the definitions of both structs to `unsigned int`.
> Furthermore, `flags` is passed by reference (of `pattern` in attr.c and of
> `exclude` in dir.c) to the function `parse_exclude_pattern` defined in
> dir.c, that accepts an `int *` type for `flags`.
> When make was run, it gave
> a warning for ‘converting between pointers to integer types of different
> sign’, so I changed the type of that respective argument to `unsigned int *`.

I think this explanation can be left out or has to be replaced by
something less compiler-driven, i.e. why does it actually make sense for
parse_exclude_pattern to have an unsigned int flags as parameter.

> In the end, running make to build didn’t produce any more warnings, and
> running make in t/ didn’t produce any breakage that wasn’t ‘#TODO known
> breakage’.

For the tests it is, from what I've seen, just assumed that you ran them
(and the reviewers/the maintainer will confirm this for themselves), so
no need to mention it. But it's good you ran them.

> I also thought it’d be helpful to add the comment /* EXC_FLAG_* */ next
> to `flags` of `exclude`, just like it exists for `flags` of `pattern`.

I would reformulate this as well more direct to something like "when
we're at it, document exclude->flags as EXC_FLAG".

Thanks,
Moritz

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] GSoC Micoproject: Hunt down signed int flags
  2016-02-21 23:22 ` Moritz Neeb
@ 2016-02-22  0:48   ` Eric Sunshine
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Sunshine @ 2016-02-22  0:48 UTC (permalink / raw)
  To: Moritz Neeb; +Cc: Saurav Sachidanand, Git List

On Sun, Feb 21, 2016 at 6:22 PM, Moritz Neeb <lists@moritzneeb.de> wrote:
> Thanks for your patch. Just to let you know, this will be my first
> review, but I hope it will be helpful anyway. I will mostly review your
> commit text. First some general remarks:

Thanks for taking on this review. I think you've covered everything I
was going to say (thus saving me a lot of time). I agree with pretty
much everything you said, with (I think) only one exception (below).

> The text you are submitting with you email is directly used as commit
> message (the email subject as well, as the first line). You might want
> to take care that the description is useful as a "bit of history", I
> will give examples of what I mean below. Some guidelines for that can be
> found in "Documentation/SubmittingPatches" section (2).
>
> On 02/21/2016 12:13 PM, Saurav Sachidanand wrote:
>> This is patch is for a suggested micro project for GSoC 2016; namely,
>> that of searching for a field of a struct that is of signed integral
>> type and used as a collection of multiple bits, and converting it to
>> an unsigned type if the MSB isn’t used in any special way.
>
> Especially, you might not want to include the fact that this is a GSoC
> project. You might want to add this kind of information in the
> "notes"-section of your email after the three dashes "---", this will be
> skipped when the patch is applied.

Correct. That this was a GSoC mini-project is not interesting in the
permanent project history, but it's helpful information for reviewers,
so you'd place it in the commentary section after the "---" just below
your sign-off.

>> Two structs, `pattern` defined in attr.c and `exclude` defined in dir.h,
>> have a `flags` field of signed int type.
>
> I have never seen the Markdown-style quotes ` in git.git commits. To be
> in the same style as previous git (which helps e.g. in readability
> because it is homogeneous), you can use the "-quote for code. Or even
> leave them out if its clear from context.
>
>> The fields of both structs take
>> on values from the same set of positive integers {1, 4, 8, 16},
>> enumerated through the marco EXC_FLAG_*.
>
> marco -> macro.
>
> I'd say this is a good observation to state.
>
> Maybe it's also helpful to further explain why the two structs are
> logically connected, or if that turns out to be false, to split up you
> changes into two commits. I am not fully convinced that it should be one
> commit.

If I'm reading the code correctly, I think these changes are
interconnected, thus they ought to remain together in a single patch.
Specifically, the change to the signature of parse_exclude_pattern()
in dir.h has an impact on both structs. Thus, it should not be
necessary to explain further that these structs are connected (they
aren't really); rather the changes to both are merely natural
consequence of the change to parse_exclude_pattern()'s signature.

>>`pattern` is used only in attr.c,
>> and `exclude` is used only in builtin/check-ignore.c and dir.c, and in
>> those files, either, the value of `flags` is checked using the `&` operator
>> (e.g.: flags & EXC_FLAG_NODIR), or the value of `flags` is first set to 0
>> and then set to any one of {1, 4, 8, 16} using the `|=` operator
>> (e.g.: flags |= EXC_FLAG_NODIR). And, so it does not appear that the MSB
>> of `flags` is used in any special way.
>
> This is the conclusion that is needed, but you might want state it more
> direct, like "the MSB is not used...".
>
>> Therefore, I thought to change the
>> type of `flags` in the definitions of both structs to `unsigned int`.
>> Furthermore, `flags` is passed by reference (of `pattern` in attr.c and of
>> `exclude` in dir.c) to the function `parse_exclude_pattern` defined in
>> dir.c, that accepts an `int *` type for `flags`.
>> When make was run, it gave
>> a warning for ‘converting between pointers to integer types of different
>> sign’, so I changed the type of that respective argument to `unsigned int *`.
>
> I think this explanation can be left out or has to be replaced by
> something less compiler-driven, i.e. why does it actually make sense for
> parse_exclude_pattern to have an unsigned int flags as parameter.

Right, the entire paragraph in the commit message could be collapsed
to something like:

    Since the MSB of parse_exclude_pattern()'s 'flags' argument
    is not special, change its type from 'int' to 'unsigned' to better
    reflect this.

Everything else is implied by the above. The reader understands
implicitly that changing the types in the structs is a natural
consequence of changing the signature of parse_exclude_pattern(), thus
need not be stated explicitly. The bit about compiler warnings and
such is equally obvious and need not be mentioned.

One other comment: In this project, I think it is more common to give
these "flags" variables type "unsigned" rather than "unsigned int".

>> In the end, running make to build didn’t produce any more warnings, and
>> running make in t/ didn’t produce any breakage that wasn’t ‘#TODO known
>> breakage’.
>
> For the tests it is, from what I've seen, just assumed that you ran them
> (and the reviewers/the maintainer will confirm this for themselves), so
> no need to mention it. But it's good you ran them.
>
>> I also thought it’d be helpful to add the comment /* EXC_FLAG_* */ next
>> to `flags` of `exclude`, just like it exists for `flags` of `pattern`.
>
> I would reformulate this as well more direct to something like "when
> we're at it, document exclude->flags as EXC_FLAG".

Yep.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] GSoC Micoproject: Hunt down signed int flags
  2016-02-21 11:13 [PATCH] GSoC Micoproject: Hunt down signed int flags Saurav Sachidanand
  2016-02-21 23:22 ` Moritz Neeb
@ 2016-02-22  9:32 ` Duy Nguyen
  1 sibling, 0 replies; 4+ messages in thread
From: Duy Nguyen @ 2016-02-22  9:32 UTC (permalink / raw)
  To: Saurav Sachidanand; +Cc: Git Mailing List

On Sun, Feb 21, 2016 at 6:13 PM, Saurav Sachidanand
<sauravsachidanand@gmail.com> wrote:
> This is patch is for a suggested micro project for GSoC 2016; namely,
> that of searching for a field of a struct that is of signed integral
> type and used as a collection of multiple bits, and converting it to
> an unsigned type if the MSB isn’t used in any special way.

if you use gcc, you can try to build git with -Wsign-conversion (i.e.
"make CFLAGS=-Wsign-conversion") with and without your patch then see
if there are any new warnings. I only checked dir.c and attr.c, there
were 4 new warnings. From a quick look, I think gcc was correct, you
just need to convert some more "int" to unsigned int" to prevent
implicit conversion.
-- 
Duy

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-02-22  9:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-21 11:13 [PATCH] GSoC Micoproject: Hunt down signed int flags Saurav Sachidanand
2016-02-21 23:22 ` Moritz Neeb
2016-02-22  0:48   ` Eric Sunshine
2016-02-22  9:32 ` Duy Nguyen

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).