Skip to content

Commit

Permalink
better fix
Browse files Browse the repository at this point in the history
  • Loading branch information
t-kalinowski committed Sep 16, 2024
1 parent 817c988 commit 69f0d75
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions src/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,6 @@ bool is_interactive() {
return s_isInteractive;
}

// a simplified version of loadSymbol adopted from libpython.cpp
void loadSymbol(void* pLib, const std::string& name, void** ppSymbol)
{
*ppSymbol = NULL;
#ifdef _WIN32
*ppSymbol = (void*) ::GetProcAddress((HINSTANCE)pLib, name.c_str());
#else
*ppSymbol = ::dlsym(pLib, name.c_str());
#endif
}


// track whether we have required numpy
std::string s_numpy_load_error;
bool haveNumPy() {
Expand Down Expand Up @@ -2811,6 +2799,13 @@ SEXP main_process_python_info_win32() {

#else

// a simplified version of loadSymbol adopted from libpython.cpp
void loadSymbol(void* pLib, const std::string& name, void** ppSymbol)
{
*ppSymbol = NULL;
*ppSymbol = ::dlsym(pLib, name.c_str());
}

SEXP main_process_python_info_unix() {

// bail early if we already know that Python symbols are not available
Expand Down Expand Up @@ -2845,6 +2840,7 @@ SEXP main_process_python_info_unix() {
}

if (PyGILState_Release == NULL) {
// PyGILState_Ensure is always not NULL, since we set it in reticulate_init()
loadSymbol(pLib, "PyGILState_Release", (void**)&PyGILState_Release);
loadSymbol(pLib, "PyGILState_Ensure", (void**)&PyGILState_Ensure);
}
Expand Down Expand Up @@ -2929,17 +2925,6 @@ void py_initialize(const std::string& python,
// if R is embedded in a python environment, rpycall has to be loaded as a regular
// module.

// We don't currently support running embedded on windows?
#ifndef _WIN32
void* pLib = NULL;
pLib = ::dlopen(NULL, RTLD_NOW | RTLD_GLOBAL);
// replace symbols that we initialized with dummy functions
// in reticulate_init
loadSymbol(pLib, "PyIter_Check", (void**) &PyIter_Check);
loadSymbol(pLib, "PyCallable_Check", (void**) &PyCallable_Check);
loadSymbol(pLib, "PyGILState_Ensure", (void**) &PyGILState_Ensure);
::dlclose(pLib);
#endif

GILScope scope;
PyImport_AddModule("rpycall");
Expand Down

0 comments on commit 69f0d75

Please sign in to comment.