Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when running under radian #1670

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
27 changes: 10 additions & 17 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,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
Expand Down Expand Up @@ -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;

Expand Down
Loading