On Sat, 18 Jun 2005 19:52:20 +0400 "Denis S. Otkidach" <[EMAIL PROTECTED]> wrote:
> I use datetime C API in extension module generated with SIP. But SIP > break the code into several .cpp files compiled separately and > PyDateTimeAPI used by all macros constituting public interface is > declared static. > > The current solution is to define my own functions in main module as > workaround: > > %ModuleHeaderCode > PyObject * mxo_PyDateTime_FromDateAndTime(int year, int month, int day, > int hour, int minute, int seconds, > int usecs); > %End > > %ModuleCode > PyObject * mxo_PyDateTime_FromDateAndTime(int year, int month, int day, > int hour, int minute, int seconds, > int usecs) { > return PyDateTime_FromDateAndTime(year, month, day, hour, minute, seconds, > usecs); > } > // and so on for each macro used > %End > > %PostInitialisationCode > PyDateTime_IMPORT; > %End > > But I wonder why PyDateTimeAPI is declared static, and is the a better > solution? To prevent namespace pollution. Numeric and numarray have a different solution. From Numeric/arrayobject.h: /* C API address pointer */ #if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY) extern void **PyArray_API; #else #if defined(PY_ARRAY_UNIQUE_SYMBOL) void **PyArray_API; #else static void **PyArray_API; #endif which lets you use whatever you like and even rename the C API address pointer. However, keep in mind that SIP can concatenate all C++ files which breaks clever #defines that work if SIP generates separate C++ source files. In fact, I use your method, when wrapping the Numeric and numarray files for PyQwt. The only difference is that I put all access to the C-API in handwritten C++ files to use the conflicting APIs of Numeric and numarray in the same Python extension. Gerard _______________________________________________ PyKDE mailing list PyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde