Greg Ewing <[EMAIL PROTECTED]> wrote:
> Be careful -- getting the class names right isn't the
> only reason Pyrex needs to know the qualified name.
> Don't mess with this unless you fully understand all
> the implications.
I did the test with a cdef class:
cdef class Foo:
pass
I confirm that it fails when we move foo.pyd among packages.
Same as my original point, it's because the name is hardcoded instead of
being retrieved through the module once created.
If, before PyType_Ready'ing types, we build the type's tp_name at runtime
(for example by the following code), the module can be moved among packages.
PyObject* name;
const char* modname;
int modlen;
char* classname;
name = PyObject_GetAttrString(__pyx_m, "__name__");
PyObject_AsCharBuffer(name, &modname, &modlen);
classname = (char*)malloc(modlen + 1 + sizeof("Foo"));
strcpy(classname, modname);
classname[modlen] = '.';
strcpy(classname + modlen + 1, "Foo");
__pyx_type_3foo_Foo.tp_name = classname;
PY_DECREF(name);
(note that foo.Foo().__module__ is not defined contrary to Python classes.
We have to use foo.Foo().__class__.__module__ instead. I don't know yet what
the issue is).
There are maybe some other situations where Pyrex/Cython hardcodes the
module name in the generated code, but I'm quite confident that they can be
replaced by the module's name retrieved at runtime.
At the end, it's your decision whether you want to stop hardcoding module
name.
Here are my arguments to ask for this change:
- in our situation, module developpers don't care where their modules will
be located and I don't think we want to add this constraint.
- moreover, if we add this constraint:
- module tests will now fail,
- all users of our modules will have to put them in the same package
name.
- but maybe the main point is that pure Python modules have no (static)
knowledge of their destination package, why not Pyrex/Cython modules?
Cheers,
Stephane
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev