summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2007-05-23 18:47:08 +0000
committerTravis Oliphant <oliphant@enthought.com>2007-05-23 18:47:08 +0000
commit519e621cce49d0f6bf3f76ffbe84537ec81b532a (patch)
tree86b63054239ac6c657911bff197c159c1dfa6441 /numpy
parent5b87029e229fa3dcf0e81231899c36bd52a7616c (diff)
downloadnumpy-519e621cce49d0f6bf3f76ffbe84537ec81b532a.tar.gz
Fix so that _internal.py gets imported when it is needed. Perhaps this will fix the problem with multiple-interpreters not working correctly.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/include/numpy/ndarrayobject.h7
-rw-r--r--numpy/core/src/arraymethods.c6
-rw-r--r--numpy/core/src/arrayobject.c12
-rw-r--r--numpy/core/src/multiarraymodule.c12
-rw-r--r--numpy/core/src/scalartypes.inc.src12
5 files changed, 37 insertions, 12 deletions
diff --git a/numpy/core/include/numpy/ndarrayobject.h b/numpy/core/include/numpy/ndarrayobject.h
index b5ef4290c..65b2df121 100644
--- a/numpy/core/include/numpy/ndarrayobject.h
+++ b/numpy/core/include/numpy/ndarrayobject.h
@@ -1230,6 +1230,13 @@ typedef struct PyArrayObject {
#define fortran fortran_ /* For some compilers */
+/* Array Flags Object */
+typedef struct PyArrayFlagsObject {
+ PyObject_HEAD
+ PyObject *arr;
+ int flags;
+} PyArrayFlagsObject;
+
/* Mirrors buffer object to ptr */
typedef struct {
diff --git a/numpy/core/src/arraymethods.c b/numpy/core/src/arraymethods.c
index 54bda5d1e..26c45e839 100644
--- a/numpy/core/src/arraymethods.c
+++ b/numpy/core/src/arraymethods.c
@@ -872,12 +872,15 @@ array_sort(PyArrayObject *self, PyObject *args, PyObject *kwds)
if (order == Py_None) order = NULL;
if (order != NULL) {
PyObject *new_name;
+ PyObject *_numpy_internal;
saved = self->descr;
if (saved->names == NULL) {
PyErr_SetString(PyExc_ValueError, "Cannot specify " \
"order when the array has no fields.");
return NULL;
}
+ _numpy_internal = PyImport_ImportModule("numpy.core._internal");
+ if (_numpy_internal == NULL) return NULL;
new_name = PyObject_CallMethod(_numpy_internal, "_newnames",
"OO", saved, order);
if (new_name == NULL) return NULL;
@@ -914,12 +917,15 @@ array_argsort(PyArrayObject *self, PyObject *args, PyObject *kwds)
if (order == Py_None) order = NULL;
if (order != NULL) {
PyObject *new_name;
+ PyObject *_numpy_internal;
saved = self->descr;
if (saved->names == NULL) {
PyErr_SetString(PyExc_ValueError, "Cannot specify " \
"order when the array has no fields.");
return NULL;
}
+ _numpy_internal = PyImport_ImportModule("numpy.core._internal");
+ if (_numpy_internal == NULL) return NULL;
new_name = PyObject_CallMethod(_numpy_internal, "_newnames",
"OO", saved, order);
if (new_name == NULL) return NULL;
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index c774ae5a2..d86ec6171 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -6131,6 +6131,9 @@ array_dataptr_get(PyArrayObject *self)
static PyObject *
array_ctypes_get(PyArrayObject *self)
{
+ PyObject *_numpy_internal;
+ _numpy_internal = PyImport_ImportModule("numpy.core._internal");
+ if (_numpy_internal == NULL) return NULL;
return PyObject_CallMethod(_numpy_internal, "_ctypes",
"ON", self,
PyLong_FromVoidPtr(self->data));
@@ -10844,6 +10847,7 @@ static PyObject *
arraydescr_protocol_descr_get(PyArray_Descr *self)
{
PyObject *dobj, *res;
+ PyObject *_numpy_internal;
if (self->names == NULL) {
/* get default */
@@ -10858,6 +10862,8 @@ arraydescr_protocol_descr_get(PyArray_Descr *self)
return res;
}
+ _numpy_internal = PyImport_ImportModule("numpy.core._internal");
+ if (_numpy_internal == NULL) return NULL;
return PyObject_CallMethod(_numpy_internal, "_array_descr",
"O", self);
}
@@ -11637,12 +11643,6 @@ static PyTypeObject PyArrayDescr_Type = {
/** Array Flags Object **/
-typedef struct PyArrayFlagsObject {
- PyObject_HEAD
- PyObject *arr;
- int flags;
-} PyArrayFlagsObject;
-
/*OBJECT_API
Get New ArrayFlagsObject
*/
diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c
index 98ec58e28..405f58403 100644
--- a/numpy/core/src/multiarraymodule.c
+++ b/numpy/core/src/multiarraymodule.c
@@ -23,9 +23,9 @@
#include "numpy/arrayobject.h"
#define PyAO PyArrayObject
+
static PyObject *typeDict=NULL; /* Must be explicitly loaded */
-static PyObject *_numpy_internal=NULL; /* A Python module for callbacks */
static PyArray_Descr *
_arraydescr_fromobj(PyObject *obj)
@@ -4859,8 +4859,11 @@ _convert_from_commastring(PyObject *obj, int align)
{
PyObject *listobj;
PyArray_Descr *res;
+ PyObject *_numpy_internal;
if (!PyString_Check(obj)) return NULL;
+ _numpy_internal = PyImport_ImportModule("numpy.core._internal");
+ if (_numpy_internal == NULL) return NULL;
listobj = PyObject_CallMethod(_numpy_internal, "_commastring",
"O", obj);
if (!listobj) return NULL;
@@ -4926,6 +4929,9 @@ then it will be checked for conformity and used directly.
static PyArray_Descr *
_use_fields_dict(PyObject *obj, int align)
{
+ PyObject *_numpy_internal;
+ _numpy_internal = PyImport_ImportModule("numpy.core._internal");
+ if (_numpy_internal == NULL) return NULL;
return (PyArray_Descr *)PyObject_CallMethod(_numpy_internal,
"_usefields",
"Oi", obj, align);
@@ -7583,9 +7589,7 @@ PyMODINIT_FUNC initmultiarray(void) {
set_flaginfo(d);
if (set_typeinfo(d) != 0) goto err;
-
- _numpy_internal = PyImport_ImportModule("numpy.core._internal");
- if (_numpy_internal != NULL) return;
+ return;
err:
if (!PyErr_Occurred()) {
diff --git a/numpy/core/src/scalartypes.inc.src b/numpy/core/src/scalartypes.inc.src
index 6739edfb4..e3cd5c031 100644
--- a/numpy/core/src/scalartypes.inc.src
+++ b/numpy/core/src/scalartypes.inc.src
@@ -740,8 +740,12 @@ gentype_flags_get(PyObject *self)
static PyObject *
voidtype_flags_get(PyVoidScalarObject *self)
{
- return PyObject_CallMethod(_numpy_internal, "flagsobj", "Oii",
- self, self->flags, 1);
+ PyObject *flagobj;
+ flagobj = PyArrayFlags_Type.tp_alloc(&PyArrayFlags_Type, 0);
+ if (flagobj == NULL) return NULL;
+ ((PyArrayFlagsObject *)flagobj)->arr = NULL;
+ ((PyArrayFlagsObject *)flagobj)->flags = self->flags;
+ return flagobj;
}
static PyObject *
@@ -2657,11 +2661,15 @@ PyArray_FieldNames(PyObject *fields)
{
PyObject *tup;
PyObject *ret;
+ PyObject *_numpy_internal;
+
if (!PyDict_Check(fields)) {
PyErr_SetString(PyExc_TypeError,
"Fields must be a dictionary");
return NULL;
}
+ _numpy_internal = PyImport_ImportModule("numpy.core._internal");
+ if (_numpy_internal == NULL) return NULL;
tup = PyObject_CallMethod(_numpy_internal, "_makenames_list", "O", fields);
if (tup == NULL) return NULL;
ret = PyTuple_GET_ITEM(tup, 0);