Object oriented databae for Python

Gerhard Haering gh at ghaering.de
Fri Mar 21 19:47:16 CET 2003


* Konstantin Knizhnik <knizhnik at garret.ru> [2003-03-21 21:31 +0300]:
> Hello achrist,
> 
> This is problem with definition DL_EXPORT macro in Python 2.2.2 [...]

There is no problem. The problem might be in the Makefiles you use. So
don't use Makefiles. Use distutils through the setup.py I created :-)

The only thing you'll likely have to change is the library to link
against, cos MSVC doesn't have any libstdc++. It's called otherwise, but
I don't recall how.

The proper solution for setup.py on win32 is to distinguish the compiler
used and then set the appropriate libraries. As that's probably not
easily done, make it configurable in that the user has to edit setup.py
manually, with clear instructions.

> With 2.3 it works ok, but not with 2.2.2.

> May be I just do not define some environment variable. But neither
> USE_DL_EXPORT, USE_DL_IMPORT properly works:

There is no need to set any defines.

> So looks like USE_DL_EXPORT should be used for building Python core,
> and USE_DL_IMPORT is not enough for building proper client extension
> - it doesn't define DL_EXPORT, so module init function is not
> imported.

If you want to use Makefiles, get a working extension module (like
PySQLite ;-), then invoke "python setup.py build" and look which
compiler options are used with MSVC.

> That is why in original version I did it it  such way:
> 
> #ifdef _WIN32
> __declspec(dllexport)
> #endif
> void
> initpythonapi(void)
> {
>     Py_InitModule("pythonapi", dybase_methods);
> }
> 
> But Gerhard send me patch where this my hack was removed (by using
> DL_EXPORT macro).
> At this moment I already forgot the reason of such hack, so I check
> that this code works (with Python 2.3) and apply the fix.
> I forgot about the problem with Python 2.2.
> So no I am going to return back to my original code which should work
> with both versions of Python. Or may be there is some better solution?

Please leave it as it is, as there is no problem with DL_EXPORT. The
problem is in your Makefiles, so just use distutils. Well, I'm getting
redundant.

Once I get to a machine with MSVC6 installed (or I dig for the CD at
home) I'll check the combination DyBASE/MSVC6/distutils.

Anyways, in Pyhton 2.3, DL_EXPORT is deprecated in favour of a better
solution, but DL_EXPORT still works under 2.3. Here's what a contributor
to PySQLite sent me:

#v+
/* Compatibility macros
 *
 * From Python 2.2 to 2.3, the way to export the module init function
 * has changed. These macros keep the code compatible to both ways.
 */
#if PY_VERSION_HEX >= 0x02030000
#  define PySQLite_DECLARE_MODINIT_FUNC(name) PyMODINIT_FUNC name(void)
#  define PySQLite_MODINIT_FUNC(name)         PyMODINIT_FUNC name(void)
#else
#  define PySQLite_DECLARE_MODINIT_FUNC(name) void name(void)
#  define PySQLite_MODINIT_FUNC(name)         DL_EXPORT(void) name(void)
#endif

[...]


PySQLite_DECLARE_MODINIT_FUNC(init_sqlite);

[...]

PySQLite_MODINIT_FUNC(init_sqlite)
{
    [...]
}
#v-

HTH,

Gerhard
-- 
mail:   gh at ghaering.de
web:    http://ghaering.de/





More information about the Python-list mailing list