diff --git a/NEWS.md b/NEWS.md index fdb0ef4a7..7d7ba883e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # reticulate (development version) +- Fixed error when using reticulate with radian (#1668, #1670). + - Fixed segfault encountered when running Python finalizer (#1663, #1664) - Fixed segfault encountered in RStudio when rapidly switching diff --git a/src/python.cpp b/src/python.cpp index 483a561dc..8768073fd 100644 --- a/src/python.cpp +++ b/src/python.cpp @@ -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() { @@ -2811,6 +2799,12 @@ 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 @@ -2844,12 +2838,11 @@ SEXP main_process_python_info_unix() { return R_NilValue; } - - if (PyGILState_Ensure == NULL) - loadSymbol(pLib, "PyGILState_Ensure", (void**)&PyGILState_Ensure); - - if (PyGILState_Release == NULL) + if (PyGILState_Release == NULL) { loadSymbol(pLib, "PyGILState_Release", (void**)&PyGILState_Release); + // PyGILState_Ensure is always not NULL, since we set it in reticulate_init() + loadSymbol(pLib, "PyGILState_Ensure", (void**)&PyGILState_Ensure); + } GILScope scope;