This commit is contained in:
blueloveTH 2023-10-15 15:20:22 +08:00
parent 3c6e4b4e76
commit b3e77cdb51
2 changed files with 9 additions and 5 deletions

View File

@ -113,6 +113,12 @@ static PyObject* convert_cjson_to_python_object(const cJSON * const item, VM* vm
void add_module_cjson(VM* vm){ void add_module_cjson(VM* vm){
PyObject* mod = vm->new_module("cjson"); PyObject* mod = vm->new_module("cjson");
PK_LOCAL_STATIC cJSON_Hooks hooks;
hooks.malloc_fn = pool64_alloc;
hooks.free_fn = pool64_dealloc;
cJSON_InitHooks(&hooks);
vm->bind_func<1>(mod, "loads", [](VM* vm, ArgsView args){ vm->bind_func<1>(mod, "loads", [](VM* vm, ArgsView args){
const Str& string = CAST(Str&, args[0]); const Str& string = CAST(Str&, args[0]);
cJSON *json = cJSON_ParseWithLength(string.data, string.size); cJSON *json = cJSON_ParseWithLength(string.data, string.size);

View File

@ -7,11 +7,9 @@ if not os.path.exists("build"):
os.chdir("build") os.chdir("build")
code = os.system(r""" code = os.system("cmake .. -DPK_USE_CJSON=ON -DPK_USE_BOX2D=ON")
cmake .. -DPK_USE_CJSON=ON -DPK_USE_BOX2D=ON assert code == 0
cmake --build . --config Release code = os.system("cmake --build . --config Release")
""")
assert code == 0 assert code == 0
if sys.platform == "win32": if sys.platform == "win32":