fix: 修复脚本调用因参数类型可能失败的问题和内存泄漏;
This commit is contained in:
parent
263e3eb7e2
commit
69ae150df5
|
@ -306,12 +306,12 @@
|
|||
<location filename="../testplugin.cpp" line="246"/>
|
||||
<location filename="../testplugin.cpp" line="253"/>
|
||||
<location filename="../testplugin.cpp" line="260"/>
|
||||
<location filename="../testplugin.cpp" line="289"/>
|
||||
<location filename="../testplugin.cpp" line="297"/>
|
||||
<location filename="../testplugin.cpp" line="305"/>
|
||||
<location filename="../testplugin.cpp" line="313"/>
|
||||
<location filename="../testplugin.cpp" line="322"/>
|
||||
<location filename="../testplugin.cpp" line="329"/>
|
||||
<location filename="../testplugin.cpp" line="288"/>
|
||||
<location filename="../testplugin.cpp" line="296"/>
|
||||
<location filename="../testplugin.cpp" line="304"/>
|
||||
<location filename="../testplugin.cpp" line="312"/>
|
||||
<location filename="../testplugin.cpp" line="321"/>
|
||||
<location filename="../testplugin.cpp" line="328"/>
|
||||
<source>InvalidParamsCount</source>
|
||||
<translation>无效参数个数</translation>
|
||||
</message>
|
||||
|
@ -322,7 +322,7 @@
|
|||
<translation>非法参数</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../testplugin.cpp" line="280"/>
|
||||
<location filename="../testplugin.cpp" line="279"/>
|
||||
<source>AllocArrayFailed</source>
|
||||
<translation>分配数组失败</translation>
|
||||
</message>
|
||||
|
|
|
@ -263,7 +263,7 @@ WingHex::UNSAFE_RET TestPlugin::colorTable(const QList<void *> ¶ms) {
|
|||
void *array = nullptr;
|
||||
QVector<void *> colors;
|
||||
for (auto &c : colorTable()) {
|
||||
colors.append(new QColor(c));
|
||||
colors.append(&c);
|
||||
}
|
||||
|
||||
auto invoked =
|
||||
|
@ -271,7 +271,6 @@ WingHex::UNSAFE_RET TestPlugin::colorTable(const QList<void *> ¶ms) {
|
|||
qReturnArg(array), WingHex::MetaType::Meta_Color, colors);
|
||||
if (invoked) {
|
||||
if (array) {
|
||||
qDeleteAll(colors);
|
||||
return array;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5467,18 +5467,18 @@
|
|||
<translation>为 AngelScript 脚本提供调用主机 API 能力的内部插件。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../src/class/wingangelapi.cpp" line="1307"/>
|
||||
<location filename="../../src/class/wingangelapi.cpp" line="1310"/>
|
||||
<source>NotSupportedQMetaType:</source>
|
||||
<translation>不支持的 QT 数据元类型:</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../src/class/wingangelapi.cpp" line="1764"/>
|
||||
<location filename="../../src/class/wingangelapi.cpp" line="1848"/>
|
||||
<location filename="../../src/class/wingangelapi.cpp" line="1767"/>
|
||||
<location filename="../../src/class/wingangelapi.cpp" line="1851"/>
|
||||
<source>Get Exception While ScriptCall: (%1) %2</source>
|
||||
<translation>脚本调用发生异常:(%1)%2</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../src/class/wingangelapi.cpp" line="1790"/>
|
||||
<location filename="../../src/class/wingangelapi.cpp" line="1793"/>
|
||||
<source>InvalidRetType: need </source>
|
||||
<translation>无效返回值:需要 </translation>
|
||||
</message>
|
||||
|
|
|
@ -5467,18 +5467,18 @@
|
|||
<translation>為 AngelScript 腳本提供調用主機 API 能力的內部插件。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../src/class/wingangelapi.cpp" line="1307"/>
|
||||
<location filename="../../src/class/wingangelapi.cpp" line="1310"/>
|
||||
<source>NotSupportedQMetaType:</source>
|
||||
<translation>不支持的 QT 數據元類型:</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../src/class/wingangelapi.cpp" line="1764"/>
|
||||
<location filename="../../src/class/wingangelapi.cpp" line="1848"/>
|
||||
<location filename="../../src/class/wingangelapi.cpp" line="1767"/>
|
||||
<location filename="../../src/class/wingangelapi.cpp" line="1851"/>
|
||||
<source>Get Exception While ScriptCall: (%1) %2</source>
|
||||
<translation>腳本調用發生異常:(%1)%2</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../src/class/wingangelapi.cpp" line="1790"/>
|
||||
<location filename="../../src/class/wingangelapi.cpp" line="1793"/>
|
||||
<source>InvalidRetType: need </source>
|
||||
<translation>無效返回值:需要 </translation>
|
||||
</message>
|
||||
|
|
|
@ -600,7 +600,7 @@ bool PluginSystem::invokeServiceImpl(const QObject *sender, const QString &puid,
|
|||
if (met.name() == method) {
|
||||
bool err = false;
|
||||
for (int i = 1; i < paramCount; ++i) {
|
||||
if (met.parameterType(i) != metaTypes[i]->typeId) {
|
||||
if (met.parameterTypeName(i).compare(metaTypes[i]->name)) {
|
||||
err = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1061,12 +1061,10 @@ QStringList WingAngelAPI::cArray2QStringList(const CScriptArray &array,
|
|||
|
||||
QStringList buffer;
|
||||
buffer.reserve(array.GetSize());
|
||||
array.AddRef();
|
||||
for (asUINT i = 0; i < array.GetSize(); ++i) {
|
||||
auto item = reinterpret_cast<const QString *>(array.At(i));
|
||||
buffer.append(*item);
|
||||
}
|
||||
array.Release();
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@ -1217,9 +1215,10 @@ void WingAngelAPI::qvariantCastOp(
|
|||
assignTmpBuffer(buffer, var.toULongLong());
|
||||
fn(&buffer, type);
|
||||
break;
|
||||
case QMetaType::QChar:
|
||||
fn(new QChar(var.toChar()), type);
|
||||
break;
|
||||
case QMetaType::QChar: {
|
||||
auto obj = var.toChar();
|
||||
fn(&obj, type);
|
||||
} break;
|
||||
case QMetaType::Float:
|
||||
assignTmpBuffer(buffer, var.toULongLong());
|
||||
fn(&buffer, type);
|
||||
|
@ -1229,21 +1228,24 @@ void WingAngelAPI::qvariantCastOp(
|
|||
fn(&buffer, type);
|
||||
break;
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
case QMetaType::Char16:
|
||||
fn(new QChar(var.value<char16_t>()), type);
|
||||
break;
|
||||
case QMetaType::Char32:
|
||||
fn(new QChar(var.value<char32_t>()), type);
|
||||
break;
|
||||
case QMetaType::Char16: {
|
||||
auto obj = QChar(var.value<char16_t>());
|
||||
fn(&obj, type);
|
||||
} break;
|
||||
case QMetaType::Char32: {
|
||||
auto obj = QChar(var.value<char32_t>());
|
||||
fn(&obj, type);
|
||||
} break;
|
||||
#endif
|
||||
case QMetaType::UChar:
|
||||
case QMetaType::SChar:
|
||||
case QMetaType::Char:
|
||||
assignTmpBuffer(buffer, var.value<uchar>());
|
||||
break;
|
||||
case QMetaType::QString:
|
||||
fn(new QString(var.toString()), type);
|
||||
break;
|
||||
case QMetaType::QString: {
|
||||
auto obj = var.toString();
|
||||
fn(&obj, type);
|
||||
} break;
|
||||
case QMetaType::QByteArray: {
|
||||
auto value = var.toByteArray();
|
||||
auto info = engine->GetTypeInfoByDecl("array<byte>");
|
||||
|
@ -1298,9 +1300,10 @@ void WingAngelAPI::qvariantCastOp(
|
|||
fn(arr, type);
|
||||
arr->Release();
|
||||
} break;
|
||||
case QMetaType::QColor:
|
||||
fn(new QColor(var.value<QColor>()), type);
|
||||
break;
|
||||
case QMetaType::QColor: {
|
||||
auto obj = var.value<QColor>();
|
||||
fn(&obj, type);
|
||||
} break;
|
||||
case QMetaType::Void:
|
||||
break;
|
||||
default:
|
||||
|
@ -2000,7 +2003,9 @@ void *WingAngelAPI::vector2AsArray(const WingHex::SenderInfo &sender,
|
|||
if (info) {
|
||||
auto len = content.length();
|
||||
auto arr = CScriptArray::Create(info, len);
|
||||
std::memcpy(arr->GetBuffer(), content.data(), len);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
arr->SetValue(i, content.at(i));
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
return nullptr;
|
||||
|
@ -2009,37 +2014,8 @@ void *WingAngelAPI::vector2AsArray(const WingHex::SenderInfo &sender,
|
|||
void *WingAngelAPI::list2AsArray(const WingHex::SenderInfo &sender,
|
||||
WingHex::MetaType type,
|
||||
const QList<void *> &content) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
static_assert(std::is_same_v<QList<int>, QVector<int>>);
|
||||
return vector2AsArray(sender, type, content);
|
||||
#else
|
||||
Q_UNUSED(sender);
|
||||
auto typeStr = type2AngelScriptString(MetaType(type | MetaType::Meta_Array),
|
||||
false, true);
|
||||
if (typeStr.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto engine = ScriptMachine::instance().engine();
|
||||
auto info = engine->GetTypeInfoByDecl(typeStr.toUtf8());
|
||||
if (info) {
|
||||
auto len = content.length();
|
||||
auto arr = CScriptArray::Create(info, len);
|
||||
for (decltype(len) i = 0; i < len; ++i) {
|
||||
arr->SetValue(i, content.at(i));
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
void WingAngelAPI::deleteAsArray(const WingHex::SenderInfo &sender,
|
||||
void *array) {
|
||||
Q_UNUSED(sender);
|
||||
if (array) {
|
||||
reinterpret_cast<CScriptArray *>(array)->Release();
|
||||
}
|
||||
}
|
||||
|
||||
void *WingAngelAPI::newAsDictionary(
|
||||
|
@ -2063,14 +2039,6 @@ void *WingAngelAPI::newAsDictionary(
|
|||
return dic;
|
||||
}
|
||||
|
||||
void WingAngelAPI::deleteAsDictionary(const WingHex::SenderInfo &sender,
|
||||
void *dic) {
|
||||
Q_UNUSED(sender);
|
||||
if (dic) {
|
||||
reinterpret_cast<CScriptDictionary *>(dic)->Release();
|
||||
}
|
||||
}
|
||||
|
||||
void WingAngelAPI::cleanUpHandles(const QVector<int> &handles) {
|
||||
for (auto &h : _handles) {
|
||||
if (!handles.contains(h)) {
|
||||
|
|
|
@ -175,14 +175,10 @@ private:
|
|||
WING_SERVICE void *list2AsArray(const WingHex::SenderInfo &sender,
|
||||
WingHex::MetaType type,
|
||||
const QList<void *> &content);
|
||||
WING_SERVICE void deleteAsArray(const WingHex::SenderInfo &sender,
|
||||
void *array);
|
||||
|
||||
WING_SERVICE void *newAsDictionary(
|
||||
const WingHex::SenderInfo &sender,
|
||||
const QHash<QString, QPair<WingHex::MetaType, void *>> &content);
|
||||
WING_SERVICE void deleteAsDictionary(const WingHex::SenderInfo &sender,
|
||||
void *dic);
|
||||
|
||||
// =========================================================
|
||||
|
||||
|
|
Loading…
Reference in New Issue