forked from numpy/numpy
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store the context used to import _multiarray so that legacy functions
and external extensions can find it. This removes the dependency on _HPyGetContext() which is specific to the cpython ABI.
- Loading branch information
Showing
3 changed files
with
24 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
#if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY) | ||
extern void **PyArray_API; | ||
#else | ||
HPyContext *numpy_global_ctx = NULL; | ||
#if defined(PY_ARRAY_UNIQUE_SYMBOL) | ||
void **PyArray_API; | ||
#else | ||
|
@@ -51,7 +52,6 @@ | |
return -1; | ||
} | ||
c_api = PyObject_GetAttrString(numpy, "_ARRAY_API"); | ||
Py_DECREF(numpy); | ||
if (c_api == NULL) { | ||
PyErr_SetString(PyExc_AttributeError, "_ARRAY_API not found"); | ||
return -1; | ||
|
@@ -69,6 +69,11 @@ | |
return -1; | ||
} | ||
PyObject *ctx_capsule = PyObject_GetAttrString(numpy, "_HPY_CONTEXT"); | ||
Py_DECREF(numpy); | ||
numpy_global_ctx = (HPyContext *)PyCapsule_GetPointer(ctx_capsule, NULL); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rlamy
Author
Member
|
||
Py_DECREF(ctx_capsule); | ||
/* Perform runtime check of C API version */ | ||
if (NPY_VERSION != PyArray_GetNDArrayCVersion()) { | ||
PyErr_Format(PyExc_RuntimeError, "module compiled against "\ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,7 @@ set_legacy_print_mode(PyObject *NPY_UNUSED(self), PyObject *args) | |
} | ||
|
||
NPY_NO_EXPORT PyTypeObject* _PyArray_Type_p = NULL; | ||
NPY_NO_EXPORT HPyContext *numpy_global_ctx = NULL; | ||
|
||
/* Only here for API compatibility */ | ||
NPY_NO_EXPORT PyTypeObject PyBigArray_Type; | ||
|
@@ -4938,6 +4939,16 @@ static HPy init__multiarray_umath_impl(HPyContext *ctx) { | |
goto err; | ||
} | ||
#endif | ||
|
||
/* Store the context so legacy functions and extensions can access it */ | ||
numpy_global_ctx = ctx; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rlamy
Author
Member
|
||
s = PyCapsule_New((void *)ctx, NULL, NULL); | ||
if (s == NULL) { | ||
goto err; | ||
} | ||
PyDict_SetItemString(d, "_HPY_CONTEXT", s); | ||
Py_DECREF(s); | ||
|
||
return HPy_FromPyObject(ctx, m); | ||
|
||
err: | ||
|
and here you probably want an
assert(numpy_global_ctx != NULL)
?