[Python-3000-checkins] r64672 - in python/branches/py3k: Lib/test/test_re.py Lib/test/test_winreg.py Lib/test/test_zlib.py Modules/_bsddb.c Modules/_sre.c Modules/_ssl.c Modules/_threadmodule.c Modules/_tkinter.c Modules/parsermodule.c Modules/selectmodule.c Modules/zlibmodule.c PC/_subprocess.c PC/winreg.c

amaury.forgeotdarc python-3000-checkins at python.org
Wed Jul 2 22:50:16 CEST 2008


Author: amaury.forgeotdarc
Date: Wed Jul  2 22:50:16 2008
New Revision: 64672

Log:
#3247 Get rid of Py_FindMethod; use tp_members instead.
Otherwise dir(_sre.SRE_Match) returns an empty list.

First step: handle most occurrences, remove tp_getattr and fill the tp_methods and tp_members slots.
Add some test about attribute access.


Modified:
   python/branches/py3k/Lib/test/test_re.py
   python/branches/py3k/Lib/test/test_winreg.py
   python/branches/py3k/Lib/test/test_zlib.py
   python/branches/py3k/Modules/_bsddb.c
   python/branches/py3k/Modules/_sre.c
   python/branches/py3k/Modules/_ssl.c
   python/branches/py3k/Modules/_threadmodule.c
   python/branches/py3k/Modules/_tkinter.c
   python/branches/py3k/Modules/parsermodule.c
   python/branches/py3k/Modules/selectmodule.c
   python/branches/py3k/Modules/zlibmodule.c
   python/branches/py3k/PC/_subprocess.c
   python/branches/py3k/PC/winreg.c

Modified: python/branches/py3k/Lib/test/test_re.py
==============================================================================
--- python/branches/py3k/Lib/test/test_re.py	(original)
+++ python/branches/py3k/Lib/test/test_re.py	Wed Jul  2 22:50:16 2008
@@ -326,6 +326,13 @@
         self.assertNotEqual(re.match("^x{}$", "x{}"), None)
 
     def test_getattr(self):
+        self.assertEqual(re.compile("(?i)(a)(b)").pattern, "(?i)(a)(b)")
+        self.assertEqual(re.compile("(?i)(a)(b)").flags, re.I)
+        self.assertEqual(re.compile("(?i)(a)(b)").groups, 2)
+        self.assertEqual(re.compile("(?i)(a)(b)").groupindex, {})
+        self.assertEqual(re.compile("(?i)(?P<first>a)(?P<other>b)").groupindex,
+                         {'first': 1, 'other': 2})
+
         self.assertEqual(re.match("(a)", "a").pos, 0)
         self.assertEqual(re.match("(a)", "a").endpos, 1)
         self.assertEqual(re.match("(a)", "a").string, "a")

Modified: python/branches/py3k/Lib/test/test_winreg.py
==============================================================================
--- python/branches/py3k/Lib/test/test_winreg.py	(original)
+++ python/branches/py3k/Lib/test/test_winreg.py	Wed Jul  2 22:50:16 2008
@@ -29,6 +29,7 @@
         # Set the default value for this key.
         SetValue(root_key, test_key_name, REG_SZ, "Default value")
         key = CreateKey(root_key, test_key_name)
+        self.assert_(key.handle != 0)
         # Create a sub-key
         sub_key = CreateKey(key, subkeystr)
         # Give the sub-key some named values

Modified: python/branches/py3k/Lib/test/test_zlib.py
==============================================================================
--- python/branches/py3k/Lib/test/test_zlib.py	(original)
+++ python/branches/py3k/Lib/test/test_zlib.py	Wed Jul  2 22:50:16 2008
@@ -161,6 +161,7 @@
             self.assertEqual(b'', dco.unconsumed_tail, ########
                              "(A) uct should be b'': not %d long" %
                                        len(dco.unconsumed_tail))
+            self.assertEqual(b'', dco.unused_data)
         if flush:
             bufs.append(dco.flush())
         else:
@@ -173,6 +174,7 @@
         self.assertEqual(b'', dco.unconsumed_tail, ########
                          "(B) uct should be b'': not %d long" %
                                        len(dco.unconsumed_tail))
+        self.assertEqual(b'', dco.unused_data)
         self.assertEqual(data, b''.join(bufs))
         # Failure means: "decompressobj with init options failed"
 

Modified: python/branches/py3k/Modules/_bsddb.c
==============================================================================
--- python/branches/py3k/Modules/_bsddb.c	(original)
+++ python/branches/py3k/Modules/_bsddb.c	Wed Jul  2 22:50:16 2008
@@ -5324,54 +5324,21 @@
 };
 #endif
 
-
-static PyObject*
-DB_getattr(DBObject* self, char *name)
-{
-    return Py_FindMethod(DB_methods, (PyObject* )self, name);
-}
-
-
 static PyObject*
-DBEnv_getattr(DBEnvObject* self, char *name)
+DBEnv_db_home_get(DBEnvObject* self)
 {
-    if (!strcmp(name, "db_home")) {
-        CHECK_ENV_NOT_CLOSED(self);
-        if (self->db_env->db_home == NULL) {
-            RETURN_NONE();
-        }
-        return PyUnicode_FromString(self->db_env->db_home);
+    CHECK_ENV_NOT_CLOSED(self);
+    if (self->db_env->db_home == NULL) {
+        RETURN_NONE();
     }
-
-    return Py_FindMethod(DBEnv_methods, (PyObject* )self, name);
+    return PyUnicode_FromString(self->db_env->db_home);
 }
 
+static PyGetSetDef DBEnv_getsets[] = {
+    {"db_home", (getter)DBEnv_db_home_get, NULL,},
+    {NULL}
+};
 
-static PyObject*
-DBCursor_getattr(DBCursorObject* self, char *name)
-{
-    return Py_FindMethod(DBCursor_methods, (PyObject* )self, name);
-}
-
-static PyObject*
-DBTxn_getattr(DBTxnObject* self, char *name)
-{
-    return Py_FindMethod(DBTxn_methods, (PyObject* )self, name);
-}
-
-static PyObject*
-DBLock_getattr(DBLockObject* self, char *name)
-{
-    return NULL;
-}
-
-#if (DBVER >= 43)
-static PyObject*
-DBSequence_getattr(DBSequenceObject* self, char *name)
-{
-    return Py_FindMethod(DBSequence_methods, (PyObject* )self, name);
-}
-#endif
 
 static PyTypeObject DB_Type = {
     PyVarObject_HEAD_INIT(NULL, 0)
@@ -5381,8 +5348,8 @@
     /* methods */
     (destructor)DB_dealloc, /*tp_dealloc*/
     0,                  /*tp_print*/
-    (getattrfunc)DB_getattr, /*tp_getattr*/
-    0,                      /*tp_setattr*/
+    0,                  /*tp_getattr*/
+    0,                  /*tp_setattr*/
     0,          /*tp_compare*/
     0,          /*tp_repr*/
     0,          /*tp_as_number*/
@@ -5400,6 +5367,9 @@
     0,			/* tp_clear */
     0,			/* tp_richcompare */
     offsetof(DBObject, in_weakreflist),   /* tp_weaklistoffset */
+    0,			/* tp_iter */
+    0,			/* tp_iternext */
+    DB_methods,		/* tp_methods */
 };
 
 
@@ -5411,7 +5381,7 @@
     /* methods */
     (destructor)DBCursor_dealloc,/*tp_dealloc*/
     0,                  /*tp_print*/
-    (getattrfunc)DBCursor_getattr, /*tp_getattr*/
+    0,                  /*tp_getattr*/
     0,                  /*tp_setattr*/
     0,                  /*tp_compare*/
     0,                  /*tp_repr*/
@@ -5430,6 +5400,9 @@
     0,			/* tp_clear */
     0,			/* tp_richcompare */
     offsetof(DBCursorObject, in_weakreflist),   /* tp_weaklistoffset */
+    0,			/* tp_iter */
+    0,			/* tp_iternext */
+    DBCursor_methods,	/* tp_methods */
 };
 
 
@@ -5441,7 +5414,7 @@
     /* methods */
     (destructor)DBEnv_dealloc, /*tp_dealloc*/
     0,          /*tp_print*/
-    (getattrfunc)DBEnv_getattr, /*tp_getattr*/
+    0,          /*tp_getattr*/
     0,          /*tp_setattr*/
     0,          /*tp_compare*/
     0,          /*tp_repr*/
@@ -5460,6 +5433,11 @@
     0,			/* tp_clear */
     0,			/* tp_richcompare */
     offsetof(DBEnvObject, in_weakreflist),   /* tp_weaklistoffset */
+    0,                  /* tp_iter */
+    0,                  /* tp_iternext */
+    DBEnv_methods,      /* tp_methods */
+    0,                  /* tp_members */
+    DBEnv_getsets,      /* tp_getsets */
 };
 
 static PyTypeObject DBTxn_Type = {
@@ -5470,8 +5448,8 @@
     /* methods */
     (destructor)DBTxn_dealloc, /*tp_dealloc*/
     0,          /*tp_print*/
-    (getattrfunc)DBTxn_getattr, /*tp_getattr*/
-    0,                      /*tp_setattr*/
+    0,          /*tp_getattr*/
+    0,          /*tp_setattr*/
     0,          /*tp_compare*/
     0,          /*tp_repr*/
     0,          /*tp_as_number*/
@@ -5489,6 +5467,9 @@
     0,			/* tp_clear */
     0,			/* tp_richcompare */
     offsetof(DBTxnObject, in_weakreflist),   /* tp_weaklistoffset */
+    0,			/* tp_iter */
+    0,			/* tp_iternext */
+    DBTxn_methods,	/* tp_methods */
 };
 
 
@@ -5500,8 +5481,8 @@
     /* methods */
     (destructor)DBLock_dealloc, /*tp_dealloc*/
     0,          /*tp_print*/
-    (getattrfunc)DBLock_getattr, /*tp_getattr*/
-    0,                      /*tp_setattr*/
+    0,          /*tp_getattr*/
+    0,          /*tp_setattr*/
     0,          /*tp_compare*/
     0,          /*tp_repr*/
     0,          /*tp_as_number*/
@@ -5530,7 +5511,7 @@
     /* methods */
     (destructor)DBSequence_dealloc, /*tp_dealloc*/
     0,          /*tp_print*/
-    (getattrfunc)DBSequence_getattr,/*tp_getattr*/
+    0,          /*tp_getattr*/
     0,          /*tp_setattr*/
     0,          /*tp_compare*/
     0,          /*tp_repr*/
@@ -5549,6 +5530,9 @@
     0,			/* tp_clear */
     0,			/* tp_richcompare */
     offsetof(DBSequenceObject, in_weakreflist),   /* tp_weaklistoffset */
+    0,			/* tp_iter */
+    0,			/* tp_iternext */
+    DBSequence_methods,	/* tp_methods */
 };
 #endif
 
@@ -5668,16 +5652,21 @@
     PyObject* svnid_s = PyUnicode_FromString(svn_id);
     PyObject* py_api;
 
-    /* Initialize the type of the new type objects here; doing it here
-       is required for portability to Windows without requiring C++. */
-    Py_TYPE(&DB_Type) = &PyType_Type;
-    Py_TYPE(&DBCursor_Type) = &PyType_Type;
-    Py_TYPE(&DBEnv_Type) = &PyType_Type;
-    Py_TYPE(&DBTxn_Type) = &PyType_Type;
-    Py_TYPE(&DBLock_Type) = &PyType_Type;
-#if (DBVER >= 43)    
-    Py_TYPE(&DBSequence_Type) = &PyType_Type;
-#endif    
+    /* Initialize object types */
+    if (PyType_Ready(&DB_Type) < 0)
+        return NULL;
+    if (PyType_Ready(&DBCursor_Type) < 0)
+        return NULL;
+    if (PyType_Ready(&DBEnv_Type) < 0)
+        return NULL;
+    if (PyType_Ready(&DBTxn_Type) < 0)
+        return NULL;
+    if (PyType_Ready(&DBLock_Type) < 0)
+        return NULL;
+#if (DBVER >= 43)
+    if (PyType_Ready(&DBSequence_Type) < 0)
+        return NULL;
+#endif
 
 
 #if defined(WITH_THREAD) && !defined(MYDB_USE_GILSTATE)

Modified: python/branches/py3k/Modules/_sre.c
==============================================================================
--- python/branches/py3k/Modules/_sre.c	(original)
+++ python/branches/py3k/Modules/_sre.c	Wed Jul  2 22:50:16 2008
@@ -2597,46 +2597,22 @@
     {NULL, NULL}
 };
 
-static PyObject*
-pattern_getattr(PatternObject* self, char* name)
-{
-    PyObject* res;
-
-    res = Py_FindMethod(pattern_methods, (PyObject*) self, name);
-
-    if (res)
-        return res;
-
-    PyErr_Clear();
-
-    /* attributes */
-    if (!strcmp(name, "pattern")) {
-        Py_INCREF(self->pattern);
-        return self->pattern;
-    }
-
-    if (!strcmp(name, "flags"))
-        return Py_BuildValue("i", self->flags);
-
-    if (!strcmp(name, "groups"))
-        return Py_BuildValue("i", self->groups);
-
-    if (!strcmp(name, "groupindex") && self->groupindex) {
-        Py_INCREF(self->groupindex);
-        return self->groupindex;
-    }
-
-    PyErr_SetString(PyExc_AttributeError, name);
-    return NULL;
-}
+#define PAT_OFF(x) offsetof(PatternObject, x)
+static PyMemberDef pattern_members[] = {
+    {"pattern",    T_OBJECT,    PAT_OFF(pattern),       READONLY},
+    {"flags",      T_INT,       PAT_OFF(flags),         READONLY},
+    {"groups",     T_PYSSIZET,  PAT_OFF(groups),        READONLY},
+    {"groupindex", T_OBJECT,    PAT_OFF(groupindex),    READONLY},
+    {NULL}  /* Sentinel */
+};
 
 static PyTypeObject Pattern_Type = {
     PyVarObject_HEAD_INIT(NULL, 0)
     "_" SRE_MODULE ".SRE_Pattern",
     sizeof(PatternObject), sizeof(SRE_CODE),
-    (destructor)pattern_dealloc, /*tp_dealloc*/
-    0, /*tp_print*/
-    (getattrfunc)pattern_getattr, /*tp_getattr*/
+    (destructor)pattern_dealloc,	/* tp_dealloc */
+    0,					/* tp_print */
+    0,					/* tp_getattr */
     0,					/* tp_setattr */
     0,					/* tp_compare */
     0,					/* tp_repr */
@@ -2655,6 +2631,10 @@
     0,					/* tp_clear */
     0,					/* tp_richcompare */
     offsetof(PatternObject, weakreflist),	/* tp_weaklistoffset */
+    0,					/* tp_iter */
+    0,					/* tp_iternext */
+    pattern_methods,			/* tp_methods */
+    pattern_members,			/* tp_members */
 };
 
 static PyObject *
@@ -3098,69 +3078,55 @@
     {NULL, NULL}
 };
 
-static PyObject*
-match_getattr(MatchObject* self, char* name)
+static PyObject *
+match_lastindex_get(MatchObject *self)
 {
-    PyObject* res;
-
-    res = Py_FindMethod(match_methods, (PyObject*) self, name);
-    if (res)
-        return res;
-
-    PyErr_Clear();
-
-    if (!strcmp(name, "lastindex")) {
-        if (self->lastindex >= 0)
-            return Py_BuildValue("i", self->lastindex);
-        Py_INCREF(Py_None);
-        return Py_None;
-    }
-
-    if (!strcmp(name, "lastgroup")) {
-        if (self->pattern->indexgroup && self->lastindex >= 0) {
-            PyObject* result = PySequence_GetItem(
-                self->pattern->indexgroup, self->lastindex
-                );
-            if (result)
-                return result;
-            PyErr_Clear();
-        }
-        Py_INCREF(Py_None);
-        return Py_None;
-    }
-
-    if (!strcmp(name, "string")) {
-        if (self->string) {
-            Py_INCREF(self->string);
-            return self->string;
-        } else {
-            Py_INCREF(Py_None);
-            return Py_None;
-        }
-    }
-
-    if (!strcmp(name, "regs")) {
-        if (self->regs) {
-            Py_INCREF(self->regs);
-            return self->regs;
-        } else
-            return match_regs(self);
-    }
+    if (self->lastindex >= 0)
+	return Py_BuildValue("i", self->lastindex);
+    Py_INCREF(Py_None);
+    return Py_None;
+}
 
-    if (!strcmp(name, "re")) {
-        Py_INCREF(self->pattern);
-        return (PyObject*) self->pattern;
+static PyObject *
+match_lastgroup_get(MatchObject *self)
+{
+    if (self->pattern->indexgroup && self->lastindex >= 0) {
+        PyObject* result = PySequence_GetItem(
+            self->pattern->indexgroup, self->lastindex
+            );
+        if (result)
+            return result;
+        PyErr_Clear();
     }
+    Py_INCREF(Py_None);
+    return Py_None;
+}
 
-    if (!strcmp(name, "pos"))
-        return Py_BuildValue("i", self->pos);
+static PyObject *
+match_regs_get(MatchObject *self)
+{
+    if (self->regs) {
+        Py_INCREF(self->regs);
+        return self->regs;
+    } else
+        return match_regs(self);
+}
 
-    if (!strcmp(name, "endpos"))
-        return Py_BuildValue("i", self->endpos);
+static PyGetSetDef match_getset[] = {
+    {"lastindex", (getter)match_lastindex_get, (setter)NULL},
+    {"lastgroup", (getter)match_lastgroup_get, (setter)NULL},
+    {"regs",      (getter)match_regs_get,      (setter)NULL},
+    {NULL}
+};
 
-    PyErr_SetString(PyExc_AttributeError, name);
-    return NULL;
-}
+#define MATCH_OFF(x) offsetof(MatchObject, x)
+static PyMemberDef match_members[] = {
+    {"string",  T_OBJECT,   MATCH_OFF(string),  READONLY},
+    {"re",      T_OBJECT,   MATCH_OFF(pattern), READONLY},
+    {"pos",     T_PYSSIZET, MATCH_OFF(pos),     READONLY},
+    {"endpos",  T_PYSSIZET, MATCH_OFF(endpos),  READONLY},
+    {NULL}
+};
 
 /* FIXME: implement setattr("string", None) as a special case (to
    detach the associated string, if any */
@@ -3169,9 +3135,32 @@
     PyVarObject_HEAD_INIT(NULL,0)
     "_" SRE_MODULE ".SRE_Match",
     sizeof(MatchObject), sizeof(Py_ssize_t),
-    (destructor)match_dealloc, /*tp_dealloc*/
-    0, /*tp_print*/
-    (getattrfunc)match_getattr /*tp_getattr*/
+    (destructor)match_dealloc,	/* tp_dealloc */
+    0,				/* tp_print */
+    0,				/* tp_getattr */
+    0,				/* tp_setattr */
+    0,				/* tp_compare */
+    0,				/* tp_repr */
+    0,				/* tp_as_number */
+    0,				/* tp_as_sequence */
+    0,				/* tp_as_mapping */
+    0,				/* tp_hash */
+    0,				/* tp_call */
+    0,				/* tp_str */
+    0,				/* tp_getattro */
+    0,				/* tp_setattro */
+    0,				/* tp_as_buffer */
+    Py_TPFLAGS_DEFAULT,		/* tp_flags */
+    0,				/* tp_doc */
+    0,				/* tp_traverse */
+    0,				/* tp_clear */
+    0,				/* tp_richcompare */
+    0,				/* tp_weaklistoffset */
+    0,				/* tp_iter */
+    0,				/* tp_iternext */
+    match_methods,		/* tp_methods */
+    match_members,		/* tp_members */
+    match_getset,  	        /* tp_getset */
 };
 
 static PyObject*
@@ -3320,34 +3309,42 @@
     {NULL, NULL}
 };
 
-static PyObject*
-scanner_getattr(ScannerObject* self, char* name)
-{
-    PyObject* res;
-
-    res = Py_FindMethod(scanner_methods, (PyObject*) self, name);
-    if (res)
-        return res;
-
-    PyErr_Clear();
-
-    /* attributes */
-    if (!strcmp(name, "pattern")) {
-        Py_INCREF(self->pattern);
-        return self->pattern;
-    }
-
-    PyErr_SetString(PyExc_AttributeError, name);
-    return NULL;
-}
+#define SCAN_OFF(x) offsetof(ScannerObject, x)
+static PyMemberDef scanner_members[] = {
+    {"pattern",	T_OBJECT,	SCAN_OFF(pattern),	READONLY},
+    {NULL}  /* Sentinel */
+};
 
 static PyTypeObject Scanner_Type = {
     PyVarObject_HEAD_INIT(NULL, 0)
     "_" SRE_MODULE ".SRE_Scanner",
     sizeof(ScannerObject), 0,
-    (destructor)scanner_dealloc, /*tp_dealloc*/
-    0, /*tp_print*/
-    (getattrfunc)scanner_getattr, /*tp_getattr*/
+    (destructor)scanner_dealloc,/* tp_dealloc */
+    0,				/* tp_print */
+    0,				/* tp_getattr */
+    0,				/* tp_setattr */
+    0,				/* tp_compare */
+    0,				/* tp_repr */
+    0,				/* tp_as_number */
+    0,				/* tp_as_sequence */
+    0,				/* tp_as_mapping */
+    0,				/* tp_hash */
+    0,				/* tp_call */
+    0,				/* tp_str */
+    0,				/* tp_getattro */
+    0,				/* tp_setattro */
+    0,				/* tp_as_buffer */
+    Py_TPFLAGS_DEFAULT,		/* tp_flags */
+    0,				/* tp_doc */
+    0,				/* tp_traverse */
+    0,				/* tp_clear */
+    0,				/* tp_richcompare */
+    0,				/* tp_weaklistoffset */
+    0,				/* tp_iter */
+    0,				/* tp_iternext */
+    scanner_methods,		/* tp_methods */
+    scanner_members,		/* tp_members */
+    0,				/* tp_getset */
 };
 
 static PyObject*

Modified: python/branches/py3k/Modules/_ssl.c
==============================================================================
--- python/branches/py3k/Modules/_ssl.c	(original)
+++ python/branches/py3k/Modules/_ssl.c	Wed Jul  2 22:50:16 2008
@@ -1384,11 +1384,6 @@
 	{NULL, NULL}
 };
 
-static PyObject *PySSL_getattr(PySSLObject *self, char *name)
-{
-	return Py_FindMethod(PySSLMethods, (PyObject *)self, name);
-}
-
 static PyTypeObject PySSL_Type = {
 	PyVarObject_HEAD_INIT(NULL, 0)
 	"ssl.SSLContext",		/*tp_name*/
@@ -1397,7 +1392,7 @@
 	/* methods */
 	(destructor)PySSL_dealloc,	/*tp_dealloc*/
 	0,				/*tp_print*/
-	(getattrfunc)PySSL_getattr,	/*tp_getattr*/
+	0,				/*tp_getattr*/
 	0,				/*tp_setattr*/
 	0,				/*tp_compare*/
 	0,				/*tp_repr*/
@@ -1405,6 +1400,20 @@
 	0,				/*tp_as_sequence*/
 	0,				/*tp_as_mapping*/
 	0,				/*tp_hash*/
+	0,				/*tp_call*/
+	0,				/*tp_str*/
+	0,				/*tp_getattro*/
+	0,				/*tp_setattro*/
+	0,				/*tp_as_buffer*/
+	Py_TPFLAGS_DEFAULT,		/*tp_flags*/
+	0,				/*tp_doc*/
+	0,				/*tp_traverse*/
+	0,				/*tp_clear*/
+	0,				/*tp_richcompare*/
+	0,				/*tp_weaklistoffset*/
+	0,				/*tp_iter*/
+	0,				/*tp_iternext*/
+	PySSLMethods,			/*tp_methods*/
 };
 
 #ifdef HAVE_OPENSSL_RAND
@@ -1581,7 +1590,8 @@
 {
 	PyObject *m, *d;
 
-	Py_TYPE(&PySSL_Type) = &PyType_Type;
+	if (PyType_Ready(&PySSL_Type) < 0)
+		return NULL;
 
 	m = PyModule_Create(&_sslmodule);
 	if (m == NULL)

Modified: python/branches/py3k/Modules/_threadmodule.c
==============================================================================
--- python/branches/py3k/Modules/_threadmodule.c	(original)
+++ python/branches/py3k/Modules/_threadmodule.c	Wed Jul  2 22:50:16 2008
@@ -119,12 +119,6 @@
 	{NULL,           NULL}		/* sentinel */
 };
 
-static PyObject *
-lock_getattr(lockobject *self, char *name)
-{
-	return Py_FindMethod(lock_methods, (PyObject *)self, name);
-}
-
 static PyTypeObject Locktype = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
 	"_thread.lock",			/*tp_name*/
@@ -133,10 +127,28 @@
 	/* methods */
 	(destructor)lock_dealloc,	/*tp_dealloc*/
 	0,				/*tp_print*/
-	(getattrfunc)lock_getattr,	/*tp_getattr*/
+	0,				/*tp_getattr*/
 	0,				/*tp_setattr*/
 	0,				/*tp_compare*/
 	0,				/*tp_repr*/
+	0,				/*tp_as_number*/
+	0,				/*tp_as_sequence*/
+	0,				/*tp_as_mapping*/
+	0,				/*tp_hash*/
+	0,				/*tp_call*/
+	0,				/*tp_str*/
+	0,				/*tp_getattro*/
+	0,				/*tp_setattro*/
+	0,				/*tp_as_buffer*/
+	Py_TPFLAGS_DEFAULT,		/*tp_flags*/
+	0,				/*tp_doc*/
+	0,				/*tp_traverse*/
+	0,				/*tp_clear*/
+	0,				/*tp_richcompare*/
+	0,				/*tp_weaklistoffset*/
+	0,				/*tp_iter*/
+	0,				/*tp_iternext*/
+	lock_methods,			/*tp_methods*/
 };
 
 static lockobject *

Modified: python/branches/py3k/Modules/_tkinter.c
==============================================================================
--- python/branches/py3k/Modules/_tkinter.c	(original)
+++ python/branches/py3k/Modules/_tkinter.c	Wed Jul  2 22:50:16 2008
@@ -2327,12 +2327,6 @@
 	return PyUnicode_FromString(buf);
 }
 
-static PyObject *
-Tktt_GetAttr(PyObject *self, char *name)
-{
-	return Py_FindMethod(Tktt_methods, self, name);
-}
-
 static PyTypeObject Tktt_Type =
 {
 	PyVarObject_HEAD_INIT(NULL, 0)
@@ -2341,7 +2335,7 @@
 	0,				     /*tp_itemsize */
 	Tktt_Dealloc,			     /*tp_dealloc */
 	0,				     /*tp_print */
-	Tktt_GetAttr,			     /*tp_getattr */
+	0,				     /*tp_getattr */
 	0,				     /*tp_setattr */
 	0,				     /*tp_compare */
 	Tktt_Repr,			     /*tp_repr */
@@ -2349,6 +2343,20 @@
 	0,				     /*tp_as_sequence */
 	0,				     /*tp_as_mapping */
 	0,				     /*tp_hash */
+	0,				     /*tp_call*/
+	0,				     /*tp_str*/
+	0,				     /*tp_getattro*/
+	0,				     /*tp_setattro*/
+	0,				     /*tp_as_buffer*/
+	Py_TPFLAGS_DEFAULT,		     /*tp_flags*/
+	0,				     /*tp_doc*/
+	0,				     /*tp_traverse*/
+	0,				     /*tp_clear*/
+	0,				     /*tp_richcompare*/
+	0,				     /*tp_weaklistoffset*/
+	0,				     /*tp_iter*/
+	0,				     /*tp_iternext*/
+	Tktt_methods,			     /*tp_methods*/
 };
 
 
@@ -2671,12 +2679,6 @@
 	DisableEventHook();
 }
 
-static PyObject *
-Tkapp_GetAttr(PyObject *self, char *name)
-{
-	return Py_FindMethod(Tkapp_methods, self, name);
-}
-
 static PyTypeObject Tkapp_Type =
 {
 	PyVarObject_HEAD_INIT(NULL, 0)
@@ -2685,7 +2687,7 @@
 	0,				     /*tp_itemsize */
 	Tkapp_Dealloc,			     /*tp_dealloc */
 	0,				     /*tp_print */
-	Tkapp_GetAttr,			     /*tp_getattr */
+	0,				     /*tp_getattr */
 	0,				     /*tp_setattr */
 	0,				     /*tp_compare */
 	0,				     /*tp_repr */
@@ -2693,6 +2695,20 @@
 	0,				     /*tp_as_sequence */
 	0,				     /*tp_as_mapping */
 	0,				     /*tp_hash */
+	0,				     /*tp_call*/
+	0,				     /*tp_str*/
+	0,				     /*tp_getattro*/
+	0,				     /*tp_setattro*/
+	0,				     /*tp_as_buffer*/
+	Py_TPFLAGS_DEFAULT,		     /*tp_flags*/
+	0,				     /*tp_doc*/
+	0,				     /*tp_traverse*/
+	0,				     /*tp_clear*/
+	0,				     /*tp_richcompare*/
+	0,				     /*tp_weaklistoffset*/
+	0,				     /*tp_iter*/
+	0,				     /*tp_iternext*/
+	Tkapp_methods,			     /*tp_methods*/
 };
 
 
@@ -3026,7 +3042,8 @@
 {
 	PyObject *m, *d, *uexe, *cexe;
 
-	Py_TYPE(&Tkapp_Type) = &PyType_Type;
+	if (PyType_Ready(&Tkapp_Type) < 0)
+		return NULL;
 
 #ifdef WITH_THREAD
 	tcl_lock = PyThread_allocate_lock();
@@ -3054,7 +3071,8 @@
 
 	PyDict_SetItemString(d, "TkappType", (PyObject *)&Tkapp_Type);
 
-	Py_TYPE(&Tktt_Type) = &PyType_Type;
+	if (PyType_Ready(&Tktt_Type) < 0)
+		return NULL;
 	PyDict_SetItemString(d, "TkttType", (PyObject *)&Tktt_Type);
 
 	Py_TYPE(&PyTclObject_Type) = &PyType_Type;

Modified: python/branches/py3k/Modules/parsermodule.c
==============================================================================
--- python/branches/py3k/Modules/parsermodule.c	(original)
+++ python/branches/py3k/Modules/parsermodule.c	Wed Jul  2 22:50:16 2008
@@ -161,8 +161,28 @@
 
 static void parser_free(PyST_Object *st);
 static int parser_compare(PyST_Object *left, PyST_Object *right);
-static PyObject *parser_getattr(PyObject *self, char *name);
+static PyObject* parser_compilest(PyST_Object *, PyObject *, PyObject *);
+static PyObject* parser_isexpr(PyST_Object *, PyObject *, PyObject *);
+static PyObject* parser_issuite(PyST_Object *, PyObject *, PyObject *);
+static PyObject* parser_st2list(PyST_Object *, PyObject *, PyObject *);
+static PyObject* parser_st2tuple(PyST_Object *, PyObject *, PyObject *);
 
+#define PUBLIC_METHOD_TYPE (METH_VARARGS|METH_KEYWORDS)
+
+static PyMethodDef parser_methods[] = {
+    {"compile",         (PyCFunction)parser_compilest,  PUBLIC_METHOD_TYPE,
+        PyDoc_STR("Compile this ST object into a code object.")},
+    {"isexpr",          (PyCFunction)parser_isexpr,     PUBLIC_METHOD_TYPE,
+        PyDoc_STR("Determines if this ST object was created from an expression.")},
+    {"issuite",         (PyCFunction)parser_issuite,    PUBLIC_METHOD_TYPE,
+        PyDoc_STR("Determines if this ST object was created from a suite.")},
+    {"tolist",          (PyCFunction)parser_st2list,    PUBLIC_METHOD_TYPE,
+        PyDoc_STR("Creates a list-tree representation of this ST.")},
+    {"totuple",         (PyCFunction)parser_st2tuple,   PUBLIC_METHOD_TYPE,
+        PyDoc_STR("Creates a tuple-tree representation of this ST.")},
+
+    {NULL, NULL, 0, NULL}
+};
 
 static
 PyTypeObject PyST_Type = {
@@ -172,7 +192,7 @@
     0,                                  /* tp_itemsize          */
     (destructor)parser_free,            /* tp_dealloc           */
     0,                                  /* tp_print             */
-    parser_getattr,                     /* tp_getattr           */
+    0,                                  /* tp_getattr           */
     0,                                  /* tp_setattr           */
     (cmpfunc)parser_compare,            /* tp_compare           */
     0,                                  /* tp_repr              */
@@ -191,7 +211,14 @@
     Py_TPFLAGS_DEFAULT,                 /* tp_flags             */
 
     /* __doc__ */
-    "Intermediate representation of a Python parse tree."
+    "Intermediate representation of a Python parse tree.",
+    0,                                  /* tp_traverse */
+    0,                                  /* tp_clear */
+    0,                                  /* tp_richcompare */
+    0,                                  /* tp_weaklistoffset */
+    0,                                  /* tp_iter */
+    0,                                  /* tp_iternext */
+    parser_methods,                     /* tp_methods */
 };  /* PyST_Type */
 
 
@@ -450,32 +477,6 @@
 }
 
 
-#define PUBLIC_METHOD_TYPE (METH_VARARGS|METH_KEYWORDS)
-
-static PyMethodDef
-parser_methods[] = {
-    {"compile",         (PyCFunction)parser_compilest,  PUBLIC_METHOD_TYPE,
-        PyDoc_STR("Compile this ST object into a code object.")},
-    {"isexpr",          (PyCFunction)parser_isexpr,     PUBLIC_METHOD_TYPE,
-        PyDoc_STR("Determines if this ST object was created from an expression.")},
-    {"issuite",         (PyCFunction)parser_issuite,    PUBLIC_METHOD_TYPE,
-        PyDoc_STR("Determines if this ST object was created from a suite.")},
-    {"tolist",          (PyCFunction)parser_st2list,    PUBLIC_METHOD_TYPE,
-        PyDoc_STR("Creates a list-tree representation of this ST.")},
-    {"totuple",         (PyCFunction)parser_st2tuple,   PUBLIC_METHOD_TYPE,
-        PyDoc_STR("Creates a tuple-tree representation of this ST.")},
-
-    {NULL, NULL, 0, NULL}
-};
-
-
-static PyObject*
-parser_getattr(PyObject *self, char *name)
-{
-    return (Py_FindMethod(parser_methods, self, name));
-}
-
-
 /*  err_string(char* message)
  *
  *  Sets the error string for an exception of type ParserError.
@@ -3067,7 +3068,8 @@
 {
     PyObject *module, *copyreg;
 
-    Py_TYPE(&PyST_Type) = &PyType_Type;
+    if (PyType_Ready(&PyST_Type) < 0)
+        return NULL;
     module = PyModule_Create(&parsermodule);
     if (module == NULL)
     	return NULL;

Modified: python/branches/py3k/Modules/selectmodule.c
==============================================================================
--- python/branches/py3k/Modules/selectmodule.c	(original)
+++ python/branches/py3k/Modules/selectmodule.c	Wed Jul  2 22:50:16 2008
@@ -625,12 +625,6 @@
   	PyObject_Del(self);
 }
 
-static PyObject *
-poll_getattr(pollObject *self, char *name)
-{
-	return Py_FindMethod(poll_methods, (PyObject *)self, name);
-}
-
 static PyTypeObject poll_Type = {
 	/* The ob_type field must be initialized in the module init function
 	 * to be portable to Windows without using C++. */
@@ -641,7 +635,7 @@
 	/* methods */
 	(destructor)poll_dealloc, /*tp_dealloc*/
 	0,			/*tp_print*/
-	(getattrfunc)poll_getattr, /*tp_getattr*/
+	0,			/*tp_getattr*/
 	0,                      /*tp_setattr*/
 	0,			/*tp_compare*/
 	0,			/*tp_repr*/
@@ -649,6 +643,20 @@
 	0,			/*tp_as_sequence*/
 	0,			/*tp_as_mapping*/
 	0,			/*tp_hash*/
+	0,			/*tp_call*/
+	0,			/*tp_str*/
+	0,			/*tp_getattro*/
+	0,			/*tp_setattro*/
+	0,			/*tp_as_buffer*/
+	Py_TPFLAGS_DEFAULT,	/*tp_flags*/
+	0,			/*tp_doc*/
+	0,			/*tp_traverse*/
+	0,			/*tp_clear*/
+	0,			/*tp_richcompare*/
+	0,			/*tp_weaklistoffset*/
+	0,			/*tp_iter*/
+	0,			/*tp_iternext*/
+	poll_methods,		/*tp_methods*/
 };
 
 PyDoc_STRVAR(poll_doc,
@@ -1764,7 +1772,8 @@
 #else
 	{
 #endif
-		Py_TYPE(&poll_Type) = &PyType_Type;
+		if (PyType_Ready(&poll_Type) < 0)
+			return NULL;
 		PyModule_AddIntConstant(m, "POLLIN", POLLIN);
 		PyModule_AddIntConstant(m, "POLLPRI", POLLPRI);
 		PyModule_AddIntConstant(m, "POLLOUT", POLLOUT);

Modified: python/branches/py3k/Modules/zlibmodule.c
==============================================================================
--- python/branches/py3k/Modules/zlibmodule.c	(original)
+++ python/branches/py3k/Modules/zlibmodule.c	Wed Jul  2 22:50:16 2008
@@ -5,6 +5,7 @@
 
 
 #include "Python.h"
+#include "structmember.h"
 #include "zlib.h"
 
 #ifdef WITH_THREAD
@@ -879,35 +880,12 @@
     {NULL, NULL}
 };
 
-static PyObject *
-Comp_getattr(compobject *self, char *name)
-{
-  /* No ENTER/LEAVE_ZLIB is necessary because this fn doesn't touch
-     internal data. */
-
-  return Py_FindMethod(comp_methods, (PyObject *)self, name);
-}
-
-static PyObject *
-Decomp_getattr(compobject *self, char *name)
-{
-    PyObject * retval;
-
-    ENTER_ZLIB
-
-    if (strcmp(name, "unused_data") == 0) {
-	Py_INCREF(self->unused_data);
-	retval = self->unused_data;
-    } else if (strcmp(name, "unconsumed_tail") == 0) {
-	Py_INCREF(self->unconsumed_tail);
-	retval = self->unconsumed_tail;
-    } else
-	retval = Py_FindMethod(Decomp_methods, (PyObject *)self, name);
-
-    LEAVE_ZLIB
-
-    return retval;
-}
+#define COMP_OFF(x) offsetof(compobject, x)
+static PyMemberDef Decomp_members[] = {
+    {"unused_data",     T_OBJECT, COMP_OFF(unused_data), READONLY},
+    {"unconsumed_tail", T_OBJECT, COMP_OFF(unconsumed_tail), READONLY},
+    {NULL},
+};
 
 PyDoc_STRVAR(adler32__doc__,
 "adler32(string[, start]) -- Compute an Adler-32 checksum of string.\n"
@@ -972,13 +950,28 @@
     0,
     (destructor)Comp_dealloc,       /*tp_dealloc*/
     0,                              /*tp_print*/
-    (getattrfunc)Comp_getattr,      /*tp_getattr*/
+    0,                              /*tp_getattr*/
     0,                              /*tp_setattr*/
     0,                              /*tp_compare*/
     0,                              /*tp_repr*/
     0,                              /*tp_as_number*/
     0,                              /*tp_as_sequence*/
     0,                              /*tp_as_mapping*/
+    0,                              /*tp_hash*/
+    0,                              /*tp_call*/
+    0,                              /*tp_str*/
+    0,                              /*tp_getattro*/
+    0,                              /*tp_setattro*/
+    0,                              /*tp_as_buffer*/
+    Py_TPFLAGS_DEFAULT,             /*tp_flags*/
+    0,                              /*tp_doc*/
+    0,                              /*tp_traverse*/
+    0,                              /*tp_clear*/
+    0,                              /*tp_richcompare*/
+    0,                              /*tp_weaklistoffset*/
+    0,                              /*tp_iter*/
+    0,                              /*tp_iternext*/
+    comp_methods,                   /*tp_methods*/
 };
 
 static PyTypeObject Decomptype = {
@@ -988,13 +981,29 @@
     0,
     (destructor)Decomp_dealloc,     /*tp_dealloc*/
     0,                              /*tp_print*/
-    (getattrfunc)Decomp_getattr,    /*tp_getattr*/
+    0,                              /*tp_getattr*/
     0,                              /*tp_setattr*/
     0,                              /*tp_compare*/
     0,                              /*tp_repr*/
     0,                              /*tp_as_number*/
     0,                              /*tp_as_sequence*/
     0,                              /*tp_as_mapping*/
+    0,                              /*tp_hash*/
+    0,                              /*tp_call*/
+    0,                              /*tp_str*/
+    0,                              /*tp_getattro*/
+    0,                              /*tp_setattro*/
+    0,                              /*tp_as_buffer*/
+    Py_TPFLAGS_DEFAULT,             /*tp_flags*/
+    0,                              /*tp_doc*/
+    0,                              /*tp_traverse*/
+    0,                              /*tp_clear*/
+    0,                              /*tp_richcompare*/
+    0,                              /*tp_weaklistoffset*/
+    0,                              /*tp_iter*/
+    0,                              /*tp_iternext*/
+    Decomp_methods,                 /*tp_methods*/
+    Decomp_members,                 /*tp_members*/
 };
 
 PyDoc_STRVAR(zlib_module_documentation,
@@ -1028,8 +1037,10 @@
 PyInit_zlib(void)
 {
     PyObject *m, *ver;
-    Py_TYPE(&Comptype) = &PyType_Type;
-    Py_TYPE(&Decomptype) = &PyType_Type;
+    if (PyType_Ready(&Comptype) < 0)
+	    return NULL;
+    if (PyType_Ready(&Decomptype) < 0)
+	    return NULL;
     m = PyModule_Create(&zlibmodule);
     if (m == NULL)
 	return NULL;

Modified: python/branches/py3k/PC/_subprocess.c
==============================================================================
--- python/branches/py3k/PC/_subprocess.c	(original)
+++ python/branches/py3k/PC/_subprocess.c	Wed Jul  2 22:50:16 2008
@@ -111,12 +111,6 @@
 };
 
 static PyObject*
-sp_handle_getattr(sp_handle_object* self, char* name)
-{
-	return Py_FindMethod(sp_handle_methods, (PyObject*) self, name);
-}
-
-static PyObject*
 sp_handle_as_int(sp_handle_object* self)
 {
 	return PyLong_FromLong((long) self->handle);
@@ -129,14 +123,28 @@
 	"_subprocess_handle", sizeof(sp_handle_object), 0,
 	(destructor) sp_handle_dealloc, /*tp_dealloc*/
 	0, /*tp_print*/
-	(getattrfunc) sp_handle_getattr,/*tp_getattr*/
+	0,				/*tp_getattr*/
 	0,				/*tp_setattr*/
 	0,				/*tp_compare*/
 	0,				/*tp_repr*/
 	&sp_handle_as_number,		/*tp_as_number */
 	0,				/*tp_as_sequence */
 	0,				/*tp_as_mapping */
-	0				/*tp_hash*/
+	0,				/*tp_hash*/
+	0,				/*tp_call*/
+	0,				/*tp_str*/
+	0,				/*tp_getattro*/
+	0,				/*tp_setattro*/
+	0,				/*tp_as_buffer*/
+	Py_TPFLAGS_DEFAULT,		/*tp_flags*/
+	0,				/*tp_doc*/
+	0,				/*tp_traverse*/
+	0,				/*tp_clear*/
+	0,				/*tp_richcompare*/
+	0,				/*tp_weaklistoffset*/
+	0,				/*tp_iter*/
+	0,				/*tp_iternext*/
+	sp_handle_methods,		/*tp_methods*/
 };
 
 /* -------------------------------------------------------------------- */
@@ -560,8 +568,9 @@
 	PyObject *m;
 
 	/* patch up object descriptors */
-	Py_TYPE(&sp_handle_type) = &PyType_Type;
 	sp_handle_as_number.nb_int = (unaryfunc) sp_handle_as_int;
+	if (PyType_Ready(&sp_handle_type) < 0)
+		return NULL;
 
 	m = PyModule_Create(&_subprocessmodule);
 	if (m == NULL)

Modified: python/branches/py3k/PC/winreg.c
==============================================================================
--- python/branches/py3k/PC/winreg.c	(original)
+++ python/branches/py3k/PC/winreg.c	Wed Jul  2 22:50:16 2008
@@ -455,9 +455,24 @@
 	PyHKEY_unaryFailureFunc,	/* nb_float */
 };
 
+static PyObject *PyHKEY_CloseMethod(PyObject *self, PyObject *args);
+static PyObject *PyHKEY_DetachMethod(PyObject *self, PyObject *args);
+static PyObject *PyHKEY_Enter(PyObject *self);
+static PyObject *PyHKEY_Exit(PyObject *self, PyObject *args);
 
-/* fwd declare __getattr__ */
-static PyObject *PyHKEY_getattr(PyObject *self, const char *name);
+static struct PyMethodDef PyHKEY_methods[] = {
+	{"Close",  PyHKEY_CloseMethod, METH_VARARGS, PyHKEY_Close_doc},
+	{"Detach", PyHKEY_DetachMethod, METH_VARARGS, PyHKEY_Detach_doc},
+	{"__enter__", (PyCFunction)PyHKEY_Enter, METH_NOARGS, NULL},
+	{"__exit__", PyHKEY_Exit, METH_VARARGS, NULL},
+	{NULL}
+};
+
+#define OFF(e) offsetof(PyHKEYObject, e)
+static PyMemberDef PyHKEY_memberlist[] = {
+	{"handle",      T_INT,      OFF(hkey), READONLY},
+	{NULL}    /* Sentinel */
+};
 
 /* The type itself */
 PyTypeObject PyHKEY_Type =
@@ -468,7 +483,7 @@
 	0,
 	PyHKEY_deallocFunc,		/* tp_dealloc */
 	0,				/* tp_print */
-	PyHKEY_getattr,			/* tp_getattr */
+	0,				/* tp_getattr */
 	0,				/* tp_setattr */
 	PyHKEY_compareFunc,		/* tp_compare */
 	0,				/* tp_repr */
@@ -483,13 +498,14 @@
 	0,				/* tp_as_buffer */
 	0,				/* tp_flags */
 	PyHKEY_doc,			/* tp_doc */
-};
-
-#define OFF(e) offsetof(PyHKEYObject, e)
-
-static PyMemberDef PyHKEY_memberlist[] = {
-	{"handle",      T_INT,      OFF(hkey), READONLY},
-	{NULL}    /* Sentinel */
+	0,				/*tp_traverse*/
+	0,				/*tp_clear*/
+	0,				/*tp_richcompare*/
+	0,				/*tp_weaklistoffset*/
+	0,				/*tp_iter*/
+	0,				/*tp_iternext*/
+	PyHKEY_methods,			/*tp_methods*/
+	PyHKEY_memberlist,		/*tp_members*/
 };
 
 /************************************************************************
@@ -536,31 +552,6 @@
 }
 
 
-static struct PyMethodDef PyHKEY_methods[] = {
-	{"Close",  PyHKEY_CloseMethod, METH_VARARGS, PyHKEY_Close_doc},
-	{"Detach", PyHKEY_DetachMethod, METH_VARARGS, PyHKEY_Detach_doc},
-	{"__enter__", (PyCFunction)PyHKEY_Enter, METH_NOARGS, NULL},
-	{"__exit__", PyHKEY_Exit, METH_VARARGS, NULL},
-	{NULL}
-};
-
-/*static*/ PyObject *
-PyHKEY_getattr(PyObject *self, const char *name)
-{
-	PyObject *res;
-
-	res = Py_FindMethod(PyHKEY_methods, self, name);
-	if (res != NULL)
-		return res;
-	PyErr_Clear();
-	if (strcmp(name, "handle") == 0)
-		return PyLong_FromVoidPtr(((PyHKEYObject *)self)->hkey);
-	PyErr_Format(PyExc_AttributeError,
-                     "'%.50s' object has no attribute '%.400s'",
-                     Py_TYPE(self)->tp_name, name);
-	return NULL;
-}
-
 /************************************************************************
    The public PyHKEY API (well, not public yet :-)
 ************************************************************************/
@@ -1582,8 +1573,9 @@
 	if (m == NULL)
 		return NULL;
 	d = PyModule_GetDict(m);
-	Py_TYPE(&PyHKEY_Type) = &PyType_Type;
 	PyHKEY_Type.tp_doc = PyHKEY_doc;
+	if (PyType_Ready(&PyHKEY_Type) < 0)
+		return NULL;
 	Py_INCREF(&PyHKEY_Type);
 	if (PyDict_SetItemString(d, "HKEYType",
 				 (PyObject *)&PyHKEY_Type) != 0)


More information about the Python-3000-checkins mailing list