Skip to content

Commit

Permalink
Merge pull request scipy#8482 from pv/integrate-intptr
Browse files Browse the repository at this point in the history
TST: integrate: use integers instead of PyCapsules to store pointers
  • Loading branch information
person142 authored Feb 26, 2018
2 parents d3f28b5 + 8e6fe57 commit 322f519
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
22 changes: 11 additions & 11 deletions scipy/integrate/tests/_test_multivariate.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ static const routine_t routines[] = {
};


static int create_capsules(PyObject *module)
static int create_pointers(PyObject *module)
{
PyObject *d, *capsule = NULL;
PyObject *d, *obj = NULL;
int i;

d = PyModule_GetDict(module);
Expand All @@ -75,24 +75,24 @@ static int create_capsules(PyObject *module)
}

for (i = 0; i < sizeof(routines) / sizeof(routine_t); ++i) {
capsule = PyCapsule_New(routines[i].ptr, NULL, NULL);
if (capsule == NULL) {
obj = PyLong_FromVoidPtr(routines[i].ptr);
if (obj == NULL) {
goto fail;
}

if (PyDict_SetItemString(d, routines[i].name, capsule)) {
if (PyDict_SetItemString(d, routines[i].name, obj)) {
goto fail;
}

Py_DECREF(capsule);
capsule = NULL;
Py_DECREF(obj);
obj = NULL;
}

Py_XDECREF(capsule);
Py_XDECREF(obj);
return 0;

fail:
Py_XDECREF(capsule);
Py_XDECREF(obj);
return -1;
}

Expand All @@ -118,7 +118,7 @@ PyInit__test_multivariate(void)
if (m == NULL) {
return NULL;
}
if (create_capsules(m)) {
if (create_pointers(m)) {
Py_DECREF(m);
return NULL;
}
Expand All @@ -135,6 +135,6 @@ init_test_multivariate(void)
if (m == NULL) {
return;
}
create_capsules(m);
create_pointers(m);
}
#endif
6 changes: 1 addition & 5 deletions scipy/integrate/tests/test_quadpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ def assert_quad(value_and_err, tabled_value, errTol=1.5e-8):


def get_clib_test_routine(name, restype, *argtypes):
capsule = getattr(clib_test, name)
PyCapsule_GetPointer = ctypes.pythonapi.PyCapsule_GetPointer
PyCapsule_GetPointer.restype = ctypes.c_void_p
PyCapsule_GetPointer.argtypes = [ctypes.py_object, ctypes.c_char_p]
ptr = PyCapsule_GetPointer(capsule, None)
ptr = getattr(clib_test, name)
return ctypes.cast(ptr, ctypes.CFUNCTYPE(restype, *argtypes))


Expand Down

0 comments on commit 322f519

Please sign in to comment.