Fixed bug in the D bindings that could cause memory corruption on string deletion. Renamed clear to destroy

This commit is contained in:
Filippo Cucchetto 2014-12-29 21:19:33 +01:00
parent 8819b7ef10
commit 3e9bd71a9e
3 changed files with 18 additions and 9 deletions

View File

@ -97,8 +97,9 @@ class QQuickView
string source()
{
auto array = new CharArray();
scope(exit) destroy(array);
dos_qquickview_source(data, array.dataRef(), array.sizeRef());
return to!(string)(array.data());
return array.toString();
}
void setSource(string filename)
@ -136,8 +137,9 @@ class QQmlContext
string baseUrl()
{
auto array = new CharArray();
scope(exit) destroy(array);
dos_qqmlcontext_baseUrl(data, array.dataRef(), array.sizeRef());
return to!(string)(array.data());
return array.toString();
}
void setContextProperty(string name, QVariant value)
@ -245,9 +247,10 @@ class QVariant
override string toString()
{
auto array = new CharArray();
dos_qvariant_toString(this.data, array.dataRef(), array.sizeRef());
return to!(string)(array.data());
auto result = new CharArray();
scope(exit) destroy(result);
dos_qvariant_toString(this.data, result.dataRef(), result.sizeRef());
return result.toString();
}
private void* data;
@ -299,6 +302,11 @@ class CharArray
return _size;
}
override string toString()
{
return fromStringz(_data).dup;
}
private char* _data;
private int _size;
}
}

View File

@ -18,7 +18,7 @@ void dos_qquickview_delete(void*);
void dos_chararray_create(ref char*);
void dos_chararray_create(ref char*, int size);
void dos_chararray_delete(ref char*);
void dos_chararray_delete(char*);
void dos_qqmlcontext_baseUrl(void*, ref char*, ref int);
void dos_qqmlcontext_setcontextproperty(void*, immutable (char)*, void*);

View File

@ -47,12 +47,13 @@ void main()
try
{
auto app = new QGuiApplication;
scope(exit) clear(app);
scope(exit) destroy(app);
auto view = new QQuickView;
scope(exit) clear(view);
scope(exit) destroy(view);
auto myObject = new MyObject();
scope(exit) destroy(myObject);
auto context = view.rootContext();
context.setContextProperty("myObject", new QVariant(myObject));