# HG changeset patch
# User eldar
# Date 1244374949 0
# Node ID 7ae9bc9d69353e269267397a7b4251d676c9dd90
# Parent 9c97adeef76342fba8831abce1c0745e7f5c0325
reference counting for return values. applied to QMenu
diff -r 9c97adeef763 -r 7ae9bc9d6935 Makefile
--- a/Makefile Fri Jun 05 15:48:27 2009 +0000
+++ b/Makefile Sun Jun 07 11:42:29 2009 +0000
@@ -182,7 +182,7 @@
## DMD compile template bug fix
$(1)_D_RULE =$(TMP_PATH)/$(1)_dobj.$(D_OBJ_EXT)
$$($(1)_D_RULE):
- $(DC) $(D_CFLAGS) $(D_INCLUDE) -c $$($(1)_d_files) -singleobj -of$$($(1)_D_RULE)
+ $(DC) $(D_CFLAGS) $(D_INCLUDE) -c $$($(1)_d_files) -of$$($(1)_D_RULE)
else
$(1)_D_RULE = $$($(1)_d_files:qt/%.d=$(TMP_PATH)/%_d.o)
endif
diff -r 9c97adeef763 -r 7ae9bc9d6935 examples/desktop/systray/build.sh
--- a/examples/desktop/systray/build.sh Fri Jun 05 15:48:27 2009 +0000
+++ b/examples/desktop/systray/build.sh Sun Jun 07 11:42:29 2009 +0000
@@ -1,4 +1,4 @@
#! /bin/bash
../../../tools/drcc/drcc systray.qrc > qrc_systray.d
-dmd main.d window.d qrc_systray.d -I../../../ -I../../../qt/d1 -L-L../../../lib -L-lqtdgui -L-lqtdcore -L-lQtCore -L-lQtGui -ofsystray
+ldmd main.d window.d qrc_systray.d -I../../../ -I../../../qt/d1 -L-L../../../lib -L-lqtdgui -L-lqtdcore -L-lQtCore -L-lQtGui -ofsystray
diff -r 9c97adeef763 -r 7ae9bc9d6935 examples/mainwindows/dockwidgets/build.bat
--- a/examples/mainwindows/dockwidgets/build.bat Fri Jun 05 15:48:27 2009 +0000
+++ b/examples/mainwindows/dockwidgets/build.bat Sun Jun 07 11:42:29 2009 +0000
@@ -1,1 +1,1 @@
-dmd main.d mainwindow.d libqtdcore.lib libqtdgui.lib -I../../../
\ No newline at end of file
+dmd main.d mainwindow.d libqtdcore.lib libqtdgui.lib -I../../../ -I../../../qt/d1
\ No newline at end of file
diff -r 9c97adeef763 -r 7ae9bc9d6935 generator/dgenerator.cpp
--- a/generator/dgenerator.cpp Fri Jun 05 15:48:27 2009 +0000
+++ b/generator/dgenerator.cpp Sun Jun 07 11:42:29 2009 +0000
@@ -675,12 +675,16 @@
s << INDENT << this->translateType(d_function->type(), d_function->ownerClass(), NoOption) << " res;" << endl;
}
- //returning string or a struct
+ // returning string or a struct
bool return_in_arg = return_type && (return_type->isTargetLangString() ||
return_type->name() == "QModelIndex" ||
return_type->isContainer() ||
return_type->typeEntry()->isStructInD());
+ // bool flag showing if we return value immediately, without any conversions
+ // which is commpon for primitive types, initially set up to return_in_arg, because in that case
+ // we don't need type conversions
+ bool returnImmediately = return_in_arg;
s << INDENT;
if ( (has_return_type && d_function->argumentReplaced(0).isEmpty() ) || d_function->isConstructor()) { //qtd
@@ -701,6 +705,7 @@
} else if (return_type && return_type->isArray()) {
s << return_type->arrayElementType()->name() + "* __qt_return_value = ";
} else {
+ returnImmediately = true;
s << "return ";
}
@@ -840,41 +845,8 @@
// qtd2 if (return_type && (/* qtdreturn_type->isTargetLangEnum() ||*/ return_type->isTargetLangFlags()))
// s << ")";
- foreach (ReferenceCount referenceCount, referenceCounts) {
- writeReferenceCount(s, referenceCount, "__qt_return_value");
- }
-
s << ";" << endl;
- // return value marschalling
- if(return_type) {
- if ( ( has_return_type && d_function->argumentReplaced(0).isEmpty() )) // qtd
- if(return_type->isQObject())
- s << INDENT << "return qtd_" << return_type->name() << "_from_ptr(__qt_return_value);" << endl;
-
- if (return_type->isValue() && !return_type->typeEntry()->isStructInD())
- s << INDENT << "return new " << return_type->name() << "(__qt_return_value, false);" << endl;
-
- if (return_type->isVariant())
- s << INDENT << "return new QVariant(__qt_return_value, false);" << endl;
-
- if (return_type->isNativePointer() && return_type->typeEntry()->isValue())
- s << INDENT << "return new " << return_type->name() << "(__qt_return_value, true);" << endl;
-
- if (return_type->isObject()) {
- if(d_function->storeResult())
- s << INDENT << QString("__m_%1.nativeId = __qt_return_value;").arg(d_function->name()) << endl
- << INDENT << QString("return __m_%1;").arg(d_function->name()) << endl;
- else
- s << INDENT << "return qtd_" << return_type->name() << "_from_ptr(__qt_return_value);" << endl;
- s << endl;
- }
-
- if (return_type->isArray()) {
- s << INDENT << "return __qt_return_value[0 .. " << return_type->arrayElementCount() << "];" << endl;
- }
- }
- writeInjectedCode(s, d_function, CodeSnip::End);
/* qtd2
if (needs_return_variable) {
if (owner != TypeSystem::InvalidOwnership) {
@@ -894,6 +866,53 @@
s << INDENT << "this." << function_call_for_ownership(owner) << ";" << endl;
}
+ // return value marschalling
+ if(return_type) {
+ if (!returnImmediately && !d_function->storeResult()) {
+ s << INDENT;
+ QString modified_type = d_function->typeReplaced(0);
+ if (modified_type.isEmpty())
+ s << translateType(d_function->type(), d_function->implementingClass());
+ else
+ s << modified_type.replace('$', '.');
+ s << " __d_return_value = ";
+ }
+
+ if ( ( has_return_type && d_function->argumentReplaced(0).isEmpty() )) // qtd
+ if(return_type->isQObject())
+ s << "qtd_" << return_type->name() << "_from_ptr(__qt_return_value);" << endl;
+
+ if (return_type->isValue() && !return_type->typeEntry()->isStructInD())
+ s << "new " << return_type->name() << "(__qt_return_value, false);" << endl;
+
+ if (return_type->isVariant())
+ s << "new QVariant(__qt_return_value, false);" << endl;
+
+ if (return_type->isNativePointer() && return_type->typeEntry()->isValue())
+ s << "new " << return_type->name() << "(__qt_return_value, true);" << endl;
+
+ if (return_type->isObject()) {
+ if(d_function->storeResult())
+ s << INDENT << QString("__m_%1.nativeId = __qt_return_value;").arg(d_function->name()) << endl
+ << INDENT << QString("return __m_%1;").arg(d_function->name()) << endl;
+ else
+ s << "qtd_" << return_type->name() << "_from_ptr(__qt_return_value);" << endl;
+ s << endl;
+ }
+
+ if (return_type->isArray()) {
+ s << "__qt_return_value[0 .. " << return_type->arrayElementCount() << "];" << endl;
+ }
+
+ foreach (ReferenceCount referenceCount, referenceCounts) {
+ writeReferenceCount(s, referenceCount, "__d_return_value");
+ }
+
+ if (!returnImmediately && !d_function->storeResult())
+ s << INDENT << "return __d_return_value;" << endl;
+ }
+ writeInjectedCode(s, d_function, CodeSnip::End);
+
if(return_in_arg) // qtd
s << INDENT << "return res;" << endl;
}
diff -r 9c97adeef763 -r 7ae9bc9d6935 generator/typesystem_gui.xml
--- a/generator/typesystem_gui.xml Fri Jun 05 15:48:27 2009 +0000
+++ b/generator/typesystem_gui.xml Sun Jun 07 11:42:29 2009 +0000
@@ -3459,6 +3459,16 @@
+
+
+
+
+
+
+
+
+
+