On Wed, Mar 3, 2010 at 3:54 PM, Lisandro Dalcin <[email protected]> wrote: > On 3 March 2010 20:28, Ondrej Certik <[email protected]> wrote: >>> >>> Cython could grow support for your use case... If you really feel you >>> will need this (as opposed to implementing the "Python" class), >>> perhaps I could take a look at it and implement something... >> >> Do you have some ideas how Cython could be improved to make my use case >> easier? >> > > The easier way to get something working would be to use a preprocessor > macro to control the storage (i.e. static vs. extern) of the symbols > you get in the generated C header... Then you just have to #include > the module API header like this: > > #define CYTHON_USE_GLOBAL_API > #include <mymodule_api.h> > > You will still need to call import_mymodule(), but you just need to do > it earlier in your code, likely a few lines below Py_Initialize() > > Does this look good/easy enough for you?
That looks cool, I'll give it a shot. > >> I can try to write something too --- I am still in the stage of >> figuring things out, not sure yet what I really want in details. I >> only know my general goal --- it should be easy for C++ users to use >> it, should be robust (no segfaults) and Python internals should not be >> visible at all. I am half way there already. >> > > I have to insist: The best (though admittedly complex) way to do this > is you have a 'Python' class, in such a way its instances serve as a > execution context... If you start with this, using separate > interpreters (like Apache's mod_python) in the near future could be > straightforward. Yes, I currently store the context in the "namespace" global dictionary in Cython. I'll give it a shot too. I don't mind using one interpreter, but at least each Python class instance should have it's own namespace. One more question --- can there be any problem if I call for example from Python: m.add() and add() is implemented in C++, and internally it calls some stuff in Python (like scipy). In principle it could be recursively nested couple times. Can the Python interpreter be confused by this "nesting"? Normally it's not an issue since one usually just wraps a C/C++ code, which doesn't call Python. Ondrej _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
