summaryrefslogtreecommitdiff
path: root/numpy/numarray
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2010-07-17 18:15:12 +0000
committerPauli Virtanen <pav@iki.fi>2010-07-17 18:15:12 +0000
commitd74911d5be8916efd3b6e6f0728c9685c6970608 (patch)
tree0b003f9eebbc419db8be43ee5454410ca377f0ce /numpy/numarray
parent8a4fb936484cf0ba8b5e76706dc9b52b535549af (diff)
downloadnumpy-d74911d5be8916efd3b6e6f0728c9685c6970608.tar.gz
3K: numarray: Python3 fixes in _capi.c
Thanks to Christoph Gohlke.
Diffstat (limited to 'numpy/numarray')
-rw-r--r--numpy/numarray/_capi.c44
1 files changed, 24 insertions, 20 deletions
diff --git a/numpy/numarray/_capi.c b/numpy/numarray/_capi.c
index 56e291055..446594d99 100644
--- a/numpy/numarray/_capi.c
+++ b/numpy/numarray/_capi.c
@@ -2,7 +2,7 @@
#define _libnumarray_MODULE
#include "include/numpy/libnumarray.h"
-#include "npy_config.h"
+#include "numpy/npy_3kcompat.h"
#include <float.h>
#if (defined(__unix__) || defined(unix)) && !defined(USG)
@@ -940,12 +940,16 @@ cfunc_repr(PyObject *self)
me->descr.name, (unsigned long ) me->descr.fptr,
me->descr.chkself, me->descr.align,
me->descr.wantIn, me->descr.wantOut);
- return PyString_FromString(buf);
+ return PyUString_FromString(buf);
}
static PyTypeObject CfuncType = {
- PyObject_HEAD_INIT(NULL)
- 0,
+#if defined(NPY_PY3K)
+ PyVarObject_HEAD_INIT(0,0)
+#else
+ PyObject_HEAD_INIT(0)
+ 0, /* ob_size */
+#endif
"Cfunc",
sizeof(CfuncObject),
0,
@@ -2048,8 +2052,7 @@ static int
getShape(PyObject *a, maybelong *shape, int dims)
{
long slen;
-
- if (PyString_Check(a)) {
+ if (PyBytes_Check(a)) {
PyErr_Format(PyExc_TypeError,
"getShape: numerical sequences can't contain strings.");
return -1;
@@ -2124,11 +2127,12 @@ setArrayFromSequence(PyArrayObject *a, PyObject *s, int dim, long offset)
if (NA_setFromPythonScalar(a, offset, o) < 0)
return -2;
mustbe = NUMBER;
- } else if (PyString_Check(o)) {
+ } else if (PyBytes_Check(o)) {
PyErr_SetString( PyExc_ValueError,
"setArrayFromSequence: strings can't define numeric numarray.");
return -3;
} else if (PySequence_Check(o)) {
+
if ((mustbe == NOTHING) || (mustbe == SEQUENCE)) {
if (mustbe == NOTHING) {
mustbe = SEQUENCE;
@@ -2219,7 +2223,7 @@ _NA_maxType(PyObject *seq, int limit)
"Expecting a python numeric type, got something else.");
return -1;
}
- } else if (PySequence_Check(seq) && !PyString_Check(seq)) {
+ } else if (PySequence_Check(seq) && !PyBytes_Check(seq)) {
long i, maxtype=BOOL_SCALAR, slen;
slen = PySequence_Length(seq);
@@ -2246,9 +2250,13 @@ _NA_maxType(PyObject *seq, int limit)
return BOOL_SCALAR;
else
#endif
+#if defined(NPY_PY3K)
if (PyInt_Check(seq))
return INT_SCALAR;
else if (PyLong_Check(seq))
+#else
+ if (PyLong_Check(seq))
+#endif
return LONG_SCALAR;
else if (PyFloat_Check(seq))
return FLOAT_SCALAR;
@@ -2278,7 +2286,7 @@ NA_isPythonScalar(PyObject *o)
PyLong_Check(o) ||
PyFloat_Check(o) ||
PyComplex_Check(o) ||
- (PyString_Check(o) && (PyString_Size(o) == 1));
+ (PyBytes_Check(o) && (PyBytes_Size(o) == 1));
return rval;
}
@@ -2455,18 +2463,14 @@ _setFromPythonScalarCore(PyArrayObject *a, long offset, PyObject*value, int entr
rval = _setFromPythonScalarCore(a, offset, value, entries+1);
Py_DECREF(value);
return rval;
- } else if (PyString_Check(value)) {
- long size = PyString_Size(value);
+ } else if (PyBytes_Check(value)) {
+ long size = PyBytes_Size(value);
if ((size <= 0) || (size > 1)) {
PyErr_Format( PyExc_ValueError,
"NA_setFromPythonScalar: len(string) must be 1.");
return -1;
}
-#if defined(NPY_PY3K)
NA_set_Int64(a, offset, *PyBytes_AsString(value));
-#else
- NA_set_Int64(a, offset, *PyString_AsString(value));
-#endif
} else {
PyErr_Format(PyExc_TypeError,
"NA_setFromPythonScalar: bad value type.");
@@ -3372,7 +3376,7 @@ static PyMethodDef _libnumarrayMethods[] = {
#endif
/* boiler plate API init */
-#if PY_VERSION_HEX >= 0x03010000
+#if defined(NPY_PY3K)
#define RETVAL m
@@ -3388,7 +3392,7 @@ static struct PyModuleDef moduledef = {
NULL
};
-PyObject *PyInit___capi(void)
+PyObject *PyInit__capi(void)
#else
#define RETVAL
@@ -3402,13 +3406,13 @@ PyMODINIT_FUNC init_capi(void)
_Error = PyErr_NewException("numpy.numarray._capi.error", NULL, NULL);
/* Create a CObject containing the API pointer array's address */
-#if PY_VERSION_HEX >= 0x03010000
+#if defined(NPY_PY3K)
m = PyModule_Create(&moduledef);
#else
m = Py_InitModule("_capi", _libnumarrayMethods);
#endif
-#if PY_VERSION_HEX >= 0x03000000
+#if defined(NPY_PY3K)
c_api_object = PyCapsule_New((void *)libnumarray_API, NULL, NULL);
if (c_api_object == NULL) {
PyErr_Clear();
@@ -3428,7 +3432,7 @@ PyMODINIT_FUNC init_capi(void)
else {
return RETVAL;
}
- if (PyModule_AddObject(m, "__version__", PyString_FromString("0.9")) < 0) {
+ if (PyModule_AddObject(m, "__version__", PyUString_FromString("0.9")) < 0) {
return RETVAL;
}
if (_import_array() < 0) {