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

antocuni at codespeak.net antocuni at codespeak.net
Thu Jul 8 17:08:23 CEST 2010


Author: antocuni
Date: Thu Jul  8 17:08:22 2010
New Revision: 76036

Modified:
   pypy/branch/reflex-support/pypy/module/cppyy/capi.py
   pypy/branch/reflex-support/pypy/module/cppyy/include/reflexcwrapper.h
   pypy/branch/reflex-support/pypy/module/cppyy/src/reflexcwrapper.cxx
Log:
introduce two new types, cppyy_typehandle_t and cppyy_object_t, which are just
void* but make the code a bit easier to understand



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	Thu Jul  8 17:08:22 2010
@@ -22,67 +22,70 @@
     use_cpp_linker=True,
 )
 
-C_METHPTRGETTER = lltype.FuncType([rffi.VOIDP], rffi.VOIDP)
+C_TYPEHANDLE = rffi.VOIDP
+C_OBJECT = rffi.VOIDP
+
+C_METHPTRGETTER = lltype.FuncType([C_OBJECT], rffi.VOIDP)
 C_METHPTRGETTER_PTR = lltype.Ptr(C_METHPTRGETTER)
 
 c_cppyy_get_typehandle = rffi.llexternal(
     "cppyy_get_typehandle",
-    [rffi.CCHARP], rffi.VOIDP,
+    [rffi.CCHARP], C_TYPEHANDLE,
     compilation_info=eci)
 
 c_callstatic_l = rffi.llexternal(
     "callstatic_l",
-    [rffi.VOIDP, rffi.INT, rffi.INT, rffi.VOIDPP], rffi.LONG,
+    [C_TYPEHANDLE, rffi.INT, rffi.INT, rffi.VOIDPP], rffi.LONG,
     compilation_info=eci)
 c_cppyy_construct = rffi.llexternal(
     "cppyy_construct",
-    [rffi.VOIDP, rffi.INT, rffi.VOIDPP], rffi.VOIDP,
+    [C_TYPEHANDLE, rffi.INT, rffi.VOIDPP], C_OBJECT,
     compilation_info=eci)
 c_cppyy_call_l = rffi.llexternal(
     "cppyy_call_l",
-    [rffi.VOIDP, rffi.INT, rffi.VOIDP, rffi.INT, rffi.VOIDPP], rffi.LONG,
+    [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDPP], rffi.LONG,
     compilation_info=eci)
 c_cppyy_call_d = rffi.llexternal(
     "cppyy_call_d",
-    [rffi.VOIDP, rffi.INT, rffi.VOIDP, rffi.INT, rffi.VOIDPP], rffi.DOUBLE,
+    [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDPP], rffi.DOUBLE,
     compilation_info=eci)
 c_cppyy_destruct = rffi.llexternal(
     "cppyy_destruct",
-    [rffi.VOIDP, rffi.VOIDP], lltype.Void,
+    [C_TYPEHANDLE, C_OBJECT], lltype.Void,
     compilation_info=eci)
 c_cppyy_get_methptr_getter = rffi.llexternal(
     "cppyy_get_methptr_getter",
-    [rffi.VOIDP, rffi.INT], C_METHPTRGETTER_PTR,
+    [C_TYPEHANDLE, rffi.INT], C_METHPTRGETTER_PTR,
     compilation_info=eci)
 
 
 c_num_methods = rffi.llexternal(
     "num_methods",
-    [rffi.VOIDP], rffi.INT,
+    [C_TYPEHANDLE], rffi.INT,
     compilation_info=eci)
 c_method_name = rffi.llexternal(
     "method_name",
-    [rffi.VOIDP, rffi.INT], rffi.CCHARP,
+    [C_TYPEHANDLE, rffi.INT], rffi.CCHARP,
     compilation_info=eci)
 c_result_type_method = rffi.llexternal(
     "result_type_method",
-    [rffi.VOIDP, rffi.INT], rffi.CCHARP,
+    [C_TYPEHANDLE, rffi.INT], rffi.CCHARP,
     compilation_info=eci)
 c_num_args_method = rffi.llexternal(
     "num_args_method",
-    [rffi.VOIDP, rffi.INT], rffi.INT,
+    [C_TYPEHANDLE, rffi.INT], rffi.INT,
     compilation_info=eci)
 c_arg_type_method = rffi.llexternal(
     "arg_type_method",
-    [rffi.VOIDP, rffi.INT, rffi.INT], rffi.CCHARP,
+    [C_TYPEHANDLE, rffi.INT, rffi.INT], rffi.CCHARP,
     compilation_info=eci)
 c_is_constructor = rffi.llexternal(
     "is_constructor",
-    [rffi.VOIDP, rffi.INT], rffi.INT,
+    [C_TYPEHANDLE, rffi.INT], rffi.INT,
     compilation_info=eci)
 c_is_static = rffi.llexternal(
     "is_static",
-    [rffi.VOIDP, rffi.INT], rffi.INT,
+    [C_TYPEHANDLE, rffi.INT], rffi.INT,
     compilation_info=eci)
 c_myfree = rffi.llexternal(
     "myfree",

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	Thu Jul  8 17:08:22 2010
@@ -5,25 +5,28 @@
 #ifdef __cplusplus
 extern "C" {
 #endif // ifdef __cplusplus
-    typedef void* (*cppyy_methptrgetter_t)(void*);
+    typedef void* cppyy_typehandle_t;
+    typedef void* cppyy_object_t;
+    typedef void* (*cppyy_methptrgetter_t)(cppyy_object_t);
 
-    void* cppyy_get_typehandle(const char* class_name);
+    cppyy_typehandle_t cppyy_get_typehandle(const char* class_name);
 
-    void* cppyy_construct(void* handle, int numargs, void* args[]);
-    long cppyy_call_l(void* handle, int method_index, void* self, int numargs, void* args[]);
-    double cppyy_call_d(void* handle, int method_index, void* self, int numargs, void* args[]);
-    void cppyy_destruct(void* handle, void* self);
-    cppyy_methptrgetter_t cppyy_get_methptr_getter(void* handle, int method_index);
-
-    int num_methods(void* handle);
-    char* method_name(void* handle, int method_index);
-    char* result_type_method(void* handle, int method_index);
-    int num_args_method(void* handle, int method_index);
-    char* arg_type_method(void* handle, int method_index, int index);
-    int is_constructor(void* handle, int method_index);
-    int is_static(void* handle, int method_index);
+    cppyy_object_t cppyy_construct(cppyy_typehandle_t handle, 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);
+    cppyy_methptrgetter_t cppyy_get_methptr_getter(cppyy_typehandle_t handle, int method_index);
+
+    int num_methods(cppyy_typehandle_t handle);
+    char* method_name(cppyy_typehandle_t handle, int method_index);
+    char* result_type_method(cppyy_typehandle_t handle, int method_index);
+    int num_args_method(cppyy_typehandle_t handle, int method_index);
+    char* arg_type_method(cppyy_typehandle_t handle, int method_index, int index);
+    int is_constructor(cppyy_typehandle_t handle, int method_index);
+    int is_static(cppyy_typehandle_t handle, int method_index);
 
     void myfree(void* ptr);
+
 #ifdef __cplusplus
 }
 #endif // ifdef __cplusplus

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	Thu Jul  8 17:08:22 2010
@@ -4,12 +4,12 @@
 #include <iostream>
 
 
-void* cppyy_get_typehandle(const char* class_name) {
+cppyy_typehandle_t cppyy_get_typehandle(const char* class_name) {
    return Reflex::Type::ByName(class_name).Id();
 }
 
 
-void* cppyy_construct(void* handle, int numargs, void* args[]) {
+cppyy_object_t cppyy_construct(cppyy_typehandle_t handle, int numargs, void* args[]) {
     std::vector<void*> arguments(args, args+numargs);
     Reflex::Type t((Reflex::TypeName*)handle);
     std::vector<Reflex::Type> argtypes;
@@ -22,8 +22,8 @@
     return t.Construct(constructor_type, arguments).Address();
 }
 
-long cppyy_call_l(void* handle, int method_index,
-	          void* self, int numargs, void* args[]) {
+long cppyy_call_l(cppyy_typehandle_t handle, int method_index,
+                  cppyy_object_t self, int numargs, void* args[]) {
     long result;
     std::vector<void*> arguments(args, args+numargs);
     Reflex::Type t((Reflex::TypeName*)handle);
@@ -37,8 +37,8 @@
     return result;
 }
 
-double cppyy_call_d(void* handle, int method_index,
-                    void* self, int numargs, void* args[]) {
+double cppyy_call_d(cppyy_typehandle_t handle, int method_index,
+                    cppyy_object_t self, int numargs, void* args[]) {
     double result;
     std::vector<void*> arguments(args, args+numargs);
     Reflex::Type t((Reflex::TypeName*)handle);
@@ -52,7 +52,7 @@
     return result;
 }   
 
-void cppyy_destruct(void* handle, void* self) {
+void cppyy_destruct(cppyy_typehandle_t handle, cppyy_object_t self) {
     Reflex::Type t((Reflex::TypeName*)handle);
     t.Destruct(self, true);
 }
@@ -68,7 +68,7 @@
     return 0;
 }
 
-cppyy_methptrgetter_t cppyy_get_methptr_getter(void* handle, int method_index)
+cppyy_methptrgetter_t cppyy_get_methptr_getter(cppyy_typehandle_t handle, int method_index)
 {
     Reflex::Type t((Reflex::TypeName*)handle);
     Reflex::Member m = t.FunctionMemberAt(method_index);
@@ -76,7 +76,7 @@
 }
 
 
-int num_methods(void* handle) {
+int 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);
@@ -91,7 +91,7 @@
     return t.FunctionMemberSize();
 }
 
-char* method_name(void* handle, int method_index) {
+char* method_name(cppyy_typehandle_t handle, int method_index) {
     Reflex::Type t((Reflex::TypeName*)handle);
     Reflex::Member m = t.FunctionMemberAt(method_index);
     std::string name = m.Name();
@@ -100,7 +100,7 @@
     return name_char;
 }
 
-char* result_type_method(void* handle, int method_index) {
+char* result_type_method(cppyy_typehandle_t handle, int method_index) {
     Reflex::Type t((Reflex::TypeName*)handle);
     Reflex::Member m = t.FunctionMemberAt(method_index);
     Reflex::Type rt = m.TypeOf().ReturnType();
@@ -110,13 +110,13 @@
     return name_char;
 }
 
-int num_args_method(void* handle, int method_index) {
+int num_args_method(cppyy_typehandle_t handle, int method_index) {
     Reflex::Type t((Reflex::TypeName*)handle);
     Reflex::Member m = t.FunctionMemberAt(method_index);
     return m.FunctionParameterSize();
 }
 
-char* arg_type_method(void* handle, int method_index, int arg_index) {
+char* arg_type_method(cppyy_typehandle_t handle, int method_index, int arg_index) {
 
     Reflex::Type t((Reflex::TypeName*)handle);
     Reflex::Member m = t.FunctionMemberAt(method_index);
@@ -127,13 +127,13 @@
     return name_char;
 }
 
-int is_constructor(void* handle, int method_index) {
+int is_constructor(cppyy_typehandle_t handle, int method_index) {
     Reflex::Type t((Reflex::TypeName*)handle);
     Reflex::Member m = t.FunctionMemberAt(method_index);
     return m.IsConstructor();
 }
 
-int is_static(void* handle, int method_index) {
+int is_static(cppyy_typehandle_t handle, int method_index) {
     Reflex::Type t((Reflex::TypeName*)handle);
     Reflex::Member m = t.FunctionMemberAt(method_index);
     return m.IsStatic();



More information about the Pypy-commit mailing list