Hi, On Sun, 2007-10-21 at 13:43 -0300, Gabriel Genellina wrote: > En Sun, 21 Oct 2007 08:21:50 -0300, Sudharshan S <[EMAIL PROTECTED]> > escribi�: > > What is foo? a directory? And bar/_foo/baz, source files in C? Each one > defining a module object, or is there a single module - foo perhaps? >
Sorry, let me explain things a bit, foo is a directory with an __init__.py to tell the interpreter that foo is a package and bar, _foo, baz are shared extension objects, with their sources as bar.c, _foo.c and baz.c, each with its own PyMODINIT_FUNC function. > Is it a global C variable, or a module attribute? If you want it to be > available to other Python code, it should be a module attribute. In this > case, you retrieve the value using PyObject_GetAttrString as with any > other object. > If it's a global C variable, once it's assigned it should be visible to > all (but decades of warning against using global variables can't be > wrong...) > The single most common error using the Python API is getting wrong the > reference counts. If you lose a reference, your object may be garbage > collected. If you leak a reference, it will never be freed. Maybe this is > what happens here. Its not a module attribute, Just a good old C structure. I thought I couldnt use Py_INCREF on non-PyObjects. After a gdb session, I found that my variable say spam, is initialised when the _foo.so is loaded but the moment baz.so or something get loaded, it becomes NULL again, although its still in the current scope. (found that on my backtrace). I hope I am right with the loading of .so part. Is that how python works, bringing all the symbols in the different modules in a common namespace?. If so why is spam losing its value. I also found that the interpreter calls init functions of all the modules the moment I do a "import foo". I also suspect my setup script is kinda doing something wrong. > Perhaps if you explain a bit more what you want to do someone can give > some advice. Well, my code should tell everything. But a word of request, try not to laugh at it. http://projects.openmoko.org/plugins/scmsvn/viewcvs.php/python-gsmd/?root=python-openmoko It would be great if anyone could take a look and guide me out of this. The variable in question is "lgsmh" defined in _pygsmd.c. I really feel I am missing something very trivial yet important thing. Thanks for all the help.. -- Sudharshan S http://www.sudharsh.wordpress.com -- http://mail.python.org/mailman/listinfo/python-list