pybank r78 - in trunk: . bank



Author: walters
Date: Thu Oct  2 21:27:28 2008
New Revision: 78
URL: http://svn.gnome.org/viewvc/pybank?rev=78&view=rev

Log:
Adapt for bug 552961.


Modified:
   trunk/ChangeLog
   trunk/bank/bank-info.c
   trunk/bank/btypes.py

Modified: trunk/bank/bank-info.c
==============================================================================
--- trunk/bank/bank-info.c	(original)
+++ trunk/bank/bank-info.c	Thu Oct  2 21:27:28 2008
@@ -326,6 +326,7 @@
     GArgument *in_args;
     GArgument *out_args;
     GArgument return_arg;
+    gboolean is_method;
     int n_in_args;
     int n_out_args;
     int i;
@@ -334,8 +335,13 @@
     GError *error = NULL;
     GIArgInfo *arg_info;
     PyObject *retval;
+    int flags;
+
+    flags = g_function_info_get_flags((GIFunctionInfo*)self->info);
+    is_method = (flags & GI_FUNCTION_IS_METHOD) != 0 &&
+	(flags & GI_FUNCTION_IS_CONSTRUCTOR) == 0;
     
-    n_in_args = 0;
+    n_in_args = is_method ? 1 : 0;
     n_out_args = 0;
     for (i = 0; i < g_callable_info_get_n_args((GICallableInfo*)self->info); i++) {
 	arg_info = g_callable_info_get_arg((GICallableInfo*)self->info, i);
@@ -349,12 +355,24 @@
 
     in_args = g_new0(GArgument, n_in_args);
     out_args = g_new0(GArgument, n_out_args);
+    if (is_method) {
+	py_arg = PyTuple_GetItem(args, 0);
+	if (!py_arg)
+	    return NULL;
+	if (py_arg == Py_None)
+	    in_args[0].v_pointer = NULL;
+	else
+	    in_args[0].v_pointer = PyCObject_AsVoidPtr(py_arg);
+    }
     for (i = 0; i < g_callable_info_get_n_args((GICallableInfo*)self->info); i++) {
 	arg_info = g_callable_info_get_arg((GICallableInfo*)self->info, i);
 	direction = g_arg_info_get_direction(arg_info);
+	int offset = i + (is_method ? 1 : 0);
 	if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) {
-	    py_arg = PyTuple_GetItem(args, i);
-	    in_args[i] = pyg_argument_from_pyobject(py_arg, arg_info);
+	    py_arg = PyTuple_GetItem(args, offset);
+	    if (!py_arg)
+		return NULL;
+	    in_args[offset] = pyg_argument_from_pyobject(py_arg, arg_info);
 	}
 	
 	g_base_info_unref((GIBaseInfo*)arg_info);

Modified: trunk/bank/btypes.py
==============================================================================
--- trunk/bank/btypes.py	(original)
+++ trunk/bank/btypes.py	Thu Oct  2 21:27:28 2008
@@ -49,7 +49,7 @@
     def __call__(self, *args, **kwargs):
         infoArgs = list(self.info.getArgs())
         totalInArgs = len(args) + len(kwargs)
-        requiredArgs = 0
+        requiredArgs = self.info.isMethod() and 1 or 0
         for arg in infoArgs:
             if arg.getDirection() == repo.DIRECTION_IN:
                 requiredArgs += 1
@@ -103,25 +103,28 @@
                 requiredArgs += 1
 
         obj = None
+        is_method = self.info.isMethod() and not self.info.isConstructor()
         if not self.static:
+            requiredArgs += 1
             if self.info.isConstructor():
-                requiredArgs += 1
                 obj = args[0]
                 args = args[1:]
-            elif self.info.isMethod():
+            elif is_method:
                 obj = args[0]
-                args = (obj._object,) + args[1:]
 
         if totalInArgs != requiredArgs:
             raise TypeError('%s requires %d arguments' % (
                 self.__name__, requiredArgs))
 
         inArgs = []
+        offset = is_method and 1 or 0
         for i, value in enumerate(args):
-            infoArg = infoArgs[i]
-            argType = infoArg.getType()
-            name = infoArg.getName()
-            self.type_check(name, value, argType)
+            # We'll type check later
+            if not (is_method and i == 0):
+                infoArg = infoArgs[i-offset]
+                argType = infoArg.getType()
+                name = infoArg.getName()
+                self.type_check(name, value, argType)
 
             value = getattr(value, '_object', value)
             inArgs.append(value)
@@ -143,7 +146,7 @@
         if type(retval).__name__ == 'PyCObject':
              rinfo = self.info.getReturnType()
              tag = rinfo.getTag()
-             if tag == 21:
+             if tag == repo.TYPE_TAG_INTERFACE:
                  retval = self.newType(retval)
              else:
                  raise NotImplementedError



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]