Patchwork [4,of,6] cext: modernize charencode.c to use Py_ssize_t

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 8, 2017, 2:30 p.m.
Message ID <9a77fc7505ac35764963.1502202623@mimosa>
Download mbox | patch
Permalink /patch/22750/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 8, 2017, 2:30 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1501509486 -32400
#      Mon Jul 31 22:58:06 2017 +0900
# Node ID 9a77fc7505ac35764963080f38266b9e5cab0934
# Parent  bc781471fcea7c9f2e5dc9db0b6696ad31c681cc
cext: modernize charencode.c to use Py_ssize_t

Patch

diff --git a/mercurial/cext/charencode.c b/mercurial/cext/charencode.c
--- a/mercurial/cext/charencode.c
+++ b/mercurial/cext/charencode.c
@@ -7,6 +7,7 @@ 
  the GNU General Public License, incorporated herein by reference.
 */
 
+#define PY_SSIZE_T_CLEAN
 #include <Python.h>
 
 #include "charencode.h"
@@ -57,11 +58,11 @@  static const char uppertable[128] = {
 /*
  * Turn a hex-encoded string into binary.
  */
-PyObject *unhexlify(const char *str, int len)
+PyObject *unhexlify(const char *str, Py_ssize_t len)
 {
 	PyObject *ret;
 	char *d;
-	int i;
+	Py_ssize_t i;
 
 	ret = PyBytes_FromStringAndSize(NULL, len / 2);
 
diff --git a/mercurial/cext/charencode.h b/mercurial/cext/charencode.h
--- a/mercurial/cext/charencode.h
+++ b/mercurial/cext/charencode.h
@@ -18,7 +18,7 @@  enum normcase_spec {
 	NORMCASE_OTHER = 0
 };
 
-PyObject *unhexlify(const char *str, int len);
+PyObject *unhexlify(const char *str, Py_ssize_t len);
 PyObject *asciilower(PyObject *self, PyObject *args);
 PyObject *asciiupper(PyObject *self, PyObject *args);
 PyObject *make_file_foldmap(PyObject *self, PyObject *args);
diff --git a/mercurial/cext/parsers.c b/mercurial/cext/parsers.c
--- a/mercurial/cext/parsers.c
+++ b/mercurial/cext/parsers.c
@@ -85,7 +85,7 @@  static PyObject *parse_manifest(PyObject
 
 		nlen = newline - zero - 1;
 
-		node = unhexlify(zero + 1, nlen > 40 ? 40 : (int)nlen);
+		node = unhexlify(zero + 1, nlen > 40 ? 40 : (Py_ssize_t)nlen);
 		if (!node)
 			goto bail;