[pypy-svn] r75202 - pypy/branch/cpyext-init-cleanup/pypy/module/cpyext

afa at codespeak.net afa at codespeak.net
Tue Jun 8 17:58:01 CEST 2010


Author: afa
Date: Tue Jun  8 17:57:59 2010
New Revision: 75202

Modified:
   pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/api.py
Log:
progress


Modified: pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/api.py
==============================================================================
--- pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/api.py	(original)
+++ pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/api.py	Tue Jun  8 17:57:59 2010
@@ -115,14 +115,6 @@
     for name in ("pypy_decl.h", "pypy_macros.h"):
         udir.join(name).copy(interfaces_dir / name)
 
-class BaseGlobalObject:
-    """Base class for all objects (pointers and structures)"""
-
-    @classmethod
-    def declare(cls, *args, **kwargs):
-        obj = cls(*args, **kwargs)
-        GLOBALS[obj.name] = obj
-
 _NOT_SPECIFIED = object()
 CANNOT_FAIL = object()
 
@@ -342,18 +334,32 @@
 INIT_FUNCTIONS = []
 BOOTSTRAP_FUNCTIONS = []
 
+class BaseGlobalObject:
+    """Base class for all objects (pointers and structures)"""
+
+    @classmethod
+    def declare(cls, *args, **kwargs):
+        obj = cls(*args, **kwargs)
+        GLOBALS[obj.name] = obj
+
 class GlobalStaticPyObject(BaseGlobalObject):
     def __init__(self, name, expr):
         self.name = name + '#'
         self.type = 'PyObject*'
         self.expr = expr
 
+    def get_global_code_for_bridge(self):
+        return []
+
 class GlobalStructurePointer(BaseGlobalObject):
     def __init__(self, name, type, expr):
         self.name = name
         self.type = type
         self.expr = expr
 
+    def get_global_code_for_bridge(self):
+        return ['%s _%s;' % (self.type, self.name)]
+
 class GlobalExceptionPointer(BaseGlobalObject):
     def __init__(self, exc_name):
         self.name = 'PyExc_' + exc_name
@@ -361,12 +367,18 @@
         self.expr = ('space.gettypeobject(interp_exceptions.W_%s.typedef)'
                      % (exc_name,))
 
+    def get_global_code_for_bridge(self):
+        return ['%s _%s;' % (self.type[:-1], self.name)]
+
 class GlobalTypeObject(BaseGlobalObject):
     def __init__(self, name, expr):
         self.name = 'Py%s_Type#' % (name,)
         self.type = 'PyTypeObject*'
         self.expr = expr
 
+    def get_global_code_for_bridge(self):
+        return []
+
 GlobalStaticPyObject.declare('_Py_NoneStruct', 'space.w_None')
 GlobalStaticPyObject.declare('_Py_TrueStruct', 'space.w_True')
 GlobalStaticPyObject.declare('_Py_ZeroStruct', 'space.w_False')
@@ -648,14 +660,7 @@
 
     global_objects = []
     for obj in GLOBALS.values():
-        if "#" in obj.name:
-            continue
-        if obj.type == 'PyDateTime_CAPI*':
-            global_objects.append('%s _%s;' % (obj.type, obj.name))
-        elif obj.name.startswith('PyExc_'):
-            global_objects.append('%s _%s;' % (obj.type[:-1], obj.name))
-        else:
-            global_objects.append('%s %s = NULL;' % (obj.typ, obj.name))
+        global_objects.extend(obj.get_global_code_for_bridge())
     global_code = '\n'.join(global_objects)
 
     prologue = "#include <Python.h>\n"



More information about the Pypy-commit mailing list