Skip to content

Commit

Permalink
Added lib_from_sym to detect openmp conflict and proper threading lay…
Browse files Browse the repository at this point in the history
…er default value
  • Loading branch information
anton-malakhov committed Sep 22, 2018
1 parent 0073a10 commit 73b25cb
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions numba/_helpermod.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Expose all functions as pointers in a dedicated C extension.
/* Import _pymodule.h first, for a recent _POSIX_C_SOURCE */
#include "_pymodule.h"
#include <math.h>
#ifdef __linux__
#define _GNU_SOURCE 1
#include <dlfcn.h>
#include <string.h>
#undef _GNU_SOURCE
#endif
#ifdef _MSC_VER
#define false 0
#define true 1
Expand Down Expand Up @@ -160,6 +166,33 @@ build_npymath_exports_dict(void)
return dct;
}

static PyObject *
_numba_lib_from_sym(PyObject *m, PyObject *arg)
{
void *sym;
Dl_info di;
PyObject *ret = NULL;
assert(arg);
#ifdef __linux__
/* Treat arg as a borrowed reference. */
Py_INCREF(arg);

sym = dlsym(RTLD_DEFAULT, PyString_AsString(arg));
if(sym) {
if(dladdr(sym, &di))
ret = PyString_FromString(di.dli_fname);
else
ret = PyString_FromString("(unknown)");
}

/* Treat arg as a borrowed reference. */
Py_DECREF(arg);
if(ret)
return ret;
#endif
Py_RETURN_NONE;
}

static PyMethodDef ext_methods[] = {
{ "rnd_get_state", (PyCFunction) _numba_rnd_get_state, METH_O, NULL },
{ "rnd_get_py_state_ptr", (PyCFunction) _numba_rnd_get_py_state_ptr, METH_NOARGS, NULL },
Expand All @@ -168,6 +201,7 @@ static PyMethodDef ext_methods[] = {
{ "rnd_set_state", (PyCFunction) _numba_rnd_set_state, METH_VARARGS, NULL },
{ "rnd_shuffle", (PyCFunction) _numba_rnd_shuffle, METH_O, NULL },
{ "_import_cython_function", (PyCFunction) _numba_import_cython_function, METH_VARARGS, NULL },
{ "lib_from_sym", (PyCFunction) _numba_lib_from_sym, METH_O, NULL },
{ NULL },
};

Expand Down

0 comments on commit 73b25cb

Please sign in to comment.