C99: declare bool experiment a success
cover C99: declare bool experiment a success
From: Phillip Wood <[email protected]>
We've had a test balloon for C99's bool type since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As it has been over 18 months since this was added and there have been no complaints let's declare it a success and convert the return type our other string predicates to match.
Base-Commit: a30f80fde927d70950b3b4d1820813480968fb0d
Published-As: https://github.com/phillipwood/git/releases/tag/pw%2Fuse-c99-bool%2Fv1
View-Changes-At: https://github.com/phillipwood/git/compare/a30f80fde...7eaf80420
Fetch-It-Via: git fetch https://github.com/phillipwood/git pw/use-c99-bool/v1
Phillip Wood (3):
CodingGuildlines: allow the use of bool
git-compat-util: convert string predicates to return bool
strbuf: convert predicates to return bool
Documentation/CodingGuidelines | 3 +++ git-compat-util.h | 12 ++++++------ strbuf.c | 28 ++++++++++++++-------------- strbuf.h | 12 ++++++------ 4 files changed, 29 insertions(+), 26 deletions(-)
Signature · 1 line
2.49.0.897.gfad3eb7d210
PATCH 1/3 CodingGuildlines: allow the use of bool
From: Phillip Wood <[email protected]>
We have had a test balloon for C99's bool type since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As we've had it over 18 months without any complaints let's declare it a success.
--- Documentation/CodingGuidelines | 3 +++ 1 file changed, 3 insertions(+)
Documentation/CodingGuidelines +3 -0
@@ -298,6 +298,9 @@ For C programs: . since late 2021 with 44ba10d6, we have had variables declared in the for loop "for (int i = 0; i < 10; i++)". + . since late 2023 with 8277dbe987 we have been using the bool type + from <stdbool.h>. + New C99 features that we cannot use yet: . %z and %zu as a printf() argument for a size_t (the %z being for
Signature · 1 line
2.49.0.897.gfad3eb7d210
Re: [PATCH 1/3] CodingGuildlines: allow the use of bool
Quoted 17 lines · Phillip Wood
From: Phillip Wood <[email protected]>
We have had a test balloon for C99's bool type since
8277dbe987(git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As we've had it over 18 months without any complaints let's declare it a success.Signed-off-by Phillip Wood <[email protected]>--- Documentation/CodingGuidelines | 3 +++ 1 file changed, 3 insertions(+)Documentation/CodingGuidelines +0
-0
Documentation/CodingGuidelines For C programs: · line 302
Quoted 5 lines
Documentation/CodingGuidelines +2
-0@@ -298,6 +298,9 @@ For C programs: . since late 2021 with 44ba10d6, we have had variables declared in the for loop "for (int i = 0; i < 10; i++)". + . since late 2023 with 8277dbe987 we have been using the bool type + from <stdbool.h>.
Let's see the other ones in the same list.
* initializer elements that are not static (used since 2b6854c8 (Cleanup variables in cat-file, 2007-04-21), declared official with 442c27dd (CodingGuidelines: mention dynamic C99 initializer elements, 2022-10-10).
* trailing comma in enum definition (used since e1327023 (grep:
refactor the concept of "grep source" into an object, 2012-02-02), declared official with cc0c4297 (CodingGuidelines:
spell out post-C89 rules, 2019-07-16).
* designated initialiers for struct and arrays (used since cbc0f81d (strbuf: use designated initializers in STRBUF_INIT, 2017-07-10) and 512f41cf (clean.c: use designated initializer, 2017-07-14), declared official with cc0c4297 (CodingGuidelines: spell out post-C89 rules, 2019-07-16).
* variadic macros (used since 765dc168 (git-compat-util: always enable variadic macros, 2021-01-28), declared official with 56a29d2c (C99: remove hardcoded-out !HAVE_VARIADIC_MACROS code, 2022-02-21).
* declaring a control variable in for(;;) loop (used since 44ba10d6 (revision: use C99 declaration of variable in for() loop, 2021-11-14), declared official with 82dd01d8 (CodingGuidelines:
allow declaring variables in for loops, 2022-10-10).
A year and a half sounds roughly the average timespan.
Will queue. Thanks.
PATCH 2/3 git-compat-util: convert string predicates to return bool
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
Since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16) a number of our sting predicates have been returning bool instead of int. Now we've declared that experiment a success lets convert the return type the case independent skip_iprefix() and skip_iprefix_mem() functions to match the return type of their case dependent equivalents. Returning bool instead of int makes it clear that these functions are predicates.
--- git-compat-util.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
git-compat-util.h +6 -6
@@ -897,35 +897,35 @@ static inline size_t xsize_t(off_t len)* is done via tolower(), so it is strictly ASCII (no multi-byte characters or * locale-specific conversions). */ -static inline int skip_iprefix (const char *str,const char *prefix, +static inline bool skip_iprefix (const char *str,const char *prefix,const char **out) {do {if (!*prefix) { *out = str; -return 1 ; +return true; } }while (tolower (*str++) ==tolower (*prefix++)); -return 0 ; +return false; }/* * Like skip_prefix_mem, but compare case-insensitively. Note that the * comparison is done via tolower(), so it is strictly ASCII (no multi-byte * characters or locale-specific conversions). */ -static inline int skip_iprefix_mem (const char *buf,size_t len, +static inline bool skip_iprefix_mem (const char *buf,size_t len,const char *prefix,const char **out,size_t *outlen) {do {if (!*prefix) { *out = buf; *outlen = len; -return 1 ; +return true; } }while (len-- >0 &&tolower (*buf++) ==tolower (*prefix++)); -return 0 ; +return false; }static inline int strtoul_ui (char const *s,int base,unsigned int *result)
Signature · 1 line
2.49.0.897.gfad3eb7d210
Re: [PATCH 2/3] git-compat-util: convert string predicates to return bool
Quoted 2 lines · Phillip Wood
Since
8277dbe987(git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16) a number of our sting predicates have been
s/sting/string/
Quoted 2 lines
returning bool instead of int. Now we've declared that experiment a success lets convert the return type the case independent
s/lets/let's/
/type/& of/
Quoted 5 lines
skip_iprefix()andskip_iprefix_mem()functions to match the return type of their case dependent equivalents. Returning bool instead of int makes it clear that these functions are predicates.Signed-off-by Phillip Wood <[email protected]>
Re: [PATCH 2/3] git-compat-util: convert string predicates to return bool
In reply to Phillip WoodQuoted 6 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Since
8277dbe987(git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16) a number of our sting predicates have been returning bool instead of int. Now we've declared that experiment
Now we've -> Now that we've
Quoted 1 line
a success lets convert the return type the case independent
success lets -> success, let's
type the -> type of the
Quoted 2 lines
skip_iprefix()andskip_iprefix_mem()functions to match the return type of their case dependent equivalents. Returning bool instead of
I wonder if case-independent and case-dependent should be hyphenated, or as separate words as you had them. Anyone know?
Quoted 54 lines
int makes it clear that these functions are predicates.
Signed-off-by Phillip Wood <[email protected]>--- git-compat-util.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)git-compat-util.h +6
-7@@ -897,35 +897,35 @@ static inline size_t xsize_t(off_t len)* is done via tolower(), so it is strictly ASCII (no multi-byte characters or * locale-specific conversions). */ -static inline int skip_iprefix (const char *str,const char *prefix, +static inline bool skip_iprefix (const char *str,const char *prefix,const char **out) {do {if (!*prefix) { *out = str; -return 1 ; +return true; } }while (tolower (*str++) ==tolower (*prefix++)); -return 0 ; +return false; }/* * Like skip_prefix_mem, but compare case-insensitively. Note that the * comparison is done via tolower(), so it is strictly ASCII (no multi-byte * characters or locale-specific conversions). */ -static inline int skip_iprefix_mem (const char *buf,size_t len, +static inline bool skip_iprefix_mem (const char *buf,size_t len,const char *prefix,const char **out,size_t *outlen) {do {if (!*prefix) { *out = buf; *outlen = len; -return 1 ; +return true; } }while (len-- >0 &&tolower (*buf++) ==tolower (*prefix++)); -return 0 ; +return false; }static inline int strtoul_ui (char const *s,int base,unsigned int *result) --
Quoted 1 line
2.49.0.897.gfad3eb7d210
Patch looks good.
Re: [PATCH 2/3] git-compat-util: convert string predicates to return bool
Quoted 12 lines · Elijah Newren
Quoted 6 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Since
8277dbe987(git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16) a number of our sting predicates have been returning bool instead of int. Now we've declared that experimentNow we've -> Now that we've
Quoted 1 line
a success lets convert the return type the case independent
Quoted 8 lines
success lets -> success, let's
type the -> type of theQuoted 2 lines
skip_iprefix()andskip_iprefix_mem()functions to match the return type of their case dependent equivalents. Returning bool instead ofI wonder if case-independent and case-dependent should be hyphenated, or as separate words as you had them. Anyone know?
I would hyphenate them. The Chicago Manual of Style, 18th Edition, says in § 7.91, “When compound modifiers (also called phrasal adjectives) such as _high-profile_ or _book-length_ precede a noun, hyphenation usually lends clarity. With the exception of proper nouns (such as _United States_) and compounds formed by an adverb ending in _-ly_ plus an adjective…, it is never incorrect to hyphenate adjectival compounds before a noun.”
They go on to state that hyphenation is usually omitted _after_ a noun.
I usually follow this rule in my writing and commit messages and I haven't gotten any complaints or comments about it, for what it's worth.
Signature · 2 lines
brian m. carlson (they/them) Toronto, Ontario, CA
Re: [PATCH 2/3] git-compat-util: convert string predicates to return bool
Quoted 14 lines · brian m. carlson
Quoted 4 lines · Elijah Newren
Quoted 1 line · Phillip Wood
I wonder if case-independent and case-dependent should be hyphenated, or as separate words as you had them. Anyone know?
I would hyphenate them. The Chicago Manual of Style, 18th Edition, says in § 7.91, “When compound modifiers (also called phrasal adjectives) such as _high-profile_ or _book-length_ precede a noun, hyphenation usually lends clarity. With the exception of proper nouns (such as
_UnitedStates_) and compounds formed by an adverb ending in _-ly_ plus an adjective…, it is never incorrect to hyphenate adjectival compounds before a noun.”
Quoted 4 lines
They go on to state that hyphenation is usually omitted _after_ a noun.
I usually follow this rule in my writing and commit messages and I haven't gotten any complaints or comments about it, for what it's worth.
Thanks for that - I'll hyphenate them then.
Thank you also to Elijah and Eric for the typo fixes - I seem to have had my brain turned off when I proofread this message.
Phillip
PATCH 3/3 strbuf: convert predicates to return bool
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
Now that the string predicates defined in git-compat-util.h all return bool let's convert the return type of the string predicates in strbuf.{c,h} to match them.
--- strbuf.c | 28 ++++++++++++++-------------- strbuf.h | 12 ++++++------ 2 files changed, 20 insertions(+), 20 deletions(-)
strbuf.c +14 -14
@@ -8,55 +8,55 @@#include "utf8.h" #include "date.h" -int starts_with (const char *str,const char *prefix) +bool starts_with (const char *str,const char *prefix) {for (; ; str++, prefix++)if (!*prefix) -return 1 ; +return true;else if (*str != *prefix) -return 0 ; +return false; } -int istarts_with (const char *str,const char *prefix) +bool istarts_with (const char *str,const char *prefix) {for (; ; str++, prefix++)if (!*prefix) -return 1 ; +return true;else if (tolower (*str) !=tolower (*prefix)) -return 0 ; +return false; } -int starts_with_mem (const char *str,size_t len,const char *prefix) +bool starts_with_mem (const char *str,size_t len,const char *prefix) {const char *end = str + len;for (; ; str++, prefix++) {if (!*prefix) -return 1 ; +return true;else if (str == end || *str != *prefix) -return 0 ; +return false; } } -int skip_to_optional_arg_default (const char *str,const char *prefix, +bool skip_to_optional_arg_default (const char *str,const char *prefix,const char **arg,const char *def) {const char *p;if (!skip_prefix (str, prefix, &p)) -return 0 ; +return false;if (!*p) {if (arg) *arg = def; -return 1 ; +return true; }if (*p !='=' ) -return 0 ; +return false;if (arg) *arg = p +1 ; -return 1 ; +return true; }/*
strbuf.h +6 -6
@@ -660,9 +660,9 @@ char *xstrvfmt(const char *fmt, va_list ap); __attribute__((format (printf,1 ,2 )))char *xstrfmt (const char *fmt, ...); -int starts_with (const char *str,const char *prefix); -int istarts_with (const char *str,const char *prefix); -int starts_with_mem (const char *str,size_t len,const char *prefix); +bool starts_with (const char *str,const char *prefix); +bool istarts_with (const char *str,const char *prefix); +bool starts_with_mem (const char *str,size_t len,const char *prefix);/* * If the string "str" is the same as the string in "prefix", then the "arg"
@@ -678,16 +678,16 @@ int starts_with_mem(const char *str, size_t len, const char *prefix);* can be used instead of !strcmp(arg, "--key") and then * skip_prefix(arg, "--key=", &arg) to parse such an option. */ -int skip_to_optional_arg_default (const char *str,const char *prefix, +bool skip_to_optional_arg_default (const char *str,const char *prefix,const char **arg,const char *def); -static inline int skip_to_optional_arg (const char *str,const char *prefix, +static inline bool skip_to_optional_arg (const char *str,const char *prefix,const char **arg) {return skip_to_optional_arg_default (str, prefix, arg,"" ); } -static inline int ends_with (const char *str,const char *suffix) +static inline bool ends_with (const char *str,const char *suffix) {size_t len;return strip_suffix (str, suffix, &len);
Signature · 1 line
2.49.0.897.gfad3eb7d210
v2 cover C99: declare bool experiment a success
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
We've had a test balloon for C99's bool type since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As it has been over 18 months since this was added and there have been no complaints let's declare it a success and convert the return type our other string predicates to match.
Thank you to everyone who commented on V1, the only change here is to fix the typos in the commit message for patch 2.
Base-Commit: a30f80fde927d70950b3b4d1820813480968fb0d
Published-As: https://github.com/phillipwood/git/releases/tag/pw%2Fuse-c99-bool%2Fv2
View-Changes-At: https://github.com/phillipwood/git/compare/a30f80fde...669687147
Fetch-It-Via: git fetch https://github.com/phillipwood/git pw/use-c99-bool/v2
Phillip Wood (3):
CodingGuildlines: allow the use of bool
git-compat-util: convert string predicates to return bool
strbuf: convert predicates to return bool
Documentation/CodingGuidelines | 3 +++ git-compat-util.h | 12 ++++++------ strbuf.c | 28 ++++++++++++++-------------- strbuf.h | 12 ++++++------ 4 files changed, 29 insertions(+), 26 deletions(-)
Range-diff against v1:
1: 352f80c49b7 = 1: 352f80c49b7 CodingGuildlines: allow the use of bool 2: a0f9182aa20 ! 2: 0b2402e11cc git-compat-util: convert string predicates to return bool
@@ Commit message
git-compat-util: convert string predicates to return bool
Since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem}
- to bool, 2023-12-16) a number of our sting predicates have been
- returning bool instead of int. Now we've declared that experiment
- a success lets convert the return type the case independent
+ to bool, 2023-12-16) a number of our string predicates have been
+ returning bool instead of int. Now that we've declared that experiment
+ a success, let's convert the return type of the case-independent
skip_iprefix() and skip_iprefix_mem() functions to match the return
- type of their case dependent equivalents. Returning bool instead of
+ type of their case-dependent equivalents. Returning bool instead of
int makes it clear that these functions are predicates.
3: 7eaf8042061 = 3: 66968714739 strbuf: convert predicates to return bool
Signature · 1 line
2.49.0.897.gfad3eb7d210
PATCH v2 1/3 CodingGuildlines: allow the use of bool
From: Phillip Wood <[email protected]>
We have had a test balloon for C99's bool type since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As we've had it over 18 months without any complaints let's declare it a success.
--- Documentation/CodingGuidelines | 3 +++ 1 file changed, 3 insertions(+)
Documentation/CodingGuidelines +3 -0
@@ -298,6 +298,9 @@ For C programs: . since late 2021 with 44ba10d6, we have had variables declared in the for loop "for (int i = 0; i < 10; i++)". + . since late 2023 with 8277dbe987 we have been using the bool type + from <stdbool.h>. + New C99 features that we cannot use yet: . %z and %zu as a printf() argument for a size_t (the %z being for
Signature · 1 line
2.49.0.897.gfad3eb7d210
Re: [PATCH v2 1/3] CodingGuildlines: allow the use of bool
Quoted 1 line · Phillip Wood
Subject: Re: [PATCH v2 1/3] CodingGuildlines: allow the use of bool
I was lots of discussion about grammar elsewhere, but nobody seems to have mentioned "Guildlines" instead of "Guidelines". :)
-Peff
Re: [PATCH v2 1/3] CodingGuildlines: allow the use of bool
Quoted 6 lines · Jeff King
Quoted 1 line · Phillip Wood
Subject: Re: [PATCH v2 1/3] CodingGuildlines: allow the use of bool
I was lots of discussion about grammar elsewhere, but nobody seems to have mentioned "Guildlines" instead of "Guidelines". :)
s/was/saw/, obviously.
Surely somebody has coined a name for the law that any statement pointing out a typo or grammatical issue is vastly more likely to contain one itself.
-Peff
Re: [PATCH v2 1/3] CodingGuildlines: allow the use of bool
Quoted 11 lines · Jeff King
Quoted 6 lines · Jeff King
Quoted 1 line · Phillip Wood
Subject: Re: [PATCH v2 1/3] CodingGuildlines: allow the use of bool
I was lots of discussion about grammar elsewhere, but nobody seems to have mentioned "Guildlines" instead of "Guidelines". :)
s/was/saw/, obviously.
hehe
Quoted 3 lines
Surely somebody has coined a name for the law that any statement pointing out a typo or grammatical issue is vastly more likely to contain one itself.
PATCH v2 2/3 git-compat-util: convert string predicates to return bool
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
Since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16) a number of our string predicates have been returning bool instead of int. Now that we've declared that experiment a success, let's convert the return type of the case-independent skip_iprefix() and skip_iprefix_mem() functions to match the return type of their case-dependent equivalents. Returning bool instead of int makes it clear that these functions are predicates.
--- git-compat-util.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
git-compat-util.h +6 -6
@@ -897,35 +897,35 @@ static inline size_t xsize_t(off_t len)* is done via tolower(), so it is strictly ASCII (no multi-byte characters or * locale-specific conversions). */ -static inline int skip_iprefix (const char *str,const char *prefix, +static inline bool skip_iprefix (const char *str,const char *prefix,const char **out) {do {if (!*prefix) { *out = str; -return 1 ; +return true; } }while (tolower (*str++) ==tolower (*prefix++)); -return 0 ; +return false; }/* * Like skip_prefix_mem, but compare case-insensitively. Note that the * comparison is done via tolower(), so it is strictly ASCII (no multi-byte * characters or locale-specific conversions). */ -static inline int skip_iprefix_mem (const char *buf,size_t len, +static inline bool skip_iprefix_mem (const char *buf,size_t len,const char *prefix,const char **out,size_t *outlen) {do {if (!*prefix) { *out = buf; *outlen = len; -return 1 ; +return true; } }while (len-- >0 &&tolower (*buf++) ==tolower (*prefix++)); -return 0 ; +return false; }static inline int strtoul_ui (char const *s,int base,unsigned int *result)
Signature · 1 line
2.49.0.897.gfad3eb7d210
PATCH v2 3/3 strbuf: convert predicates to return bool
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
Now that the string predicates defined in git-compat-util.h all return bool let's convert the return type of the string predicates in strbuf.{c,h} to match them.
--- strbuf.c | 28 ++++++++++++++-------------- strbuf.h | 12 ++++++------ 2 files changed, 20 insertions(+), 20 deletions(-)
strbuf.c +14 -14
@@ -8,55 +8,55 @@#include "utf8.h" #include "date.h" -int starts_with (const char *str,const char *prefix) +bool starts_with (const char *str,const char *prefix) {for (; ; str++, prefix++)if (!*prefix) -return 1 ; +return true;else if (*str != *prefix) -return 0 ; +return false; } -int istarts_with (const char *str,const char *prefix) +bool istarts_with (const char *str,const char *prefix) {for (; ; str++, prefix++)if (!*prefix) -return 1 ; +return true;else if (tolower (*str) !=tolower (*prefix)) -return 0 ; +return false; } -int starts_with_mem (const char *str,size_t len,const char *prefix) +bool starts_with_mem (const char *str,size_t len,const char *prefix) {const char *end = str + len;for (; ; str++, prefix++) {if (!*prefix) -return 1 ; +return true;else if (str == end || *str != *prefix) -return 0 ; +return false; } } -int skip_to_optional_arg_default (const char *str,const char *prefix, +bool skip_to_optional_arg_default (const char *str,const char *prefix,const char **arg,const char *def) {const char *p;if (!skip_prefix (str, prefix, &p)) -return 0 ; +return false;if (!*p) {if (arg) *arg = def; -return 1 ; +return true; }if (*p !='=' ) -return 0 ; +return false;if (arg) *arg = p +1 ; -return 1 ; +return true; }/*
strbuf.h +6 -6
@@ -660,9 +660,9 @@ char *xstrvfmt(const char *fmt, va_list ap); __attribute__((format (printf,1 ,2 )))char *xstrfmt (const char *fmt, ...); -int starts_with (const char *str,const char *prefix); -int istarts_with (const char *str,const char *prefix); -int starts_with_mem (const char *str,size_t len,const char *prefix); +bool starts_with (const char *str,const char *prefix); +bool istarts_with (const char *str,const char *prefix); +bool starts_with_mem (const char *str,size_t len,const char *prefix);/* * If the string "str" is the same as the string in "prefix", then the "arg"
@@ -678,16 +678,16 @@ int starts_with_mem(const char *str, size_t len, const char *prefix);* can be used instead of !strcmp(arg, "--key") and then * skip_prefix(arg, "--key=", &arg) to parse such an option. */ -int skip_to_optional_arg_default (const char *str,const char *prefix, +bool skip_to_optional_arg_default (const char *str,const char *prefix,const char **arg,const char *def); -static inline int skip_to_optional_arg (const char *str,const char *prefix, +static inline bool skip_to_optional_arg (const char *str,const char *prefix,const char **arg) {return skip_to_optional_arg_default (str, prefix, arg,"" ); } -static inline int ends_with (const char *str,const char *suffix) +static inline bool ends_with (const char *str,const char *suffix) {size_t len;return strip_suffix (str, suffix, &len);
Signature · 1 line
2.49.0.897.gfad3eb7d210
Quoted 47 lines · Phillip Wood
From: Phillip Wood <[email protected]>
We've had a test balloon for C99's bool type since
8277dbe987(git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As it has been over 18 months since this was added and there have been no complaints let's declare it a success and convert the return type our other string predicates to match.Thank you to everyone who commented on V1, the only change here is to fix the typos in the commit message for patch 2.
Base-Commit:
a30f80fde927d70950b3b4d1820813480968fb0d
Published-As: https://github.com/phillipwood/git/releases/tag/pw%2Fuse-c99-bool%2Fv2
View-Changes-At: https://github.com/phillipwood/git/compare/a30f80fde...669687147
Fetch-It-Via: git fetch https://github.com/phillipwood/git pw/use-c99-bool/v2Phillip Wood (3):
CodingGuildlines: allow the use of bool
git-compat-util: convert string predicates to return bool
strbuf: convert predicates to return boolDocumentation/CodingGuidelines | 3 +++ git-compat-util.h | 12 ++++++------ strbuf.c | 28 ++++++++++++++-------------- strbuf.h | 12 ++++++------ 4 files changed, 29 insertions(+), 26 deletions(-)Range-diff against v1:
1: 352f80c49b7 = 1: 352f80c49b7 CodingGuildlines: allow the use of bool 2: a0f9182aa20 ! 2: 0b2402e11cc git-compat-util: convert string predicates to return bool@@ Commit message
git-compat-util: convert string predicates to return boolSince
8277dbe987(git-compat-util: convert skip_{prefix,suffix}{,_mem}
- to bool, 2023-12-16) a number of our sting predicates have been
- returning bool instead of int. Now we've declared that experiment
- a success lets convert the return type the case independent
+ to bool, 2023-12-16) a number of our string predicates have been
+ returning bool instead of int. Now that we've declared that experiment
+ a success, let's convert the return type of the case-independent
skip_iprefix()andskip_iprefix_mem()functions to match the return
- type of their case dependent equivalents. Returning bool instead of
+ type of their case-dependent equivalents. Returning bool instead of
int makes it clear that these functions are predicates.
Quoted 4 lines
Signed-off-by Phillip Wood <[email protected]>3:
7eaf8042061= 3: 66968714739 strbuf: convert predicates to return bool --
2.49.0.897.gfad3eb7d210
This version looks good to me, thanks!
Quoted 34 lines · Elijah Newren
Quoted 32 lines · Phillip Wood
From: Phillip Wood <[email protected]>
We've had a test balloon for C99's bool type since
8277dbe987(git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As it has been over 18 months since this was added and there have been no complaints let's declare it a success and convert the return type our other string predicates to match.Thank you to everyone who commented on V1, the only change here is to fix the typos in the commit message for patch 2.
Base-Commit:
a30f80fde927d70950b3b4d1820813480968fb0dPublished-As:
https://github.com/phillipwood/git/releases/tag/pw%2Fuse-c99-bool%2Fv2
View-Changes-At:
https://github.com/phillipwood/git/compare/a30f80fde...669687147
Fetch-It-Via: git fetch https://github.com/phillipwood/git
pw/use-c99-bool/v2Phillip Wood (3):
CodingGuildlines: allow the use of bool
git-compat-util: convert string predicates to return bool
strbuf: convert predicates to return boolDocumentation/CodingGuidelines | 3 +++ git-compat-util.h | 12 ++++++------ strbuf.c | 28 ++++++++++++++-------------- strbuf.h | 12 ++++++------ 4 files changed, 29 insertions(+), 26 deletions(-)
Quoted 23 lines
Quoted 4 lines
Range-diff against v1:
1:352f80c49b7= 1:352f80c49b7CodingGuildlines: allow the use of bool
2:a0f9182aa20! 2:0b2402e11ccgit-compat-util: convert string predicates toreturn bool
Quoted 18 lines
@@ Commit message
git-compat-util: convert string predicates to return boolSince
8277dbe987(git-compat-util: convert skip_{prefix,suffix}{,_mem}
- to bool, 2023-12-16) a number of our sting predicates have been
- returning bool instead of int. Now we've declared that experiment
- a success lets convert the return type the case independent
+ to bool, 2023-12-16) a number of our string predicates have been
+ returning bool instead of int. Now that we've declared that experiment
+ a success, let's convert the return type of the case-independent
skip_iprefix()andskip_iprefix_mem()functions to match the return
- type of their case dependent equivalents. Returning bool instead of
+ type of their case-dependent equivalents. Returning bool instead of
int makes it clear that these functions are predicates.Signed-off-by Phillip Wood <[email protected]>3:
7eaf8042061= 3: 66968714739 strbuf: convert predicates to return bool
bool is not standard in all c99 implementations. I have to #include <stdbool.h> in order to use this type. Please make sure there is a mechanism for that.
Quoted 13 lines · On Tue, Jul 15, 2025 at 11:23 AM <[email protected]> wrote:
Quoted 11 lines · Elijah Newren
Quoted 9 lines · Phillip Wood
From: Phillip Wood <[email protected]>
We've had a test balloon for C99's bool type since
8277dbe987(git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As it has been over 18 months since this was added and there have been no complaints let's declare it a success and convert the return type our other string predicates to match.
[...]
Quoted 3 lines
bool is not standard in all c99 implementations. I have to #include <
stdbool.h> in order to use this type. Please make sure there is a mechanism for that.
From the referenced commit in the commit message:
$ git log --oneline -1 -p 8277dbe987 | head -n 13
8277dbe9872 git-compat-util: convert skip_{prefix,suffix}{,_mem} to boolgit-compat-util.h +1 -0
@@ -225,6 +225,7 @@ struct strbuf;#include <stddef.h> #include <stdlib.h> #include <stdarg.h> +#include <stdbool.h> #include <string.h> #ifdef HAVE_STRINGS_H #include <strings.h> /* for strcasecmp() */
So, there's not only a mechanism for that, it has already been done for you 1.5 years ago. No extra work on your or anyone else's part needed. :-)
Quoted 38 lines · Elijah Newren
Quoted 14 lines · On Tue, Jul 15, 2025 at 11:23 AM <[email protected]> wrote:
Quoted 12 lines · Elijah Newren
Quoted 9 lines · Phillip Wood
From: Phillip Wood <[email protected]>
We've had a test balloon for C99's bool type since
8277dbe987(git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As it has been over 18 months since this was added and there have been no complaints let's declare it a success and convert the return type our other string predicates to match.[...]
Quoted 3 lines
bool is not standard in all c99 implementations. I have to #include <
stdbool.h> in order to use this type. Please make sure there is a mechanism forthat.
Quoted 1 line
From the referenced commit in the commit message:
$ git log --oneline -1 -p 8277dbe987 | head -n 13 8277dbe9872 git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool diff --git a/git-compat-util.h b/git-compat-util.h index 3e7a59b5ff1..603c97e3b3f 100644git-compat-util.h +1
-0@@ -225,6 +225,7 @@ struct strbuf;#include <stddef.h> #include <stdlib.h> #include <stdarg.h> +#include <stdbool.h> #include <string.h> #ifdef HAVE_STRINGS_H #include <strings.h> /* for strcasecmp() */
Quoted 2 lines
So, there's not only a mechanism for that, it has already been done for you 1.5 years ago. No extra work on your or anyone else's part needed. :-)
Many thanks.
Quoted 2 lines · <[email protected]> writes:
bool is not standard in all c99 implementations. I have to #include <
stdbool.h> in order to use this type. Please make sure there is a mechanism for that.
Given that <git-compat-util.h> unconditionally includes <compat/posix.h> and <compat/posix.h> unconditionally includes <stdbool.h> even in today's code, that should be OK.
Quoted 12 lines · Elijah Newren
Quoted 12 lines
Since
8277dbe987(git-compat-util: convert skip_{prefix,suffix}{,_mem}
- to bool, 2023-12-16) a number of our sting predicates have been
- returning bool instead of int. Now we've declared that experiment
- a success lets convert the return type the case independent
+ to bool, 2023-12-16) a number of our string predicates have been
+ returning bool instead of int. Now that we've declared that experiment
+ a success, let's convert the return type of the case-independent
skip_iprefix()andskip_iprefix_mem()functions to match the return
- type of their case dependent equivalents. Returning bool instead of
+ type of their case-dependent equivalents. Returning bool instead of
int makes it clear that these functions are predicates.
Quoted 6 lines
Quoted 4 lines
Signed-off-by Phillip Wood <[email protected]>3:
7eaf8042061= 3: 66968714739 strbuf: convert predicates to return bool --
2.49.0.897.gfad3eb7d210This version looks good to me, thanks!
Thanks, looking good.
Quoted 10 lines · Phillip Wood
From: Phillip Wood <[email protected]>
We've had a test balloon for C99's bool type since
8277dbe987(git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As it has been over 18 months since this was added and there have been no complaints let's declare it a success and convert the return type our other string predicates to match.Thank you to everyone who commented on V1, the only change here is to fix the typos in the commit message for patch 2.
This series looked good to me. I especially like the fact that we've made it easier for me to figure out whether starts_with and friends are booleans (that is, true if it starts with the value) or our standard zero/negative-one (that is, false if it starts with the value).
Signature · 2 lines
brian m. carlson (they/them) Toronto, Ontario, CA
Quoted 4 lines · brian m. carlson
This series looked good to me. I especially like the fact that we've made it easier for me to figure out whether
starts_withand friends are booleans (that is, true if it starts with the value) or our standard zero/negative-one (that is, false if it starts with the value).
Hmph, this is a tangent, I've never thought of it that way.
The "0 is success and negative is failure" is exactly about success and failure. We expect such a call to succeed most of the time and failure is a note-worthy event.
Functions like starts_with() and friends, those that Lispers might name with q suffix, are quite different. A predicate is asking "is it, or isn't it?" question and returning "false" from it does not imply a failure in any way.
I wouldn't dream of making them return -1 for "failure", because starts_with(buf.buf, "#") that finds buf.buf does not begin with "#" is no way failing.
Anyway, we may start rewriting our old-fashioned idiom to normalize a "true if non-zero" integers, i.e.
return !!some_true_if_non_zero_integer_variable;
into
return (bool)some_true_if_non_zero_integer_variable;
perhaps ;-).
v3 cover C99: declare bool experiment a success
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
We've had a test balloon for C99's bool type since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As it has been over 18 months since this was added and there have been no complaints let's declare it a success and convert the return type our other string predicates to match.
Thanks to peff for spotting yet another typo - I've updated the commit message for patch 1 accordingly.
Base-Commit: a30f80fde927d70950b3b4d1820813480968fb0d
Published-As: https://github.com/phillipwood/git/releases/tag/pw%2Fuse-c99-bool%2Fv3
View-Changes-At: https://github.com/phillipwood/git/compare/a30f80fde...80e5cd3b9
Fetch-It-Via: git fetch https://github.com/phillipwood/git pw/use-c99-bool/v3
Phillip Wood (3):
CodingGuidelines: allow the use of bool
git-compat-util: convert string predicates to return bool
strbuf: convert predicates to return bool
Documentation/CodingGuidelines | 3 +++ git-compat-util.h | 12 ++++++------ strbuf.c | 28 ++++++++++++++-------------- strbuf.h | 12 ++++++------ 4 files changed, 29 insertions(+), 26 deletions(-)
Range-diff against v2:
1: 352f80c49b7 ! 1: 3ff7ae61f45 CodingGuildlines: allow the use of bool
@@ Metadata
Author: Phillip Wood <[email protected]>
## Commit message ##
- CodingGuildlines: allow the use of bool
+ CodingGuidelines: allow the use of bool
We have had a test balloon for C99's bool type since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool,
2: 0b2402e11cc = 2: 26c3f48ac6c git-compat-util: convert string predicates to return bool 3: 66968714739 = 3: 80e5cd3b9df strbuf: convert predicates to return bool
Signature · 1 line
2.49.0.897.gfad3eb7d210
PATCH v3 1/3 CodingGuidelines: allow the use of bool
From: Phillip Wood <[email protected]>
We have had a test balloon for C99's bool type since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As we've had it over 18 months without any complaints let's declare it a success.
--- Documentation/CodingGuidelines | 3 +++ 1 file changed, 3 insertions(+)
Documentation/CodingGuidelines +3 -0
@@ -298,6 +298,9 @@ For C programs: . since late 2021 with 44ba10d6, we have had variables declared in the for loop "for (int i = 0; i < 10; i++)". + . since late 2023 with 8277dbe987 we have been using the bool type + from <stdbool.h>. + New C99 features that we cannot use yet: . %z and %zu as a printf() argument for a size_t (the %z being for
Signature · 1 line
2.49.0.897.gfad3eb7d210
PATCH v3 2/3 git-compat-util: convert string predicates to return bool
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
Since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16) a number of our string predicates have been returning bool instead of int. Now that we've declared that experiment a success, let's convert the return type of the case-independent skip_iprefix() and skip_iprefix_mem() functions to match the return type of their case-dependent equivalents. Returning bool instead of int makes it clear that these functions are predicates.
--- git-compat-util.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
git-compat-util.h +6 -6
@@ -897,35 +897,35 @@ static inline size_t xsize_t(off_t len)* is done via tolower(), so it is strictly ASCII (no multi-byte characters or * locale-specific conversions). */ -static inline int skip_iprefix (const char *str,const char *prefix, +static inline bool skip_iprefix (const char *str,const char *prefix,const char **out) {do {if (!*prefix) { *out = str; -return 1 ; +return true; } }while (tolower (*str++) ==tolower (*prefix++)); -return 0 ; +return false; }/* * Like skip_prefix_mem, but compare case-insensitively. Note that the * comparison is done via tolower(), so it is strictly ASCII (no multi-byte * characters or locale-specific conversions). */ -static inline int skip_iprefix_mem (const char *buf,size_t len, +static inline bool skip_iprefix_mem (const char *buf,size_t len,const char *prefix,const char **out,size_t *outlen) {do {if (!*prefix) { *out = buf; *outlen = len; -return 1 ; +return true; } }while (len-- >0 &&tolower (*buf++) ==tolower (*prefix++)); -return 0 ; +return false; }static inline int strtoul_ui (char const *s,int base,unsigned int *result)
Signature · 1 line
2.49.0.897.gfad3eb7d210
Re: [PATCH v3 2/3] git-compat-util: convert string predicates to return bool
Quoted 38 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Since
8277dbe987(git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16) a number of our string predicates have been returning bool instead of int. Now that we've declared that experiment a success, let's convert the return type of the case-independentskip_iprefix()andskip_iprefix_mem()functions to match the return type of their case-dependent equivalents. Returning bool instead of int makes it clear that these functions are predicates.Signed-off-by Phillip Wood <[email protected]>--- git-compat-util.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)git-compat-util.h +3
-3@@ -897,35 +897,35 @@ static inline size_t xsize_t(off_t len)* is done via tolower(), so it is strictly ASCII (no multi-byte characters or * locale-specific conversions). */ -static inline int skip_iprefix (const char *str,const char *prefix, +static inline bool skip_iprefix (const char *str,const char *prefix,const char **out) {do {if (!*prefix) { *out = str; -return 1 ; +return true; } }while (tolower (*str++) ==tolower (*prefix++)); -return 0 ; +return false; }
git-compat-util.h static inline size_t xsize_t(off_t len) · line 920
Quoted 10 lines
git-compat-util.h +1
-1/* * Like skip_prefix_mem, but compare case-insensitively. Note that the * comparison is done via tolower(), so it is strictly ASCII (no multi-byte * characters or locale-specific conversions). */ -static inline int skip_iprefix_mem (const char *buf,size_t len, +static inline bool skip_iprefix_mem (const char *buf,size_t len,const char *prefix,const char **out,size_t *outlen)
Nit: clang-format complains that we should also format the arguments now that the first line's length changes
$ ./ci/run-style-check.sh @~1
git-compat-util.h +1 -1
@@ -898,7 +898,7 @@ static inline size_t xsize_t(off_t len)* locale-specific conversions). */ static inline bool skip_iprefix (const char *str,const char *prefix, -const char **out) +const char **out) { do { if (!*prefix) {
@@ -915,8 +915,8 @@ static inline bool skip_iprefix(const char *str,
const char *prefix,
* characters or locale-specific conversions).
*/
static inline bool skip_iprefix_mem(const char *buf, size_t len,
- const char *prefix,
- const char **out, size_t *outlen)
+ const char *prefix,
+ const char **out, size_t *outlen)
{
do {
if (!*prefix) {
[snip]
PATCH v3 3/3 strbuf: convert predicates to return bool
In reply to Phillip WoodFrom: Phillip Wood <[email protected]>
Now that the string predicates defined in git-compat-util.h all return bool let's convert the return type of the string predicates in strbuf.{c,h} to match them.
--- strbuf.c | 28 ++++++++++++++-------------- strbuf.h | 12 ++++++------ 2 files changed, 20 insertions(+), 20 deletions(-)
strbuf.c +14 -14
@@ -8,55 +8,55 @@#include "utf8.h" #include "date.h" -int starts_with (const char *str,const char *prefix) +bool starts_with (const char *str,const char *prefix) {for (; ; str++, prefix++)if (!*prefix) -return 1 ; +return true;else if (*str != *prefix) -return 0 ; +return false; } -int istarts_with (const char *str,const char *prefix) +bool istarts_with (const char *str,const char *prefix) {for (; ; str++, prefix++)if (!*prefix) -return 1 ; +return true;else if (tolower (*str) !=tolower (*prefix)) -return 0 ; +return false; } -int starts_with_mem (const char *str,size_t len,const char *prefix) +bool starts_with_mem (const char *str,size_t len,const char *prefix) {const char *end = str + len;for (; ; str++, prefix++) {if (!*prefix) -return 1 ; +return true;else if (str == end || *str != *prefix) -return 0 ; +return false; } } -int skip_to_optional_arg_default (const char *str,const char *prefix, +bool skip_to_optional_arg_default (const char *str,const char *prefix,const char **arg,const char *def) {const char *p;if (!skip_prefix (str, prefix, &p)) -return 0 ; +return false;if (!*p) {if (arg) *arg = def; -return 1 ; +return true; }if (*p !='=' ) -return 0 ; +return false;if (arg) *arg = p +1 ; -return 1 ; +return true; }/*
strbuf.h +6 -6
@@ -660,9 +660,9 @@ char *xstrvfmt(const char *fmt, va_list ap); __attribute__((format (printf,1 ,2 )))char *xstrfmt (const char *fmt, ...); -int starts_with (const char *str,const char *prefix); -int istarts_with (const char *str,const char *prefix); -int starts_with_mem (const char *str,size_t len,const char *prefix); +bool starts_with (const char *str,const char *prefix); +bool istarts_with (const char *str,const char *prefix); +bool starts_with_mem (const char *str,size_t len,const char *prefix);/* * If the string "str" is the same as the string in "prefix", then the "arg"
@@ -678,16 +678,16 @@ int starts_with_mem(const char *str, size_t len, const char *prefix);* can be used instead of !strcmp(arg, "--key") and then * skip_prefix(arg, "--key=", &arg) to parse such an option. */ -int skip_to_optional_arg_default (const char *str,const char *prefix, +bool skip_to_optional_arg_default (const char *str,const char *prefix,const char **arg,const char *def); -static inline int skip_to_optional_arg (const char *str,const char *prefix, +static inline bool skip_to_optional_arg (const char *str,const char *prefix,const char **arg) {return skip_to_optional_arg_default (str, prefix, arg,"" ); } -static inline int ends_with (const char *str,const char *suffix) +static inline bool ends_with (const char *str,const char *suffix) {size_t len;return strip_suffix (str, suffix, &len);
Signature · 1 line
2.49.0.897.gfad3eb7d210
Re: [PATCH v3 3/3] strbuf: convert predicates to return bool
Quoted 6 lines · Phillip Wood
From: Phillip Wood <[email protected]>
Now that the string predicates defined in
git-compat-util.hall return bool let's convert the return type of the string predicates in strbuf.{c,h} to match them.
Quoted 6 lines
Signed-off-by Phillip Wood <[email protected]>--- strbuf.c | 28 ++++++++++++++-------------- strbuf.h | 12 ++++++------ 2 files changed, 20 insertions(+), 20 deletions(-)
Nit: same here as the previous patch
$ ./ci/run-style-check.sh @~1
strbuf.c +0 -0
@@ -38,7 +38,7 @@ bool starts_with_mem(const char *str, size_t len,
const char *prefix)
}
bool skip_to_optional_arg_default(const char *str, const char *prefix,
- const char **arg, const char *def)
+ const char **arg, const char *def)
{
const char *p;
strbuf.h +0 -0
@@ -679,10 +679,10 @@ bool starts_with_mem(const char *str, size_t
len, const char *prefix);
* skip_prefix(arg, "--key=", &arg) to parse such an option. */
bool skip_to_optional_arg_default(const char *str, const char *prefix,
- const char **arg, const char *def);
+ const char **arg, const char *def);
static inline bool skip_to_optional_arg(const char *str, const char *prefix,
- const char **arg)
+ const char **arg)
{
return skip_to_optional_arg_default(str, prefix, arg, "");
}
[snip]
Quoted 8 lines · Phillip Wood
From: Phillip Wood <[email protected]>
We've had a test balloon for C99's bool type since
8277dbe987(git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As it has been over 18 months since this was added and there have been no complaints let's declare it a success and convert the return type our other string predicates to match.
Neat, I didn't even know we were running such an experiment. Thanks for getting around to it, I think the patches look great, added some complaints from 'clang-format', feel free to ignore.
Thanks,
Karthik
[snip]
Hi Karthik
Quoted 11 lines · Karthik Nayak
Quoted 8 lines · Phillip Wood
From: Phillip Wood <[email protected]>
We've had a test balloon for C99's bool type since
8277dbe987(git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As it has been over 18 months since this was added and there have been no complaints let's declare it a success and convert the return type our other string predicates to match.
Quoted 3 lines
Neat, I didn't even know we were running such an experiment. Thanks for getting around to it, I think the patches look great, added some complaints from 'clang-format', feel free to ignore.
Thanks for taking a look. I would have fixed the formatting but this is in next already so I'll leave it as it is if that's ok with you.
Thanks
Phillip
Quoted 14 lines · Phillip Wood
Hi Karthik
Quoted 11 lines · Karthik Nayak
Quoted 8 lines · Phillip Wood
From: Phillip Wood <[email protected]>
We've had a test balloon for C99's bool type since
8277dbe987(git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As it has been over 18 months since this was added and there have been no complaints let's declare it a success and convert the return type our other string predicates to match.
Quoted 7 lines
Quoted 3 lines
Neat, I didn't even know we were running such an experiment. Thanks for getting around to it, I think the patches look great, added some complaints from 'clang-format', feel free to ignore.
Thanks for taking a look. I would have fixed the formatting but this is in next already so I'll leave it as it is if that's ok with you.
Of course :) These are small nits. I'm mostly interested in getting clang-format to work without any/many false positives, so I'm trying to test it with different patches that I read and report back!
Quoted 3 lines
Thanks
Phillip