[Import-sig] Imputil
M.-A. Lemburg
mal@lemburg.com
Thu, 01 Feb 2001 18:11:30 +0100
Fredrik Lundh wrote:
>
> M.-A. Lemburg wrote:
> > Changing cPickle.c doesn't help here: the PyImport_ImportModule()
> > API would have to be made __import__ aware to fix this problem
> > because a lot of Python code including the core itself uses
> > this more direct import API.
>
> any reason cPickle.c cannot just use PyImport_Import
> instead of PyImport_ImportModule?
Sure, but what about all the other instances where
PyImport_ImportModule() is used instead of PyImport_Import() ?
Just fixing cPickle.c won't help much -- we'd need a more generic
change to make Python fully imputil aware. Perhaps we could
redirect PyImport_ImportModule() to PyImport_Import() with some
extra logic to make it work during the interpreter startupo phase
too.
--
BTW, while looking around in Modules/ I found some really old
code in cStringIO.c which should probably be updated to the
new string methods:
static char O_writelines__doc__[] =
"writelines(sequence_of_strings): write each string";
static PyObject *
O_writelines(Oobject *self, PyObject *args) {
PyObject *tmp = 0;
static PyObject *string_joinfields = 0;
UNLESS (PyArg_ParseTuple(args, "O:writelines", &args)) return NULL;
if (!string_joinfields) {
UNLESS (tmp = PyImport_ImportModule("string")) return NULL;
string_joinfields=PyObject_GetAttrString(tmp, "joinfields");
Py_DECREF(tmp);
UNLESS (string_joinfields) return NULL;
}
if (PyObject_Size(args) < 0) return NULL;
tmp = PyObject_CallFunction(string_joinfields, "Os", args, "");
UNLESS (tmp) return NULL;
args = Py_BuildValue("(O)", tmp);
Py_DECREF(tmp);
UNLESS (args) return NULL;
tmp = O_write(self, args);
Py_DECREF(args);
return tmp;
}
--
Marc-Andre Lemburg
______________________________________________________________________
Company: http://www.egenix.com/
Consulting: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/