[pypy-svn] r7562 - pypy/trunk/src/pypy/translator

arigo at codespeak.net arigo at codespeak.net
Mon Nov 22 14:44:01 CET 2004


Author: arigo
Date: Mon Nov 22 14:44:01 2004
New Revision: 7562

Modified:
   pypy/trunk/src/pypy/translator/genc.h
   pypy/trunk/src/pypy/translator/genc.py
Log:
Old-style classes getting in the way, as always.


Modified: pypy/trunk/src/pypy/translator/genc.h
==============================================================================
--- pypy/trunk/src/pypy/translator/genc.h	(original)
+++ pypy/trunk/src/pypy/translator/genc.h	Mon Nov 22 14:44:01 2004
@@ -164,9 +164,10 @@
 #define SETUP_INSTANCE_ATTR(t, attr, value)	\
 	(PyObject_SetAttrString(t, attr, value) >= 0)
 
-#define SETUP_INSTANCE(i, cls)                  \
-	(i = PyType_GenericAlloc((PyTypeObject *)cls, 0))
-
+#define SETUP_INSTANCE(i, cls)						\
+	(PyType_Check(cls) ?						\
+		(i = PyType_GenericAlloc((PyTypeObject *)cls, 0)) :	\
+		(i = PyInstance_NewRaw(cls, NULL)))
 
 
 #if defined(USE_CALL_TRACE)

Modified: pypy/trunk/src/pypy/translator/genc.py
==============================================================================
--- pypy/trunk/src/pypy/translator/genc.py	(original)
+++ pypy/trunk/src/pypy/translator/genc.py	Mon Nov 22 14:44:01 2004
@@ -303,9 +303,14 @@
         if issubclass(cls, Exception):
             if cls.__module__ == 'exceptions':
                 return 'PyExc_%s'%cls.__name__
-            else:
-                # exceptions must be old-style classes (grr!)
-                metaclass = "&PyClass_Type"
+            #else:
+            #    # exceptions must be old-style classes (grr!)
+            #    metaclass = "&PyClass_Type"
+        # For the moment, use old-style classes exactly when the
+        # pypy source uses old-style classes, to avoid strange problems.
+        if not isinstance(cls, type):
+            assert type(cls) is type(Exception)
+            metaclass = "&PyClass_Type"
 
         name = self.uniquename('gcls_' + cls.__name__)
         basenames = [self.nameof(base) for base in cls.__bases__]



More information about the Pypy-commit mailing list