From: Saurav Sachidanand <sauravsachidanand@gmail.com>
To: git@vger.kernel.org
Cc: Saurav Sachidanand <sauravsachidanand@gmail.com>
Subject: [PATCH] GSoC Micoproject: Hunt down signed int flags
Date: Sun, 21 Feb 2016 16:43:09 +0530 [thread overview]
Message-ID: <1456053189-5221-1-git-send-email-sauravsachidanand@gmail.com> (raw)
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
next reply other threads:[~2016-02-21 18:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-21 11:13 Saurav Sachidanand [this message]
2016-02-21 23:22 ` [PATCH] GSoC Micoproject: Hunt down signed int flags Moritz Neeb
2016-02-22 0:48 ` Eric Sunshine
2016-02-22 9:32 ` Duy Nguyen
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=1456053189-5221-1-git-send-email-sauravsachidanand@gmail.com \
--to=sauravsachidanand@gmail.com \
--cc=git@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).