[Python-Dev] towards a faster Python
Skip Montanaro
skip@pobox.com
Mon, 9 Jun 2003 16:30:29 -0500
Skip> I was thinking more along the lines of making the dict itself
Skip> read-only.
Fred> That certainly makes global variables more difficult, doesn't it?
Yes, but we all know globals are bad, right? ;-)
At first blush, it doesn't seem all that tough to worm around this in the
interpreter (postulating a read_only flag for dicts or at least for that
variety of dict used as a module dict):
case STORE_GLOBAL:
w = GETITEM(names, oparg);
v = POP();
ro = f->f_globals->read_only;
f->f_globals->read_only = 0;
err = PyDict_SetItem(f->f_globals, w, v);
f->f_globals->read_only = ro;
Py_DECREF(v);
break;
or something like that. I think the STORE_GLOBAL instruction will only be
executed to set a global in the current module. Any foreign setting,
e.g. "fileinput.open = 10", will be handled by STORE_ATTR. Can executing
PyDict_SetItem() cause arbitrary Python code to execute?
(I'm almost purposely adopting an XP approach here - do just enough to
address the current breakage and see what the next problem is which pops
up.)
Skip