[Kde-bindings] playground/bindings/kimono
Richard Dale
Richard_Dale at tipitina.demon.co.uk
Fri Dec 30 09:57:27 UTC 2005
SVN commit 492532 by rdale:
* Added a 'char *' marshaller
* Non-primitive return types now work
CCMAIL: kde-bindings at kde.org
M +13 -2 SmokeInvocation.cs
M +59 -22 qt3handlers.cpp
--- trunk/playground/bindings/kimono/SmokeInvocation.cs #492531:492532
@@ -72,6 +72,9 @@
static extern IntPtr StringToQString(string str);
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern string StringFromQString(IntPtr ptr);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
static extern void AddGetSmokeObject(GetIntPtr callback);
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
@@ -91,6 +94,9 @@
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
static extern void AddIntPtrToQString(GetIntPtr callback);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern void AddIntPtrFromQString(GetIntPtr callback);
static IntPtr GetSmokeObject(IntPtr instancePtr) {
Object instance = ((GCHandle) instancePtr).Target;
@@ -160,6 +166,10 @@
return StringToQString(temp);
}
+ static IntPtr IntPtrFromQString(IntPtr ptr) {
+ return (IntPtr) GCHandle.Alloc(StringFromQString(ptr));
+ }
+
static private Hashtable pointerMap = new Hashtable();
static private GetIntPtr getSmokeObject = new GetIntPtr(GetSmokeObject);
static private SetIntPtr setSmokeObject = new SetIntPtr(SetSmokeObject);
@@ -170,6 +180,7 @@
static private GetIntPtr intPtrToCharStarStar = new GetIntPtr(IntPtrToCharStarStar);
static private GetIntPtr intPtrToQString = new GetIntPtr(IntPtrToQString);
+ static private GetIntPtr intPtrFromQString = new GetIntPtr(IntPtrFromQString);
static SmokeInvocation() {
AddGetSmokeObject(getSmokeObject);
@@ -181,6 +192,7 @@
AddIntPtrToCharStarStar(intPtrToCharStarStar);
AddIntPtrToQString(intPtrToQString);
+ AddIntPtrFromQString(intPtrFromQString);
}
private Type _classToProxy;
@@ -346,8 +358,7 @@
} 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[])) {
+ returnValue.ReturnValue = ((GCHandle) (IntPtr) stack[0].s_class).Target;
}
}
}
--- trunk/playground/bindings/kimono/qt3handlers.cpp #492531:492532
@@ -28,6 +28,7 @@
extern "C" {
static GetIntPtr IntPtrToCharStarStar;
static GetIntPtr IntPtrToQString;
+static GetIntPtr IntPtrFromQString;
void AddIntPtrToCharStarStar(GetIntPtr callback)
{
@@ -41,6 +42,12 @@
IntPtrToQString = callback;
}
+void AddIntPtrFromQString(GetIntPtr callback)
+{
+ printf("In AddIntPtrFromQString 0x%8.8x\n", callback);
+ IntPtrFromQString = callback;
+}
+
extern void * set_obj_info(const char * className, smokeqyoto_object * o);
//extern void * IntPtrToCharStarStar(void * item);
};
@@ -259,8 +266,14 @@
return (void *) result;
}
+char *
+StringFromQString(void *ptr)
+{
+ return (char *) ((QString *) ptr)->latin1();
}
+}
+
void
marshall_basetype(Marshall *m)
{
@@ -425,7 +438,6 @@
switch(m->action()) {
case Marshall::FromObject:
{
-printf("In Marshall::FromObject m->var().s_class: %p\n", m->var().s_class);
if (m->var().s_class == 0) {
m->item().s_class = 0;
return;
@@ -456,8 +468,6 @@
break;
case Marshall::ToObject:
{
-printf("In Marshall::ToObject m->item().s_voidp: %p\n", m->item().s_voidp);
-printf("In Marshall::ToObject m->var().s_voidp: %p\n", m->var().s_voidp);
if(m->item().s_voidp == 0) {
m->var().s_voidp = 0;
break;
@@ -465,7 +475,6 @@
void *p = m->item().s_voidp;
void * obj = getPointerObject(p);
-printf("In Marshall::ToObject p: %p obj: %p\n", p, obj);
if (obj != 0) {
m->var().s_voidp = obj;
break;
@@ -487,9 +496,9 @@
}
obj = set_obj_info(classname, o);
-// if (do_debug & qtdb_calls) {
+ if (do_debug & qtdb_calls) {
printf("allocating %s %p -> %p\n", classname, o->ptr, (void*)obj);
-// }
+ }
if(m->type().isStack()) {
o->allocated = true;
@@ -516,12 +525,41 @@
m->unsupported();
}
+static void marshall_charP(Marshall *m) {
+ switch(m->action()) {
+ case Marshall::FromObject:
+ {
+ QString * s = (QString *) (*IntPtrToQString)(m->var().s_class);
+ m->item().s_voidp = (void *) s->latin1();
+ }
+ break;
+ case Marshall::ToObject:
+ {
+ char *p = (char*) m->item().s_voidp;
+ if (p != 0) {
+ QString s(p);
+ m->var().s_class = (*IntPtrFromQString)(&s);
+ } else {
+ QString s;
+ m->var().s_class = (*IntPtrFromQString)(&s);
+ }
+
+ if (m->cleanup()) {
+ delete[] p;
+ }
+ }
+ break;
+ default:
+ m->unsupported();
+ break;
+ }
+}
+
static void marshall_QString(Marshall *m) {
switch(m->action()) {
case Marshall::FromObject:
{
QString* s = 0;
-printf("In marshall_QString m->var().s_voidp: %p\n", m->var().s_voidp);
if( m->var().s_voidp != 0) {
s = (QString *) (*IntPtrToQString)(m->var().s_voidp);
@@ -555,12 +593,12 @@
case Marshall::ToObject:
{
QString *s = (QString*)m->item().s_voidp;
- if(s) {
- if (s->isNull()) {
- m->var().s_voidp = 0;
- } else {
-// *(m->var()) = rb_str_new2(s->latin1());
- }
+ if (s) {
+ if (s->isNull()) {
+ m->var().s_voidp = 0;
+ } else {
+ m->var().s_class = (*IntPtrFromQString)(s);
+ }
// if(!(PL_hints & HINT_BYTES))
// {
// sv_setpv_mg(m->var(), (const char *)s->utf8());
@@ -570,15 +608,15 @@
// sv_setpv_mg(m->var(), (const char *)s->local8Bit());
// else
// sv_setpv_mg(m->var(), (const char *)s->latin1());
- if(m->cleanup())
- delete s;
- } else {
- m->var().s_voidp = 0;
- }
+ if (m->cleanup())
+ delete s;
+ } else {
+ m->var().s_voidp = 0;
+ }
}
break;
- default:
- m->unsupported();
+ default:
+ m->unsupported();
break;
}
}
@@ -589,7 +627,6 @@
case Marshall::FromObject:
{
int * i = new int;
-printf("marshall_intR m->item().s_int: %d m->var().s_int: %d\n", m->item().s_int, m->var().s_int);
*i = m->var().s_int;
m->item().s_voidp = i;
m->next();
@@ -620,7 +657,6 @@
{
m->item().s_voidp = (*IntPtrToCharStarStar)(m->var().s_voidp);
char ** temp = (char **) m->item().s_voidp;
-printf("marshall_charP_array temp[0]: %s\n", temp[0]);
}
break;
default:
@@ -637,6 +673,7 @@
{ "QString*", marshall_QString },
{ "int&", marshall_intR },
{ "int*", marshall_intR },
+ { "char*", marshall_charP },
{ "char**", marshall_charP_array },
{ 0, 0 }
More information about the Kde-bindings
mailing list