##// END OF EJS Templates
parsers: convert PyString* to PyBytes*...
Gregory Szorc -
r30100:c5afe553 default
parent child Browse files
Show More
@@ -610,37 +610,37 b' static PyObject *pack_dirstate(PyObject '
610 /* Figure out how much we need to allocate. */
610 /* Figure out how much we need to allocate. */
611 for (nbytes = 40, pos = 0; PyDict_Next(map, &pos, &k, &v);) {
611 for (nbytes = 40, pos = 0; PyDict_Next(map, &pos, &k, &v);) {
612 PyObject *c;
612 PyObject *c;
613 if (!PyString_Check(k)) {
613 if (!PyBytes_Check(k)) {
614 PyErr_SetString(PyExc_TypeError, "expected string key");
614 PyErr_SetString(PyExc_TypeError, "expected string key");
615 goto bail;
615 goto bail;
616 }
616 }
617 nbytes += PyString_GET_SIZE(k) + 17;
617 nbytes += PyBytes_GET_SIZE(k) + 17;
618 c = PyDict_GetItem(copymap, k);
618 c = PyDict_GetItem(copymap, k);
619 if (c) {
619 if (c) {
620 if (!PyString_Check(c)) {
620 if (!PyBytes_Check(c)) {
621 PyErr_SetString(PyExc_TypeError,
621 PyErr_SetString(PyExc_TypeError,
622 "expected string key");
622 "expected string key");
623 goto bail;
623 goto bail;
624 }
624 }
625 nbytes += PyString_GET_SIZE(c) + 1;
625 nbytes += PyBytes_GET_SIZE(c) + 1;
626 }
626 }
627 }
627 }
628
628
629 packobj = PyString_FromStringAndSize(NULL, nbytes);
629 packobj = PyBytes_FromStringAndSize(NULL, nbytes);
630 if (packobj == NULL)
630 if (packobj == NULL)
631 goto bail;
631 goto bail;
632
632
633 p = PyString_AS_STRING(packobj);
633 p = PyBytes_AS_STRING(packobj);
634
634
635 pn = PySequence_ITEM(pl, 0);
635 pn = PySequence_ITEM(pl, 0);
636 if (PyString_AsStringAndSize(pn, &s, &l) == -1 || l != 20) {
636 if (PyBytes_AsStringAndSize(pn, &s, &l) == -1 || l != 20) {
637 PyErr_SetString(PyExc_TypeError, "expected a 20-byte hash");
637 PyErr_SetString(PyExc_TypeError, "expected a 20-byte hash");
638 goto bail;
638 goto bail;
639 }
639 }
640 memcpy(p, s, l);
640 memcpy(p, s, l);
641 p += 20;
641 p += 20;
642 pn = PySequence_ITEM(pl, 1);
642 pn = PySequence_ITEM(pl, 1);
643 if (PyString_AsStringAndSize(pn, &s, &l) == -1 || l != 20) {
643 if (PyBytes_AsStringAndSize(pn, &s, &l) == -1 || l != 20) {
644 PyErr_SetString(PyExc_TypeError, "expected a 20-byte hash");
644 PyErr_SetString(PyExc_TypeError, "expected a 20-byte hash");
645 goto bail;
645 goto bail;
646 }
646 }
@@ -685,21 +685,21 b' static PyObject *pack_dirstate(PyObject '
685 putbe32((uint32_t)mtime, p + 8);
685 putbe32((uint32_t)mtime, p + 8);
686 t = p + 12;
686 t = p + 12;
687 p += 16;
687 p += 16;
688 len = PyString_GET_SIZE(k);
688 len = PyBytes_GET_SIZE(k);
689 memcpy(p, PyString_AS_STRING(k), len);
689 memcpy(p, PyBytes_AS_STRING(k), len);
690 p += len;
690 p += len;
691 o = PyDict_GetItem(copymap, k);
691 o = PyDict_GetItem(copymap, k);
692 if (o) {
692 if (o) {
693 *p++ = '\0';
693 *p++ = '\0';
694 l = PyString_GET_SIZE(o);
694 l = PyBytes_GET_SIZE(o);
695 memcpy(p, PyString_AS_STRING(o), l);
695 memcpy(p, PyBytes_AS_STRING(o), l);
696 p += l;
696 p += l;
697 len += l + 1;
697 len += l + 1;
698 }
698 }
699 putbe32((uint32_t)len, t);
699 putbe32((uint32_t)len, t);
700 }
700 }
701
701
702 pos = p - PyString_AS_STRING(packobj);
702 pos = p - PyBytes_AS_STRING(packobj);
703 if (pos != nbytes) {
703 if (pos != nbytes) {
704 PyErr_Format(PyExc_SystemError, "bad dirstate size: %ld != %ld",
704 PyErr_Format(PyExc_SystemError, "bad dirstate size: %ld != %ld",
705 (long)pos, (long)nbytes);
705 (long)pos, (long)nbytes);
@@ -796,7 +796,7 b' static const char *index_deref(indexObje'
796 return self->offsets[pos];
796 return self->offsets[pos];
797 }
797 }
798
798
799 return PyString_AS_STRING(self->data) + pos * v1_hdrsize;
799 return PyBytes_AS_STRING(self->data) + pos * v1_hdrsize;
800 }
800 }
801
801
802 static inline int index_get_parents(indexObject *self, Py_ssize_t rev,
802 static inline int index_get_parents(indexObject *self, Py_ssize_t rev,
@@ -926,7 +926,7 b' static const char *index_node(indexObjec'
926 PyObject *tuple, *str;
926 PyObject *tuple, *str;
927 tuple = PyList_GET_ITEM(self->added, pos - self->length + 1);
927 tuple = PyList_GET_ITEM(self->added, pos - self->length + 1);
928 str = PyTuple_GetItem(tuple, 7);
928 str = PyTuple_GetItem(tuple, 7);
929 return str ? PyString_AS_STRING(str) : NULL;
929 return str ? PyBytes_AS_STRING(str) : NULL;
930 }
930 }
931
931
932 data = index_deref(self, pos);
932 data = index_deref(self, pos);
@@ -937,7 +937,7 b' static int nt_insert(indexObject *self, '
937
937
938 static int node_check(PyObject *obj, char **node, Py_ssize_t *nodelen)
938 static int node_check(PyObject *obj, char **node, Py_ssize_t *nodelen)
939 {
939 {
940 if (PyString_AsStringAndSize(obj, node, nodelen) == -1)
940 if (PyBytes_AsStringAndSize(obj, node, nodelen) == -1)
941 return -1;
941 return -1;
942 if (*nodelen == 20)
942 if (*nodelen == 20)
943 return 0;
943 return 0;
@@ -1825,7 +1825,7 b' static PyObject *index_partialmatch(inde'
1825 case -2:
1825 case -2:
1826 Py_RETURN_NONE;
1826 Py_RETURN_NONE;
1827 case -1:
1827 case -1:
1828 return PyString_FromStringAndSize(nullid, 20);
1828 return PyBytes_FromStringAndSize(nullid, 20);
1829 }
1829 }
1830
1830
1831 fullnode = index_node(self, rev);
1831 fullnode = index_node(self, rev);
@@ -1834,7 +1834,7 b' static PyObject *index_partialmatch(inde'
1834 "could not access rev %d", rev);
1834 "could not access rev %d", rev);
1835 return NULL;
1835 return NULL;
1836 }
1836 }
1837 return PyString_FromStringAndSize(fullnode, 20);
1837 return PyBytes_FromStringAndSize(fullnode, 20);
1838 }
1838 }
1839
1839
1840 static PyObject *index_m_get(indexObject *self, PyObject *args)
1840 static PyObject *index_m_get(indexObject *self, PyObject *args)
@@ -2247,7 +2247,7 b' static void nt_invalidate_added(indexObj'
2247 PyObject *tuple = PyList_GET_ITEM(self->added, i);
2247 PyObject *tuple = PyList_GET_ITEM(self->added, i);
2248 PyObject *node = PyTuple_GET_ITEM(tuple, 7);
2248 PyObject *node = PyTuple_GET_ITEM(tuple, 7);
2249
2249
2250 nt_insert(self, PyString_AS_STRING(node), -1);
2250 nt_insert(self, PyBytes_AS_STRING(node), -1);
2251 }
2251 }
2252
2252
2253 if (start == 0)
2253 if (start == 0)
@@ -2372,9 +2372,9 b' static int index_assign_subscript(indexO'
2372 */
2372 */
2373 static Py_ssize_t inline_scan(indexObject *self, const char **offsets)
2373 static Py_ssize_t inline_scan(indexObject *self, const char **offsets)
2374 {
2374 {
2375 const char *data = PyString_AS_STRING(self->data);
2375 const char *data = PyBytes_AS_STRING(self->data);
2376 Py_ssize_t pos = 0;
2376 Py_ssize_t pos = 0;
2377 Py_ssize_t end = PyString_GET_SIZE(self->data);
2377 Py_ssize_t end = PyBytes_GET_SIZE(self->data);
2378 long incr = v1_hdrsize;
2378 long incr = v1_hdrsize;
2379 Py_ssize_t len = 0;
2379 Py_ssize_t len = 0;
2380
2380
@@ -2416,11 +2416,11 b' static int index_init(indexObject *self,'
2416
2416
2417 if (!PyArg_ParseTuple(args, "OO", &data_obj, &inlined_obj))
2417 if (!PyArg_ParseTuple(args, "OO", &data_obj, &inlined_obj))
2418 return -1;
2418 return -1;
2419 if (!PyString_Check(data_obj)) {
2419 if (!PyBytes_Check(data_obj)) {
2420 PyErr_SetString(PyExc_TypeError, "data is not a string");
2420 PyErr_SetString(PyExc_TypeError, "data is not a string");
2421 return -1;
2421 return -1;
2422 }
2422 }
2423 size = PyString_GET_SIZE(data_obj);
2423 size = PyBytes_GET_SIZE(data_obj);
2424
2424
2425 self->inlined = inlined_obj && PyObject_IsTrue(inlined_obj);
2425 self->inlined = inlined_obj && PyObject_IsTrue(inlined_obj);
2426 self->data = data_obj;
2426 self->data = data_obj;
@@ -2613,7 +2613,7 b' static PyObject *readshas('
2613 return NULL;
2613 return NULL;
2614 }
2614 }
2615 for (i = 0; i < num; i++) {
2615 for (i = 0; i < num; i++) {
2616 PyObject *hash = PyString_FromStringAndSize(source, hashwidth);
2616 PyObject *hash = PyBytes_FromStringAndSize(source, hashwidth);
2617 if (hash == NULL) {
2617 if (hash == NULL) {
2618 Py_DECREF(list);
2618 Py_DECREF(list);
2619 return NULL;
2619 return NULL;
@@ -2669,7 +2669,7 b' static PyObject *fm1readmarker(const cha'
2669 if (data + hashwidth > dataend) {
2669 if (data + hashwidth > dataend) {
2670 goto overflow;
2670 goto overflow;
2671 }
2671 }
2672 prec = PyString_FromStringAndSize(data, hashwidth);
2672 prec = PyBytes_FromStringAndSize(data, hashwidth);
2673 data += hashwidth;
2673 data += hashwidth;
2674 if (prec == NULL) {
2674 if (prec == NULL) {
2675 goto bail;
2675 goto bail;
@@ -2712,9 +2712,9 b' static PyObject *fm1readmarker(const cha'
2712 if (meta + leftsize + rightsize > dataend) {
2712 if (meta + leftsize + rightsize > dataend) {
2713 goto overflow;
2713 goto overflow;
2714 }
2714 }
2715 left = PyString_FromStringAndSize(meta, leftsize);
2715 left = PyBytes_FromStringAndSize(meta, leftsize);
2716 meta += leftsize;
2716 meta += leftsize;
2717 right = PyString_FromStringAndSize(meta, rightsize);
2717 right = PyBytes_FromStringAndSize(meta, rightsize);
2718 meta += rightsize;
2718 meta += rightsize;
2719 tmp = PyTuple_New(2);
2719 tmp = PyTuple_New(2);
2720 if (!left || !right || !tmp) {
2720 if (!left || !right || !tmp) {
General Comments 0
You need to be logged in to leave comments. Login now