summaryrefslogtreecommitdiff
path: root/numpy/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core/src')
-rw-r--r--numpy/core/src/arraymethods.c2
-rw-r--r--numpy/core/src/arrayobject.c59
-rw-r--r--numpy/core/src/multiarraymodule.c36
-rw-r--r--numpy/core/src/scalartypes.inc.src32
4 files changed, 86 insertions, 43 deletions
diff --git a/numpy/core/src/arraymethods.c b/numpy/core/src/arraymethods.c
index d4567401b..352300779 100644
--- a/numpy/core/src/arraymethods.c
+++ b/numpy/core/src/arraymethods.c
@@ -877,7 +877,7 @@ array_reduce(PyArrayObject *self, PyObject *args)
ret = PyTuple_New(3);
if (ret == NULL) return NULL;
- mod = PyImport_ImportModule("numpy.core._internal");
+ mod = PyImport_ImportModule("numpy.core.multiarray");
if (mod == NULL) {Py_DECREF(ret); return NULL;}
obj = PyObject_GetAttrString(mod, "_reconstruct");
Py_DECREF(mod);
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index 3a3e0f4b1..ccc068692 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -1771,7 +1771,7 @@ array_dealloc(PyArrayObject *self) {
**************** Implement Mapping Protocol ***************************
*************************************************************************/
-static _int_or_ssize_t
+static Py_ssize_t
array_length(PyArrayObject *self)
{
if (self->nd != 0) {
@@ -1812,7 +1812,7 @@ array_big_item(PyArrayObject *self, intp i)
/* contains optimization for 1-d arrays */
static PyObject *
-array_item_nice(PyArrayObject *self, _int_or_ssize_t i)
+array_item_nice(PyArrayObject *self, Py_ssize_t i)
{
if (self->nd == 1) {
char *item;
@@ -1877,7 +1877,7 @@ array_ass_big_item(PyArrayObject *self, intp i, PyObject *v)
#endif
#ifndef array_ass_item
static int
-array_ass_item(PyArrayObject *self, _int_or_ssize_t i, PyObject *v)
+array_ass_item(PyArrayObject *self, Py_ssize_t i, PyObject *v)
{
return array_ass_big_item(self, (intp) i, v);
}
@@ -2825,8 +2825,8 @@ static PyMappingMethods array_as_mapping = {
/* removed multiple segment interface */
-static _int_or_ssize_t
-array_getsegcount(PyArrayObject *self, _int_or_ssize_t *lenp)
+static Py_ssize_t
+array_getsegcount(PyArrayObject *self, Py_ssize_t *lenp)
{
if (lenp)
*lenp = PyArray_NBYTES(self);
@@ -2840,8 +2840,8 @@ array_getsegcount(PyArrayObject *self, _int_or_ssize_t *lenp)
return 0;
}
-static _int_or_ssize_t
-array_getreadbuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)
+static Py_ssize_t
+array_getreadbuf(PyArrayObject *self, Py_ssize_t segment, void **ptrptr)
{
if (segment != 0) {
PyErr_SetString(PyExc_ValueError,
@@ -2859,8 +2859,8 @@ array_getreadbuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)
}
-static _int_or_ssize_t
-array_getwritebuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)
+static Py_ssize_t
+array_getwritebuf(PyArrayObject *self, Py_ssize_t segment, void **ptrptr)
{
if (PyArray_CHKFLAGS(self, WRITEABLE))
return array_getreadbuf(self, segment, (void **) ptrptr);
@@ -2871,8 +2871,8 @@ array_getwritebuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)
}
}
-static _int_or_ssize_t
-array_getcharbuf(PyArrayObject *self, _int_or_ssize_t segment, const char **ptrptr)
+static Py_ssize_t
+array_getcharbuf(PyArrayObject *self, Py_ssize_t segment, const char **ptrptr)
{
if (self->descr->type_num == PyArray_STRING || \
self->descr->type_num == PyArray_UNICODE)
@@ -3670,11 +3670,11 @@ static PyNumberMethods array_as_number = {
static PyObject *
-array_slice(PyArrayObject *self, _int_or_ssize_t ilow,
- _int_or_ssize_t ihigh)
+array_slice(PyArrayObject *self, Py_ssize_t ilow,
+ Py_ssize_t ihigh)
{
PyArrayObject *r;
- _int_or_ssize_t l;
+ Py_ssize_t l;
char *data;
if (self->nd == 0) {
@@ -3715,8 +3715,8 @@ array_slice(PyArrayObject *self, _int_or_ssize_t ilow,
static int
-array_ass_slice(PyArrayObject *self, _int_or_ssize_t ilow,
- _int_or_ssize_t ihigh, PyObject *v) {
+array_ass_slice(PyArrayObject *self, Py_ssize_t ilow,
+ Py_ssize_t ihigh, PyObject *v) {
int ret;
PyArrayObject *tmp;
@@ -5546,6 +5546,13 @@ array_dataptr_get(PyArrayObject *self)
}
static PyObject *
+array_ctypes_get(PyArrayObject *self)
+{
+ return PyObject_CallMethod(_numpy_internal, "_ctypes",
+ "O", self);
+}
+
+static PyObject *
array_interface_get(PyArrayObject *self)
{
PyObject *dict;
@@ -6102,6 +6109,10 @@ static PyGetSetDef array_getsetlist[] = {
(getter)array_flat_get,
(setter)array_flat_set,
"a 1-d view of a contiguous array"},
+ {"ctypes",
+ (getter)array_ctypes_get,
+ NULL,
+ "Ctypes interface object"},
{"__array_interface__",
(getter)array_interface_get,
NULL,
@@ -7997,7 +8008,7 @@ arrayiter_dealloc(PyArrayIterObject *it)
_pya_free(it);
}
-static _int_or_ssize_t
+static Py_ssize_t
iter_length(PyArrayIterObject *self)
{
return self->size;
@@ -10290,9 +10301,11 @@ arraydescr_richcompare(PyArray_Descr *self, PyObject *other, int cmp_op)
**************** Implement Mapping Protocol ***************************
*************************************************************************/
-static _int_or_ssize_t
-descr_length(PyArray_Descr *self)
+static Py_ssize_t
+descr_length(PyObject *self0)
{
+
+ PyArray_Descr *self = (PyArray_Descr *)self0;
if (self->fields && self->fields != Py_None)
/* Remove the last entry (root) */
@@ -10335,13 +10348,9 @@ descr_subscript(PyArray_Descr *self, PyObject *op)
}
static PyMappingMethods descr_as_mapping = {
-#if PY_VERSION_HEX >= 0x02050000
- (lenfunc)descr_length, /*mp_length*/
-#else
- (inquiry)descr_length, /*mp_length*/
-#endif
+ descr_length, /*mp_length*/
(binaryfunc)descr_subscript, /*mp_subscript*/
- (objobjargproc)NULL, /*mp_ass_subscript*/
+ (objobjargproc)NULL, /*mp_ass_subscript*/
};
/****************** End of Mapping Protocol ******************************/
diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c
index 6bf6bfa4c..d4c1513be 100644
--- a/numpy/core/src/multiarraymodule.c
+++ b/numpy/core/src/multiarraymodule.c
@@ -15,6 +15,7 @@
/* $Id: multiarraymodule.c,v 1.36 2005/09/14 00:14:00 teoliphant Exp $ */
+#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "structmember.h"
/*#include <string.h>
@@ -5031,7 +5032,7 @@ array_fromString(PyObject *ignored, PyObject *args, PyObject *keywds)
char *data;
longlong nin=-1;
char *sep=NULL;
- int s;
+ Py_ssize_t s;
static char *kwlist[] = {"string", "dtype", "count", "sep", NULL};
PyArray_Descr *descr=NULL;
@@ -5807,6 +5808,37 @@ array__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds)
return PyInt_FromLong( (long) PyArray_GetNDArrayCVersion() );
}
+static char
+doc__reconstruct[] = "_reconstruct(subtype, shape, dtype) constructs an empty array. Used by Pickles.";
+
+static PyObject *
+array__reconstruct(PyObject *dummy, PyObject *args)
+{
+
+ PyTypeObject *subtype;
+ PyArray_Dims shape = {NULL, 0};
+ PyArray_Descr *dtype=NULL;
+ if (!PyArg_ParseTuple(args, "O!O&O&", &PyType_Type, &subtype,
+ PyArray_IntpConverter, &shape,
+ PyArray_DescrConverter, &dtype))
+ goto fail;
+
+ if (!PyType_IsSubtype(subtype, &PyArray_Type)) {
+ PyErr_SetString(PyExc_TypeError,
+ "_reconstruct: First argument must be " \
+ "a sub-type of ndarray");
+ goto fail;
+ }
+
+ return PyArray_NewFromDescr(subtype, dtype,
+ (int)shape.len, shape.ptr,
+ NULL, NULL, 0, NULL);
+ fail:
+ Py_XDECREF(dtype);
+ if (shape.ptr) PyDimMem_FREE(shape.ptr);
+ return NULL;
+}
+
static char
doc_set_string_function[] = "set_string_function(f, repr=1) sets the python function f to be the function used to obtain a pretty printable string version of a array whenever a array is printed. f(M) should expect a array argument M, and should return a string consisting of the desired representation of M for printing.";
@@ -6047,6 +6079,8 @@ format_longfloat(PyObject *dummy, PyObject *args, PyObject *kwds)
static struct PyMethodDef array_module_methods[] = {
{"_get_ndarray_c_version", (PyCFunction)array__get_ndarray_c_version,
METH_VARARGS|METH_KEYWORDS, doc__get_ndarray_c_version},
+ {"_reconstruct", (PyCFunction)array__reconstruct,
+ METH_VARARGS, doc__reconstruct},
{"set_string_function", (PyCFunction)array_set_string_function,
METH_VARARGS|METH_KEYWORDS, doc_set_string_function},
{"set_numeric_ops", (PyCFunction)array_set_ops_function,
diff --git a/numpy/core/src/scalartypes.inc.src b/numpy/core/src/scalartypes.inc.src
index ae7c610e3..ed53778aa 100644
--- a/numpy/core/src/scalartypes.inc.src
+++ b/numpy/core/src/scalartypes.inc.src
@@ -1400,7 +1400,7 @@ static PyMethodDef voidtype_methods[] = {
/************* As_mapping functions for void array scalar ************/
-static _int_or_ssize_t
+static Py_ssize_t
voidtype_length(PyVoidScalarObject *self)
{
if (!self->descr->fields || self->descr->fields == Py_None) {
@@ -1418,7 +1418,7 @@ voidtype_length(PyVoidScalarObject *self)
}
static PyObject *
-voidtype_item(PyVoidScalarObject *self, _int_or_ssize_t n)
+voidtype_item(PyVoidScalarObject *self, Py_ssize_t n)
{
intp m;
PyObject *flist=NULL, *key, *fieldinfo;
@@ -1467,7 +1467,7 @@ voidtype_subscript(PyVoidScalarObject *self, PyObject *ind)
n = PyArray_PyIntAsIntp(ind);
if (error_converting(n)) goto fail;
- return voidtype_item(self, (_int_or_ssize_t)n);
+ return voidtype_item(self, (Py_ssize_t)n);
fail:
PyErr_SetString(PyExc_IndexError, "invalid index");
@@ -1476,7 +1476,7 @@ voidtype_subscript(PyVoidScalarObject *self, PyObject *ind)
}
static int
-voidtype_ass_item(PyVoidScalarObject *self, _int_or_ssize_t n, PyObject *val)
+voidtype_ass_item(PyVoidScalarObject *self, Py_ssize_t n, PyObject *val)
{
intp m;
PyObject *flist=NULL, *key, *fieldinfo, *newtup;
@@ -1542,7 +1542,7 @@ voidtype_ass_subscript(PyVoidScalarObject *self, PyObject *ind, PyObject *val)
/* try to convert it to a number */
n = PyArray_PyIntAsIntp(ind);
if (error_converting(n)) goto fail;
- return voidtype_ass_item(self, (_int_or_ssize_t)n, val);
+ return voidtype_ass_item(self, (Py_ssize_t)n, val);
fail:
PyErr_SetString(PyExc_IndexError, msg);
@@ -2001,14 +2001,14 @@ object_arrtype_concat(PyObjectScalarObject *self, PyObject *other)
return PySequence_Concat(self->obval, other);
}
-static _int_or_ssize_t
+static Py_ssize_t
object_arrtype_length(PyObjectScalarObject *self)
{
return PyObject_Length(self->obval);
}
static PyObject *
-object_arrtype_repeat(PyObjectScalarObject *self, _int_or_ssize_t count)
+object_arrtype_repeat(PyObjectScalarObject *self, Py_ssize_t count)
{
return PySequence_Repeat(self->obval, count);
}
@@ -2039,7 +2039,7 @@ object_arrtype_inplace_concat(PyObjectScalarObject *self, PyObject *o)
}
static PyObject *
-object_arrtype_inplace_repeat(PyObjectScalarObject *self, _int_or_ssize_t count)
+object_arrtype_inplace_repeat(PyObjectScalarObject *self, Py_ssize_t count)
{
return PySequence_InPlaceRepeat(self->obval, count);
}
@@ -2082,8 +2082,8 @@ static PyMappingMethods object_arrtype_as_mapping = {
#endif
};
-static _int_or_ssize_t
-object_arrtype_getsegcount(PyObjectScalarObject *self, _int_or_ssize_t *lenp)
+static Py_ssize_t
+object_arrtype_getsegcount(PyObjectScalarObject *self, Py_ssize_t *lenp)
{
int newlen;
int cnt;
@@ -2100,8 +2100,8 @@ object_arrtype_getsegcount(PyObjectScalarObject *self, _int_or_ssize_t *lenp)
return cnt;
}
-static _int_or_ssize_t
-object_arrtype_getreadbuf(PyObjectScalarObject *self, _int_or_ssize_t segment, void **ptrptr)
+static Py_ssize_t
+object_arrtype_getreadbuf(PyObjectScalarObject *self, Py_ssize_t segment, void **ptrptr)
{
PyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;
@@ -2116,8 +2116,8 @@ object_arrtype_getreadbuf(PyObjectScalarObject *self, _int_or_ssize_t segment, v
return (*pb->bf_getreadbuffer)(self->obval, segment, ptrptr);
}
-static _int_or_ssize_t
-object_arrtype_getwritebuf(PyObjectScalarObject *self, _int_or_ssize_t segment, void **ptrptr)
+static Py_ssize_t
+object_arrtype_getwritebuf(PyObjectScalarObject *self, Py_ssize_t segment, void **ptrptr)
{
PyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;
@@ -2132,8 +2132,8 @@ object_arrtype_getwritebuf(PyObjectScalarObject *self, _int_or_ssize_t segment,
return (*pb->bf_getwritebuffer)(self->obval, segment, ptrptr);
}
-static _int_or_ssize_t
-object_arrtype_getcharbuf(PyObjectScalarObject *self, _int_or_ssize_t segment,
+static Py_ssize_t
+object_arrtype_getcharbuf(PyObjectScalarObject *self, Py_ssize_t segment,
const char **ptrptr)
{
PyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;