[Kde-bindings] playground/bindings/phpqt/php_qt

Thomas Moenicke tm at php-qt.org
Sat Jun 23 20:15:50 UTC 2007


SVN commit 679380 by moenicke:

* fixed memory issue in virtual method calls

CCMAIL: kde-bindings at kde.org



 M  +11 -13    marshall_basetypes.h  
 M  +1 -2      marshall_types.cpp  
 M  +1 -4      php_qt.cpp  
 M  +2 -9      phpqt_internals.cpp  
 M  +4 -6      smokephp.cpp  


--- trunk/playground/bindings/phpqt/php_qt/marshall_basetypes.h #679379:679380
@@ -159,7 +159,7 @@
 			*(m->return_value_ptr()) = const_cast<zval*>(o->zval_ptr());
 
 			if(!strcmp(m->identifier, "VirtualMethodCall")){
-				((VirtualMethodCall*)m)->var(*m->return_value_ptr());
+  				((VirtualMethodCall*)m)->var(*m->return_value_ptr());
 			}
 		}
 		return;
@@ -175,26 +175,24 @@
 	    if (Z_TYPE_P(m->var()) == IS_OBJECT)
 	    {
 	    	_ce = Z_OBJCE_P(m->var());
-		// object has to be casted
-	    } else if(!strcmp(__className, "QObject")) { // classname == QObject
-			// cast the Qt object: from, to
+		//! object has to be casted
+	    } else if(!strcmp(__className, "QObject")) {
+			//! cast the Qt object: from, to
 			__p = m->smoke()->cast(__p, m->smoke()->idClass("QObject"), m->type().classId());
-			// cast the php one
+			//! cast the php one
 			_ce = zend_fetch_class((char*) __qo->metaObject()->className(), strlen(__qo->metaObject()->className()), ZEND_FETCH_CLASS_AUTO TSRMLS_DC);
 
-	    // fallback, already with correct type
+	    //! fallback, already with correct type
 	    } else {
 			_ce = zend_fetch_class(__className, __strLenClassName, ZEND_FETCH_CLASS_AUTO TSRMLS_DC);
 	    }
-		smokephp_object *o;
+
 		if(!strcmp(m->identifier, "VirtualMethodCall")){
-			zval* z = (zval*) emalloc(sizeof(zval));
-// 			zval* z = (zval*) alloca(sizeof(zval));
+ 			zval* z = (zval*) emalloc(sizeof(zval));
 			((VirtualMethodCall*) m)->var(z);
-			o = PHPQt::createObject(m->var(), __p, _ce, m->type().classId());
-			m->var()->refcount--;
-		} else
-		/*smokephp_object **/o = PHPQt::createObject(m->var(), __p, _ce, m->type().classId());
+// 			o = PHPQt::createObject(m->var(), __p, _ce, m->type().classId());
+		}
+		smokephp_object *o = PHPQt::createObject(m->var(), __p, _ce, m->type().classId());
 
 //	    if(m->type().isConst() && m->type().isRef()) {
 	    if(m->type().isRef())
--- trunk/playground/bindings/phpqt/php_qt/marshall_types.cpp #679379:679380
@@ -441,8 +441,7 @@
 {
 	if (_called) return;
 	_called = true;
-// TODO _obj gets lost
-	_obj = activeScope;
+
 	zval* retval = PHPQt::callPHPMethod(_obj, _smoke->methodNames[method().name], items(), __sp);
 	VirtualMethodReturnValue r(_smoke, _method, _stack, retval);
 }
--- trunk/playground/bindings/phpqt/php_qt/php_qt.cpp #679379:679380
@@ -160,11 +160,8 @@
 ZEND_METHOD(php_qt_generic_class, __destruct)
 {
 	if(PHPQt::SmokePHPObjectExists(getThis())) {
-qDebug() << "destruct" << getThis();
-
  		smokephp_object *o = PHPQt::getSmokePHPObjectFromZval(getThis());
-
-//		its not a reference
+		//! its not a reference
 		if(!PZVAL_IS_REF(getThis()))
 		{
 			o->setAllocated(false);
--- trunk/playground/bindings/phpqt/php_qt/phpqt_internals.cpp #679379:679380
@@ -48,7 +48,7 @@
 	int offset = d->methodCount();
 
 #if MOC_DEBUG
-	cout << "qt_metacall " << so->ce_ptr->name << endl;
+	qDebug() << "qt_metacall " << so->ce_ptr()->name << endl;
 #endif
 
 	// call the C++ one
@@ -58,7 +58,7 @@
 
 		// methodId
 		Smoke::Index nameId = so->smoke()->idMethodName("qt_metacall$$?");
-		Smoke::Index method = so->smoke()->findMethod(so->classId(), nameId);
+ 		Smoke::Index method = so->smoke()->findMethod(so->classId(), nameId);
 
 		if(method > 0){
 			Smoke::Method &m = so->smoke()->methods[so->smoke()->methodMaps[method].method];
@@ -425,15 +425,8 @@
 PHPQt::createOriginal(zval* zval_ptr, void* ptr)
 {
 	smokephp_object* o = getSmokePHPObjectFromQt(ptr);
-/* 		ZVAL_ZVAL(zval_ptr, o->zval_ptr, 1, 0);
-// 		zval_ptr->is_ref = 1;
-		Z_OBJ_HT_P(zval_ptr) = &php_qt_handler;
-		zval_x_smokephp.insert(zval_ptr, o);*/
-	Z_OBJ_HT_P(zval_ptr) = &php_qt_handler;
  	zval_ptr = const_cast<zval*>(o->zval_ptr());
-
 	zval_add_ref(&zval_ptr);
-
 	return o;
 }
 
--- trunk/playground/bindings/phpqt/php_qt/smokephp.cpp #679379:679380
@@ -51,7 +51,6 @@
     PHPQtSmokeBinding(Smoke *s) : SmokeBinding(s) {}
 
     virtual void deleted(Smoke::Index classId, void* ptr) {
-qDebug("deleted");
         if(PHPQt::SmokePHPObjectExists(ptr)){
 			smokephp_object *o = (smokephp_object*) PHPQt::getSmokePHPObjectFromQt(ptr);
 			if(!o->allocated()){
@@ -63,7 +62,7 @@
 			SmokeQtObjects.remove(o->ptr());
 		}
     }
-    bool callMethod(Smoke::Index method, void* QtPtr, Smoke::Stack args, bool /*isAbstract*/) {
+    virtual bool callMethod(Smoke::Index method, void* QtPtr, Smoke::Stack args, bool /*isAbstract*/) {
 
 		smokephp_object *o = (smokephp_object*) PHPQt::getSmokePHPObjectFromQt(QtPtr);
 
@@ -88,10 +87,9 @@
 		if(PHPQt::methodExists(o->ce_ptr(), (char*) methodName)){
 			activeScope = const_cast<zval*>(o->zval_ptr());
 			activeCe = const_cast<zend_class_entry*>(o->ce_ptr());
-check_qobject(activeScope);
 			zval* zmem = ALLOCA_N(zval, smoke->methods[method].numArgs);
-// 			zval* zmem = (zval*) safe_emalloc(sizeof(zval), smoke->methods[method].numArgs,0);
-		    VirtualMethodCall c(smoke, method, args, activeScope, &zmem, &activeScope);
+			zval* tmp = (zval*) emalloc(sizeof(zval));
+ 		    VirtualMethodCall c(smoke, method, args, activeScope, &zmem, &tmp);
 			c.next();
  			return true;
 		}
@@ -131,7 +129,7 @@
 	php_error(E_ERROR,"could not initialize smoke (no class definitions)");
     }
 
-    PQ::smoke()->binding = new PHPQtSmokeBinding(PQ::smoke());
+	PQ::smoke()->binding = new PHPQtSmokeBinding(PQ::smoke());
 
 }
 



More information about the Kde-bindings mailing list