[pypy-commit] pypy reflex-support: unlike for stubs (for which a value type is used), libffi requires a pointer type for const builtin&

wlav noreply at buildbot.pypy.org
Fri Apr 13 05:43:25 CEST 2012


Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r54321:86397c9e6d24
Date: 2012-04-12 11:52 -0700
http://bitbucket.org/pypy/pypy/changeset/86397c9e6d24/

Log:	unlike for stubs (for which a value type is used), libffi requires a
	pointer type for const builtin&

diff --git a/pypy/module/cppyy/converter.py b/pypy/module/cppyy/converter.py
--- a/pypy/module/cppyy/converter.py
+++ b/pypy/module/cppyy/converter.py
@@ -275,6 +275,10 @@
     def _unwrap_object(self, space, w_obj):
         return rffi.cast(rffi.SHORT, space.int_w(w_obj))
 
+class ConstShortRefConverter(ShortConverter):
+    _immutable_ = True
+    libffitype = lltype.nullptr(clibffi.FFI_TYPE_P.TO)
+
 class UnsignedShortConverter(IntTypeConverterMixin, TypeConverter):
     _immutable_ = True
     libffitype = libffi.types.sshort
@@ -286,6 +290,10 @@
     def _unwrap_object(self, space, w_obj):
         return rffi.cast(rffi.USHORT, space.int_w(w_obj))
 
+class ConstUnsignedShortRefConverter(UnsignedShortConverter):
+    _immutable_ = True
+    libffitype = lltype.nullptr(clibffi.FFI_TYPE_P.TO)
+
 class IntConverter(IntTypeConverterMixin, TypeConverter):
     _immutable_ = True
     libffitype = libffi.types.sint
@@ -297,6 +305,10 @@
     def _unwrap_object(self, space, w_obj):
         return rffi.cast(rffi.INT, space.c_int_w(w_obj))
 
+class ConstIntRefConverter(IntConverter):
+    _immutable_ = True
+    libffitype = lltype.nullptr(clibffi.FFI_TYPE_P.TO)
+
 class UnsignedIntConverter(IntTypeConverterMixin, TypeConverter):
     _immutable_ = True
     libffitype = libffi.types.uint
@@ -308,6 +320,10 @@
     def _unwrap_object(self, space, w_obj):
         return rffi.cast(rffi.UINT, space.uint_w(w_obj))
 
+class ConstUnsignedIntRefConverter(UnsignedIntConverter):
+    _immutable_ = True
+    libffitype = lltype.nullptr(clibffi.FFI_TYPE_P.TO)
+
 class LongConverter(IntTypeConverterMixin, TypeConverter):
     _immutable_ = True
     libffitype = libffi.types.slong
@@ -319,6 +335,10 @@
     def _unwrap_object(self, space, w_obj):
         return space.int_w(w_obj)
 
+class ConstLongRefConverter(LongConverter):
+    _immutable_ = True
+    libffitype = lltype.nullptr(clibffi.FFI_TYPE_P.TO)
+
 class UnsignedLongConverter(IntTypeConverterMixin, TypeConverter):
     _immutable_ = True
     libffitype = libffi.types.ulong
@@ -330,6 +350,9 @@
     def _unwrap_object(self, space, w_obj):
         return space.uint_w(w_obj)
 
+class ConstUnsignedLongRefConverter(UnsignedLongConverter):
+    _immutable_ = True
+    libffitype = lltype.nullptr(clibffi.FFI_TYPE_P.TO)
 
 class FloatConverter(FloatTypeConverterMixin, TypeConverter):
     _immutable_ = True
@@ -352,6 +375,10 @@
         rffiptr = rffi.cast(self.rffiptype, address)
         return space.wrap(float(rffiptr[0]))
 
+class ConstFloatRefConverter(FloatConverter):
+    _immutable_ = True
+    libffitype = lltype.nullptr(clibffi.FFI_TYPE_P.TO)
+
 class DoubleConverter(FloatTypeConverterMixin, TypeConverter):
     _immutable_ = True
     libffitype = libffi.types.double
@@ -367,6 +394,10 @@
     def _unwrap_object(self, space, w_obj):
         return space.float_w(w_obj)
 
+class ConstDoubleRefConverter(DoubleConverter):
+    _immutable_ = True
+    libffitype = lltype.nullptr(clibffi.FFI_TYPE_P.TO)
+
 
 class CStringConverter(TypeConverter):
     _immutable_ = True
@@ -593,10 +624,10 @@
     #   1) full, exact match
     #       1a) const-removed match
     #   2) match of decorated, unqualified type
-    #   3) accept const ref as by value
-    #   4) accept ref as pointer
-    #   5) generalized cases (covers basically all user classes)
-    #   6) void converter, which fails on use
+    #   3) accept ref as pointer (for the stubs, const& can be
+    #       by value, but that does not work for the ffi path)
+    #   4) generalized cases (covers basically all user classes)
+    #   5) void converter, which fails on use
 
     name = capi.c_resolve_name(name)
 
@@ -622,14 +653,9 @@
     except KeyError:
         pass
 
-    #   3) accept const ref as by value
-    if compound and compound[len(compound)-1] == "&":
-        try:
-            return _converters[clean_name](space, default)
-        except KeyError:
-            pass
+    #   3) TODO: accept ref as pointer
 
-    #   5) generalized cases (covers basically all user classes)
+    #   4) generalized cases (covers basically all user classes)
     from pypy.module.cppyy import interp_cppyy
     cppclass = interp_cppyy.scope_byname(space, clean_name)
     if cppclass:
@@ -643,7 +669,7 @@
     elif capi.c_is_enum(clean_name):
         return UnsignedIntConverter(space, default)
     
-    #   6) void converter, which fails on use
+    #   5) void converter, which fails on use
     #
     # return a void converter here, so that the class can be build even
     # when some types are unknown; this overload will simply fail on use
@@ -654,17 +680,29 @@
 _converters["char"]                     = CharConverter
 _converters["unsigned char"]            = CharConverter
 _converters["short int"]                = ShortConverter
+_converters["const short int&"]         = ConstIntRefConverter
 _converters["short"]                    = _converters["short int"]
+_converters["const short&"]             = _converters["const short int&"]
 _converters["unsigned short int"]       = UnsignedShortConverter
+_converters["const unsigned short int&"] = ConstUnsignedShortRefConverter
 _converters["unsigned short"]           = _converters["unsigned short int"]
+_converters["const unsigned short&"]    = _converters["const unsigned short int&"]
 _converters["int"]                      = IntConverter
+_converters["const int&"]               = ConstIntRefConverter
 _converters["unsigned int"]             = UnsignedIntConverter
+_converters["const unsigned int&"]      = ConstUnsignedIntRefConverter
 _converters["long int"]                 = LongConverter
+_converters["const long int&"]          = ConstLongRefConverter
 _converters["long"]                     = _converters["long int"]
+_converters["const long&"]              = _converters["const long int&"]
 _converters["unsigned long int"]        = UnsignedLongConverter
+_converters["const unsigned long int&"] = ConstUnsignedLongRefConverter
 _converters["unsigned long"]            = _converters["unsigned long int"]
+_converters["const unsigned long&"]     = _converters["const unsigned long int&"]
 _converters["float"]                    = FloatConverter
+_converters["const float&"]             = ConstFloatRefConverter
 _converters["double"]                   = DoubleConverter
+_converters["const double&"]            = ConstDoubleRefConverter
 _converters["const char*"]              = CStringConverter
 _converters["char*"]                    = CStringConverter
 _converters["void*"]                    = VoidPtrConverter
diff --git a/pypy/module/cppyy/genreflex-methptrgetter.patch b/pypy/module/cppyy/genreflex-methptrgetter.patch
--- a/pypy/module/cppyy/genreflex-methptrgetter.patch
+++ b/pypy/module/cppyy/genreflex-methptrgetter.patch
@@ -1,6 +1,6 @@
 Index: cint/reflex/python/genreflex/gendict.py
 ===================================================================
---- cint/reflex/python/genreflex/gendict.py	(revision 40448)
+--- cint/reflex/python/genreflex/gendict.py	(revision 43705)
 +++ cint/reflex/python/genreflex/gendict.py	(working copy)
 @@ -52,6 +52,7 @@
      self.typedefs_for_usr = []
@@ -10,7 +10,7 @@
      # The next is to avoid a known problem with gccxml that it generates a
      # references to id equal '_0' which is not defined anywhere
      self.xref['_0'] = {'elem':'Unknown', 'attrs':{'id':'_0','name':''}, 'subelems':[]}
-@@ -1281,6 +1282,8 @@
+@@ -1306,6 +1307,8 @@
      bases = self.getBases( attrs['id'] )
      if inner and attrs.has_key('demangled') and self.isUnnamedType(attrs['demangled']) :
        cls = attrs['demangled']
@@ -19,7 +19,7 @@
        clt = ''
      else:
        cls = self.genTypeName(attrs['id'],const=True,colon=True)
-@@ -1318,7 +1321,7 @@
+@@ -1343,7 +1346,7 @@
        # Inner class/struct/union/enum.
        for m in memList :
          member = self.xref[m]
@@ -28,7 +28,7 @@
             and member['attrs'].get('access') in ('private','protected') \
             and not self.isUnnamedType(member['attrs'].get('demangled')):
            cmem = self.genTypeName(member['attrs']['id'],const=True,colon=True)
-@@ -1956,8 +1959,15 @@
+@@ -1981,8 +1984,15 @@
      else    : params  = '0'
      s = '  .AddFunctionMember(%s, Reflex::Literal("%s"), %s%s, 0, %s, %s)' % (self.genTypeID(id), name, type, id, params, mod)
      s += self.genCommentProperty(attrs)
@@ -44,7 +44,7 @@
    def genMCODef(self, type, name, attrs, args):
      id       = attrs['id']
      cl       = self.genTypeName(attrs['context'],colon=True)
-@@ -2024,8 +2034,44 @@
+@@ -2049,8 +2059,44 @@
            if returns == 'void' : body += '  }\n'
            else :                 body += '  }\n'
      body += '}\n'
@@ -92,7 +92,7 @@
      for a in args :
 Index: cint/reflex/python/genreflex/genreflex.py
 ===================================================================
---- cint/reflex/python/genreflex/genreflex.py	(revision 40448)
+--- cint/reflex/python/genreflex/genreflex.py	(revision 43705)
 +++ cint/reflex/python/genreflex/genreflex.py	(working copy)
 @@ -108,6 +108,10 @@
           Print extra debug information while processing. Keep intermediate files\n
diff --git a/pypy/module/cppyy/test/Makefile b/pypy/module/cppyy/test/Makefile
--- a/pypy/module/cppyy/test/Makefile
+++ b/pypy/module/cppyy/test/Makefile
@@ -46,17 +46,9 @@
 
 ifeq ($(CINT),)
 # TODO: methptrgetter causes these tests to crash, so don't use it for now
-#stltypesDict.so: stltypes.cxx stltypes.h stltypes.xml
-#	$(genreflex) stltypes.h --selection=stltypes.xml
-#	g++ -o $@ stltypes_rflx.cpp stltypes.cxx -shared -lReflex $(cppflags) $(cppflags2)
-
 std_streamsDict.so: std_streams.cxx std_streams.h std_streams.xml
 	$(genreflex) std_streams.h --selection=std_streams.xml
 	g++ -o $@ std_streams_rflx.cpp std_streams.cxx -shared -lReflex $(cppflags) $(cppflags2)
-
-operatorsDict.so: operators.cxx operators.h operators.xml
-	$(genreflex) operators.h --selection=operators.xml
-	g++ -o $@ operators_rflx.cpp operators.cxx -shared -lReflex $(cppflags) $(cppflags2)
 endif
 
 .PHONY: clean
diff --git a/pypy/module/cppyy/test/datatypes.cxx b/pypy/module/cppyy/test/datatypes.cxx
--- a/pypy/module/cppyy/test/datatypes.cxx
+++ b/pypy/module/cppyy/test/datatypes.cxx
@@ -114,18 +114,26 @@
 cppyy_test_pod*& cppyy_test_data::get_pod_ptrref() { return m_ppod; }
 
 //- setters -----------------------------------------------------------------
-void cppyy_test_data::set_bool(bool b)              { m_bool   = b; }
-void cppyy_test_data::set_char(char c)              { m_char   = c; }
-void cppyy_test_data::set_uchar(unsigned char uc)   { m_uchar  = uc; }
-void cppyy_test_data::set_short(short s)            { m_short  = s; }
-void cppyy_test_data::set_ushort(unsigned short us) { m_ushort = us; }
-void cppyy_test_data::set_int(int i)                { m_int    = i; }
-void cppyy_test_data::set_uint(unsigned int ui)     { m_uint   = ui; }
-void cppyy_test_data::set_long(long l)              { m_long   = l; }
-void cppyy_test_data::set_ulong(unsigned long ul)   { m_ulong  = ul; }
-void cppyy_test_data::set_float(float f)            { m_float  = f; }
-void cppyy_test_data::set_double(double d)          { m_double = d; }
-void cppyy_test_data::set_enum(what w)              { m_enum   = w; }
+void cppyy_test_data::set_bool(bool b)                       { m_bool   = b; }
+void cppyy_test_data::set_char(char c)                       { m_char   = c; }
+void cppyy_test_data::set_uchar(unsigned char uc)            { m_uchar  = uc; }
+void cppyy_test_data::set_short(short s)                     { m_short  = s; }
+void cppyy_test_data::set_short_c(const short& s)            { m_short  = s; }
+void cppyy_test_data::set_ushort(unsigned short us)          { m_ushort = us; }
+void cppyy_test_data::set_ushort_c(const unsigned short& us) { m_ushort = us; }
+void cppyy_test_data::set_int(int i)                         { m_int    = i; }
+void cppyy_test_data::set_int_c(const int& i)                { m_int    = i; }
+void cppyy_test_data::set_uint(unsigned int ui)              { m_uint   = ui; }
+void cppyy_test_data::set_uint_c(const unsigned int& ui)     { m_uint   = ui; }
+void cppyy_test_data::set_long(long l)                       { m_long   = l; }
+void cppyy_test_data::set_long_c(const long& l)              { m_long   = l; }
+void cppyy_test_data::set_ulong(unsigned long ul)            { m_ulong  = ul; }
+void cppyy_test_data::set_ulong_c(const unsigned long& ul)   { m_ulong  = ul; }
+void cppyy_test_data::set_float(float f)                     { m_float  = f; }
+void cppyy_test_data::set_float_c(const float& f)            { m_float  = f; }
+void cppyy_test_data::set_double(double d)                   { m_double = d; }
+void cppyy_test_data::set_double_c(const double& d)          { m_double = d; }
+void cppyy_test_data::set_enum(what w)                       { m_enum   = w; }
 
 char           cppyy_test_data::s_char   = 's';
 unsigned char  cppyy_test_data::s_uchar  = 'u';
diff --git a/pypy/module/cppyy/test/datatypes.h b/pypy/module/cppyy/test/datatypes.h
--- a/pypy/module/cppyy/test/datatypes.h
+++ b/pypy/module/cppyy/test/datatypes.h
@@ -62,13 +62,21 @@
     void set_char(char c);
     void set_uchar(unsigned char uc);
     void set_short(short s);
+    void set_short_c(const short& s);
     void set_ushort(unsigned short us);
+    void set_ushort_c(const unsigned short& us);
     void set_int(int i);
+    void set_int_c(const int& i);
     void set_uint(unsigned int ui);
+    void set_uint_c(const unsigned int& ui);
     void set_long(long l);
+    void set_long_c(const long& l);
     void set_ulong(unsigned long ul);
+    void set_ulong_c(const unsigned long& ul);
     void set_float(float f);
+    void set_float_c(const float& f);
     void set_double(double d);
+    void set_double_c(const double& d);
     void set_enum(what w);
 
 public:
diff --git a/pypy/module/cppyy/test/test_datatypes.py b/pypy/module/cppyy/test/test_datatypes.py
--- a/pypy/module/cppyy/test/test_datatypes.py
+++ b/pypy/module/cppyy/test/test_datatypes.py
@@ -152,8 +152,12 @@
             assert eval('c.get_%s()' % names[i]) == i
 
         for i in range(len(names)):
-            exec 'c.set_%s = %d' % (names[i],2*i)
-            assert eval('c.m_%s' % names[i]) == i
+            exec 'c.set_%s(%d)' % (names[i],2*i)
+            assert eval('c.m_%s' % names[i]) == 2*i
+
+        for i in range(len(names)):
+            exec 'c.set_%s_c(%d)' % (names[i],3*i)
+            assert eval('c.m_%s' % names[i]) == 3*i
 
         # float types through functions
         c.set_float( 0.123 );  assert round(c.get_float()  - 0.123, 5) == 0
@@ -161,9 +165,11 @@
 
         # float types through data members
         c.m_float = 0.123;     assert round(c.get_float()  - 0.123, 5) == 0
-        c.set_float( 0.234 );  assert round(c.m_float      - 0.234, 5) == 0
-        c.m_double = 0.456;    assert round(c.get_double() - 0.456, 8) == 0
-        c.set_double( 0.567 ); assert round(c.m_double     - 0.567, 8) == 0
+        c.set_float(0.234);    assert round(c.m_float      - 0.234, 5) == 0
+        c.set_float_c(0.456);  assert round(c.m_float      - 0.456, 5) == 0
+        c.m_double = 0.678;    assert round(c.get_double() - 0.678, 8) == 0
+        c.set_double(0.890);   assert round(c.m_double     - 0.890, 8) == 0
+        c.set_double_c(0.012); assert round(c.m_double     - 0.012, 8) == 0
 
         # arrays; there will be pointer copies, so destroy the current ones
         c.destroy_arrays()


More information about the pypy-commit mailing list