[PATCH 3 of 7] pathencode: convert PyString* to PyBytes*
Gregory Szorc
gregory.szorc at gmail.com
Sat Oct 8 16:48:09 EDT 2016
# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1475956867 -7200
# Sat Oct 08 22:01:07 2016 +0200
# Node ID 5ce286c00dcefb7c432265417eb3d5d1fe368296
# Parent 921f070e83bcf78ffccac50c75ad6f8eebf2894b
pathencode: convert PyString* to PyBytes*
diff --git a/mercurial/pathencode.c b/mercurial/pathencode.c
--- a/mercurial/pathencode.c
+++ b/mercurial/pathencode.c
@@ -155,9 +155,9 @@ PyObject *encodedir(PyObject *self, PyOb
if (!PyArg_ParseTuple(args, "O:encodedir", &pathobj))
return NULL;
- if (PyString_AsStringAndSize(pathobj, &path, &len) == -1) {
+ if (PyBytes_AsStringAndSize(pathobj, &path, &len) == -1) {
PyErr_SetString(PyExc_TypeError, "expected a string");
return NULL;
}
@@ -167,13 +167,13 @@ PyObject *encodedir(PyObject *self, PyOb
Py_INCREF(pathobj);
return pathobj;
}
- newobj = PyString_FromStringAndSize(NULL, newlen);
+ newobj = PyBytes_FromStringAndSize(NULL, newlen);
if (newobj) {
- PyString_GET_SIZE(newobj)--;
- _encodedir(PyString_AS_STRING(newobj), newlen, path,
+ PyBytes_GET_SIZE(newobj)--;
+ _encodedir(PyBytes_AS_STRING(newobj), newlen, path,
len + 1);
}
return newobj;
@@ -514,11 +514,11 @@ PyObject *lowerencode(PyObject *self, Py
if (!PyArg_ParseTuple(args, "s#:lowerencode", &path, &len))
return NULL;
newlen = _lowerencode(NULL, 0, path, len);
- ret = PyString_FromStringAndSize(NULL, newlen);
+ ret = PyBytes_FromStringAndSize(NULL, newlen);
if (ret)
- _lowerencode(PyString_AS_STRING(ret), newlen, path, len);
+ _lowerencode(PyBytes_AS_STRING(ret), newlen, path, len);
return ret;
}
@@ -567,13 +567,13 @@ static PyObject *hashmangle(const char *
destsize = 120;
if (lastdot >= 0)
destsize += len - lastdot - 1;
- ret = PyString_FromStringAndSize(NULL, destsize);
+ ret = PyBytes_FromStringAndSize(NULL, destsize);
if (ret == NULL)
return NULL;
- dest = PyString_AS_STRING(ret);
+ dest = PyBytes_AS_STRING(ret);
memcopy(dest, &destlen, destsize, "dh/", 3);
/* Copy up to dirprefixlen bytes of each path component, up to
a limit of maxshortdirslen bytes. */
@@ -637,9 +637,9 @@ static PyObject *hashmangle(const char *
if (lastdot >= 0)
memcopy(dest, &destlen, destsize, &src[lastdot],
len - lastdot - 1);
- PyString_GET_SIZE(ret) = destlen;
+ PyBytes_GET_SIZE(ret) = destlen;
return ret;
}
@@ -652,9 +652,9 @@ static int sha1hash(char hash[20], const
static PyObject *shafunc;
PyObject *shaobj, *hashobj;
if (shafunc == NULL) {
- PyObject *hashlib, *name = PyString_FromString("hashlib");
+ PyObject *hashlib, *name = PyBytes_FromString("hashlib");
if (name == NULL)
return -1;
@@ -685,16 +685,16 @@ static int sha1hash(char hash[20], const
Py_DECREF(shaobj);
if (hashobj == NULL)
return -1;
- if (!PyString_Check(hashobj) || PyString_GET_SIZE(hashobj) != 20) {
+ if (!PyBytes_Check(hashobj) || PyBytes_GET_SIZE(hashobj) != 20) {
PyErr_SetString(PyExc_TypeError,
"result of digest is not a 20-byte hash");
Py_DECREF(hashobj);
return -1;
}
- memcpy(hash, PyString_AS_STRING(hashobj), 20);
+ memcpy(hash, PyBytes_AS_STRING(hashobj), 20);
Py_DECREF(hashobj);
return 0;
}
@@ -730,9 +730,9 @@ PyObject *pathencode(PyObject *self, PyO
if (!PyArg_ParseTuple(args, "O:pathencode", &pathobj))
return NULL;
- if (PyString_AsStringAndSize(pathobj, &path, &len) == -1) {
+ if (PyBytes_AsStringAndSize(pathobj, &path, &len) == -1) {
PyErr_SetString(PyExc_TypeError, "expected a string");
return NULL;
}
@@ -746,13 +746,13 @@ PyObject *pathencode(PyObject *self, PyO
Py_INCREF(pathobj);
return pathobj;
}
- newobj = PyString_FromStringAndSize(NULL, newlen);
+ newobj = PyBytes_FromStringAndSize(NULL, newlen);
if (newobj) {
- PyString_GET_SIZE(newobj)--;
- basicencode(PyString_AS_STRING(newobj), newlen, path,
+ PyBytes_GET_SIZE(newobj)--;
+ basicencode(PyBytes_AS_STRING(newobj), newlen, path,
len + 1);
}
}
else
More information about the Mercurial-devel
mailing list