From de45471a9d23478277ae9e52d82855429f23f03c Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 13 May 2023 16:31:56 +0800 Subject: [PATCH] ... --- src/cffi.h | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/cffi.h b/src/cffi.h index 3fe819e1..d63634aa 100644 --- a/src/cffi.h +++ b/src/cffi.h @@ -69,24 +69,6 @@ struct PlainOldData{ } }; -inline void add_module_c(VM* vm){ - PyObject* mod = vm->new_module("c"); - - vm->bind_func<1>(mod, "malloc", [](VM* vm, ArgsView args){ - i64 size = CAST(i64, args[0]); - return VAR(malloc(size)); - }); - - vm->bind_func<1>(mod, "free", [](VM* vm, ArgsView args){ - void* p = CAST(void*, args[0]); - free(p); - return vm->None; - }); - - VoidP::register_class(vm, mod); - PlainOldData::register_class(vm, mod); -} - inline PyObject* py_var(VM* vm, void* p){ return VAR_T(VoidP, p); } @@ -163,4 +145,23 @@ inline void bind_any_c_fp(VM* vm, PyObject* obj, Str name, T fp){ func->attr().set("__proxy__", VAR_T(VoidP, proxy)); obj->attr().set(name, func); } + +inline void add_module_c(VM* vm){ + PyObject* mod = vm->new_module("c"); + + vm->bind_func<1>(mod, "malloc", [](VM* vm, ArgsView args){ + i64 size = CAST(i64, args[0]); + return VAR(malloc(size)); + }); + + vm->bind_func<1>(mod, "free", [](VM* vm, ArgsView args){ + void* p = CAST(void*, args[0]); + free(p); + return vm->None; + }); + + VoidP::register_class(vm, mod); + PlainOldData::register_class(vm, mod); +} + } // namespace pkpy \ No newline at end of file