Message59874
After some debug work, I found an explanation:
- The attribute "name" is the name of a type slot. So it becomes cached
during the type construction.
- in function ctypes/_ctypes.c::StructUnionType_new(), the type's
__dict__ is replaced by a "stgdict".
- this "stgdict" is then modified with PyDict_ functions, without any
call to _PyType_Lookup()
- the method cache becomes out of sync ==> boom.
I have come with a patch which corrects the problem, and all ctypes
tests pass:
Index: Modules/_ctypes/stgdict.c
===================================================================
--- Modules/_ctypes/stgdict.c (revision 59939)
+++ Modules/_ctypes/stgdict.c (working copy)
@@ -470,7 +470,7 @@
Py_DECREF(pair);
return -1;
}
- if (-1 == PyDict_SetItem(realdict, name, prop)) {
+ if (-1 == PyObject_SetAttr(type, name, prop)) {
Py_DECREF(prop);
Py_DECREF(pair);
return -1;
Index: Modules/_ctypes/_ctypes.c
===================================================================
--- Modules/_ctypes/_ctypes.c (revision 59939)
+++ Modules/_ctypes/_ctypes.c (working copy)
@@ -410,7 +410,7 @@
StructType_setattro(PyObject *self, PyObject *key, PyObject *value)
{
/* XXX Should we disallow deleting _fields_? */
- if (-1 == PyObject_GenericSetAttr(self, key, value))
+ if (-1 == Py_TYPE(self)->tp_base->tp_setattro(self, key, value))
return -1;
if (value && PyString_Check(key) &&
I think that these changes are sensible: The first one deal with the
type's attribute instead of updating its __dict__, and the second
properly delegates "tp_setattro" to the base class ('type' in this case). |
|
Date |
User |
Action |
Args |
2008-01-14 00:01:42 | amaury.forgeotdarc | set | spambayes_score: 0.0159514 -> 0.0159514 recipients:
+ amaury.forgeotdarc, nnorwitz, arigo, georg.brandl, rhettinger, peaker, bioinformed, ntoronto |
2008-01-14 00:01:42 | amaury.forgeotdarc | set | spambayes_score: 0.0159514 -> 0.0159514 messageid: <1200268902.74.0.748767279197.issue1700288@psf.upfronthosting.co.za> |
2008-01-14 00:01:41 | amaury.forgeotdarc | link | issue1700288 messages |
2008-01-14 00:01:41 | amaury.forgeotdarc | create | |
|