Skip to content

Commit

Permalink
RF: refactor import_array as documented
Browse files Browse the repository at this point in the history
Instead of calling `import_array()` in every C function, use the method
of sharing the numpy API pointer table documented here:

http://docs.scipy.org/doc/numpy/reference/c-api.array.html#importing-the-api

Also, deal with different return types from `import_array()` in Python 3
and Python 2 - see
http://mail.scipy.org/pipermail/numpy-discussion/2010-December/054345.html
  • Loading branch information
matthew-brett committed Aug 28, 2015
1 parent ded2e3d commit 0471c74
Show file tree
Hide file tree
Showing 16 changed files with 7,001 additions and 5,626 deletions.
10 changes: 6 additions & 4 deletions lib/fff_python_wrapper/fffpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
because PyArray_API is defined static, in order not to share that symbol
within the dso. (import_array() asks the pointer value to the python process)
*/
void fffpy_import_array(void) {
import_array();
return;
/*
* deal with differences in macro return result between Python 2 and 3
* http://mail.scipy.org/pipermail/numpy-discussion/2010-December/054350.html
*/
IMP_OUT fffpy_import_array(void) {
import_array();
}


/* Static functions */
static npy_intp _PyArray_main_axis(const PyArrayObject* x, int* ok);
static fff_vector* _fff_vector_new_from_buffer(const char* data, npy_intp dim, npy_intp stride, int type, int itemsize);
Expand Down
11 changes: 10 additions & 1 deletion lib/fff_python_wrapper/fffpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,17 @@
static, in order not to share that symbol within the
dso. (import_array() asks the pointer value to the python process)
*/
extern void fffpy_import_array(void);
/*
* deal with differences in macro return result between Python 2 and 3
* http://mail.scipy.org/pipermail/numpy-discussion/2010-December/054350.html
*/
#if PY_MAJOR_VERSION >= 3
typedef int IMP_OUT;
#else
typedef void IMP_OUT;
#endif

extern IMP_OUT fffpy_import_array(void);

/*!
\brief Convert \c PyArrayObject to \c fff_vector
Expand Down

0 comments on commit 0471c74

Please sign in to comment.