[pypy-svn] r25060 - in pypy/dist/pypy: rpython/lltypesystem translator/c/test

tismer at codespeak.net tismer at codespeak.net
Tue Mar 28 07:27:40 CEST 2006


Author: tismer
Date: Tue Mar 28 07:27:37 2006
New Revision: 25060

Modified:
   pypy/dist/pypy/rpython/lltypesystem/rclass.py
   pypy/dist/pypy/translator/c/test/test_wrapping.py
Log:
changes towards chaching the wrapper instance

Modified: pypy/dist/pypy/rpython/lltypesystem/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rclass.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/rclass.py	Tue Mar 28 07:27:37 2006
@@ -16,7 +16,7 @@
      cast_pointer, castable, nullptr, \
      RuntimeTypeInfo, getRuntimeTypeInfo, typeOf, \
      Array, Char, Void, attachRuntimeTypeInfo, \
-     FuncType, Bool, Signed, functionptr, FuncType
+     FuncType, Bool, Signed, functionptr, FuncType, PyObject
 from pypy.rpython.robject import PyObjRepr, pyobj_repr
 from pypy.rpython import extregistry
 
@@ -328,6 +328,13 @@
 
             self.rbase = getinstancerepr(self.rtyper, self.classdef.basedef, not self.needsgc)
             self.rbase.setup()
+            #
+            # PyObject wrapper support
+            if (self.rtyper.needs_wrapper(self.classdef) and '_wrapper_'
+                not in self.rbase.allinstancefields):
+                fields['_wrapper_'] = 'wrapper', pyobj_repr
+                llfields.append(('wrapper', Ptr(PyObject)))
+
             if self.needsgc:
                 MkStruct = GcStruct
             else:
@@ -588,9 +595,22 @@
 def ll_call_destructor(thang):
     return 42 # will be mapped
 
+def ll_clear_wrapper(inst):
+    # Note: we must ensure to enforce creation of this extra field.
+    # this is done when we set up the instantiators in XXX which module???
+    pass # inst.inst___wrapper__ = None
+    #inst.fields.au = 42
+    #setattr(inst, 'inst___wrapper__', None)
+    #inst.inst___wrapper__ = Ptr(33)#inst.inst___wrapper__
+    #p = ll_cast_to_object(inst)
+
+    #inst.inst___wrapper__ = nullptr(PyObject)
+    #inst.inst_a = 42
+    
 def rtype_destruct_object(hop):
-    v_any, = hop.inputargs(*hop.args_r)
-    hop.genop('gc_unprotect', [v_any])
+    v, = hop.inputargs(*hop.args_r)
+    hop.gendirectcall(ll_clear_wrapper, v)
+    hop.genop('gc_unprotect', [v])
 
 extregistry.register_value(ll_call_destructor, 
     compute_result_annotation=lambda *args:None,

Modified: pypy/dist/pypy/translator/c/test/test_wrapping.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_wrapping.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_wrapping.py	Tue Mar 28 07:27:37 2006
@@ -30,9 +30,7 @@
     global t # allow us to view later
     t = TranslationContext()
     do_register(t)
-    t.buildannotator().build_types(func, get_annotation(func))
-    if view:
-        t.viewcg()
+    t.buildannotator()
     rtyper = t.buildrtyper()
     bk = rtyper.annotator.bookkeeper
     instantiators = {}
@@ -40,10 +38,16 @@
         if isinstance(obj, type):
             cls = obj
             def make():
-                return instantiate(cls)
+                obj = instantiate(cls)
+                return obj
             make.__name__ = cls.__name__ + '__new__'
-            t.annotator.build_types(make, [])
+            t.annotator.build_types(make, [], complete_now=False)
             instantiators[cls] = make
+            clsdef = bk.getuniqueclassdef(cls)
+            rtyper.add_wrapper(clsdef)
+    t.annotator.build_types(func, get_annotation(func))
+    if view:
+        t.viewcg()
     rtyper.specialize()
     if view:
         t.viewcg()
@@ -161,8 +165,11 @@
 
 delmonitor = DelMonitor()
 
+class DemoBaseNotExposed(object):
+    pass
+
 # a trivial class to be exposed
-class DemoClass(object):
+class DemoClass(DemoBaseNotExposed):
     def __init__(self, a, b):
         self.a = a
         self.b = b
@@ -181,6 +188,11 @@
 
 # see if we get things exported with subclassing
 class DemoSubclass(DemoClass):
+    def __init__(self, a, b, c):
+        #super(DemoSubclass, self).__init__(a, b)
+        DemoClass.__init__(self, b, a)
+        self.c = c
+
     def demo(self):
         return float(DemoClass.demo(self))
     
@@ -230,7 +242,7 @@
 def democlass_helper2(a=int, b=int):
     self = DemoClass(a, b)
     self.demo()
-    self2 = DemoSubclass(a, b)
+    self2 = DemoSubclass(a, b, 42)
     return self
 
 # creating an object, wrapping, unwrapping, call function, check whether __del__ is called



More information about the Pypy-commit mailing list