diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2006-03-04 18:49:58 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2006-03-04 18:49:58 (GMT) |
commit | 1fc4b776d47b45133a2730d191552ec2f1928baa (patch) | |
tree | b4aabdec7ebdef5cf5f9c362ff19c23ca9e4024e | |
parent | 8c49c82889d1af480fa159b56c0e70ef81cf6749 (diff) | |
download | cpython-1fc4b776d47b45133a2730d191552ec2f1928baa.zip cpython-1fc4b776d47b45133a2730d191552ec2f1928baa.tar.gz cpython-1fc4b776d47b45133a2730d191552ec2f1928baa.tar.bz2 |
Change some sequnce APIs to use Py_ssize_t.
-rw-r--r-- | Include/abstract.h | 8 | ||||
-rw-r--r-- | Objects/abstract.c | 14 |
2 files changed, 13 insertions, 9 deletions
diff --git a/Include/abstract.h b/Include/abstract.h index 03eb30a..73dc91d 100644 --- a/Include/abstract.h +++ b/Include/abstract.h @@ -1042,7 +1042,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ /* Return a pointer to the underlying item array for an object retured by PySequence_Fast */ - PyAPI_FUNC(int) PySequence_Count(PyObject *o, PyObject *value); + PyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value); /* Return the number of occurrences on value on o, that is, @@ -1060,8 +1060,8 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ #define PY_ITERSEARCH_COUNT 1 #define PY_ITERSEARCH_INDEX 2 #define PY_ITERSEARCH_CONTAINS 3 - PyAPI_FUNC(int) _PySequence_IterSearch(PyObject *seq, PyObject *obj, - int operation); + PyAPI_FUNC(Py_ssize_t) _PySequence_IterSearch(PyObject *seq, + PyObject *obj, int operation); /* Iterate over seq. Result depends on the operation: PY_ITERSEARCH_COUNT: return # of times obj appears in seq; -1 if @@ -1086,7 +1086,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ is equivalent to the Python expression: value in o. */ - PyAPI_FUNC(int) PySequence_Index(PyObject *o, PyObject *value); + PyAPI_FUNC(Py_ssize_t) PySequence_Index(PyObject *o, PyObject *value); /* Return the first index for which o[i]=value. On error, diff --git a/Objects/abstract.c b/Objects/abstract.c index dc46193..7ded61a 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -1577,10 +1577,10 @@ PySequence_Fast(PyObject *v, const char *m) set ValueError and return -1 if none found; also return -1 on error. Py_ITERSEARCH_CONTAINS: return 1 if obj in seq, else 0; -1 on error. */ -int +Py_ssize_t _PySequence_IterSearch(PyObject *seq, PyObject *obj, int operation) { - int n; + Py_ssize_t n; int wrapped; /* for PY_ITERSEARCH_INDEX, true iff n wrapped around */ PyObject *it; /* iter(seq) */ @@ -1614,6 +1614,7 @@ _PySequence_IterSearch(PyObject *seq, PyObject *obj, int operation) case PY_ITERSEARCH_COUNT: ++n; if (n <= 0) { + /* XXX(nnorwitz): int means ssize_t */ PyErr_SetString(PyExc_OverflowError, "count exceeds C int size"); goto Fail; @@ -1622,6 +1623,7 @@ _PySequence_IterSearch(PyObject *seq, PyObject *obj, int operation) case PY_ITERSEARCH_INDEX: if (wrapped) { + /* XXX(nnorwitz): int means ssize_t */ PyErr_SetString(PyExc_OverflowError, "index exceeds C int size"); goto Fail; @@ -1660,7 +1662,7 @@ Done: } /* Return # of times o appears in s. */ -int +Py_ssize_t PySequence_Count(PyObject *s, PyObject *o) { return _PySequence_IterSearch(s, o, PY_ITERSEARCH_COUNT); @@ -1672,12 +1674,14 @@ PySequence_Count(PyObject *s, PyObject *o) int PySequence_Contains(PyObject *seq, PyObject *ob) { + Py_ssize_t result; if (PyType_HasFeature(seq->ob_type, Py_TPFLAGS_HAVE_SEQUENCE_IN)) { PySequenceMethods *sqm = seq->ob_type->tp_as_sequence; if (sqm != NULL && sqm->sq_contains != NULL) return (*sqm->sq_contains)(seq, ob); } - return _PySequence_IterSearch(seq, ob, PY_ITERSEARCH_CONTAINS); + result = _PySequence_IterSearch(seq, ob, PY_ITERSEARCH_CONTAINS); + return Py_SAFE_DOWNCAST(result, Py_ssize_t, int); } /* Backwards compatibility */ @@ -1688,7 +1692,7 @@ PySequence_In(PyObject *w, PyObject *v) return PySequence_Contains(w, v); } -int +Py_ssize_t PySequence_Index(PyObject *s, PyObject *o) { return _PySequence_IterSearch(s, o, PY_ITERSEARCH_INDEX); |