Commits

wlav  committed 530dc82

reshuffling to allow back-end specific pythonizations

  • Participants
  • Parent commits f800d0b
  • Branches reflex-support

Comments (0)

Files changed (6)

File pypy/module/cppyy/capi/__init__.py

 import reflex_capi as backend
 #import cint_capi as backend
 
-identify = backend.identify
+identify  = backend.identify
+pythonize = backend.pythonize
 ts_reflect = backend.ts_reflect
 ts_call    = backend.ts_call
 ts_memory  = backend.ts_memory

File pypy/module/cppyy/capi/cint_capi.py

         err = rdynload.dlerror()
         raise rdynload.DLOpenError(err)
     return libffi.CDLL(name)       # should return handle to already open file
+
+# CINT-specific pythonizations     
+def pythonize(space, name, w_pycppclass):
+
+    if name[0:8] == "TVectorT":
+        space.setattr(w_pycppclass, space.wrap("__len__"),
+                      space.getattr(w_pycppclass, space.wrap("GetNoElements")))

File pypy/module/cppyy/capi/reflex_capi.py

 
 def c_load_dictionary(name):
     return libffi.CDLL(name)
+
+# Reflex-specific pythonizations
+def pythonize(space, name, w_pycppclass):
+    pass

File pypy/module/cppyy/interp_cppyy.py

 def register_class(space, w_pycppclass):
     w_cppclass = space.findattr(w_pycppclass, space.wrap("_cpp_proxy"))
     cppclass = space.interp_w(W_CPPClass, w_cppclass, can_be_None=False)
+    # add back-end specific method pythonizations (doing this on the wrapped
+    # class allows simple aliasing of methods)
+    capi.pythonize(space, cppclass.name, w_pycppclass)
     state = space.fromcache(State)
     state.cppclass_registry[cppclass.handle] = w_pycppclass
 
                     methods_temp.setdefault("__getitem__", []).append(cppmethod)
             except KeyError:
                 pass          # just means there's no __setitem__ either
+
+        # create the overload methods from the method sets
         for pyname, methods in methods_temp.iteritems():
             overload = W_CPPOverload(self.space, self, methods[:])
             self.methods[pyname] = overload
         w_pycppclass = state.cppclass_registry[handle]
     except KeyError:
         final_name = capi.c_scoped_final_name(handle)
+        # the callback will cache the class by calling register_class
         w_pycppclass = space.call_function(state.w_clgen_callback, space.wrap(final_name))
     return w_pycppclass
 

File pypy/module/cppyy/pythonify.py

         if cppdm.is_static():
             setattr(metacpp, dm_name, pydm)
 
+    # the call to register will add back-end specific pythonizations and thus
+    # needs to run first, so that the generic pythonizations can use them
+    cppyy._register_class(pycppclass)
     _pythonize(pycppclass)
-    cppyy._register_class(pycppclass)
     return pycppclass
 
 def make_cpptemplatetype(scope, template_name):
         pyclass.__eq__ = eq
         pyclass.__str__ = pyclass.c_str
 
-    # TODO: clean this up
-    # fixup lack of __getitem__ if no const return
-    if hasattr(pyclass, '__setitem__') and not hasattr(pyclass, '__getitem__'):
-        pyclass.__getitem__ = pyclass.__setitem__
-
 _loaded_dictionaries = {}
 def load_reflection_info(name):
     """Takes the name of a library containing reflection info, returns a handle

File pypy/module/cppyy/test/test_cint.py

         # TVectorF is a typedef of floats
         v = cppyy.gbl.TVectorF(N)
         for i in range(N):
-            v[i] = i*i
+             v[i] = i*i
 
-        #for j in v:       # TODO: raise exception on out-of-bounds
-        #   assert round(v[int(math.sqrt(j)+0.5)]-j, 5) == 0.
-        for i in range(N):
-            j = v[i]
-            assert round(v[int(math.sqrt(j)+0.5)]-j, 5) == 0.
+        assert len(v) == N
+        for j in v:
+             assert round(v[int(math.sqrt(j)+0.5)]-j, 5) == 0.