[pypy-svn] r76283 - in pypy/branch/reflex-support/pypy/module/cppyy: . include src test

wlav at codespeak.net wlav at codespeak.net
Mon Jul 19 19:56:57 CEST 2010


Author: wlav
Date: Mon Jul 19 19:56:55 2010
New Revision: 76283

Modified:
   pypy/branch/reflex-support/pypy/module/cppyy/capi.py
   pypy/branch/reflex-support/pypy/module/cppyy/converter.py
   pypy/branch/reflex-support/pypy/module/cppyy/executor.py
   pypy/branch/reflex-support/pypy/module/cppyy/include/reflexcwrapper.h
   pypy/branch/reflex-support/pypy/module/cppyy/src/reflexcwrapper.cxx
   pypy/branch/reflex-support/pypy/module/cppyy/test/test_datatypes.py
Log:
Initial converters/executors for char and unsigned char.


Modified: pypy/branch/reflex-support/pypy/module/cppyy/capi.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/capi.py	(original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/capi.py	Mon Jul 19 19:56:55 2010
@@ -49,6 +49,10 @@
     "cppyy_call_b",
     [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDPP], rffi.INT,
     compilation_info=eci)
+c_call_c = rffi.llexternal(
+    "cppyy_call_c",
+    [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDPP], rffi.CHAR,
+    compilation_info=eci)
 c_call_l = rffi.llexternal(
     "cppyy_call_l",
     [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDPP], rffi.LONG,

Modified: pypy/branch/reflex-support/pypy/module/cppyy/converter.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/converter.py	(original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/converter.py	Mon Jul 19 19:56:55 2010
@@ -31,6 +31,15 @@
         x[0] = arg
         return rffi.cast(rffi.VOIDP, x)
 
+class CharConverter(TypeConverter):
+    def convert_argument(self, space, w_obj):
+        arg = space.str_w(w_obj)
+        if len(arg) != 1:
+            raise OperationError(space.w_TypeError,
+                                 space.wrap("char expecter, got string of size %d" % len(arg)))
+        x = rffi.str2charp(arg)
+        return rffi.cast(rffi.VOIDP, x)
+
 class IntConverter(TypeConverter):
     def convert_argument(self, space, w_obj):
         arg = space.c_int_w(w_obj)
@@ -100,6 +109,8 @@
 
 
 _converters["bool"]                = BoolConverter()
+_converters["char"]                = CharConverter()
+_converters["unsigned char"]       = CharConverter()
 _converters["int"]                 = IntConverter()
 _converters["double"]              = DoubleConverter()
 _converters["const char*"]         = CStringConverter()

Modified: pypy/branch/reflex-support/pypy/module/cppyy/executor.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/executor.py	(original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/executor.py	Mon Jul 19 19:56:55 2010
@@ -20,6 +20,11 @@
         result = capi.c_call_b(func.cpptype.handle, func.method_index, cppthis, num_args, args)
         return space.wrap(result)
 
+class CharExecutor(FunctionExecutor):
+     def execute(self, space, func, cppthis, num_args, args):
+        result = capi.c_call_c(func.cpptype.handle, func.method_index, cppthis, num_args, args)
+        return space.wrap(result)
+
 class LongExecutor(FunctionExecutor):
     def execute(self, space, func, cppthis, num_args, args):
         result = capi.c_call_l(func.cpptype.handle, func.method_index, cppthis, num_args, args)
@@ -69,6 +74,8 @@
 
 _executors["void"]                = VoidExecutor()
 _executors["bool"]                = BoolExecutor()
+_executors["char"]                = CharExecutor()
+_executors["unsigned char"]       = CharExecutor()
 _executors["int"]                 = LongExecutor()
 _executors["long int"]            = LongExecutor()
 _executors["double"]              = DoubleExecutor()

Modified: pypy/branch/reflex-support/pypy/module/cppyy/include/reflexcwrapper.h
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/include/reflexcwrapper.h	(original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/include/reflexcwrapper.h	Mon Jul 19 19:56:55 2010
@@ -16,6 +16,7 @@
 
     void   cppyy_call_v(cppyy_typehandle_t handle, int method_index, cppyy_object_t self, int numargs, void* args[]);
     int    cppyy_call_b(cppyy_typehandle_t handle, int method_index, cppyy_object_t self, int numargs, void* args[]);
+    char   cppyy_call_c(cppyy_typehandle_t handle, int method_index, cppyy_object_t self, int numargs, void* args[]);
     long   cppyy_call_l(cppyy_typehandle_t handle, int method_index, cppyy_object_t self, int numargs, void* args[]);
     double cppyy_call_d(cppyy_typehandle_t handle, int method_index, cppyy_object_t self, int numargs, void* args[]);
     void cppyy_destruct(cppyy_typehandle_t handle, cppyy_object_t self);

Modified: pypy/branch/reflex-support/pypy/module/cppyy/src/reflexcwrapper.cxx
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/src/reflexcwrapper.cxx	(original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/src/reflexcwrapper.cxx	Mon Jul 19 19:56:55 2010
@@ -52,6 +52,11 @@
     return (int)cppyy_call_T<bool>(handle, method_index, self, numargs, args);
 }
 
+char cppyy_call_c(cppyy_typehandle_t handle, int method_index,
+                 cppyy_object_t self, int numargs, void* args[]) {
+   return cppyy_call_T<char>(handle, method_index, self, numargs, args);
+}
+
 long cppyy_call_l(cppyy_typehandle_t handle, int method_index,
                   cppyy_object_t self, int numargs, void* args[]) {
     return cppyy_call_T<long>(handle, method_index, self, numargs, args);
@@ -88,16 +93,16 @@
 
 int cppyy_num_methods(cppyy_typehandle_t handle) {
     Reflex::Type t((Reflex::TypeName*)handle);
-    for (int i = 0; i < (int)t.FunctionMemberSize(); i++) {
-        Reflex::Member m = t.FunctionMemberAt(i);
-        std::cout << i << " " << m.Name() << std::endl;
-        std::cout << "    " << "Stubfunction:  " << (void*)m.Stubfunction() << std::endl;
-        std::cout << "    " << "MethPtrGetter: " << (void*)get_methptr_getter(m) << std::endl;
-        for (int j = 0; j < (int)m.FunctionParameterSize(); j++) {
-            Reflex::Type at = m.TypeOf().FunctionParameterAt(j);
-            std::cout << "    " << j << " " << at.Name() << std::endl;
-        }
-    }
+    // for (int i = 0; i < (int)t.FunctionMemberSize(); i++) {
+    //     Reflex::Member m = t.FunctionMemberAt(i);
+    //     std::cout << i << " " << m.Name() << std::endl;
+    //     std::cout << "    " << "Stubfunction:  " << (void*)m.Stubfunction() << std::endl;
+    //     std::cout << "    " << "MethPtrGetter: " << (void*)get_methptr_getter(m) << std::endl;
+    //     for (int j = 0; j < (int)m.FunctionParameterSize(); j++) {
+    //         Reflex::Type at = m.TypeOf().FunctionParameterAt(j);
+    //         std::cout << "    " << j << " " << at.Name() << std::endl;
+    //     }
+    // }
     return t.FunctionMemberSize();
 }
 

Modified: pypy/branch/reflex-support/pypy/module/cppyy/test/test_datatypes.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/test/test_datatypes.py	(original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/test/test_datatypes.py	Mon Jul 19 19:56:55 2010
@@ -53,6 +53,8 @@
         """
         raises(TypeError, 'c.set_bool(10)')
 
+        c.set_char('c');   assert c.get_char()  == 'c'
+        c.set_uchar('e');  assert c.get_uchar() == 'e'
         """
         # char types
         c.m_char = 'b';    assert c.get_char()  ==     'b'
@@ -63,11 +65,13 @@
         c.m_uchar = 42;    assert c.get_uchar() == chr(42)
         c.set_uchar('e');  assert c.m_uchar     ==     'e'
         c.set_uchar(43);   assert c.m_uchar     == chr(43)
+        """
 
         raises(TypeError, 'c.set_char("string")')
-        raises(TypeError, 'c.set_uchar(-1)')
+#        raises(TypeError, 'c.set_uchar(-1)')
         raises(TypeError, 'c.set_uchar("string")')
 
+        """
         # integer types
         names = ['short', 'ushort', 'int', 'uint', 'long', 'ulong']
         for i in range(len(names)):



More information about the Pypy-commit mailing list