diff src/if_python.c @ 2329:ad2889f48843 vim73

Added support for Python 3. (Roland Puntaier)
author Bram Moolenaar <bram@vim.org>
date Sat, 17 Jul 2010 21:19:38 +0200
parents ccda151dde4e
children f414e5a4b40e
line wrap: on
line diff
--- 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, 
 
     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, 
 
     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);