[Python-Dev] are CObjects inherently unsafe?

Michael Hudson mwh at python.net
Fri Dec 5 06:04:53 EST 2003

martin at v.loewis.de (Martin v. Löwis) writes:

> Michael Hudson <mwh at python.net> writes:
>> It seems to me that it would be more sensible to have a dict mapping
>> names (maybe just module names...) to cobjects in the interpreter
>> state.  I guess there might be a way of getting ahold of the dict with
>> the gc module (though I can't think of one off hand).  This wouldn't
>> be a difficult change, and if the CObjects are left in the module
>> dicts, it shouldn't even do that much damage to binary compatibility.
>> Thoughts?
> Good idea. Alternatively, we could make "APIs" a feature of modules:
> PyModule_GetAPI, PyModule_SetAPI. We would then define
> typedef struct {
> 	PyObject_HEAD
> 	PyObject *md_dict;
>         PyObject *md_api;
> } PyModuleObject;
> We could restrict md_api to CObjects, which, means we would not need
> to change module_traverse.

I think you can still break this, though:

>>> import _curses
>>> import sys
>>> sys.modules['cStringIO'] = _curses

(doesn't break today because cStringIO and _curses use different
attribute names for the CObject).


31. Simplicity does not precede complexity, but follows it.
  -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html

More information about the Python-Dev mailing list