[Numpy-svn] r8491 - trunk/numpy/numarray
numpy-svn at scipy.org
numpy-svn at scipy.org
Sat Jul 17 14:15:12 EDT 2010
Author: ptvirtan
Date: 2010-07-17 13:15:12 -0500 (Sat, 17 Jul 2010)
New Revision: 8491
Modified:
trunk/numpy/numarray/_capi.c
Log:
3K: numarray: Python3 fixes in _capi.c
Thanks to Christoph Gohlke.
Modified: trunk/numpy/numarray/_capi.c
===================================================================
--- trunk/numpy/numarray/_capi.c 2010-07-17 18:14:46 UTC (rev 8490)
+++ trunk/numpy/numarray/_capi.c 2010-07-17 18:15:12 UTC (rev 8491)
@@ -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 @@
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 @@
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 @@
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 @@
"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 @@
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 @@
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 @@
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 @@
#endif
/* boiler plate API init */
-#if PY_VERSION_HEX >= 0x03010000
+#if defined(NPY_PY3K)
#define RETVAL m
@@ -3388,7 +3392,7 @@
NULL
};
-PyObject *PyInit___capi(void)
+PyObject *PyInit__capi(void)
#else
#define RETVAL
@@ -3402,13 +3406,13 @@
_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 @@
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) {
More information about the Numpy-svn
mailing list