Skip to content

Commit

Permalink
Auto merge of numpy#5983 - charris:rename-npy_cache_pyfunc, r=njsmith
Browse files Browse the repository at this point in the history
MAINT: Rename npy_cache_pyfunc to npy_cache_import.

The function will be new in NumPy 1.10, so get this done before
branching that version. The old name was a bit too specific for a
function that could also be used to cache other attributes than just
functions.
  • Loading branch information
homu committed Jun 19, 2015
2 parents 4027d16 + 75e4353 commit d033b6e
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/getset.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ array_descr_set(PyArrayObject *self, PyObject *arg)
PyObject *safe;
static PyObject *checkfunc = NULL;

npy_cache_pyfunc("numpy.core._internal", "_view_is_safe", &checkfunc);
npy_cache_import("numpy.core._internal", "_view_is_safe", &checkfunc);
if (checkfunc == NULL) {
return -1;
}
Expand Down
6 changes: 3 additions & 3 deletions numpy/core/src/multiarray/mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ prepare_index(PyArrayObject *self, PyObject *index,
used_ndim, PyArray_DIM(self, used_ndim),
indices[i].value);

npy_cache_pyfunc(
npy_cache_import(
"numpy", "VisibleDeprecationWarning", &warning);
if (warning == NULL) {
goto failed_building_indices;
Expand Down Expand Up @@ -1434,7 +1434,7 @@ array_subscript(PyArrayObject *self, PyObject *op)
obj_is_string_or_stringlist(op)) {
PyObject *obj;
static PyObject *indexfunc = NULL;
npy_cache_pyfunc("numpy.core._internal", "_index_fields", &indexfunc);
npy_cache_import("numpy.core._internal", "_index_fields", &indexfunc);
if (indexfunc == NULL) {
return NULL;
}
Expand Down Expand Up @@ -1795,7 +1795,7 @@ array_assign_subscript(PyArrayObject *self, PyObject *ind, PyObject *op)
"multi-field assignment is not supported");
}

npy_cache_pyfunc("numpy.core._internal", "_index_fields", &indexfunc);
npy_cache_import("numpy.core._internal", "_index_fields", &indexfunc);
if (indexfunc == NULL) {
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ PyArray_GetField(PyArrayObject *self, PyArray_Descr *typed, int offset)
PyObject *safe;
static PyObject *checkfunc = NULL;

npy_cache_pyfunc("numpy.core._internal", "_getfield_is_safe", &checkfunc);
npy_cache_import("numpy.core._internal", "_getfield_is_safe", &checkfunc);
if (checkfunc == NULL) {
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/multiarraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2403,7 +2403,7 @@ array_matmul(PyObject *NPY_UNUSED(m), PyObject *args, PyObject* kwds)
char *subscripts;
PyArrayObject *ops[2];

npy_cache_pyfunc("numpy.core.multiarray", "matmul", &matmul);
npy_cache_import("numpy.core.multiarray", "matmul", &matmul);
if (matmul == NULL) {
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/number.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ array_matrix_multiply(PyArrayObject *m1, PyObject *m2)
{
static PyObject *matmul = NULL;

npy_cache_pyfunc("numpy.core.multiarray", "matmul", &matmul);
npy_cache_import("numpy.core.multiarray", "matmul", &matmul);
if (matmul == NULL) {
return NULL;
}
Expand Down
6 changes: 3 additions & 3 deletions numpy/core/src/private/npy_import.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
* exit,
*
* @param module Absolute module name.
* @param function Function name.
* @param attr module attribute to cache.
* @param cache Storage location for imported function.
*/
NPY_INLINE static void
npy_cache_pyfunc(const char *module, const char *function, PyObject **cache)
npy_cache_import(const char *module, const char *attr, PyObject **cache)
{
if (*cache == NULL) {
PyObject *mod = PyImport_ImportModule(module);

if (mod != NULL) {
*cache = PyObject_GetAttrString(mod, function);
*cache = PyObject_GetAttrString(mod, attr);
Py_DECREF(mod);
}
}
Expand Down

0 comments on commit d033b6e

Please sign in to comment.