[Kde-bindings] playground/bindings/kimono

Richard Dale Richard_Dale at tipitina.demon.co.uk
Thu Dec 29 12:31:37 UTC 2005


SVN commit 492254 by rdale:

* Method return types for primitive values now work. The zeroth entry in the array
  of SmokeItems passed to CallMethod() is used for the reply value, which is 
  marshalled by the MethodReturnValue class from a C++ type to a C# one.
* Bug - destructors call Dispose() which then loops.

CCMAIL: kde-bindings at kde.org



 M  +38 -6     SmokeInvocation.cs  
 M  +6 -24     qt3qyoto.cpp  


--- trunk/playground/bindings/kimono/SmokeInvocation.cs #492253:492254
@@ -236,7 +236,7 @@
 								callMessage.MethodName, 
 								callMessage.TypeName, 
 								callMessage.ArgCount.ToString() );
-			
+
 			StackItem[] stack = new StackItem[callMessage.ArgCount+1];
 			
 			string mungedName = callMessage.MethodName;
@@ -261,6 +261,9 @@
 				}
 
 				methods = FindMethod(mungedName);
+				if (methods.Count == 0) {
+					return null;
+				}
 
 				for (int i = 0; i < callMessage.ArgCount; i++) {
 					if (callMessage.Args[i] == null) {
@@ -309,12 +312,43 @@
 			}
 			
 			GCHandle instanceHandle = GCHandle.Alloc(_instance);
+			IMethodReturnMessage returnMessage = (IMethodReturnMessage) message;
+			MethodReturnMessageWrapper returnValue = new MethodReturnMessageWrapper((IMethodReturnMessage) returnMessage); 
 			
 			unsafe {
 				fixed(StackItem * stackPtr = stack) {
 					CallMethod((int) methods[0], (IntPtr) instanceHandle, (IntPtr) stackPtr, callMessage.ArgCount);
-					Console.WriteLine("returned from CallMethod");
-//					Console.WriteLine("result {0}", stack[0].s_int);
+					Type returnType = ((MethodInfo) returnMessage.MethodBase).ReturnType;
+					Console.WriteLine("returned from CallMethod returnType: {0}", returnType);
+					
+					if (returnType == typeof(void)) {
+						;
+					} else if (returnType == typeof(bool)) {
+						returnValue.ReturnValue = stack[0].s_bool;
+					} else if (returnType == typeof(sbyte)) {
+						returnValue.ReturnValue = stack[0].s_char;
+					} else if (returnType == typeof(byte)) {
+						returnValue.ReturnValue = stack[0].s_uchar;
+					} else if (returnType == typeof(short)) {
+						returnValue.ReturnValue = stack[0].s_short;
+					} else if (returnType == typeof(ushort)) {
+						returnValue.ReturnValue = stack[0].s_ushort;
+					} else if (returnType == typeof(int)) {
+						returnValue.ReturnValue = stack[0].s_int;
+					} else if (returnType == typeof(uint)) {
+						returnValue.ReturnValue = stack[0].s_uint;
+					} else if (returnType == typeof(long)) {
+						returnValue.ReturnValue = stack[0].s_long;
+					} else if (returnType == typeof(ulong)) {
+						returnValue.ReturnValue = stack[0].s_ulong;
+					} else if (returnType == typeof(float)) {
+						returnValue.ReturnValue = stack[0].s_float;
+					} else if (returnType == typeof(double)) {
+						returnValue.ReturnValue = stack[0].s_double;
+					} else {
+//						stack[0].s_intptr = (IntPtr) GCHandle.Alloc(callMessage.Args[i]);
+//					} else if (returnType == typeof(string[])) {
+					}
 				}
 			}
 			
@@ -327,7 +361,6 @@
 //									stackItem[1].s_int );
 			}
 			
-			IMethodReturnMessage returnMessage = (IMethodReturnMessage) message;
 			
 			/*
 			if (returnMessage.MethodName.Equals("PointSize")) {
@@ -337,8 +370,7 @@
 			}
 			*/
 
-			MethodReturnMessageWrapper returnValue = new MethodReturnMessageWrapper((IMethodReturnMessage) returnMessage); 
-			returnValue.ReturnValue = null;
+//			returnValue.ReturnValue = null;
 			returnMessage = returnValue;
 
 			return returnMessage;
--- trunk/playground/bindings/kimono/qt3qyoto.cpp #492253:492254
@@ -166,14 +166,12 @@
 class MethodReturnValue : public Marshall {
     Smoke *_smoke;
     Smoke::Index _method;
-    Smoke::StackItem & _retval;
+    Smoke::StackItem * _retval;
     Smoke::Stack _stack;
 public:
-	MethodReturnValue(Smoke *smoke, Smoke::Index method, Smoke::Stack stack, Smoke::StackItem & retval) :
+	MethodReturnValue(Smoke *smoke, Smoke::Index method, Smoke::Stack stack, Smoke::StackItem * retval) :
 		_smoke(smoke), _method(method), _retval(retval), _stack(stack) {
-printf("In MethodReturnValue(), type: %s _stack[0] %p\n", type().name(), _stack[0]);
 		Marshall::HandlerFn fn = getMarshallFn(type());
-printf("In MethodReturnValue(), about to call return value marshaller\n");
 		(*fn)(this);
     }
 
@@ -182,7 +180,7 @@
     Marshall::Action action() { return Marshall::ToObject; }
     Smoke::StackItem &item() { return _stack[0]; }
     Smoke::StackItem &var() {
-    	return _retval;
+    	return *_retval;
     }
     void unsupported() {
 //	rb_raise(rb_eArgError, "Cannot handle '%s' as return-type of %s::%s",
@@ -206,7 +204,7 @@
 	Smoke::Index _current_object_class;
     Smoke::Stack _sp;
     int _items;
-    Smoke::StackItem _retval;
+    Smoke::StackItem * _retval;
     bool _called;
 public:
     MethodCall(Smoke *smoke, Smoke::Index method, void * target, Smoke::Stack sp, int items) :
@@ -224,7 +222,7 @@
 	_args = _smoke->argumentList + _smoke->methods[_method].args;
 	_items = _smoke->methods[_method].numArgs;
 	_stack = new Smoke::StackItem[items + 1];
-//	_retval = 0;
+	_retval = _sp;
     }
 
     ~MethodCall() {
@@ -243,7 +241,7 @@
     }
 
     Smoke::StackItem &var() {
-	if(_cur < 0) return _retval;
+	if(_cur < 0) return *_retval;
 	return _sp[_cur + 1];
     }
 
@@ -426,24 +424,8 @@
 CallMethod(int methodId, void * obj, Smoke::StackItem * sp, int items)
 {
 	printf("In CallMethod methodId: %d target: 0x%8.8x items: %d\n", methodId, obj, items);
-	printf("In CallMethod %d\n", sp[1].s_int);
-/*
-	smokeqyoto_object  * o = (smokeqyoto_object *) malloc(sizeof(smokeqyoto_object));
-	o->smoke = qt_Smoke;
-	o->classId = 123;
-	o->ptr = 0;
-	o->allocated = false;
-	(*SetSmokeObject)(obj, o);
-
-	smokeqyoto_object * optr = (smokeqyoto_object *) (*GetSmokeObject)(obj);
-	if (optr != 0) {
-		printf("In CallMethod classId: %d\n", optr->classId);
-	}
-*/
 	MethodCall c(qt_Smoke, methodId, obj, sp, items);
 	c.next();
-	
-//	sp[0].s_int = 0;
 	return;
 }
 



More information about the Kde-bindings mailing list