On Thu, Apr 23, 2009 at 1:33 AM, Stefan Behnel <[email protected]> wrote: >> I have included a first draft of such a script. It is a modification >> of the embedded mode that was checked into cython-devel. Notably, I >> use PyImport_ExtendInittab to register all the modules as built-ins, > > 1) does that work for modules in packages?
I don't know. I have never really used the Python C API before, so what I wrote is just a guess. I have no idea how to deal with packages. More testing is probably warranted. > 2) will this decref the modules in Py3? Sorry, I don't really know exactly what that means, nor do I know how to test it. I've never written and Py3 C code before. >> and I only import the first one listed (which would ideally be called >> "__main__"; see below). This seems to be a cleaner way to do things. >> This also means that any extra module listed on the command-line that >> is not imported by the first module will not be run. > > When is the init code of the modules called, and in which order? The main > module init code should be able to import and use all other modules, even > before executing its own init code. The init code of the first (main) module will be called when PyImport_ImportModule is called. The init code of others will be called if and when the main module (or some other module) imports them. By adding the modules to the inittab, they act like built-ins, so I think (but have not verified) that when they are imported, no search of sys.path is performed. >> * I create a MODINIT() macro to create the module initialization name, >> but I don't know how portable the ## concatenation is. > > Also, the functions return different things in Py2 and Py3, so they are not > easily interchangeable. This is true, but it doesn't matter. The value PyMODINIT_FUNC is set to "void" in Py2 and "PyObject*" in Py3, so only the name changes. (Cython uses this.) I don't actually call the function - I just load a pointer to the function into the struct _inittab. Thanks for the positive responses everyone! -- Mark _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
