[Kde-bindings] playground/bindings/kimono
Richard Dale
Richard_Dale at tipitina.demon.co.uk
Sun Oct 15 16:39:13 UTC 2006
SVN commit 595784 by rdale:
* When there was more than one possible candidate for a method in the
Smoke library, the SmokeInvocation code was just choosing the first one
it found. Added some code to select the one that matched the SmokeMethod()
type signature annotation. Fixes problem reported by Arno Rehn.
CCMAIL: kde-bindings at kde.org
M +7 -0 ChangeLog
M +22 -26 SmokeInvocation.cs
M +34 -9 qyoto.cpp
--- trunk/playground/bindings/kimono/ChangeLog #595783:595784
@@ -1,3 +1,10 @@
+2006-10-15 Richard Dale <rdale at foton.es>
+
+ * When there was more than one possible candidate for a method in the
+ Smoke library, the SmokeInvocation code was just choosing the first one
+ it found. Added some code to select the one that matched the SmokeMethod()
+ type signature annotation. Fixes problem reported by Arno Rehn.
+
2006-10-06 Arno Rehn <arno at arnorehn.de>
* Fixed some problems with enums in uics.
--- trunk/playground/bindings/kimono/SmokeInvocation.cs #595783:595784
@@ -57,7 +57,7 @@
static extern int MethodFromMap(int methodId);
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
- static extern int FindAmbiguousMethodId(int ambigousId);
+ static extern int FindAmbiguousMethodId(int ambigousId, string signature);
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
static extern void CallSmokeMethod(int methodId, IntPtr target, IntPtr sp, int items);
@@ -585,9 +585,7 @@
}
}
- public ArrayList FindMethod(string name) {
- ArrayList result = new ArrayList();
-
+ public int FindMethod(string name, MethodInfo methodInfo) {
// Console.WriteLine("FindMethod() className: {0} MethodName: {1}", _className, name);
int meth = FindMethodId(_className, name);
if (meth == 0) {
@@ -595,33 +593,31 @@
}
if (meth == 0) {
- return result;
+ return -1;
} else if (meth > 0) {
int i = MethodFromMap(meth);
// Console.WriteLine("FindMethod() MethodName: {0} result: {1}", name, i);
if (i == 0) { // shouldn't happen
- ;
+ return -1;
} else if (i > 0) { // single match
- result.Add(i);
+ return i;
// Console.WriteLine("FindMethod() single match {0}", i);
} else { // multiple match
i = -i; // turn into ambiguousMethodList index
int methodId;
- while ((methodId = FindAmbiguousMethodId(i)) != 0) {
- if (methodId > 0) {
- result.Add(methodId);
- }
- i++;
+ string signature = "";
+ object[] smokeMethod = methodInfo.GetCustomAttributes(typeof(SmokeMethod), false);
+ if (smokeMethod.Length > 0) {
+ signature = ((SmokeMethod) smokeMethod[0]).Signature;
}
-// Console.WriteLine("FindMethod() multiple match {0}", result[0]);
+
+ return FindAmbiguousMethodId(i, signature);
}
}
- return result;
+ return -1;
}
public override IMessage Invoke(IMessage message) {
- ArrayList methods = null;
-
IMethodCallMessage callMessage = (IMethodCallMessage) message;
#if DEBUG
Console.WriteLine( "ENTER Invoke() MethodName: {0} Type: {1} ArgCount: {2}",
@@ -654,15 +650,7 @@
mungedName += "#";
}
}
-
- methods = FindMethod(mungedName);
- if (methods.Count == 0) {
-#if DEBUG
- Console.WriteLine("LEAVE Invoke() ** Missing method ** {0}", mungedName);
-#endif
- return returnMessage;
- }
-
+
for (int i = 0; i < callMessage.ArgCount; i++) {
if (callMessage.Args[i] == null) {
unsafe {
@@ -697,13 +685,21 @@
}
}
}
+
+ int methodId = FindMethod(mungedName, (MethodInfo) callMessage.MethodBase);
+ if (methodId == -1) {
+#if DEBUG
+ Console.WriteLine("LEAVE Invoke() ** Missing method ** {0}", mungedName);
+#endif
+ return returnMessage;
+ }
GCHandle instanceHandle = GCHandle.Alloc(_instance);
MethodReturnMessageWrapper returnValue = new MethodReturnMessageWrapper((IMethodReturnMessage) returnMessage);
unsafe {
fixed(StackItem * stackPtr = stack) {
- CallSmokeMethod((int) methods[0], (IntPtr) instanceHandle, (IntPtr) stackPtr, callMessage.ArgCount);
+ CallSmokeMethod((int) methodId, (IntPtr) instanceHandle, (IntPtr) stackPtr, callMessage.ArgCount);
Type returnType = ((MethodInfo) returnMessage.MethodBase).ReturnType;
if (returnType == typeof(void)) {
--- trunk/playground/bindings/kimono/qyoto.cpp #595783:595784
@@ -866,18 +866,43 @@
}
int
-FindAmbiguousMethodId(int ambiguousId)
+FindAmbiguousMethodId(int ambiguousId, char * signature)
{
- if (qt_Smoke->ambiguousMethodList[ambiguousId] == 0) {
- return 0;
- }
-
- Smoke::Method &methodRef = qt_Smoke->methods[qt_Smoke->ambiguousMethodList[ambiguousId]];
- if ((methodRef.flags & Smoke::mf_internal) == 0) {
+ while (qt_Smoke->ambiguousMethodList[ambiguousId] != 0) {
+ Smoke::Method &methodRef = qt_Smoke->methods[qt_Smoke->ambiguousMethodList[ambiguousId]];
+ if ((methodRef.flags & Smoke::mf_internal) == 0) {
+static QByteArray * currentSignature = 0;
+ if (currentSignature == 0) {
+ currentSignature = new QByteArray("");
+ }
+
+ *currentSignature = qt_Smoke->methodNames[methodRef.name];
+ *currentSignature += "(";
+
+ for (int i = 0; i < methodRef.numArgs; i++) {
+ if (i != 0) *currentSignature += ", ";
+ *currentSignature += qt_Smoke->types[qt_Smoke->argumentList[methodRef.args + i]].name;
+ }
+
+ *currentSignature += ")";
+ if (methodRef.flags & Smoke::mf_const) {
+ *currentSignature += " const";
+ }
+
#ifdef DEBUG
- printf("\t\tIn FindAmbiguousMethodId(%d) => %d\n", ambiguousId, qt_Smoke->ambiguousMethodList[ambiguousId]);
+ printf( "\t\tIn FindAmbiguousMethodId(%d, %s) => %d (%s)\n",
+ ambiguousId,
+ signature,
+ qt_Smoke->ambiguousMethodList[ambiguousId],
+ (const char *) *currentSignature );
#endif
- return qt_Smoke->ambiguousMethodList[ambiguousId];
+
+ if (*currentSignature == signature) {
+ return qt_Smoke->ambiguousMethodList[ambiguousId];
+ }
+ }
+
+ ambiguousId++;
}
return -1;
More information about the Kde-bindings
mailing list