summaryrefslogtreecommitdiffstats
path: root/src/if_python.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/if_python.c')
-rw-r--r--src/if_python.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/if_python.c b/src/if_python.c
index e017b7137f..ea2e926ab5 100644
--- a/src/if_python.c
+++ b/src/if_python.c
@@ -96,6 +96,19 @@ struct PyMethodDef { Py_ssize_t a; };
# define HINSTANCE long_u /* for generating prototypes */
# endif
+#ifndef _WIN32
+# include <dlfcn.h>
+# define FARPROC void*
+# define HINSTANCE void*
+# define load_dll(n) dlopen((n),RTLD_LAZY)
+# define close_dll dlclose
+# define symbol_from_dll dlsym
+#else
+# define load_dll LoadLibrary
+# define close_dll FreeLibrary
+# define symbol_from_dll GetProcAddress
+#endif
+
/* This makes if_python.c compile without warnings against Python 2.5
* on Win32 and Win64. */
#undef PyRun_SimpleString
@@ -315,7 +328,7 @@ end_dynamic_python(void)
{
if (hinstPython)
{
- FreeLibrary(hinstPython);
+ close_dll(hinstPython);
hinstPython = 0;
}
}
@@ -332,7 +345,7 @@ python_runtime_link_init(char *libname, int verbose)
if (hinstPython)
return OK;
- hinstPython = LoadLibrary(libname);
+ hinstPython = load_dll(libname);
if (!hinstPython)
{
if (verbose)
@@ -342,10 +355,10 @@ python_runtime_link_init(char *libname, int verbose)
for (i = 0; python_funcname_table[i].ptr; ++i)
{
- if ((*python_funcname_table[i].ptr = GetProcAddress(hinstPython,
+ if ((*python_funcname_table[i].ptr = symbol_from_dll(hinstPython,
python_funcname_table[i].name)) == NULL)
{
- FreeLibrary(hinstPython);
+ close_dll(hinstPython);
hinstPython = 0;
if (verbose)
EMSG2(_(e_loadfunc), python_funcname_table[i].name);