Skip to content

Commit 817c988

Browse files
committed
fix running under radian
closes #1668
1 parent 6592fa7 commit 817c988

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/python.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2844,12 +2844,10 @@ SEXP main_process_python_info_unix() {
28442844
return R_NilValue;
28452845
}
28462846

2847-
2848-
if (PyGILState_Ensure == NULL)
2849-
loadSymbol(pLib, "PyGILState_Ensure", (void**)&PyGILState_Ensure);
2850-
2851-
if (PyGILState_Release == NULL)
2847+
if (PyGILState_Release == NULL) {
28522848
loadSymbol(pLib, "PyGILState_Release", (void**)&PyGILState_Release);
2849+
loadSymbol(pLib, "PyGILState_Ensure", (void**)&PyGILState_Ensure);
2850+
}
28532851

28542852
GILScope scope;
28552853

@@ -2930,6 +2928,19 @@ void py_initialize(const std::string& python,
29302928
if (Py_IsInitialized()) {
29312929
// if R is embedded in a python environment, rpycall has to be loaded as a regular
29322930
// module.
2931+
2932+
// We don't currently support running embedded on windows?
2933+
#ifndef _WIN32
2934+
void* pLib = NULL;
2935+
pLib = ::dlopen(NULL, RTLD_NOW | RTLD_GLOBAL);
2936+
// replace symbols that we initialized with dummy functions
2937+
// in reticulate_init
2938+
loadSymbol(pLib, "PyIter_Check", (void**) &PyIter_Check);
2939+
loadSymbol(pLib, "PyCallable_Check", (void**) &PyCallable_Check);
2940+
loadSymbol(pLib, "PyGILState_Ensure", (void**) &PyGILState_Ensure);
2941+
::dlclose(pLib);
2942+
#endif
2943+
29332944
GILScope scope;
29342945
PyImport_AddModule("rpycall");
29352946
PyDict_SetItemString(PyImport_GetModuleDict(), "rpycall", initializeRPYCall());

0 commit comments

Comments
 (0)