Skip to content

Commit

Permalink
Merge pull request #1670 from rstudio/fix/radian
Browse files Browse the repository at this point in the history
Fix error when running under `radian`
  • Loading branch information
t-kalinowski authored Sep 17, 2024
2 parents db56fd2 + f248072 commit ccbcf90
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
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

0 comments on commit ccbcf90

Please sign in to comment.