Commits

Amaury Forgeot d'Arc committed 307c261

more progress

  • Participants
  • Parent commits 8bde3e1
  • Branches cpyext-init-cleanup

Comments (0)

Files changed (1)

File pypy/module/cpyext/api.py

     needs_hidden_global_structure = False
     def get_global_code_for_bridge(self):
         return []
-
     def get_type_for_declaration(self):
         return 'PyObject'
 
-    is_pyobject = True
-    def get_structtype_for_ctype(self):
-        return PyObject
+    def get_struct_to_export(self, space, value):
+        value = make_ref(space, value)
+        return value._obj
 
     def set_value_in_ctypes_dll(self, space, dll, value):
         # it's a structure, get its adress
     needs_hidden_global_structure = True
     def get_global_code_for_bridge(self):
         return ['%s _%s;' % (self.type[:-1], self.name)]
+    def get_type_for_declaration(self):
+        return self.type
+
+    def get_value_to_export(self, space, value):
+        from pypy.module.cpyext.datetime import PyDateTime_CAPI
+        struct = rffi.cast(lltype.Ptr(PyDateTime_CAPI), value)._obj
 
     def set_value_in_ctypes_dll(self, space, dll, value):
         name = self.name.replace('Py', 'PyPy')
         ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
                                 ctypes.c_void_p).value
 
-    def get_type_for_declaration(self):
-        return self.type
-
-    is_pyobject = False
-    def get_structtype_for_ctype(self):
-        from pypy.module.cpyext.datetime import PyDateTime_CAPI
-        return lltype.Ptr(PyDateTime_CAPI) # XXX
-
 class GlobalExceptionPointer(BaseGlobalObject):
     def __init__(self, exc_name):
         self.name = 'PyExc_' + exc_name
     needs_hidden_global_structure = True
     def get_global_code_for_bridge(self):
         return ['%s _%s;' % (self.type[:-1], self.name)]
-
     def get_type_for_declaration(self):
         return 'PyObject*'
 
-    is_pyobject = True
-    def get_structtype_for_ctype(self):
+    def get_value_to_export(self, space, value):
         from pypy.module.cpyext.typeobjectdefs import PyTypeObjectPtr
-        return PyTypeObjectPtr
+        return rffi.cast(PyTypeObjectPtr, make_ref(space, value))._obj
 
     def set_value_in_ctypes_dll(self, space, dll, value):
         # it's a pointer
     needs_hidden_global_structure = False
     def get_global_code_for_bridge(self):
         return []
-
     def get_type_for_declaration(self):
         return 'PyTypeObject'
 
-    is_pyobject = True
-    def get_structtype_for_ctype(self):
-        return PyTypeObjectPtr
+    def get_value_to_export(self, space, value):
+        from pypy.module.cpyext.typeobjectdefs import PyTypeObjectPtr
+        return rffi.cast(PyTypeObjectPtr, make_ref(space, value))._obj
 
     def set_value_in_ctypes_dll(self, space, dll, value):
         # it's a structure, get its adress
         if obj.needs_hidden_global_structure:
             name = '_' + name
         value = obj.eval(space)
-        if obj.is_pyobject:
-            value = make_ref(space, value)
-        struct = rffi.cast(obj.get_structtype_for_ctype(), value)._obj
+        struct = obj.get_value_to_export(space, value)
         struct._compilation_info = eci
         export_struct(name, struct)