From b78722dac0a94faf96ad443b5e3031d18b1cdfd9 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Fri, 29 Sep 2023 20:20:17 +0800 Subject: [PATCH] ... --- include/pocketpy/cffi.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/pocketpy/cffi.h b/include/pocketpy/cffi.h index 9fafb79f..0cbe409b 100644 --- a/include/pocketpy/cffi.h +++ b/include/pocketpy/cffi.h @@ -59,6 +59,31 @@ inline PyObject* py_var(VM* vm, const void* p){ return VAR_T(VoidP, p); } +#define POINTER_VAR(Tp, NAME) \ + inline PyObject* py_var(VM* vm, Tp val){ \ + const static std::pair P("c", NAME); \ + PyObject* type = vm->_modules[P.first]->attr(P.second); \ + return vm->heap.gcnew(PK_OBJ_GET(Type, type), val); \ + } + +// POINTER_VAR(char*, "char_p") +// const char* is special, need to rethink about it +POINTER_VAR(const unsigned char*, "uchar_p") +POINTER_VAR(const short*, "short_p") +POINTER_VAR(const unsigned short*, "ushort_p") +POINTER_VAR(const int*, "int_p") +POINTER_VAR(const unsigned int*, "uint_p") +POINTER_VAR(const long*, "long_p") +POINTER_VAR(const unsigned long*, "ulong_p") +POINTER_VAR(const long long*, "longlong_p") +POINTER_VAR(const unsigned long long*, "ulonglong_p") +POINTER_VAR(const float*, "float_p") +POINTER_VAR(const double*, "double_p") +POINTER_VAR(const bool*, "bool_p") + +#undef POINTER_VAR + + struct C99Struct{ PY_CLASS(C99Struct, c, struct)