From dbb9f0a2d5ffde7aca3c70c5c0208973230f5f02 Mon Sep 17 00:00:00 2001 From: Jay <csj123456> Date: 星期三, 16 四月 2025 09:34:50 +0800 Subject: [PATCH] 新增参数 --- iailab-module-model/iailab-module-model-biz/src/main/resources/template/cpp.vm | 28 ++++++++++++++++------------ 1 files changed, 16 insertions(+), 12 deletions(-) diff --git a/iailab-module-model/iailab-module-model-biz/src/main/resources/template/cpp.vm b/iailab-module-model/iailab-module-model-biz/src/main/resources/template/cpp.vm index b4ddf01..b2bb6d5 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/resources/template/cpp.vm +++ b/iailab-module-model/iailab-module-model-biz/src/main/resources/template/cpp.vm @@ -37,6 +37,7 @@ cout << "model error" << endl; throw "模块调用失败!"; } + cout << "load pymodel finished" << endl; //*************导入函数****************** PyObject* pFunc = PyObject_GetAttrString(pModule, "${entity.methodName}"); @@ -45,6 +46,7 @@ cout << "func error" << endl; throw "函数调用失败!"; } + cout << "load pyfunc finished" << endl; #{foreach} ($column in [1..$entity.dataLength]) PyObject* data_${column} = ConvertJdarrToPydarr(env, data${column}); #{end} @@ -84,6 +86,18 @@ cout << "return error" << endl; throw "函数返回值异常!"; } + cout << "load pyreturn finished" << endl; + PyObject* json_module = create_py_module("json"); + PyObject* dumps_func = PyObject_GetAttrString(json_module, "dumps"); + PyObject* json_str = PyObject_CallObject(dumps_func, PyTuple_Pack(1, pReturn)); + if (json_str == NULL) { + cout << "json_str is null" << endl; + PyErr_Print(); + return NULL; + } + const char* json_cstr = PyUnicode_AsUTF8(json_str); + cout << "pyreturn" << json_cstr << endl; + //*******************返回数据封装************************ // 开辟返回数据内存空间,转换数据,拆分数据 @@ -92,19 +106,9 @@ if (result == NULL) { cout << "ConvertPydictToJhmap error" << endl; - throw "函数返回值异常!"; + throw "函数返回值解析异常!"; } - cout << "clear_py_memory" << endl; - Py_XDECREF(pFunc); -#{foreach} ($column in [1..$entity.dataLength]) - Py_XDECREF(data_${column}); -#{end} -#{if}($entity.model==1) - Py_XDECREF(model_path); -#{end} - Py_XDECREF(settings_1); - Py_XDECREF(pArg); - Py_XDECREF(pReturn); + return result; } catch (const char* msg) -- Gitblit v1.9.3