for the todo list: cStringIO uses string.joinfields

the O_writelines function in Modules/cStringIO contains the following code:
if (!string_joinfields) { UNLESS(string_module = PyImport_ImportModule("string")) { return NULL; }
UNLESS(string_joinfields= PyObject_GetAttrString(string_module, "joinfields")) { return NULL; }
Py_DECREF(string_module); }
I suppose someone should fix this some day...
(btw, the C API reference implies that ImportModule doesn't use import hooks. does that mean that cStringIO doesn't work under e.g. Gordon's installer?)
</F>

Fredrik wrote:
(btw, the C API reference implies that ImportModule doesn't use import hooks. does that mean that cStringIO doesn't work under e.g. Gordon's installer?)
You have to fool C code that uses ImportModule by doing an import first in your Python code. It's the same for freeze. It's tiresome tracking this stuff down. For example, to use shelve:
# this is needed because of the use of __import__ in anydbm # (modulefinder does not follow __import__) import dbhash # the next 2 are needed because cPickle won't use our import # hook so we need them already in sys.modules when # cPickle starts import string import copy_reg # now it will work import shelve
Imagine the c preprocessor letting you do #define snarf #include and then trying to use a dependency tracker.
- Gordon

Fredrik wrote:
(btw, the C API reference implies that ImportModule doesn't use import hooks. does that mean that cStringIO doesn't work under e.g. Gordon's installer?)
You have to fool C code that uses ImportModule by doing an import first in your Python code. It's the same for freeze. It's tiresome tracking this stuff down. For example, to use shelve:
# this is needed because of the use of __import__ in anydbm # (modulefinder does not follow __import__) import dbhash # the next 2 are needed because cPickle won't use our import # hook so we need them already in sys.modules when # cPickle starts import string import copy_reg # now it will work import shelve
Hm, the way I read the code (but I didn't write it!) it calls PyImport_Import, which is a higher level function that *does* use the __import__ hook. Maybe this wasn't always the case?
--Guido van Rossum (home page: http://www.python.org/~guido/)

[Fredrik]
(btw, the C API reference implies that ImportModule doesn't use import hooks. does that mean that cStringIO doesn't work under e.g. Gordon's installer?)
[Guido]
Hm, the way I read the code (but I didn't write it!) it calls PyImport_Import, which is a higher level function that *does* use the __import__ hook. Maybe this wasn't always the case?
In stock 1.5.2 it's PyImport_ImportModule. Same in cPickle. I'm delighted to see them moving towards PyImport_Import.
- Gordon
participants (3)
-
Fredrik Lundh
-
Gordon McMillan
-
Guido van Rossum