Patchwork D11444: dirstate: make dirstate flags char be unsigned

login
register
mail settings
Submitter phabricator
Date Sept. 17, 2021, 12:07 a.m.
Message ID <differential-rev-PHID-DREV-ko4o5pogtw4nk6beizjr-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49761/
State Superseded
Headers show

Comments

phabricator - Sept. 17, 2021, 12:07 a.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Since https://phab.mercurial-scm.org/D11387, `CC='clang -Werror' make
  local` has started failing like this:
  
    mercurial/cext/util.h:41:50: error: implicit conversion from 'int' to 'char' changes value from 128 to -128 [-Werror,-Wconstant-conversion]
    static const char dirstate_flag_rust_special = 1 << 7;
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~   ~~^~~~
  
  This patch fixes that by making the flags be an unsigned char. That
  also matches the `bool` typedef we have in `util.h`, which seems good
  since many of the `dirstate_item_c_*()` functions return a `bool`.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11444

AFFECTED FILES
  mercurial/cext/parsers.c
  mercurial/cext/util.h

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/cext/util.h b/mercurial/cext/util.h
--- a/mercurial/cext/util.h
+++ b/mercurial/cext/util.h
@@ -24,21 +24,21 @@ 
 /* clang-format off */
 typedef struct {
 	PyObject_HEAD
-	char flags;
+	unsigned char flags;
 	int mode;
 	int size;
 	int mtime;
 } dirstateItemObject;
 /* clang-format on */
 
-static const char dirstate_flag_wc_tracked = 1;
-static const char dirstate_flag_p1_tracked = 1 << 1;
-static const char dirstate_flag_p2_tracked = 1 << 2;
-static const char dirstate_flag_possibly_dirty = 1 << 3;
-static const char dirstate_flag_merged = 1 << 4;
-static const char dirstate_flag_clean_p1 = 1 << 5;
-static const char dirstate_flag_clean_p2 = 1 << 6;
-static const char dirstate_flag_rust_special = 1 << 7;
+static const unsigned char dirstate_flag_wc_tracked = 1;
+static const unsigned char dirstate_flag_p1_tracked = 1 << 1;
+static const unsigned char dirstate_flag_p2_tracked = 1 << 2;
+static const unsigned char dirstate_flag_possibly_dirty = 1 << 3;
+static const unsigned char dirstate_flag_merged = 1 << 4;
+static const unsigned char dirstate_flag_clean_p1 = 1 << 5;
+static const unsigned char dirstate_flag_clean_p2 = 1 << 6;
+static const unsigned char dirstate_flag_rust_special = 1 << 7;
 
 extern PyTypeObject dirstateItemType;
 #define dirstate_tuple_check(op) (Py_TYPE(op) == &dirstateItemType)
diff --git a/mercurial/cext/parsers.c b/mercurial/cext/parsers.c
--- a/mercurial/cext/parsers.c
+++ b/mercurial/cext/parsers.c
@@ -144,9 +144,9 @@ 
 
 static inline bool dirstate_item_c_added(dirstateItemObject *self)
 {
-	char mask = (dirstate_flag_wc_tracked | dirstate_flag_p1_tracked |
+	unsigned char mask = (dirstate_flag_wc_tracked | dirstate_flag_p1_tracked |
 	             dirstate_flag_p2_tracked);
-	char target = dirstate_flag_wc_tracked;
+	unsigned char target = dirstate_flag_wc_tracked;
 	return (self->flags & mask) == target;
 }