diff --git a/source/common/launch.c b/source/common/launch.c index 29f21f0..d059d66 100644 --- a/source/common/launch.c +++ b/source/common/launch.c @@ -54,8 +54,10 @@ DECLVAR(Py_OptimizeFlag); DECLVAR(Py_VerboseFlag); DECLPROC(Py_Initialize); DECLPROC(Py_Finalize); +#if !EMULATED_REFCNT DECLPROC(Py_IncRef); DECLPROC(Py_DecRef); +#endif DECLPROC(PyImport_ExecCodeModule); DECLPROC(PyRun_SimpleString); DECLPROC(PySys_SetArgv); @@ -387,8 +389,10 @@ int mapNames(HMODULE dll) GETVAR(dll, Py_VerboseFlag); GETPROC(dll, Py_Initialize); GETPROC(dll, Py_Finalize); +#if !EMULATED_REFCNT GETPROC(dll, Py_IncRef); GETPROC(dll, Py_DecRef); +#endif GETPROC(dll, PyImport_ExecCodeModule); GETPROC(dll, PyRun_SimpleString); GETPROC(dll, PyString_FromStringAndSize); diff --git a/source/common/launch.h b/source/common/launch.h index 77bbf96..5ee298b 100644 --- a/source/common/launch.h +++ b/source/common/launch.h @@ -42,6 +42,23 @@ #include #endif +/* Python 2.4+ exports Py_IncRef/Py_DecRef as symbols in the dynamic library. + This lets us build a bootloader which does not depend on the binary layout + of the PyObject structure. + + Currently, the problem only exists on Windows, because on other platforms we + ask users to recompile their own bootloader on their own system, so we could + even depend on Python.h. + + As a quick hack, we check for the compiler version instead of Python version, + as Python 2.3- bootloaders are compiled with MSVC6, while 2.4+ with MSVC7. +*/ +#if defined(_MSC_VER) && _MSC_VER < 1300 + #define EMULATED_REFCNT 1 +#else + #define EMULATED_REFCNT 0 +#endif + /* We use dynamic loading so one binary can be used with (nearly) any Python version. This is the cruft necessary to do dynamic loading @@ -93,8 +110,8 @@ */ /* Forward declarations of opaque Python types. */ -struct _PyObject; -typedef struct _PyObject PyObject; +struct _object; +typedef struct _object PyObject; struct _PyThreadState; typedef struct _PyThreadState PyThreadState; @@ -105,8 +122,10 @@ EXTDECLVAR(int, Py_OptimizeFlag); EXTDECLVAR(int, Py_VerboseFlag); EXTDECLPROC(int, Py_Initialize, (void)); EXTDECLPROC(int, Py_Finalize, (void)); +#if !EMULATED_REFCNT EXTDECLPROC(void, Py_IncRef, (PyObject *)); EXTDECLPROC(void, Py_DecRef, (PyObject *)); +#endif EXTDECLPROC(PyObject *, PyImport_ExecCodeModule, (char *, PyObject *)); EXTDECLPROC(int, PyRun_SimpleString, (char *)); EXTDECLPROC(int, PySys_SetArgv, (int, char **)); @@ -138,6 +157,34 @@ EXTDECLPROC(void, Py_EndInterpreter, (PyThreadState *) ); EXTDECLPROC(long, PyInt_AsLong, (PyObject *) ); EXTDECLPROC(int, PySys_SetObject, (char *, PyObject *)); +#if EMULATED_REFCNT +typedef struct _object { + int ob_refcnt; + struct _typeobject *ob_type; +} PyObject; +typedef void (*destructor)(PyObject *); +typedef struct _typeobject { + int ob_refcnt; + struct _typeobject *ob_type; + int ob_size; + char *tp_name; /* For printing */ + int tp_basicsize, tp_itemsize; /* For allocation */ + destructor tp_dealloc; + /* ignore the rest.... */ +} PyTypeObject; + +#define _Py_Dealloc(op) (*(op)->ob_type->tp_dealloc)((PyObject *)(op)) +#define Py_INCREF(op) ((op)->ob_refcnt++) +#define Py_DECREF(op) \ + if (--(op)->ob_refcnt != 0) \ + ; \ + else \ + _Py_Dealloc((PyObject *)(op)) +#define Py_XINCREF(op) if ((op) == NULL) ; else Py_INCREF(op) +#define Py_XDECREF(op) if ((op) == NULL) ; else Py_DECREF(op) + +#else + /* Macros for reference counting through exported functions * (that is: without binding to the binary structure of a PyObject. * These rely on the Py_IncRef/Py_DecRef API functions. @@ -147,6 +194,8 @@ EXTDECLPROC(int, PySys_SetObject, (char *, PyObject *)); #define Py_DECREF(o) Py_XDECREF(o) #define Py_INCREF(o) Py_XINCREF(o) +#endif + /* Macros to declare and get Python entry points in the C file. * Typedefs '__PROC__...' have been done above */ diff --git a/support/loader/inprocsrvr_6dc.dll b/support/loader/inprocsrvr_6dc.dll index 70fad0f..fde6209 100644 Binary files a/support/loader/inprocsrvr_6dc.dll and b/support/loader/inprocsrvr_6dc.dll differ diff --git a/support/loader/inprocsrvr_6dw.dll b/support/loader/inprocsrvr_6dw.dll index 0d97188..ff3b37e 100644 Binary files a/support/loader/inprocsrvr_6dw.dll and b/support/loader/inprocsrvr_6dw.dll differ diff --git a/support/loader/inprocsrvr_6rc.dll b/support/loader/inprocsrvr_6rc.dll index 79c1bdd..e898983 100644 Binary files a/support/loader/inprocsrvr_6rc.dll and b/support/loader/inprocsrvr_6rc.dll differ diff --git a/support/loader/inprocsrvr_6rw.dll b/support/loader/inprocsrvr_6rw.dll index 68d2826..770dcfc 100644 Binary files a/support/loader/inprocsrvr_6rw.dll and b/support/loader/inprocsrvr_6rw.dll differ diff --git a/support/loader/inprocsrvr_7dc.dll b/support/loader/inprocsrvr_7dc.dll index 22b87d8..53aef24 100644 Binary files a/support/loader/inprocsrvr_7dc.dll and b/support/loader/inprocsrvr_7dc.dll differ diff --git a/support/loader/inprocsrvr_7dw.dll b/support/loader/inprocsrvr_7dw.dll index 18d34dd..80254d7 100644 Binary files a/support/loader/inprocsrvr_7dw.dll and b/support/loader/inprocsrvr_7dw.dll differ diff --git a/support/loader/inprocsrvr_7rc.dll b/support/loader/inprocsrvr_7rc.dll index 02675e6..8bcfe4c 100644 Binary files a/support/loader/inprocsrvr_7rc.dll and b/support/loader/inprocsrvr_7rc.dll differ diff --git a/support/loader/inprocsrvr_7rw.dll b/support/loader/inprocsrvr_7rw.dll index 7494c10..8c46163 100644 Binary files a/support/loader/inprocsrvr_7rw.dll and b/support/loader/inprocsrvr_7rw.dll differ diff --git a/support/loader/run_6dc.exe b/support/loader/run_6dc.exe index 34840ee..c55fc89 100644 Binary files a/support/loader/run_6dc.exe and b/support/loader/run_6dc.exe differ diff --git a/support/loader/run_6dw.exe b/support/loader/run_6dw.exe index 1041ece..4e9c04f 100644 Binary files a/support/loader/run_6dw.exe and b/support/loader/run_6dw.exe differ diff --git a/support/loader/run_6rc.exe b/support/loader/run_6rc.exe index 6313e25..2b08c99 100644 Binary files a/support/loader/run_6rc.exe and b/support/loader/run_6rc.exe differ diff --git a/support/loader/run_6rw.exe b/support/loader/run_6rw.exe index 226440c..e1da2d7 100644 Binary files a/support/loader/run_6rw.exe and b/support/loader/run_6rw.exe differ diff --git a/support/loader/run_7dc.exe b/support/loader/run_7dc.exe index 5fb1e6b..eb95a54 100644 Binary files a/support/loader/run_7dc.exe and b/support/loader/run_7dc.exe differ diff --git a/support/loader/run_7dw.exe b/support/loader/run_7dw.exe index c05d3a9..36b9fde 100644 Binary files a/support/loader/run_7dw.exe and b/support/loader/run_7dw.exe differ diff --git a/support/loader/run_7rc.exe b/support/loader/run_7rc.exe index 56b5e14..4db4c65 100644 Binary files a/support/loader/run_7rc.exe and b/support/loader/run_7rc.exe differ diff --git a/support/loader/run_7rw.exe b/support/loader/run_7rw.exe index 3ec5e28..22dfc1a 100644 Binary files a/support/loader/run_7rw.exe and b/support/loader/run_7rw.exe differ