[Python-checkins] r59943 - python/trunk/Modules/_ctypes/_ctypes.c python/trunk/Modules/_ctypes/stgdict.c

amaury.forgeotdarc python-checkins at python.org
Mon Jan 14 01:22:44 CET 2008


Author: amaury.forgeotdarc
Date: Mon Jan 14 01:22:44 2008
New Revision: 59943

Modified:
   python/trunk/Modules/_ctypes/_ctypes.c
   python/trunk/Modules/_ctypes/stgdict.c
Log:
As discussed in issue 1700288: 
ctypes takes some liberties when creating python types: it modifies the types'
__dict__ directly, bypassing all the machinery of type objects which deal with
special methods.  And this broke recent optimisations of method lookup.
Now we try to modify the type with more "official" functions.


Modified: python/trunk/Modules/_ctypes/_ctypes.c
==============================================================================
--- python/trunk/Modules/_ctypes/_ctypes.c	(original)
+++ python/trunk/Modules/_ctypes/_ctypes.c	Mon Jan 14 01:22:44 2008
@@ -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) &&

Modified: python/trunk/Modules/_ctypes/stgdict.c
==============================================================================
--- python/trunk/Modules/_ctypes/stgdict.c	(original)
+++ python/trunk/Modules/_ctypes/stgdict.c	Mon Jan 14 01:22:44 2008
@@ -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;


More information about the Python-checkins mailing list