I've been wanting to code this up for a while, and almost had it a while
back, but couldn't quite get it working, and put it aside until today.
It's not ready for integration, since it's not at all tied into the
autoconf setup, and requires that you modify src/auto/config.mk to add
-DDYNAMIC_PYTHON to PYTHON_CFLAGS and wrap -lpython2.4 in PYTHON_LIBS with
-zlazyload / -znolazyload, but otherwise it seems to work: python isn't
loaded until the first python command is executed, and (as far as I've been
able to tell) executes python code just fine after that, has("python") is
true, etc.
Comments on the patch itself are appreciated. Suggestions on how it might
be made to work on Linux are also appreciated, though I don't really have
any means of testing it at the moment. And help with getting it tied in
with autoconf would be great; I'm not sure how to move forward on that. If
there are any Python script torture tests I should run, let me know; I'm
not sure what the best python scripts are to play with.
I haven't looked at doing the other interpreters yet, though I'd like to do
that, as well as see if it's possible to dynamically load the GUI.
Thanks for any thoughts,
Danek
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---
--- if_python.c.orig Sat Feb 14 13:53:41 2009
+++ if_python.c Sat Feb 14 19:21:41 2009
@@ -86,9 +86,11 @@
#endif
#if defined(DYNAMIC_PYTHON) || defined(PROTO)
+#ifdef MSWIN
# ifndef DYNAMIC_PYTHON
# define HINSTANCE long_u /* for generating prototypes */
# endif
+#endif
/* This makes if_python.c compile without warnings against Python 2.5
* on Win32 and Win64. */
@@ -215,7 +217,9 @@
static void (*dll_PyObject_Free)(void*);
# endif
+#ifdef MSWIN
static HINSTANCE hinstPython = 0; /* Instance of python.dll */
+#endif
/* Imported exception objects */
static PyObject *imp_PyExc_AttributeError;
@@ -233,11 +237,17 @@
/*
* Table of name to function pointer of python.
*/
+#ifdef MSWIN
# define PYTHON_PROC FARPROC
+# define PYTHON_PROC_STRUCT FARPROC
+#else
+# define PYTHON_PROC void
+# define PYTHON_PROC_STRUCT void *
+#endif
static struct
{
char *name;
- PYTHON_PROC *ptr;
+ PYTHON_PROC_STRUCT *ptr;
} python_funcname_table[] =
{
{"PyArg_Parse", (PYTHON_PROC*)&dll_PyArg_Parse},
@@ -301,6 +311,7 @@
{"", NULL},
};
+#ifdef MSWIN
/*
* Free python.dll
*/
@@ -358,6 +369,7 @@
{
return python_runtime_link_init(DYNAMIC_PYTHON_DLL, verbose) == OK;
}
+#endif /* MSWIN */
/* Load the standard Python exceptions - don't import the symbols from the
* DLL, as this can cause errors (importing data symbols is not reliable).
@@ -381,6 +393,58 @@
Py_XINCREF(imp_PyExc_ValueError);
Py_XDECREF(exmod);
}
+
+#ifdef SOLARIS
+#include <dlfcn.h>
+
+static void *python_dlhandle = NULL;
+
+static void
+end_dynamic_python(void)
+{
+ if (python_dlhandle) {
+ dlclose(python_dlhandle);
+ python_dlhandle = NULL;
+ }
+}
+
+static int
+python_runtime_link_init(char *libname, int verbose)
+{
+ int i;
+
+ if (python_dlhandle)
+ return OK;
+ python_dlhandle = dlopen(libname, RTLD_GLOBAL|RTLD_LAZY);
+ if (!python_dlhandle)
+ {
+ if (verbose)
+ EMSG2(_(e_loadlib), libname);
+ return FAIL;
+ }
+
+ for (i = 0; python_funcname_table[i].ptr; ++i)
+ {
+ if ((*python_funcname_table[i].ptr = dlsym(python_dlhandle,
+ python_funcname_table[i].name)) == NULL)
+ {
+ dlclose(python_dlhandle);
+ python_dlhandle = NULL;
+ if (verbose)
+ EMSG2(_(e_loadfunc), python_funcname_table[i].name);
+ return FAIL;
+ }
+ }
+
+ return OK;
+}
+
+int
+python_enabled(int verbose)
+{
+ return python_runtime_link_init("libpython2.4.so.1.0", verbose) == OK;
+}
+#endif /* SOLARIS */
#endif /* DYNAMIC_PYTHON */
/******************************************************
@@ -483,7 +547,13 @@
++recurse;
#ifdef DYNAMIC_PYTHON
- if (hinstPython && Py_IsInitialized())
+ if (
+#ifdef MSWIN
+ hinstPython
+#elif defined(SOLARIS)
+ python_dlhandle
+#endif
+ && Py_IsInitialized())
{
Python_RestoreThread(); /* enter python */
Py_Finalize();