diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-03-13 03:37:36 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-03-13 03:37:36 +0000 |
commit | 67940c3d69c51bae3561695693020ced3d9d470a (patch) | |
tree | 38d928e5ed7af6b6f72858cf76e89a75c8521bbb | |
parent | cda50abbda59616f3794ca748c791a01a6e693a5 (diff) | |
download | numpy-67940c3d69c51bae3561695693020ced3d9d470a.tar.gz |
Fix up oldnumeric.py functions to return intput class where possible. Allow complex-valued arrays in PyArray_Round. Add backward-compatible support for Python2.5 ssize_t changes.
-rw-r--r-- | numpy/core/include/numpy/arrayobject.h | 9 | ||||
-rw-r--r-- | numpy/core/numeric.py | 2 | ||||
-rw-r--r-- | numpy/core/oldnumeric.py | 250 | ||||
-rw-r--r-- | numpy/core/src/arrayobject.c | 63 | ||||
-rw-r--r-- | numpy/core/src/multiarraymodule.c | 33 | ||||
-rw-r--r-- | numpy/core/src/scalartypes.inc.src | 58 |
6 files changed, 311 insertions, 104 deletions
diff --git a/numpy/core/include/numpy/arrayobject.h b/numpy/core/include/numpy/arrayobject.h index 3c3fe6b72..4794e2e4d 100644 --- a/numpy/core/include/numpy/arrayobject.h +++ b/numpy/core/include/numpy/arrayobject.h @@ -712,7 +712,6 @@ typedef enum { typedef clongdouble Complex512; #endif - /* End of typedefs for numarray style bit-width names */ /* This is to typedef Intp to the appropriate pointer size for this platform. @@ -722,6 +721,12 @@ typedef Py_uintptr_t uintp; #define SIZEOF_INTP SIZEOF_PY_INTPTR_T #define SIZEOF_UINTP SIZEOF_PY_INTPTR_T +#if PY_VERSION_HEX >= 0x02050000 +#define _int_or_ssize_t Py_ssize_t +#else +#define _int_or_ssize_t int +#endif + #define INTP_FMT "d" #if SIZEOF_PY_INTPTR_T == SIZEOF_INT @@ -1468,6 +1473,8 @@ typedef struct { PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, data, 0, CARRAY_FLAGS, NULL) #define PyArray_SimpleNewFromDescr(nd, dims, descr) \ PyArray_NewFromDescr(&PyArray_Type, descr, nd, dims, NULL, NULL, 0, NULL) +#define PyArray_EnsureAnyArray(obj) \ + (PyArray_Check(obj) ? obj : PyArray_EnsureArray(obj)) /* These might be faster without the dereferencing of obj diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 58d943066..0bb825cd8 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -76,7 +76,7 @@ def asarray(a, dtype=None, fortran=False, ndmin=0): def asanyarray(a, dtype=None, copy=False, fortran=False, ndmin=0): """will pass subclasses through... """ - return array(a, dtype, copy=False, fortran=fortran, subok=1, ndmin=ndmin) + return array(a, dtype, copy=copy, fortran=fortran, subok=1, ndmin=ndmin) def isfortran(a): return a.flags['FNC'] diff --git a/numpy/core/oldnumeric.py b/numpy/core/oldnumeric.py index 5e661b1ad..801d71295 100644 --- a/numpy/core/oldnumeric.py +++ b/numpy/core/oldnumeric.py @@ -30,7 +30,7 @@ __all__ = ['asarray', 'array', 'concatenate', import multiarray as mu import umath as um import numerictypes as nt -from numeric import asarray, array, correlate, outer, concatenate +from numeric import asarray, array, asanyarray, correlate, outer, concatenate from umath import sign, absolute, multiply import numeric as _nx import sys @@ -160,18 +160,38 @@ from cPickle import dump, dumps # functions that are now methods +def _wrapit(obj, method, *args, **kwds): + try: + wrap = obj.__array_wrap__ + except AttributeError: + wrap = None + result = getattr(asarray(obj),method)(*args, **kwds) + if wrap: + result = wrap(result) + return result + def take(a, indices, axis=0): - a = asarray(a) - return a.take(indices, axis) + try: + result = a.take(indices, axis) + except AttributeError: + result = _wrapit(a, 'take', indices, axis) + return result def reshape(a, newshape): """Change the shape of a to newshape. Return a new view object. """ - return asarray(a).reshape(newshape) + try: + result = a.reshape(newshape) + except AttributeError: + result = _wrapit(a, 'reshape', newshape) + return result def choose(a, choices): - a = asarray(a) - return a.choose(choices) + try: + result = a.choose(choices) + except AttributeError: + result = _wrapit(a, 'choose', choices) + return result def repeat(a, repeats, axis=0): """repeat elements of a repeats times along axis @@ -181,8 +201,11 @@ def repeat(a, repeats, axis=0): a tuple of length a.shape[axis] containing repeats. The argument a can be anything array(a) will accept. """ - a = array(a, copy=False) - return a.repeat(repeats, axis) + try: + result = a.repeat(repeats, axis) + except AttributeError: + result = _wrapit(a, 'repeat', repeats, axis) + return result def put (a, ind, v): """put(a, ind, v) results in a[n] = v[n] for all n in ind @@ -209,21 +232,27 @@ def swapaxes(a, axis1, axis2): """swapaxes(a, axis1, axis2) returns array a with axis1 and axis2 interchanged. """ - a = array(a, copy=False) - return a.swapaxes(axis1, axis2) + try: + result = a.swapaxes(axis1, axis2) + except AttributeError: + result = _wrapit(a, 'swapaxes', axis1, axis2) + return result def transpose(a, axes=None): """transpose(a, axes=None) returns array with dimensions permuted according to axes. If axes is None (default) returns array with dimensions reversed. """ - a = array(a,copy=False) - return a.transpose(axes) + try: + result = a.transpose(axes) + except AttributeError: + result = _wrapit(a, 'transpose', axes) + return result def sort(a, axis=-1): """sort(a,axis=-1) returns array with elements sorted along given axis. """ - a = array(a, copy=True) + a = asanyarray(a, copy=True) a.sort(axis) return a @@ -231,28 +260,40 @@ def argsort(a, axis=-1): """argsort(a,axis=-1) return the indices into a of the sorted array along the given axis, so that take(a,result,axis) is the sorted array. """ - a = array(a, copy=False) - return a.argsort(axis) + try: + result = a.argsort(axis) + except AttributeError: + result = _wrapit(a, 'argsort', axis) + return result def argmax(a, axis=-1): """argmax(a,axis=-1) returns the indices to the maximum value of the 1-D arrays along the given axis. """ - a = array(a, copy=False) - return a.argmax(axis) + try: + result = a.argmax(axis) + except AttributeError: + result = _wrapit(a, 'argmax', axis) + return result def argmin(a, axis=-1): """argmin(a,axis=-1) returns the indices to the minimum value of the 1-D arrays along the given axis. """ - a = array(a,copy=False) - return a.argmin(axis) - + try: + result = a.argmin(axis) + except AttributeError: + result = _wrapit(a, 'argmin', axis) + return result + def searchsorted(a, v): """searchsorted(a, v) """ - a = array(a,copy=False) - return a.searchsorted(v) + try: + result = a.searchsorted(v) + except AttributeError: + result = _wrapit(a, 'searchsorted', v) + return result def resize(a, new_shape): """resize(a,new_shape) returns a new array with the specified shape. @@ -287,7 +328,11 @@ def resize(a, new_shape): def squeeze(a): "Returns a with any ones from the shape of a removed" - return asarray(a).squeeze() + try: + result = a.squeeze() + except AttributeError: + result = _wrapit(a, 'squeeze') + return result def diagonal(a, offset=0, axis1=0, axis2=1): """diagonal(a, offset=0, axis1=0, axis2=1) returns the given diagonals @@ -311,29 +356,42 @@ def nonzero(a): """nonzero(a) returns the indices of the elements of a which are not zero, a must be 1d """ - return asarray(a).nonzero() + try: + result = a.nonzero() + except AttributeError: + result = _wrapit(a, 'nonzero') + return result def shape(a): """shape(a) returns the shape of a (as a function call which also works on nested sequences). """ try: - return a.shape + result = a.shape except AttributeError: - return asarray(a).shape + result = asarray(a).shape + return result def compress(condition, m, axis=-1): """compress(condition, x, axis=-1) = those elements of x corresponding to those elements of condition that are "true". condition must be the same size as the given dimension of x.""" - return asarray(m).compress(condition, axis) + try: + result = m.compress(condition, axis) + except AttributeError: + result = _wrapit(m, 'compress', condition, axis) + return result def clip(m, m_min, m_max): """clip(m, m_min, m_max) = every entry in m that is less than m_min is replaced by m_min, and every entry greater than m_max is replaced by m_max. """ - return asarray(m).clip(m_min, m_max) + try: + result = m.clip(m_min, m_max) + except AttributeError: + result = _wrapit(m, 'clip', m_min, m_max) + return result def sum(x, axis=0, dtype=None): """Sum the array over the given axis. The optional dtype argument @@ -358,67 +416,123 @@ def sum(x, axis=0, dtype=None): """ if isinstance(x, _gentype): return _sum_(x) - return asarray(x).sum(axis, dtype) + try: + result = x.sum(axis, dtype) + except AttributeError: + result = _wrapit(x, 'sum', axis, dtype) + return result def product (x, axis=0, dtype=None): """Product of the array elements over the given axis.""" - return asarray(x).prod(axis, dtype) + try: + result = x.prod(axis, dtype) + except AttributeError: + result = _wrapit(x, 'prod', axis, dtype) + return result def sometrue (x, axis=0): """Perform a logical_or over the given axis.""" - return asarray(x).any(axis) + try: + result = x.any(axis) + except AttributeError: + result = _wrapit(x, 'any', axis) + return result def alltrue (x, axis=0): """Perform a logical_and over the given axis.""" - return asarray(x).all(axis) + try: + result = x.all(axis) + except AttributeError: + result = _wrapit(x, 'all', axis) + return result def any(x,axis=None): - """Return true if any elements of x are true: sometrue(ravel(x)) + """Return true if any elements of x are true: """ - return ravel(x).any(axis) + try: + result = x.any(axis) + except AttributeError: + result = _wrapit(x, 'any', axis) + return result def all(x,axis=None): - """Return true if all elements of x are true: alltrue(ravel(x)) + """Return true if all elements of x are true: """ - return ravel(x).all(axis) + try: + result = x.all(axis) + except AttributeError: + result = _wrapit(x, 'all', axis) + return result def cumsum (x, axis=0, dtype=None): """Sum the array over the given axis.""" - return asarray(x).cumsum(axis, dtype) + try: + result = x.cumsum(axis, dtype) + except AttributeError: + result = _wrapit(x, 'cumsum', axis, dtype) + return result def cumproduct (x, axis=0, dtype=None): """Sum the array over the given axis.""" - return asarray(x).cumprod(axis, dtype) + try: + result = x.cumprod(axis, dtype) + except AttributeError: + result = _wrapit(x, 'cumprod', axis, dtype) + return result def ptp(a, axis=0): """Return maximum - minimum along the the given dimension """ - return asarray(a).ptp(axis) + try: + result = a.ptp(axis) + except AttributeError: + result = _wrapit(a, 'ptp', axis) + return result def amax(a, axis=0): """Return the maximum of 'a' along dimension axis. """ - return asarray(a).max(axis) + try: + result = a.max(axis) + except AttributeError: + result = _wrapit(a, 'max', axis) + return result def amin(a, axis=0): """Return the minimum of a along dimension axis. """ - return asarray(a).min(axis) + try: + result = a.min(axis) + except AttributeError: + result = _wrapit(a, 'min', axis) + return result def alen(a): """Return the length of a Python object interpreted as an array + of at least 1 dimension. """ - return len(asarray(a)) + try: + return len(a) + except TypeError: + return len(atleast_1d(a)) -def prod(a, axis=0): +def prod(a, axis=0, dtype=None): """Return the product of the elements along the given axis """ - return asarray(a).prod(axis) + try: + result = a.prod(axis, dtype) + except AttributeError: + result = _wrapit(a, 'prod', axis, dtype) + return result -def cumprod(a, axis=0): +def cumprod(a, axis=0, dtype=None): """Return the cumulative product of the elments along the given axis """ - return asarray(a).cumprod(axis) + try: + result = a.cumprod(axis, dtype) + except AttributeError: + result = _wrapit(a, 'cumprod', axis, dtype) + return result def ndim(a): try: @@ -426,7 +540,7 @@ def ndim(a): except AttributeError: return asarray(a).ndim -def rank (a): +def rank(a): """Get the rank of sequence a (the number of dimensions, not a matrix rank) The rank of a scalar is zero. """ @@ -455,33 +569,31 @@ def round_(a, decimals=0): Return 'a' if the array is not floating point. Round both the real and imaginary parts separately if the array is complex. """ - a = asarray(a) - if not issubclass(a.dtype.type, _nx.inexact): - return a - if issubclass(a.dtype.type, _nx.complexfloating): - return round_(a.real, decimals) + 1j*round_(a.imag, decimals) - if decimals is not 0: - decimals = asarray(decimals) - s = sign(a) - if decimals is not 0: - a = absolute(multiply(a, 10.**decimals)) - else: - a = absolute(a) - rem = a-asarray(a).astype(_nx.intp) - a = _nx.where(_nx.less(rem, 0.5), _nx.floor(a), _nx.ceil(a)) - # convert back - if decimals is not 0: - return multiply(a, s/(10.**decimals)) - else: - return multiply(a, s) + try: + result = a.round(decimals) + except AttributeError: + result = _wrapit(a, 'round', decimals) + return result around = round_ def mean(a, axis=0, dtype=None): - return asarray(a).mean(axis, dtype) + try: + result = a.mean(axis, dtype) + except AttributeError: + result = _wrapit(a, 'mean', axis, dtype) + return result def std(a, axis=0, dtype=None): - return asarray(a).std(axis, dtype) + try: + result = a.std(axis, dtype) + except AttributeError: + result = _wrapit(a, 'std', axis, dtype) + return result def var(a, axis=0, dtype=None): - return asarray(a).var(axis, dtype) + try: + result = a.std(axis, dtype) + except AttributeError: + result = _wrapit(a, 'var', axis, dtype) + return result diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index 98ce359ae..3b57c22c6 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -1331,7 +1331,7 @@ array_dealloc(PyArrayObject *self) { **************** Implement Mapping Protocol *************************** *************************************************************************/ -static int +static _int_or_ssize_t array_length(PyArrayObject *self) { if (self->nd != 0) { @@ -1371,12 +1371,11 @@ array_big_item(PyArrayObject *self, intp i) } static PyObject * -array_item_nice(PyArrayObject *self, int i) +array_item_nice(PyArrayObject *self, _int_or_ssize_t i) { return PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i)); } - static int array_ass_big_item(PyArrayObject *self, intp i, PyObject *v) { @@ -1415,11 +1414,18 @@ array_ass_big_item(PyArrayObject *self, intp i, PyObject *v) return 0; } -#if SIZEOF_INT == SIZEOF_INTP -#define array_ass_item array_ass_big_item +#if PY_VERSION_HEX < 0x02050000 + #if SIZEOF_INT == SIZEOF_INTP + #define array_ass_item array_ass_big_item + #endif #else + #if SIZEOF_SIZE_T == SIZEOF_INTP + #define array_ass_item array_ass_big_item + #endif +#endif +#ifndef array_ass_item static int -array_ass_item(PyArrayObject *self, int i, PyObject *v) +array_ass_item(PyArrayObject *self, _int_or_ssize_t i, PyObject *v) { return array_ass_big_item(self, (intp) i, v); } @@ -2257,7 +2263,11 @@ array_subscript_nice(PyArrayObject *self, PyObject *op) static PyMappingMethods array_as_mapping = { +#if PY_VERSION_HEX >= 0x02050000 + (lenfunc)array_length, /*mp_length*/ +#else (inquiry)array_length, /*mp_length*/ +#endif (binaryfunc)array_subscript_nice, /*mp_subscript*/ (objobjargproc)array_ass_sub, /*mp_ass_subscript*/ }; @@ -2271,8 +2281,8 @@ static PyMappingMethods array_as_mapping = { /* removed multiple segment interface */ -static int -array_getsegcount(PyArrayObject *self, int *lenp) +static _int_or_ssize_t +array_getsegcount(PyArrayObject *self, _int_or_ssize_t *lenp) { if (lenp) *lenp = PyArray_NBYTES(self); @@ -2286,8 +2296,8 @@ array_getsegcount(PyArrayObject *self, int *lenp) return 0; } -static int -array_getreadbuf(PyArrayObject *self, int segment, void **ptrptr) +static _int_or_ssize_t +array_getreadbuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr) { if (segment != 0) { PyErr_SetString(PyExc_ValueError, @@ -2305,8 +2315,8 @@ array_getreadbuf(PyArrayObject *self, int segment, void **ptrptr) } -static int -array_getwritebuf(PyArrayObject *self, int segment, void **ptrptr) +static _int_or_ssize_t +array_getwritebuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr) { if (PyArray_CHKFLAGS(self, WRITEABLE)) return array_getreadbuf(self, segment, (void **) ptrptr); @@ -2317,8 +2327,8 @@ array_getwritebuf(PyArrayObject *self, int segment, void **ptrptr) } } -static int -array_getcharbuf(PyArrayObject *self, int segment, const char **ptrptr) +static _int_or_ssize_t +array_getcharbuf(PyArrayObject *self, _int_or_ssize_t segment, const char **ptrptr) { if (self->descr->type_num == PyArray_STRING || \ self->descr->type_num == PyArray_UNICODE) @@ -2332,10 +2342,17 @@ array_getcharbuf(PyArrayObject *self, int segment, const char **ptrptr) } static PyBufferProcs array_as_buffer = { +#if PY_VERSION_HEX >= 0x02050000 + (readbufferproc)array_getreadbuf, /*bf_getreadbuffer*/ + (writebufferproc)array_getwritebuf, /*bf_getwritebuffer*/ + (segcountproc)array_getsegcount, /*bf_getsegcount*/ + (charbufferproc)array_getcharbuf, /*bf_getcharbuffer*/ +#else (getreadbufferproc)array_getreadbuf, /*bf_getreadbuffer*/ (getwritebufferproc)array_getwritebuf, /*bf_getwritebuffer*/ (getsegcountproc)array_getsegcount, /*bf_getsegcount*/ (getcharbufferproc)array_getcharbuf, /*bf_getcharbuffer*/ +#endif }; /****************** End of Buffer Protocol *******************************/ @@ -3187,18 +3204,30 @@ array_contains(PyArrayObject *self, PyObject *el) return ret; } - static PySequenceMethods array_as_sequence = { +#if PY_VERSION_HEX >= 0x02050000 + (lenfunc)array_length, /*sq_length*/ + (binaryfunc)NULL, /* sq_concat is handled by nb_add*/ + (ssizeargfunc)NULL, + (ssizeargfunc)array_item_nice, + (ssizessizeargfunc)array_slice, + (ssizeobjargproc)array_ass_item, /*sq_ass_item*/ + (ssizessizeobjargproc)array_ass_slice, /*sq_ass_slice*/ + (objobjproc) array_contains, /* sq_contains */ + (binaryfunc) NULL, /* sg_inplace_concat */ + (ssizeargfunc)NULL, +#else (inquiry)array_length, /*sq_length*/ (binaryfunc)NULL, /* sq_concat is handled by nb_add*/ (intargfunc)NULL, /* sq_repeat is handled nb_multiply*/ (intargfunc)array_item_nice, /*sq_item*/ (intintargfunc)array_slice, /*sq_slice*/ - (intobjargproc)array_ass_item, /*sq_ass_item*/ + (intobjargproc)array_ass_item, /*sq_ass_item*/ (intintobjargproc)array_ass_slice, /*sq_ass_slice*/ (objobjproc) array_contains, /* sq_contains */ - (binaryfunc) NULL, /* sg_inplace_concat */ + (binaryfunc) NULL, /* sg_inplace_concat */ (intargfunc) NULL /* sg_inplace_repeat */ +#endif }; diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c index d55987959..0d6f2e4b4 100644 --- a/numpy/core/src/multiarraymodule.c +++ b/numpy/core/src/multiarraymodule.c @@ -216,6 +216,39 @@ power_of_ten(int n) static PyObject * PyArray_Round(PyArrayObject *a, int decimals) { + if (PyArray_ISCOMPLEX(a)) { + PyObject *part; + PyObject *round_part; + PyObject *new; + int res; + new = PyArray_Copy(a); + if (new == NULL) return NULL; + + /* new.real = a.real.round(decimals) */ + part = PyObject_GetAttrString(new, "real"); + if (part == NULL) {Py_DECREF(new); return NULL;} + round_part = PyArray_Round\ + ((PyArrayObject *)PyArray_EnsureAnyArray(part), + decimals); + Py_DECREF(part); + if (round_part == NULL) {Py_DECREF(new); return NULL;} + res = PyObject_SetAttrString(new, "real", round_part); + Py_DECREF(round_part); + if (res < 0) {Py_DECREF(new); return NULL;} + + /* new.imag = a.imag.round(decimals) */ + part = PyObject_GetAttrString(new, "imag"); + if (part == NULL) {Py_DECREF(new); return NULL;} + round_part = PyArray_Round\ + ((PyArrayObject *)PyArray_EnsureAnyArray(part), + decimals); + Py_DECREF(part); + if (round_part == NULL) {Py_DECREF(new); return NULL;} + res = PyObject_SetAttrString(new, "imag", round_part); + Py_DECREF(round_part); + if (res < 0) {Py_DECREF(new); return NULL;} + return new; + } /* do the most common case first */ if (decimals == 0) { if (PyArray_ISINTEGER(a)) { diff --git a/numpy/core/src/scalartypes.inc.src b/numpy/core/src/scalartypes.inc.src index 4ede7e397..f8c474039 100644 --- a/numpy/core/src/scalartypes.inc.src +++ b/numpy/core/src/scalartypes.inc.src @@ -1879,20 +1879,20 @@ object_arrtype_setattro(PyObjectScalarObject *obj, PyObject *attr, PyObject *val return PyObject_GenericSetAttr((PyObject *)obj, attr, val); } -static int -object_arrtype_length(PyObjectScalarObject *self) -{ - return PyObject_Length(self->obval); -} - static PyObject * object_arrtype_concat(PyObjectScalarObject *self, PyObject *other) { return PySequence_Concat(self->obval, other); } +static _int_or_ssize_t +object_arrtype_length(PyObjectScalarObject *self) +{ + return PyObject_Length(self->obval); +} + static PyObject * -object_arrtype_repeat(PyObjectScalarObject *self, int count) +object_arrtype_repeat(PyObjectScalarObject *self, _int_or_ssize_t count) { return PySequence_Repeat(self->obval, count); } @@ -1923,12 +1923,24 @@ object_arrtype_inplace_concat(PyObjectScalarObject *self, PyObject *o) } static PyObject * -object_arrtype_inplace_repeat(PyObjectScalarObject *self, int count) +object_arrtype_inplace_repeat(PyObjectScalarObject *self, _int_or_ssize_t count) { return PySequence_InPlaceRepeat(self->obval, count); } static PySequenceMethods object_arrtype_as_sequence = { +#if PY_VERSION_HEX >= 0x02050000 + (lenfunc)object_arrtype_length, /*sq_length*/ + (binaryfunc)object_arrtype_concat, /*sq_concat*/ + (ssizeargfunc)object_arrtype_repeat, /*sq_repeat*/ + 0, /*sq_item*/ + 0, /*sq_slice*/ + 0, /* sq_ass_item */ + 0, /* sq_ass_slice */ + (objobjproc)object_arrtype_contains, /* sq_contains */ + (binaryfunc)object_arrtype_inplace_concat, /* sq_inplace_concat */ + (ssizeargfunc)object_arrtype_inplace_repeat, /* sq_inplace_repeat */ +#else (inquiry)object_arrtype_length, /*sq_length*/ (binaryfunc)object_arrtype_concat, /*sq_concat*/ (intargfunc)object_arrtype_repeat, /*sq_repeat*/ @@ -1939,16 +1951,23 @@ static PySequenceMethods object_arrtype_as_sequence = { (objobjproc)object_arrtype_contains, /* sq_contains */ (binaryfunc)object_arrtype_inplace_concat, /* sq_inplace_concat */ (intargfunc)object_arrtype_inplace_repeat, /* sq_inplace_repeat */ +#endif }; static PyMappingMethods object_arrtype_as_mapping = { +#if PY_VERSION_HEX >= 0x02050000 + (lenfunc)object_arrtype_length, + (binaryfunc)object_arrtype_subscript, + (objobjargproc)object_arrtype_ass_subscript, +#else (inquiry)object_arrtype_length, (binaryfunc)object_arrtype_subscript, (objobjargproc)object_arrtype_ass_subscript, +#endif }; -static int -object_arrtype_getsegcount(PyObjectScalarObject *self, int *lenp) +static _int_or_ssize_t +object_arrtype_getsegcount(PyObjectScalarObject *self, _int_or_ssize_t *lenp) { int newlen; int cnt; @@ -1965,8 +1984,8 @@ object_arrtype_getsegcount(PyObjectScalarObject *self, int *lenp) return cnt; } -static int -object_arrtype_getreadbuf(PyObjectScalarObject *self, int segment, void **ptrptr) +static _int_or_ssize_t +object_arrtype_getreadbuf(PyObjectScalarObject *self, _int_or_ssize_t segment, void **ptrptr) { PyBufferProcs *pb = self->obval->ob_type->tp_as_buffer; @@ -1981,8 +2000,8 @@ object_arrtype_getreadbuf(PyObjectScalarObject *self, int segment, void **ptrptr return (*pb->bf_getreadbuffer)(self->obval, segment, ptrptr); } -static int -object_arrtype_getwritebuf(PyObjectScalarObject *self, int segment, void **ptrptr) +static _int_or_ssize_t +object_arrtype_getwritebuf(PyObjectScalarObject *self, _int_or_ssize_t segment, void **ptrptr) { PyBufferProcs *pb = self->obval->ob_type->tp_as_buffer; @@ -1997,8 +2016,8 @@ object_arrtype_getwritebuf(PyObjectScalarObject *self, int segment, void **ptrpt return (*pb->bf_getwritebuffer)(self->obval, segment, ptrptr); } -static int -object_arrtype_getcharbuf(PyObjectScalarObject *self, int segment, +static _int_or_ssize_t +object_arrtype_getcharbuf(PyObjectScalarObject *self, _int_or_ssize_t segment, const char **ptrptr) { PyBufferProcs *pb = self->obval->ob_type->tp_as_buffer; @@ -2015,10 +2034,17 @@ object_arrtype_getcharbuf(PyObjectScalarObject *self, int segment, } static PyBufferProcs object_arrtype_as_buffer = { +#if PY_VERSION_HEX >= 0x02050000 + (readbufferproc)object_arrtype_getreadbuf, + (writebufferproc)object_arrtype_getwritebuf, + (segcountproc)object_arrtype_getsegcount, + (charbufferproc)object_arrtype_getcharbuf, +#else (getreadbufferproc)object_arrtype_getreadbuf, (getwritebufferproc)object_arrtype_getwritebuf, (getsegcountproc)object_arrtype_getsegcount, (getcharbufferproc)object_arrtype_getcharbuf, +#endif }; static PyObject * |