##// END OF EJS Templates
pathencode: convert PyString* to PyBytes*
Gregory Szorc -
r30099:e60de7fc default
parent child Browse files
Show More
@@ -156,7 +156,7 b' PyObject *encodedir(PyObject *self, PyOb'
156 if (!PyArg_ParseTuple(args, "O:encodedir", &pathobj))
156 if (!PyArg_ParseTuple(args, "O:encodedir", &pathobj))
157 return NULL;
157 return NULL;
158
158
159 if (PyString_AsStringAndSize(pathobj, &path, &len) == -1) {
159 if (PyBytes_AsStringAndSize(pathobj, &path, &len) == -1) {
160 PyErr_SetString(PyExc_TypeError, "expected a string");
160 PyErr_SetString(PyExc_TypeError, "expected a string");
161 return NULL;
161 return NULL;
162 }
162 }
@@ -168,11 +168,11 b' PyObject *encodedir(PyObject *self, PyOb'
168 return pathobj;
168 return pathobj;
169 }
169 }
170
170
171 newobj = PyString_FromStringAndSize(NULL, newlen);
171 newobj = PyBytes_FromStringAndSize(NULL, newlen);
172
172
173 if (newobj) {
173 if (newobj) {
174 PyString_GET_SIZE(newobj)--;
174 PyBytes_GET_SIZE(newobj)--;
175 _encodedir(PyString_AS_STRING(newobj), newlen, path,
175 _encodedir(PyBytes_AS_STRING(newobj), newlen, path,
176 len + 1);
176 len + 1);
177 }
177 }
178
178
@@ -515,9 +515,9 b' PyObject *lowerencode(PyObject *self, Py'
515 return NULL;
515 return NULL;
516
516
517 newlen = _lowerencode(NULL, 0, path, len);
517 newlen = _lowerencode(NULL, 0, path, len);
518 ret = PyString_FromStringAndSize(NULL, newlen);
518 ret = PyBytes_FromStringAndSize(NULL, newlen);
519 if (ret)
519 if (ret)
520 _lowerencode(PyString_AS_STRING(ret), newlen, path, len);
520 _lowerencode(PyBytes_AS_STRING(ret), newlen, path, len);
521
521
522 return ret;
522 return ret;
523 }
523 }
@@ -568,11 +568,11 b' static PyObject *hashmangle(const char *'
568 if (lastdot >= 0)
568 if (lastdot >= 0)
569 destsize += len - lastdot - 1;
569 destsize += len - lastdot - 1;
570
570
571 ret = PyString_FromStringAndSize(NULL, destsize);
571 ret = PyBytes_FromStringAndSize(NULL, destsize);
572 if (ret == NULL)
572 if (ret == NULL)
573 return NULL;
573 return NULL;
574
574
575 dest = PyString_AS_STRING(ret);
575 dest = PyBytes_AS_STRING(ret);
576 memcopy(dest, &destlen, destsize, "dh/", 3);
576 memcopy(dest, &destlen, destsize, "dh/", 3);
577
577
578 /* Copy up to dirprefixlen bytes of each path component, up to
578 /* Copy up to dirprefixlen bytes of each path component, up to
@@ -638,7 +638,7 b' static PyObject *hashmangle(const char *'
638 memcopy(dest, &destlen, destsize, &src[lastdot],
638 memcopy(dest, &destlen, destsize, &src[lastdot],
639 len - lastdot - 1);
639 len - lastdot - 1);
640
640
641 PyString_GET_SIZE(ret) = destlen;
641 PyBytes_GET_SIZE(ret) = destlen;
642
642
643 return ret;
643 return ret;
644 }
644 }
@@ -653,7 +653,7 b' static int sha1hash(char hash[20], const'
653 PyObject *shaobj, *hashobj;
653 PyObject *shaobj, *hashobj;
654
654
655 if (shafunc == NULL) {
655 if (shafunc == NULL) {
656 PyObject *hashlib, *name = PyString_FromString("hashlib");
656 PyObject *hashlib, *name = PyBytes_FromString("hashlib");
657
657
658 if (name == NULL)
658 if (name == NULL)
659 return -1;
659 return -1;
@@ -686,14 +686,14 b' static int sha1hash(char hash[20], const'
686 if (hashobj == NULL)
686 if (hashobj == NULL)
687 return -1;
687 return -1;
688
688
689 if (!PyString_Check(hashobj) || PyString_GET_SIZE(hashobj) != 20) {
689 if (!PyBytes_Check(hashobj) || PyBytes_GET_SIZE(hashobj) != 20) {
690 PyErr_SetString(PyExc_TypeError,
690 PyErr_SetString(PyExc_TypeError,
691 "result of digest is not a 20-byte hash");
691 "result of digest is not a 20-byte hash");
692 Py_DECREF(hashobj);
692 Py_DECREF(hashobj);
693 return -1;
693 return -1;
694 }
694 }
695
695
696 memcpy(hash, PyString_AS_STRING(hashobj), 20);
696 memcpy(hash, PyBytes_AS_STRING(hashobj), 20);
697 Py_DECREF(hashobj);
697 Py_DECREF(hashobj);
698 return 0;
698 return 0;
699 }
699 }
@@ -731,7 +731,7 b' PyObject *pathencode(PyObject *self, PyO'
731 if (!PyArg_ParseTuple(args, "O:pathencode", &pathobj))
731 if (!PyArg_ParseTuple(args, "O:pathencode", &pathobj))
732 return NULL;
732 return NULL;
733
733
734 if (PyString_AsStringAndSize(pathobj, &path, &len) == -1) {
734 if (PyBytes_AsStringAndSize(pathobj, &path, &len) == -1) {
735 PyErr_SetString(PyExc_TypeError, "expected a string");
735 PyErr_SetString(PyExc_TypeError, "expected a string");
736 return NULL;
736 return NULL;
737 }
737 }
@@ -747,11 +747,11 b' PyObject *pathencode(PyObject *self, PyO'
747 return pathobj;
747 return pathobj;
748 }
748 }
749
749
750 newobj = PyString_FromStringAndSize(NULL, newlen);
750 newobj = PyBytes_FromStringAndSize(NULL, newlen);
751
751
752 if (newobj) {
752 if (newobj) {
753 PyString_GET_SIZE(newobj)--;
753 PyBytes_GET_SIZE(newobj)--;
754 basicencode(PyString_AS_STRING(newobj), newlen, path,
754 basicencode(PyBytes_AS_STRING(newobj), newlen, path,
755 len + 1);
755 len + 1);
756 }
756 }
757 }
757 }
General Comments 0
You need to be logged in to leave comments. Login now