[Kde-bindings] KDE/kdebindings/csharp/qyoto
Richard Dale
Richard_Dale at tipitina.demon.co.uk
Wed Jun 13 09:46:05 UTC 2007
SVN commit 674856 by rdale:
* Finished fixing the virtual method callback code
* Removed a memory leak from the 'int&' marshaller
* Fixed some other minor problems reported by valgrind
* Don't garbage collect QGraphicsItem instance for now
CCMAIL: kde-bindings at kde.org
M +7 -0 ChangeLog
M +18 -24 src/handlers.cpp
M +61 -47 src/qyoto.cpp
--- trunk/KDE/kdebindings/csharp/qyoto/ChangeLog #674855:674856
@@ -1,3 +1,10 @@
+2007-06-13 Richard Dale <rdale at foton.es>
+
+ * Finished fixing the virtual method callback code
+ * Removed a memory leak from the 'int&' marshaller
+ * Fixed some other minor problems reported by valgrind
+ * Don't garbage collect QGraphicsItem instance for now
+
2007-06-12 Richard Dale <rdale at foton.es>
* When the stack was allocated for a virtual method callback, an entry
--- trunk/KDE/kdebindings/csharp/qyoto/src/handlers.cpp #674855:674856
@@ -304,6 +304,8 @@
}
} else if (isDerivedFromByName(o->smoke, className, "QTextBlockUserData")) {
return true;
+ } else if (isDerivedFromByName(o->smoke, className, "QGraphicsItem")) {
+ return true;
}
return false;
@@ -988,32 +990,24 @@
}
static void marshall_intR(Marshall *m) {
- switch(m->action()) {
- case Marshall::FromObject:
- {
- int * i = new int;
- *i = m->var().s_int;
- m->item().s_voidp = i;
- m->next();
- if(m->cleanup() && m->type().isConst()) {
- delete i;
- } else {
-// m->item().s_voidp = new int((int)NUM2INT(rv));
- }
- }
- break;
+ switch(m->action()) {
+ case Marshall::FromObject:
+ {
+ m->item().s_voidp = &(m->var().s_int);
+ }
+ break;
- case Marshall::ToObject:
- {
- int *ip = (int*)m->item().s_voidp;
- m->var().s_int = *ip;
- }
- break;
+ case Marshall::ToObject:
+ {
+ int *ip = (int*)m->item().s_voidp;
+ m->var().s_int = *ip;
+ }
+ break;
- default:
- m->unsupported();
- break;
- }
+ default:
+ m->unsupported();
+ break;
+ }
}
/*
--- trunk/KDE/kdebindings/csharp/qyoto/src/qyoto.cpp #674855:674856
@@ -370,31 +370,33 @@
SmokeType _st;
Smoke::StackItem * _retval;
public:
- const Smoke::Method &method() { return _smoke->methods[_method]; }
- SmokeType type() { return _st; }
- Marshall::Action action() { return Marshall::FromObject; }
- Smoke::StackItem &item() { return _stack[0]; }
- Smoke::StackItem &var() {
+
+ VirtualMethodReturnValue(Smoke *smoke, Smoke::Index meth, Smoke::Stack stack, Smoke::StackItem * retval) :
+ _smoke(smoke), _method(meth), _stack(stack), _retval(retval)
+ {
+ _st.set(_smoke, method().ret);
+ Marshall::HandlerFn fn = getMarshallFn(type());
+ (*fn)(this);
+ }
+
+ const Smoke::Method &method() { return _smoke->methods[_method]; }
+ SmokeType type() { return _st; }
+ Marshall::Action action() { return Marshall::FromObject; }
+ Smoke::StackItem &item() { return _stack[0]; }
+ Smoke::StackItem &var() {
return *_retval;
- }
+ }
void unsupported() {
qFatal( "Cannot handle '%s' as return-type of virtual method %s::%s",
type().name(),
_smoke->className(method().classId),
_smoke->methodNames[method().name] );
- }
+ }
- Smoke *smoke() { return _smoke; }
- void next() {}
- bool cleanup() { return false; }
-
- VirtualMethodReturnValue(Smoke *smoke, Smoke::Index meth, Smoke::Stack stack, Smoke::StackItem * retval) :
- _smoke(smoke), _method(meth), _stack(stack), _retval(retval) {
- _st.set(_smoke, method().ret);
- Marshall::HandlerFn fn = getMarshallFn(type());
- (*fn)(this);
- }
+ Smoke *smoke() { return _smoke; }
+ void next() {}
+ bool cleanup() { return false; }
};
class VirtualMethodCall : public Marshall {
@@ -409,23 +411,37 @@
bool _called;
public:
- SmokeType type() { return SmokeType(_smoke, _args[_cur]); }
- Marshall::Action action() { return Marshall::ToObject; }
- Smoke::StackItem &item() { return _stack[_cur + 1]; }
+ VirtualMethodCall(Smoke *smoke, Smoke::Index meth, Smoke::Stack stack, void * obj, void * overridenMethod) :
+ _smoke(smoke), _method(meth), _stack(stack), _obj(obj),
+ _overridenMethod(overridenMethod), _cur(-1), _sp(0), _called(false)
+ {
+ _sp = new Smoke::StackItem[method().numArgs + 1];
+ _args = _smoke->argumentList + method().args;
+ }
+ ~VirtualMethodCall() {
+ delete[] _sp;
+ (*FreeGCHandle)(_obj);
+ (*FreeGCHandle)(_overridenMethod);
+ }
+
+ SmokeType type() { return SmokeType(_smoke, _args[_cur]); }
+ Marshall::Action action() { return Marshall::ToObject; }
+ Smoke::StackItem &item() { return _stack[_cur + 1]; }
+
Smoke::StackItem &var() {
- return _sp[_cur];
- }
+ return _sp[_cur + 1];
+ }
const Smoke::Method &method() { return _smoke->methods[_method]; }
- void unsupported() {
+ void unsupported() {
qFatal( "Cannot handle '%s' as argument of virtual method %s::%s",
type().name(),
_smoke->className(method().classId),
_smoke->methodNames[method().name] );
- }
- Smoke *smoke() { return _smoke; }
+ }
+ Smoke *smoke() { return _smoke; }
void callMethod() {
if (_called) return;
@@ -434,7 +450,7 @@
(*InvokeMethod)(_obj, _overridenMethod, _sp);
Smoke::StackItem * _retval = _sp;
VirtualMethodReturnValue r(_smoke, _method, _stack, _retval);
- }
+ }
void next() {
int oldcur = _cur;
@@ -446,21 +462,9 @@
}
callMethod();
_cur = oldcur;
- }
+ }
- bool cleanup() { return false; } // is this right?
-
- VirtualMethodCall(Smoke *smoke, Smoke::Index meth, Smoke::Stack stack, void * obj, void * overridenMethod) :
- _smoke(smoke), _method(meth), _stack(stack), _obj(obj), _overridenMethod(overridenMethod), _cur(-1), _sp(0), _called(false) {
- _sp = new Smoke::StackItem[method().numArgs + 1];
- _args = _smoke->argumentList + method().args;
- }
-
- ~VirtualMethodCall() {
- free(_sp);
- (*FreeGCHandle)(_obj);
- (*FreeGCHandle)(_overridenMethod);
- }
+ bool cleanup() { return false; } // is this right?
};
class MethodReturnValue : public Marshall {
@@ -613,7 +617,6 @@
}
}
-
void next() {
int oldcur = _cur;
_cur++;
@@ -819,6 +822,7 @@
if (_mocret[0].argType != xmoc_void) {
SlotReturnValue r(_o, ret, _mocret);
}
+ delete[] ret;
}
void next() {
@@ -847,7 +851,7 @@
~InvokeSlot() {
delete[] _stack;
delete[] _sp;
- delete _args;
+ delete[] _args;
}
};
@@ -978,10 +982,10 @@
(*FreeGCHandle)(obj);
}
- bool callMethod(Smoke::Index method, void *ptr, Smoke::Stack args, bool /*isAbstract*/) {
+ bool callMethod(Smoke::Index method, void *ptr, Smoke::Stack args, bool isAbstract) {
void * obj = (*GetInstance)(ptr, false);
- if (obj == 0) {
+ if (obj == 0 && !isAbstract) {
return false;
}
@@ -999,6 +1003,14 @@
signature += " const";
}
+ if (obj == 0) {
+ printf( "Fatal error: C# instance has been wrongly GC'd for virtual %p->%s::%s call\n",
+ ptr,
+ smoke->classes[smoke->methods[method].classId].className,
+ (const char *) signature );
+ exit(1);
+ }
+
if (do_debug & qtdb_virtual) {
printf( "virtual %p->%s::%s called\n",
ptr,
@@ -1006,6 +1018,7 @@
(const char *) signature );
fflush(stdout);
}
+
if (strcmp(signature, "qt_metacall(QMetaObject::Call, int, void**)") == 0) {
QMetaObject::Call _c = (QMetaObject::Call)args[1].s_int;
@@ -1870,13 +1883,14 @@
MocArgument * args = GetMocArguments(replyType, sig);
const QMetaObject* meta = qobj->metaObject();
- const char* signatureStr = sig.toLatin1();
int i;
for (i = 0; i < meta->methodCount(); i++) {
QMetaMethod m = meta->method(i);
- if (m.methodType() == QMetaMethod::Signal &&
- strcmp(m.signature(), signatureStr) == 0)
+ if ( m.methodType() == QMetaMethod::Signal
+ && strcmp(m.signature(), signature) == 0 )
+ {
break;
+ }
}
EmitSignal signal(qobj, i, items, args, sp);
More information about the Kde-bindings
mailing list