Patchwork D7913: cext: fix compiler warning about sign changing

login
register
mail settings
Submitter phabricator
Date Jan. 16, 2020, 8:39 p.m.
Message ID <differential-rev-PHID-DREV-s4borg2nl7ay2mskktwq-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/44452/
State Superseded
Headers show

Comments

phabricator - Jan. 16, 2020, 8:39 p.m.
spectral created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  line.len is a Py_ssize_t, and we're casing to size_t (unsigned). On my compiler,
  this causes a warning to be emitted:
  
    mercurial/cext/manifest.c: In function 'pathlen':
    mercurial/cext/manifest.c:48:44: warning: operand of ?: changes signedness from 'Py_ssize_t' {aka 'long int'} to 'long unsigned int' due to unsignedness of other operand [-Wsign-compare]
      return (end) ? (size_t)(end - l->start) : l->len;
                                                ^~~~~~

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/cext/manifest.c

CHANGE DETAILS




To: spectral, #hg-reviewers
Cc: mercurial-devel
phabricator - Jan. 17, 2020, 1:03 a.m.
mharbison72 added a comment.
mharbison72 accepted this revision.


  LGTM

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7913/new/

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

To: spectral, #hg-reviewers, mharbison72
Cc: mharbison72, mercurial-devel
Yuya Nishihara - Jan. 17, 2020, 12:09 p.m.
>  static PyObject *hashflags(line *l)
>  {
>  	char *s = l->start;
> -	size_t plen = pathlen(l);
> +	Py_ssize_t plen = pathlen(l);

We'll probably want to change `hplen` to `Py_ssize_t` as well.
phabricator - Jan. 17, 2020, 12:14 p.m.
yuja added a comment.


  > static PyObject *hashflags(line *l)
  >  {
  >
  >   	char *s = l->start;
  >
  > - size_t plen = pathlen(l);
  >
  > +	Py_ssize_t plen = pathlen(l);
  
  We'll probably want to change `hplen` to `Py_ssize_t` as well.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7913/new/

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

To: spectral, #hg-reviewers, mharbison72
Cc: yuja, mharbison72, mercurial-devel

Patch

diff --git a/mercurial/cext/manifest.c b/mercurial/cext/manifest.c
--- a/mercurial/cext/manifest.c
+++ b/mercurial/cext/manifest.c
@@ -42,17 +42,17 @@ 
 #define MANIFEST_TOO_SHORT_LINE -5
 
 /* get the length of the path for a line */
-static size_t pathlen(line *l)
+static Py_ssize_t pathlen(line *l)
 {
 	const char *end = memchr(l->start, '\0', l->len);
-	return (end) ? (size_t)(end - l->start) : l->len;
+	return (end) ? (Py_ssize_t)(end - l->start) : l->len;
 }
 
 /* get the node value of a single line */
 static PyObject *nodeof(line *l)
 {
 	char *s = l->start;
-	ssize_t llen = pathlen(l);
+	Py_ssize_t llen = pathlen(l);
 	PyObject *hash;
 	if (llen + 1 + 40 + 1 > l->len) { /* path '\0' hash '\n' */
 		PyErr_SetString(PyExc_ValueError, "manifest line too short");
@@ -76,7 +76,7 @@ 
 static PyObject *hashflags(line *l)
 {
 	char *s = l->start;
-	size_t plen = pathlen(l);
+	Py_ssize_t plen = pathlen(l);
 	PyObject *hash = nodeof(l);
 
 	/* 40 for hash, 1 for null byte, 1 for newline */
@@ -270,7 +270,7 @@ 
 
 static PyObject *lmiter_iterentriesnext(PyObject *o)
 {
-	size_t pl;
+	Py_ssize_t pl;
 	line *l;
 	Py_ssize_t consumed;
 	PyObject *ret = NULL, *path = NULL, *hash = NULL, *flags = NULL;
@@ -337,7 +337,7 @@ 
 
 static PyObject *lmiter_iterkeysnext(PyObject *o)
 {
-	size_t pl;
+	Py_ssize_t pl;
 	line *l = lmiter_nextline((lmIter *)o);
 	if (!l) {
 		return NULL;