|
|
@@ -123,14 +123,15 @@ PK_API void py_resetallvm();
|
|
|
PK_API void* py_getvmctx();
|
|
|
/// Set the current VM context. This is used for user-defined data.
|
|
|
PK_API void py_setvmctx(void* ctx);
|
|
|
+/// Setup the callbacks for the current VM.
|
|
|
+PK_API py_Callbacks* py_callbacks();
|
|
|
+
|
|
|
/// Set `sys.argv`. Used for storing command-line arguments.
|
|
|
PK_API void py_sys_setargv(int argc, char** argv);
|
|
|
/// Set the trace function for the current VM.
|
|
|
PK_API void py_sys_settrace(py_TraceFunc func, bool reset);
|
|
|
/// Invoke the garbage collector.
|
|
|
PK_API int py_gc_collect();
|
|
|
-/// Setup the callbacks for the current VM.
|
|
|
-PK_API py_Callbacks* py_callbacks();
|
|
|
|
|
|
/// Wrapper for `PK_MALLOC(size)`.
|
|
|
PK_API void* py_malloc(size_t size);
|
|
|
@@ -139,18 +140,16 @@ PK_API void* py_realloc(void* ptr, size_t size);
|
|
|
/// Wrapper for `PK_FREE(ptr)`.
|
|
|
PK_API void py_free(void* ptr);
|
|
|
|
|
|
-/// Begin the watchdog with `timeout` in milliseconds.
|
|
|
-/// `PK_ENABLE_WATCHDOG` must be defined to `1` to use this feature.
|
|
|
-/// You need to call `py_watchdog_end()` later.
|
|
|
-/// If `timeout` is reached, `TimeoutError` will be raised.
|
|
|
-PK_API void py_watchdog_begin(py_i64 timeout);
|
|
|
-/// Reset the watchdog.
|
|
|
-PK_API void py_watchdog_end();
|
|
|
+/// A shorthand for `True`.
|
|
|
+PK_API py_GlobalRef py_True();
|
|
|
+/// A shorthand for `False`.
|
|
|
+PK_API py_GlobalRef py_False();
|
|
|
+/// A shorthand for `None`.
|
|
|
+PK_API py_GlobalRef py_None();
|
|
|
+/// A shorthand for `nil`. `nil` is not a valid python object.
|
|
|
+PK_API py_GlobalRef py_NIL();
|
|
|
|
|
|
-/// Bind a compile-time function via "decl-based" style.
|
|
|
-PK_API void py_macrobind(const char* sig, py_CFunction f);
|
|
|
-/// Get a compile-time function by name.
|
|
|
-PK_API py_ItemRef py_macroget(py_Name name);
|
|
|
+/************* Frame Ops *************/
|
|
|
|
|
|
/// Get the current source location of the frame.
|
|
|
PK_API const char* py_Frame_sourceloc(py_Frame* frame, int* lineno);
|
|
|
@@ -162,6 +161,14 @@ PK_API void py_Frame_newlocals(py_Frame* frame, py_OutRef out);
|
|
|
/// Returns `NULL` if not available.
|
|
|
PK_API py_StackRef py_Frame_function(py_Frame* frame);
|
|
|
|
|
|
+/************* Code Execution *************/
|
|
|
+
|
|
|
+/// Compile a source string into a code object.
|
|
|
+/// Use python's `exec()` or `eval()` to execute it.
|
|
|
+PK_API bool py_compile(const char* source,
|
|
|
+ const char* filename,
|
|
|
+ enum py_CompileMode mode,
|
|
|
+ bool is_dynamic) PY_RAISE PY_RETURN;
|
|
|
/// Run a source string.
|
|
|
/// @param source source string.
|
|
|
/// @param filename filename (for error messages).
|
|
|
@@ -172,10 +179,8 @@ PK_API bool py_exec(const char* source,
|
|
|
const char* filename,
|
|
|
enum py_CompileMode mode,
|
|
|
py_Ref module) PY_RAISE PY_RETURN;
|
|
|
-
|
|
|
/// Evaluate a source string. Equivalent to `py_exec(source, "<string>", EVAL_MODE, module)`.
|
|
|
PK_API bool py_eval(const char* source, py_Ref module) PY_RAISE PY_RETURN;
|
|
|
-
|
|
|
/// Run a source string with smart interpretation.
|
|
|
/// Example:
|
|
|
/// `py_newstr(py_r0(), "abc");`
|
|
|
@@ -191,28 +196,7 @@ PK_API bool py_smartexec(const char* source, py_Ref module, ...) PY_RAISE PY_RET
|
|
|
/// `// res will be 3`.
|
|
|
PK_API bool py_smarteval(const char* source, py_Ref module, ...) PY_RAISE PY_RETURN;
|
|
|
|
|
|
-/// Compile a source string into a code object.
|
|
|
-/// Use python's `exec()` or `eval()` to execute it.
|
|
|
-PK_API bool py_compile(const char* source,
|
|
|
- const char* filename,
|
|
|
- enum py_CompileMode mode,
|
|
|
- bool is_dynamic) PY_RAISE PY_RETURN;
|
|
|
-
|
|
|
-/// Python equivalent to `globals()`.
|
|
|
-PK_API void py_newglobals(py_OutRef);
|
|
|
-/// Python equivalent to `locals()`.
|
|
|
-PK_API void py_newlocals(py_OutRef);
|
|
|
-
|
|
|
-/************* Values Creation *************/
|
|
|
-
|
|
|
-/// A shorthand for `True`.
|
|
|
-PK_API py_GlobalRef py_True();
|
|
|
-/// A shorthand for `False`.
|
|
|
-PK_API py_GlobalRef py_False();
|
|
|
-/// A shorthand for `None`.
|
|
|
-PK_API py_GlobalRef py_None();
|
|
|
-/// A shorthand for `nil`. `nil` is not a valid python object.
|
|
|
-PK_API py_GlobalRef py_NIL();
|
|
|
+/************* Value Creation *************/
|
|
|
|
|
|
/// Create an `int` object.
|
|
|
PK_API void py_newint(py_OutRef, py_i64);
|
|
|
@@ -241,19 +225,6 @@ PK_API void py_newellipsis(py_OutRef);
|
|
|
/// Create a `nil` object. `nil` is an invalid representation of an object.
|
|
|
/// Don't use it unless you know what you are doing.
|
|
|
PK_API void py_newnil(py_OutRef);
|
|
|
-/// Create a `tuple` with `n` UNINITIALIZED elements.
|
|
|
-/// You should initialize all elements before using it.
|
|
|
-PK_API py_ObjectRef py_newtuple(py_OutRef, int n);
|
|
|
-/// Create an empty `list`.
|
|
|
-PK_API void py_newlist(py_OutRef);
|
|
|
-/// Create a `list` with `n` UNINITIALIZED elements.
|
|
|
-/// You should initialize all elements before using it.
|
|
|
-PK_API void py_newlistn(py_OutRef, int n);
|
|
|
-/// Create an empty `dict`.
|
|
|
-PK_API void py_newdict(py_OutRef);
|
|
|
-/// Create an UNINITIALIZED `slice` object.
|
|
|
-/// You should use `py_setslot()` to set `start`, `stop`, and `step`.
|
|
|
-PK_API void py_newslice(py_OutRef);
|
|
|
/// Create a `nativefunc` object.
|
|
|
PK_API void py_newnativefunc(py_OutRef, py_CFunction);
|
|
|
/// Create a `function` object.
|
|
|
@@ -264,8 +235,15 @@ PK_API py_Name py_newfunction(py_OutRef out,
|
|
|
int slots);
|
|
|
/// Create a `boundmethod` object.
|
|
|
PK_API void py_newboundmethod(py_OutRef out, py_Ref self, py_Ref func);
|
|
|
+/// Create a new object.
|
|
|
+/// @param out output reference.
|
|
|
+/// @param type type of the object.
|
|
|
+/// @param slots number of slots. Use `-1` to create a `__dict__`.
|
|
|
+/// @param udsize size of your userdata.
|
|
|
+/// @return pointer to the userdata.
|
|
|
+PK_API void* py_newobject(py_OutRef out, py_Type type, int slots, int udsize);
|
|
|
|
|
|
-/************* Name Conversions *************/
|
|
|
+/************* Name Conversion *************/
|
|
|
|
|
|
/// Convert a null-terminated string to a name.
|
|
|
PK_API py_Name py_name(const char*);
|
|
|
@@ -278,28 +256,47 @@ PK_API py_Name py_namev(c11_sv);
|
|
|
/// Convert a name to a `c11_sv`.
|
|
|
PK_API c11_sv py_name2sv(py_Name);
|
|
|
|
|
|
-/************* Meta Operations *************/
|
|
|
-
|
|
|
-/// Create a new type.
|
|
|
-/// @param name name of the type.
|
|
|
-/// @param base base type.
|
|
|
-/// @param module module where the type is defined. Use `NULL` for built-in types.
|
|
|
-/// @param dtor destructor function. Use `NULL` if not needed.
|
|
|
-PK_API py_Type py_newtype(const char* name, py_Type base, const py_GlobalRef module, py_Dtor dtor);
|
|
|
+/************* Bindings *************/
|
|
|
|
|
|
-/// Create a new object.
|
|
|
-/// @param out output reference.
|
|
|
-/// @param type type of the object.
|
|
|
-/// @param slots number of slots. Use `-1` to create a `__dict__`.
|
|
|
-/// @param udsize size of your userdata.
|
|
|
-/// @return pointer to the userdata.
|
|
|
-PK_API void* py_newobject(py_OutRef out, py_Type type, int slots, int udsize);
|
|
|
+/// Bind a function to the object via "decl-based" style.
|
|
|
+/// @param obj the target object.
|
|
|
+/// @param sig signature of the function. e.g. `add(x, y)`.
|
|
|
+/// @param f function to bind.
|
|
|
+PK_API void py_bind(py_Ref obj, const char* sig, py_CFunction f);
|
|
|
+/// Bind a method to type via "argc-based" style.
|
|
|
+/// @param type the target type.
|
|
|
+/// @param name name of the method.
|
|
|
+/// @param f function to bind.
|
|
|
+PK_API void py_bindmethod(py_Type type, const char* name, py_CFunction f);
|
|
|
+/// Bind a static method to type via "argc-based" style.
|
|
|
+/// @param type the target type.
|
|
|
+/// @param name name of the method.
|
|
|
+/// @param f function to bind.
|
|
|
+PK_API void py_bindstaticmethod(py_Type type, const char* name, py_CFunction f);
|
|
|
+/// Bind a function to the object via "argc-based" style.
|
|
|
+/// @param obj the target object.
|
|
|
+/// @param name name of the function.
|
|
|
+/// @param f function to bind.
|
|
|
+PK_API void py_bindfunc(py_Ref obj, const char* name, py_CFunction f);
|
|
|
+/// Bind a property to type.
|
|
|
+/// @param type the target type.
|
|
|
+/// @param name name of the property.
|
|
|
+/// @param getter getter function.
|
|
|
+/// @param setter setter function. Use `NULL` if not needed.
|
|
|
+PK_API void
|
|
|
+ py_bindproperty(py_Type type, const char* name, py_CFunction getter, py_CFunction setter);
|
|
|
+/// Bind a magic method to type.
|
|
|
+PK_API void py_bindmagic(py_Type type, py_Name name, py_CFunction f);
|
|
|
+/// Bind a compile-time function via "decl-based" style.
|
|
|
+PK_API void py_macrobind(const char* sig, py_CFunction f);
|
|
|
+/// Get a compile-time function by name.
|
|
|
+PK_API py_ItemRef py_macroget(py_Name name);
|
|
|
|
|
|
-/************* Type Cast *************/
|
|
|
+/************* Value Cast *************/
|
|
|
|
|
|
/// Convert an `int` object in python to `int64_t`.
|
|
|
PK_API py_i64 py_toint(py_Ref);
|
|
|
-/// Get the address of the trivial value object.
|
|
|
+/// Get the address of the trivial value object (16 bytes).
|
|
|
PK_API void* py_totrivial(py_Ref);
|
|
|
/// Convert a `float` object in python to `double`.
|
|
|
PK_API py_f64 py_tofloat(py_Ref);
|
|
|
@@ -315,6 +312,8 @@ PK_API bool py_castint(py_Ref, py_i64* out) PY_RAISE;
|
|
|
PK_API bool py_tobool(py_Ref);
|
|
|
/// Convert a `type` object in python to `py_Type`.
|
|
|
PK_API py_Type py_totype(py_Ref);
|
|
|
+/// Convert a user-defined object to its userdata.
|
|
|
+PK_API void* py_touserdata(py_Ref);
|
|
|
/// Convert a `str` object in python to null-terminated string.
|
|
|
PK_API const char* py_tostr(py_Ref);
|
|
|
/// Convert a `str` object in python to char array.
|
|
|
@@ -325,32 +324,32 @@ PK_API c11_sv py_tosv(py_Ref);
|
|
|
PK_API unsigned char* py_tobytes(py_Ref, int* size);
|
|
|
/// Resize a `bytes` object. It can only be resized down.
|
|
|
PK_API void py_bytes_resize(py_Ref, int size);
|
|
|
-/// Convert a user-defined object to its userdata.
|
|
|
-PK_API void* py_touserdata(py_Ref);
|
|
|
-
|
|
|
-#define py_isint(self) py_istype(self, tp_int)
|
|
|
-#define py_isfloat(self) py_istype(self, tp_float)
|
|
|
-#define py_isbool(self) py_istype(self, tp_bool)
|
|
|
-#define py_isstr(self) py_istype(self, tp_str)
|
|
|
-#define py_islist(self) py_istype(self, tp_list)
|
|
|
-#define py_istuple(self) py_istype(self, tp_tuple)
|
|
|
-#define py_isdict(self) py_istype(self, tp_dict)
|
|
|
|
|
|
-#define py_isnil(self) py_istype(self, 0)
|
|
|
-#define py_isnone(self) py_istype(self, tp_NoneType)
|
|
|
+/************* Type System *************/
|
|
|
|
|
|
-/// Get the type of the object.
|
|
|
-PK_API py_Type py_typeof(py_Ref self);
|
|
|
-/// Get type by module and name. e.g. `py_gettype("time", py_name("struct_time"))`.
|
|
|
-/// Return `0` if not found.
|
|
|
-PK_API py_Type py_gettype(const char* module, py_Name name);
|
|
|
+/// Create a new type.
|
|
|
+/// @param name name of the type.
|
|
|
+/// @param base base type.
|
|
|
+/// @param module module where the type is defined. Use `NULL` for built-in types.
|
|
|
+/// @param dtor destructor function. Use `NULL` if not needed.
|
|
|
+PK_API py_Type py_newtype(const char* name, py_Type base, const py_GlobalRef module, py_Dtor dtor);
|
|
|
/// Check if the object is exactly the given type.
|
|
|
PK_API bool py_istype(py_Ref, py_Type);
|
|
|
+/// Get the type of the object.
|
|
|
+PK_API py_Type py_typeof(py_Ref self);
|
|
|
/// Check if the object is an instance of the given type.
|
|
|
PK_API bool py_isinstance(py_Ref obj, py_Type type);
|
|
|
/// Check if the derived type is a subclass of the base type.
|
|
|
PK_API bool py_issubclass(py_Type derived, py_Type base);
|
|
|
-
|
|
|
+/// Get type by module and name. e.g. `py_gettype("time", py_name("struct_time"))`.
|
|
|
+/// Return `0` if not found.
|
|
|
+PK_API py_Type py_gettype(const char* module, py_Name name);
|
|
|
+/// Check if the object is an instance of the given type exactly.
|
|
|
+/// Raise `TypeError` if the check fails.
|
|
|
+PK_API bool py_checktype(py_Ref self, py_Type type) PY_RAISE;
|
|
|
+/// Check if the object is an instance of the given type or its subclass.
|
|
|
+/// Raise `TypeError` if the check fails.
|
|
|
+PK_API bool py_checkinstance(py_Ref self, py_Type type) PY_RAISE;
|
|
|
/// Get the magic method from the given type only.
|
|
|
/// Return `nil` if not found.
|
|
|
PK_API PK_DEPRECATED py_GlobalRef py_tpgetmagic(py_Type type, py_Name name);
|
|
|
@@ -362,13 +361,10 @@ PK_API py_GlobalRef py_tpfindmagic(py_Type, py_Name name);
|
|
|
PK_API py_ItemRef py_tpfindname(py_Type, py_Name name);
|
|
|
/// Get the base type of the given type.
|
|
|
PK_API py_Type py_tpbase(py_Type type);
|
|
|
-
|
|
|
/// Get the type object of the given type.
|
|
|
PK_API py_GlobalRef py_tpobject(py_Type type);
|
|
|
/// Get the type name.
|
|
|
PK_API const char* py_tpname(py_Type type);
|
|
|
-/// Call a type to create a new instance.
|
|
|
-PK_API bool py_tpcall(py_Type type, int argc, py_Ref argv) PY_RAISE PY_RETURN;
|
|
|
/// Disable the type for subclassing.
|
|
|
PK_API void py_tpsetfinal(py_Type type);
|
|
|
/// Set attribute hooks for the given type.
|
|
|
@@ -379,26 +375,48 @@ PK_API void py_tphookattributes(py_Type type,
|
|
|
bool (*delattribute)(py_Ref self, py_Name name) PY_RAISE,
|
|
|
bool (*getunboundmethod)(py_Ref self, py_Name name) PY_RETURN);
|
|
|
|
|
|
-/// Check if the object is an instance of the given type exactly.
|
|
|
-/// Raise `TypeError` if the check fails.
|
|
|
-PK_API bool py_checktype(py_Ref self, py_Type type) PY_RAISE;
|
|
|
-
|
|
|
-/// Check if the object is an instance of the given type or its subclass.
|
|
|
-/// Raise `TypeError` if the check fails.
|
|
|
-PK_API bool py_checkinstance(py_Ref self, py_Type type) PY_RAISE;
|
|
|
+#define py_isint(self) py_istype(self, tp_int)
|
|
|
+#define py_isfloat(self) py_istype(self, tp_float)
|
|
|
+#define py_isbool(self) py_istype(self, tp_bool)
|
|
|
+#define py_isstr(self) py_istype(self, tp_str)
|
|
|
+#define py_islist(self) py_istype(self, tp_list)
|
|
|
+#define py_istuple(self) py_istype(self, tp_tuple)
|
|
|
+#define py_isdict(self) py_istype(self, tp_dict)
|
|
|
+#define py_isnil(self) py_istype(self, 0)
|
|
|
+#define py_isnone(self) py_istype(self, tp_NoneType)
|
|
|
|
|
|
#define py_checkint(self) py_checktype(self, tp_int)
|
|
|
#define py_checkfloat(self) py_checktype(self, tp_float)
|
|
|
#define py_checkbool(self) py_checktype(self, tp_bool)
|
|
|
#define py_checkstr(self) py_checktype(self, tp_str)
|
|
|
|
|
|
-/************* References *************/
|
|
|
+/************* Inspection *************/
|
|
|
+
|
|
|
+/// Get the current `function` object on the stack.
|
|
|
+/// Return `NULL` if not available.
|
|
|
+/// NOTE: This function should be placed at the beginning of your decl-based bindings.
|
|
|
+PK_API py_StackRef py_inspect_currentfunction();
|
|
|
+/// Get the current `module` object where the code is executed.
|
|
|
+/// Return `NULL` if not available.
|
|
|
+PK_API py_GlobalRef py_inspect_currentmodule();
|
|
|
+/// Get the current frame object.
|
|
|
+/// Return `NULL` if not available.
|
|
|
+PK_API py_Frame* py_inspect_currentframe();
|
|
|
+/// Python equivalent to `globals()`.
|
|
|
+PK_API void py_newglobals(py_OutRef);
|
|
|
+/// Python equivalent to `locals()`.
|
|
|
+PK_API void py_newlocals(py_OutRef);
|
|
|
+
|
|
|
+/************* Dict & Slots *************/
|
|
|
|
|
|
/// Get the i-th register.
|
|
|
/// All registers are located in a contiguous memory.
|
|
|
PK_API py_GlobalRef py_getreg(int i);
|
|
|
/// Set the i-th register.
|
|
|
PK_API void py_setreg(int i, py_Ref val);
|
|
|
+/// Get the last return value.
|
|
|
+/// Please note that `py_retval()` cannot be used as input argument.
|
|
|
+PK_API py_GlobalRef py_retval();
|
|
|
|
|
|
#define py_r0() py_getreg(0)
|
|
|
#define py_r1() py_getreg(1)
|
|
|
@@ -409,17 +427,6 @@ PK_API void py_setreg(int i, py_Ref val);
|
|
|
#define py_r6() py_getreg(6)
|
|
|
#define py_r7() py_getreg(7)
|
|
|
|
|
|
-/// Get variable in the `__main__` module.
|
|
|
-PK_API py_ItemRef py_getglobal(py_Name name);
|
|
|
-/// Set variable in the `__main__` module.
|
|
|
-PK_API void py_setglobal(py_Name name, py_Ref val);
|
|
|
-/// Get variable in the `builtins` module.
|
|
|
-PK_API py_ItemRef py_getbuiltin(py_Name name);
|
|
|
-
|
|
|
-/// Get the last return value.
|
|
|
-/// Please note that `py_retval()` cannot be used as input argument.
|
|
|
-PK_API py_GlobalRef py_retval();
|
|
|
-
|
|
|
/// Get an item from the object's `__dict__`.
|
|
|
/// Return `NULL` if not found.
|
|
|
PK_API py_ItemRef py_getdict(py_Ref self, py_Name name);
|
|
|
@@ -437,56 +444,68 @@ PK_API bool
|
|
|
py_applydict(py_Ref self, bool (*f)(py_Name name, py_Ref val, void* ctx), void* ctx) PY_RAISE;
|
|
|
/// Clear the object's `__dict__`. This function is dangerous.
|
|
|
PK_API void py_cleardict(py_Ref self);
|
|
|
-
|
|
|
/// Get the i-th slot of the object.
|
|
|
/// The object must have slots and `i` must be in valid range.
|
|
|
PK_API py_ObjectRef py_getslot(py_Ref self, int i);
|
|
|
/// Set the i-th slot of the object.
|
|
|
PK_API void py_setslot(py_Ref self, int i, py_Ref val);
|
|
|
+/// Get variable in the `builtins` module.
|
|
|
+PK_API py_ItemRef py_getbuiltin(py_Name name);
|
|
|
+/// Get variable in the `__main__` module.
|
|
|
+PK_API py_ItemRef py_getglobal(py_Name name);
|
|
|
+/// Set variable in the `__main__` module.
|
|
|
+PK_API void py_setglobal(py_Name name, py_Ref val);
|
|
|
|
|
|
-/************* Inspection *************/
|
|
|
-
|
|
|
-/// Get the current `function` object on the stack.
|
|
|
-/// Return `NULL` if not available.
|
|
|
-/// NOTE: This function should be placed at the beginning of your decl-based bindings.
|
|
|
-PK_API py_StackRef py_inspect_currentfunction();
|
|
|
-/// Get the current `module` object where the code is executed.
|
|
|
-/// Return `NULL` if not available.
|
|
|
-PK_API py_GlobalRef py_inspect_currentmodule();
|
|
|
-/// Get the current frame object.
|
|
|
-/// Return `NULL` if not available.
|
|
|
-PK_API py_Frame* py_inspect_currentframe();
|
|
|
-/************* Bindings *************/
|
|
|
+/************* Stack Ops *************/
|
|
|
|
|
|
-/// Bind a function to the object via "decl-based" style.
|
|
|
-/// @param obj the target object.
|
|
|
-/// @param sig signature of the function. e.g. `add(x, y)`.
|
|
|
-/// @param f function to bind.
|
|
|
-PK_API void py_bind(py_Ref obj, const char* sig, py_CFunction f);
|
|
|
-/// Bind a method to type via "argc-based" style.
|
|
|
-/// @param type the target type.
|
|
|
-/// @param name name of the method.
|
|
|
-/// @param f function to bind.
|
|
|
-PK_API void py_bindmethod(py_Type type, const char* name, py_CFunction f);
|
|
|
-/// Bind a static method to type via "argc-based" style.
|
|
|
-/// @param type the target type.
|
|
|
-/// @param name name of the method.
|
|
|
-/// @param f function to bind.
|
|
|
-PK_API void py_bindstaticmethod(py_Type type, const char* name, py_CFunction f);
|
|
|
-/// Bind a function to the object via "argc-based" style.
|
|
|
-/// @param obj the target object.
|
|
|
-/// @param name name of the function.
|
|
|
-/// @param f function to bind.
|
|
|
-PK_API void py_bindfunc(py_Ref obj, const char* name, py_CFunction f);
|
|
|
-/// Bind a property to type.
|
|
|
-/// @param type the target type.
|
|
|
-/// @param name name of the property.
|
|
|
-/// @param getter getter function.
|
|
|
-/// @param setter setter function. Use `NULL` if not needed.
|
|
|
-PK_API void
|
|
|
- py_bindproperty(py_Type type, const char* name, py_CFunction getter, py_CFunction setter);
|
|
|
-/// Bind a magic method to type.
|
|
|
-PK_API void py_bindmagic(py_Type type, py_Name name, py_CFunction f);
|
|
|
+/// Get the i-th object from the top of the stack.
|
|
|
+/// `i` should be negative, e.g. (-1) means TOS.
|
|
|
+PK_API py_StackRef py_peek(int i);
|
|
|
+/// Push the object to the stack.
|
|
|
+PK_API void py_push(py_Ref src);
|
|
|
+/// Push a `nil` object to the stack.
|
|
|
+PK_API void py_pushnil();
|
|
|
+/// Push a `None` object to the stack.
|
|
|
+PK_API void py_pushnone();
|
|
|
+/// Push a `py_Name` to the stack. This is used for keyword arguments.
|
|
|
+PK_API void py_pushname(py_Name name);
|
|
|
+/// Pop an object from the stack.
|
|
|
+PK_API void py_pop();
|
|
|
+/// Shrink the stack by n.
|
|
|
+PK_API void py_shrink(int n);
|
|
|
+/// Get a temporary variable from the stack.
|
|
|
+PK_API py_StackRef py_pushtmp();
|
|
|
+/// Get the unbound method of the object.
|
|
|
+/// Assume the object is located at the top of the stack.
|
|
|
+/// If return true: `[self] -> [unbound, self]`.
|
|
|
+/// If return false: `[self] -> [self]` (no change).
|
|
|
+PK_API bool py_pushmethod(py_Name name);
|
|
|
+/// Evaluate an expression and push the result to the stack.
|
|
|
+/// This function is used for testing.
|
|
|
+PK_API bool py_pusheval(const char* expr, py_GlobalRef module) PY_RAISE;
|
|
|
+/// Call a callable object via pocketpy's calling convention.
|
|
|
+/// You need to prepare the stack using the following format:
|
|
|
+/// `callable, self/nil, arg1, arg2, ..., k1, v1, k2, v2, ...`.
|
|
|
+/// `argc` is the number of positional arguments excluding `self`.
|
|
|
+/// `kwargc` is the number of keyword arguments.
|
|
|
+/// The result will be set to `py_retval()`.
|
|
|
+/// The stack size will be reduced by `2 + argc + kwargc * 2`.
|
|
|
+PK_API bool py_vectorcall(uint16_t argc, uint16_t kwargc) PY_RAISE PY_RETURN;
|
|
|
+/// Call a function.
|
|
|
+/// It prepares the stack and then performs a `vectorcall(argc, 0, false)`.
|
|
|
+/// The result will be set to `py_retval()`.
|
|
|
+/// The stack remains unchanged if successful.
|
|
|
+PK_API bool py_call(py_Ref f, int argc, py_Ref argv) PY_RAISE PY_RETURN;
|
|
|
+/// Call a type to create a new instance.
|
|
|
+PK_API bool py_tpcall(py_Type type, int argc, py_Ref argv) PY_RAISE PY_RETURN;
|
|
|
+
|
|
|
+#ifndef NDEBUG
|
|
|
+/// Call a `py_CFunction` in a safe way.
|
|
|
+/// This function does extra checks to help you debug `py_CFunction`.
|
|
|
+PK_API bool py_callcfunc(py_CFunction f, int argc, py_Ref argv) PY_RAISE PY_RETURN;
|
|
|
+#else
|
|
|
+#define py_callcfunc(f, argc, argv) (f((argc), (argv)))
|
|
|
+#endif
|
|
|
|
|
|
#define PY_CHECK_ARGC(n) \
|
|
|
if(argc != n) return TypeError("expected %d arguments, got %d", n, argc)
|
|
|
@@ -498,25 +517,13 @@ PK_API void py_bindmagic(py_Type type, py_Name name, py_CFunction f);
|
|
|
#define py_arg(i) (&argv[i])
|
|
|
#define py_assign(dst, src) *(dst) = *(src)
|
|
|
|
|
|
-/************* Python Equivalents *************/
|
|
|
-
|
|
|
-/// Python equivalent to `getattr(self, name)`.
|
|
|
-PK_API bool py_getattr(py_Ref self, py_Name name) PY_RAISE PY_RETURN;
|
|
|
-/// Python equivalent to `setattr(self, name, val)`.
|
|
|
-PK_API bool py_setattr(py_Ref self, py_Name name, py_Ref val) PY_RAISE;
|
|
|
-/// Python equivalent to `delattr(self, name)`.
|
|
|
-PK_API bool py_delattr(py_Ref self, py_Name name) PY_RAISE;
|
|
|
-/// Python equivalent to `self[key]`.
|
|
|
-PK_API bool py_getitem(py_Ref self, py_Ref key) PY_RAISE PY_RETURN;
|
|
|
-/// Python equivalent to `self[key] = val`.
|
|
|
-PK_API bool py_setitem(py_Ref self, py_Ref key, py_Ref val) PY_RAISE;
|
|
|
-/// Python equivalent to `del self[key]`.
|
|
|
-PK_API bool py_delitem(py_Ref self, py_Ref key) PY_RAISE;
|
|
|
-
|
|
|
/// Perform a binary operation.
|
|
|
/// The result will be set to `py_retval()`.
|
|
|
/// The stack remains unchanged after the operation.
|
|
|
PK_API bool py_binaryop(py_Ref lhs, py_Ref rhs, py_Name op, py_Name rop) PY_RAISE PY_RETURN;
|
|
|
+
|
|
|
+/************* Python Ops *************/
|
|
|
+
|
|
|
/// lhs + rhs
|
|
|
PK_API bool py_binaryadd(py_Ref lhs, py_Ref rhs) PY_RAISE PY_RETURN;
|
|
|
/// lhs - rhs
|
|
|
@@ -543,68 +550,74 @@ PK_API bool py_binaryor(py_Ref lhs, py_Ref rhs) PY_RAISE PY_RETURN;
|
|
|
PK_API bool py_binaryxor(py_Ref lhs, py_Ref rhs) PY_RAISE PY_RETURN;
|
|
|
/// lhs @ rhs
|
|
|
PK_API bool py_binarymatmul(py_Ref lhs, py_Ref rhs) PY_RAISE PY_RETURN;
|
|
|
+/// lhs == rhs
|
|
|
+PK_API bool py_eq(py_Ref lhs, py_Ref rhs) PY_RAISE PY_RETURN;
|
|
|
+/// lhs != rhs
|
|
|
+PK_API bool py_ne(py_Ref lhs, py_Ref rhs) PY_RAISE PY_RETURN;
|
|
|
+/// lhs < rhs
|
|
|
+PK_API bool py_lt(py_Ref lhs, py_Ref rhs) PY_RAISE PY_RETURN;
|
|
|
+/// lhs <= rhs
|
|
|
+PK_API bool py_le(py_Ref lhs, py_Ref rhs) PY_RAISE PY_RETURN;
|
|
|
+/// lhs > rhs
|
|
|
+PK_API bool py_gt(py_Ref lhs, py_Ref rhs) PY_RAISE PY_RETURN;
|
|
|
+/// lhs >= rhs
|
|
|
+PK_API bool py_ge(py_Ref lhs, py_Ref rhs) PY_RAISE PY_RETURN;
|
|
|
|
|
|
-/************* Stack Operations *************/
|
|
|
+/// Python equivalent to `lhs is rhs`.
|
|
|
+PK_API bool py_isidentical(py_Ref, py_Ref);
|
|
|
+/// Python equivalent to `bool(val)`.
|
|
|
+/// 1: true, 0: false, -1: error
|
|
|
+PK_API int py_bool(py_Ref val) PY_RAISE;
|
|
|
+/// Compare two objects.
|
|
|
+/// 1: lhs == rhs, 0: lhs != rhs, -1: error
|
|
|
+PK_API int py_equal(py_Ref lhs, py_Ref rhs) PY_RAISE;
|
|
|
+/// Compare two objects.
|
|
|
+/// 1: lhs < rhs, 0: lhs >= rhs, -1: error
|
|
|
+PK_API int py_less(py_Ref lhs, py_Ref rhs) PY_RAISE;
|
|
|
+/// Python equivalent to `callable(val)`.
|
|
|
+PK_API bool py_callable(py_Ref val);
|
|
|
+/// Get the hash value of the object.
|
|
|
+PK_API bool py_hash(py_Ref, py_i64* out) PY_RAISE;
|
|
|
+/// Get the iterator of the object.
|
|
|
+PK_API bool py_iter(py_Ref) PY_RAISE PY_RETURN;
|
|
|
+/// Get the next element from the iterator.
|
|
|
+/// 1: success, 0: StopIteration, -1: error
|
|
|
+PK_API int py_next(py_Ref) PY_RAISE PY_RETURN;
|
|
|
+/// Python equivalent to `str(val)`.
|
|
|
+PK_API bool py_str(py_Ref val) PY_RAISE PY_RETURN;
|
|
|
+/// Python equivalent to `repr(val)`.
|
|
|
+PK_API bool py_repr(py_Ref val) PY_RAISE PY_RETURN;
|
|
|
+/// Python equivalent to `len(val)`.
|
|
|
+PK_API bool py_len(py_Ref val) PY_RAISE PY_RETURN;
|
|
|
|
|
|
-/// Get the i-th object from the top of the stack.
|
|
|
-/// `i` should be negative, e.g. (-1) means TOS.
|
|
|
-PK_API py_StackRef py_peek(int i);
|
|
|
-/// Push the object to the stack.
|
|
|
-PK_API void py_push(py_Ref src);
|
|
|
-/// Push a `nil` object to the stack.
|
|
|
-PK_API void py_pushnil();
|
|
|
-/// Push a `None` object to the stack.
|
|
|
-PK_API void py_pushnone();
|
|
|
-/// Push a `py_Name` to the stack. This is used for keyword arguments.
|
|
|
-PK_API void py_pushname(py_Name name);
|
|
|
-/// Pop an object from the stack.
|
|
|
-PK_API void py_pop();
|
|
|
-/// Shrink the stack by n.
|
|
|
-PK_API void py_shrink(int n);
|
|
|
-/// Get a temporary variable from the stack.
|
|
|
-PK_API py_StackRef py_pushtmp();
|
|
|
-/// Get the unbound method of the object.
|
|
|
-/// Assume the object is located at the top of the stack.
|
|
|
-/// If return true: `[self] -> [unbound, self]`.
|
|
|
-/// If return false: `[self] -> [self]` (no change).
|
|
|
-PK_API bool py_pushmethod(py_Name name);
|
|
|
-/// Call a callable object via pocketpy's calling convention.
|
|
|
-/// You need to prepare the stack using the following format:
|
|
|
-/// `callable, self/nil, arg1, arg2, ..., k1, v1, k2, v2, ...`.
|
|
|
-/// `argc` is the number of positional arguments excluding `self`.
|
|
|
-/// `kwargc` is the number of keyword arguments.
|
|
|
-/// The result will be set to `py_retval()`.
|
|
|
-/// The stack size will be reduced by `2 + argc + kwargc * 2`.
|
|
|
-PK_API bool py_vectorcall(uint16_t argc, uint16_t kwargc) PY_RAISE PY_RETURN;
|
|
|
-/// Evaluate an expression and push the result to the stack.
|
|
|
-/// This function is used for testing.
|
|
|
-PK_API bool py_pusheval(const char* expr, py_GlobalRef module) PY_RAISE;
|
|
|
+/// Python equivalent to `getattr(self, name)`.
|
|
|
+PK_API bool py_getattr(py_Ref self, py_Name name) PY_RAISE PY_RETURN;
|
|
|
+/// Python equivalent to `setattr(self, name, val)`.
|
|
|
+PK_API bool py_setattr(py_Ref self, py_Name name, py_Ref val) PY_RAISE;
|
|
|
+/// Python equivalent to `delattr(self, name)`.
|
|
|
+PK_API bool py_delattr(py_Ref self, py_Name name) PY_RAISE;
|
|
|
+/// Python equivalent to `self[key]`.
|
|
|
+PK_API bool py_getitem(py_Ref self, py_Ref key) PY_RAISE PY_RETURN;
|
|
|
+/// Python equivalent to `self[key] = val`.
|
|
|
+PK_API bool py_setitem(py_Ref self, py_Ref key, py_Ref val) PY_RAISE;
|
|
|
+/// Python equivalent to `del self[key]`.
|
|
|
+PK_API bool py_delitem(py_Ref self, py_Ref key) PY_RAISE;
|
|
|
|
|
|
-/************* Modules *************/
|
|
|
+/************* Module System *************/
|
|
|
|
|
|
-/// Create a new module.
|
|
|
-PK_API py_GlobalRef py_newmodule(const char* path);
|
|
|
/// Get a module by path.
|
|
|
PK_API py_GlobalRef py_getmodule(const char* path);
|
|
|
+/// Create a new module.
|
|
|
+PK_API py_GlobalRef py_newmodule(const char* path);
|
|
|
/// Reload an existing module.
|
|
|
PK_API bool py_importlib_reload(py_Ref module) PY_RAISE PY_RETURN;
|
|
|
-
|
|
|
/// Import a module.
|
|
|
/// The result will be set to `py_retval()`.
|
|
|
/// -1: error, 0: not found, 1: success
|
|
|
PK_API int py_import(const char* path) PY_RAISE PY_RETURN;
|
|
|
|
|
|
-/************* Errors *************/
|
|
|
+/************* PyException *************/
|
|
|
|
|
|
-/// Raise an exception by type and message. Always return false.
|
|
|
-PK_API bool py_exception(py_Type type, const char* fmt, ...) PY_RAISE;
|
|
|
-/// Raise an exception object. Always return false.
|
|
|
-PK_API bool py_raise(py_Ref) PY_RAISE;
|
|
|
-/// Print the unhandled exception.
|
|
|
-PK_API void py_printexc();
|
|
|
-/// Format the unhandled exception and return a null-terminated string.
|
|
|
-/// The returned string should be freed by the caller.
|
|
|
-PK_API char* py_formatexc();
|
|
|
/// Check if there is an unhandled exception.
|
|
|
PK_API bool py_checkexc();
|
|
|
/// Check if the unhandled exception is an instance of the given type.
|
|
|
@@ -613,6 +626,15 @@ PK_API bool py_matchexc(py_Type type) PY_RETURN;
|
|
|
/// Clear the unhandled exception.
|
|
|
/// @param p0 the unwinding point. Use `NULL` if not needed.
|
|
|
PK_API void py_clearexc(py_StackRef p0);
|
|
|
+/// Print the unhandled exception.
|
|
|
+PK_API void py_printexc();
|
|
|
+/// Format the unhandled exception and return a null-terminated string.
|
|
|
+/// The returned string should be freed by the caller.
|
|
|
+PK_API char* py_formatexc();
|
|
|
+/// Raise an exception by type and message. Always return false.
|
|
|
+PK_API bool py_exception(py_Type type, const char* fmt, ...) PY_RAISE;
|
|
|
+/// Raise an exception object. Always return false.
|
|
|
+PK_API bool py_raise(py_Ref) PY_RAISE;
|
|
|
|
|
|
#define NameError(n) py_exception(tp_NameError, "name '%n' is not defined", (n))
|
|
|
#define TypeError(...) py_exception(tp_TypeError, __VA_ARGS__)
|
|
|
@@ -630,100 +652,40 @@ PK_API void py_clearexc(py_StackRef p0);
|
|
|
"cannot access local variable '%n' where it is not associated with a value", \
|
|
|
(n))
|
|
|
|
|
|
-PK_API bool StopIteration() PY_RAISE;
|
|
|
PK_API bool KeyError(py_Ref key) PY_RAISE;
|
|
|
+PK_API bool StopIteration() PY_RAISE;
|
|
|
|
|
|
-/************* Operators *************/
|
|
|
-
|
|
|
-/// Python equivalent to `bool(val)`.
|
|
|
-/// 1: true, 0: false, -1: error
|
|
|
-PK_API int py_bool(py_Ref val) PY_RAISE;
|
|
|
-/// Compare two objects.
|
|
|
-/// 1: lhs == rhs, 0: lhs != rhs, -1: error
|
|
|
-PK_API int py_equal(py_Ref lhs, py_Ref rhs) PY_RAISE;
|
|
|
-/// Compare two objects.
|
|
|
-/// 1: lhs < rhs, 0: lhs >= rhs, -1: error
|
|
|
-PK_API int py_less(py_Ref lhs, py_Ref rhs) PY_RAISE;
|
|
|
-
|
|
|
-/// lhs == rhs
|
|
|
-PK_API bool py_eq(py_Ref lhs, py_Ref rhs) PY_RAISE PY_RETURN;
|
|
|
-/// lhs != rhs
|
|
|
-PK_API bool py_ne(py_Ref lhs, py_Ref rhs) PY_RAISE PY_RETURN;
|
|
|
-/// lhs < rhs
|
|
|
-PK_API bool py_lt(py_Ref lhs, py_Ref rhs) PY_RAISE PY_RETURN;
|
|
|
-/// lhs <= rhs
|
|
|
-PK_API bool py_le(py_Ref lhs, py_Ref rhs) PY_RAISE PY_RETURN;
|
|
|
-/// lhs > rhs
|
|
|
-PK_API bool py_gt(py_Ref lhs, py_Ref rhs) PY_RAISE PY_RETURN;
|
|
|
-/// lhs >= rhs
|
|
|
-PK_API bool py_ge(py_Ref lhs, py_Ref rhs) PY_RAISE PY_RETURN;
|
|
|
-
|
|
|
-/// Python equivalent to `callable(val)`.
|
|
|
-PK_API bool py_callable(py_Ref val);
|
|
|
-/// Get the hash value of the object.
|
|
|
-PK_API bool py_hash(py_Ref, py_i64* out) PY_RAISE;
|
|
|
-/// Get the iterator of the object.
|
|
|
-PK_API bool py_iter(py_Ref) PY_RAISE PY_RETURN;
|
|
|
-/// Get the next element from the iterator.
|
|
|
-/// 1: success, 0: StopIteration, -1: error
|
|
|
-PK_API int py_next(py_Ref) PY_RAISE PY_RETURN;
|
|
|
-/// Python equivalent to `lhs is rhs`.
|
|
|
-PK_API bool py_isidentical(py_Ref, py_Ref);
|
|
|
-/// Call a function.
|
|
|
-/// It prepares the stack and then performs a `vectorcall(argc, 0, false)`.
|
|
|
-/// The result will be set to `py_retval()`.
|
|
|
-/// The stack remains unchanged if successful.
|
|
|
-PK_API bool py_call(py_Ref f, int argc, py_Ref argv) PY_RAISE PY_RETURN;
|
|
|
-
|
|
|
-#ifndef NDEBUG
|
|
|
-/// Call a `py_CFunction` in a safe way.
|
|
|
-/// This function does extra checks to help you debug `py_CFunction`.
|
|
|
-PK_API bool py_callcfunc(py_CFunction f, int argc, py_Ref argv) PY_RAISE PY_RETURN;
|
|
|
-#else
|
|
|
-#define py_callcfunc(f, argc, argv) (f((argc), (argv)))
|
|
|
-#endif
|
|
|
-
|
|
|
-/// Python equivalent to `str(val)`.
|
|
|
-PK_API bool py_str(py_Ref val) PY_RAISE PY_RETURN;
|
|
|
-/// Python equivalent to `repr(val)`.
|
|
|
-PK_API bool py_repr(py_Ref val) PY_RAISE PY_RETURN;
|
|
|
-/// Python equivalent to `len(val)`.
|
|
|
-PK_API bool py_len(py_Ref val) PY_RAISE PY_RETURN;
|
|
|
-/// Python equivalent to `json.dumps(val)`.
|
|
|
-PK_API bool py_json_dumps(py_Ref val, int indent) PY_RAISE PY_RETURN;
|
|
|
-/// Python equivalent to `json.loads(val)`.
|
|
|
-PK_API bool py_json_loads(const char* source) PY_RAISE PY_RETURN;
|
|
|
-/// Python equivalent to `pickle.dumps(val)`.
|
|
|
-PK_API bool py_pickle_dumps(py_Ref val) PY_RAISE PY_RETURN;
|
|
|
-/// Python equivalent to `pickle.loads(val)`.
|
|
|
-PK_API bool py_pickle_loads(const unsigned char* data, int size) PY_RAISE PY_RETURN;
|
|
|
-
|
|
|
-/************* Profiler *************/
|
|
|
-PK_API void py_profiler_begin();
|
|
|
-PK_API void py_profiler_end();
|
|
|
-PK_API void py_profiler_reset();
|
|
|
-PK_API char* py_profiler_report();
|
|
|
+/************* Debugger *************/
|
|
|
|
|
|
-/************* DAP *************/
|
|
|
#if PK_ENABLE_OS
|
|
|
PK_API void py_debugger_waitforattach(const char* hostname, unsigned short port);
|
|
|
PK_API bool py_debugger_isattached();
|
|
|
PK_API void py_debugger_exceptionbreakpoint(py_Ref exc);
|
|
|
-PK_API void py_debugger_exit(int exitCode);
|
|
|
+PK_API void py_debugger_exit(int code);
|
|
|
#else
|
|
|
#define py_debugger_waitforattach(hostname, port)
|
|
|
#define py_debugger_isattached() (false)
|
|
|
#define py_debugger_exceptionbreakpoint(exc)
|
|
|
-#define py_debugger_exit(exitCode)
|
|
|
+#define py_debugger_exit(code)
|
|
|
#endif
|
|
|
|
|
|
-/************* Unchecked Functions *************/
|
|
|
+/************* PyTuple *************/
|
|
|
|
|
|
+/// Create a `tuple` with `n` UNINITIALIZED elements.
|
|
|
+/// You should initialize all elements before using it.
|
|
|
+PK_API py_ObjectRef py_newtuple(py_OutRef, int n);
|
|
|
PK_API py_ObjectRef py_tuple_data(py_Ref self);
|
|
|
PK_API py_ObjectRef py_tuple_getitem(py_Ref self, int i);
|
|
|
PK_API void py_tuple_setitem(py_Ref self, int i, py_Ref val);
|
|
|
PK_API int py_tuple_len(py_Ref self);
|
|
|
|
|
|
+/************* PyList *************/
|
|
|
+
|
|
|
+/// Create an empty `list`.
|
|
|
+PK_API void py_newlist(py_OutRef);
|
|
|
+/// Create a `list` with `n` UNINITIALIZED elements.
|
|
|
+/// You should initialize all elements before using it.
|
|
|
+PK_API void py_newlistn(py_OutRef, int n);
|
|
|
PK_API py_ItemRef py_list_data(py_Ref self);
|
|
|
PK_API py_ItemRef py_list_getitem(py_Ref self, int i);
|
|
|
PK_API void py_list_setitem(py_Ref self, int i, py_Ref val);
|
|
|
@@ -735,6 +697,10 @@ PK_API py_ItemRef py_list_emplace(py_Ref self);
|
|
|
PK_API void py_list_clear(py_Ref self);
|
|
|
PK_API void py_list_insert(py_Ref self, int i, py_Ref val);
|
|
|
|
|
|
+/************* PyDict *************/
|
|
|
+
|
|
|
+/// Create an empty `dict`.
|
|
|
+PK_API void py_newdict(py_OutRef);
|
|
|
/// -1: error, 0: not found, 1: found
|
|
|
PK_API int py_dict_getitem(py_Ref self, py_Ref key) PY_RAISE PY_RETURN;
|
|
|
/// true: success, false: error
|
|
|
@@ -761,6 +727,14 @@ PK_API bool
|
|
|
/// noexcept
|
|
|
PK_API int py_dict_len(py_Ref self);
|
|
|
|
|
|
+/************* PySlice *************/
|
|
|
+
|
|
|
+/// Create an UNINITIALIZED `slice` object.
|
|
|
+/// You should use `py_setslot()` to set `start`, `stop`, and `step`.
|
|
|
+PK_API py_ObjectRef py_newslice(py_OutRef);
|
|
|
+/// Create a `slice` object from 3 integers.
|
|
|
+PK_API void py_newsliceint(py_OutRef out, py_i64 start, py_i64 stop, py_i64 step);
|
|
|
+
|
|
|
/************* random module *************/
|
|
|
PK_API void py_newRandom(py_OutRef out);
|
|
|
PK_API void py_Random_seed(py_Ref self, py_i64 seed);
|
|
|
@@ -789,6 +763,32 @@ PK_API c11_vec3i py_tovec3i(py_Ref self);
|
|
|
PK_API c11_mat3x3* py_tomat3x3(py_Ref self);
|
|
|
PK_API c11_color32 py_tocolor32(py_Ref self);
|
|
|
|
|
|
+/************* json module *************/
|
|
|
+/// Python equivalent to `json.dumps(val)`.
|
|
|
+PK_API bool py_json_dumps(py_Ref val, int indent) PY_RAISE PY_RETURN;
|
|
|
+/// Python equivalent to `json.loads(val)`.
|
|
|
+PK_API bool py_json_loads(const char* source) PY_RAISE PY_RETURN;
|
|
|
+
|
|
|
+/************* pickle module *************/
|
|
|
+/// Python equivalent to `pickle.dumps(val)`.
|
|
|
+PK_API bool py_pickle_dumps(py_Ref val) PY_RAISE PY_RETURN;
|
|
|
+/// Python equivalent to `pickle.loads(val)`.
|
|
|
+PK_API bool py_pickle_loads(const unsigned char* data, int size) PY_RAISE PY_RETURN;
|
|
|
+
|
|
|
+/************* pkpy module *************/
|
|
|
+/// Begin the watchdog with `timeout` in milliseconds.
|
|
|
+/// `PK_ENABLE_WATCHDOG` must be defined to `1` to use this feature.
|
|
|
+/// You need to call `py_watchdog_end()` later.
|
|
|
+/// If `timeout` is reached, `TimeoutError` will be raised.
|
|
|
+PK_API void py_watchdog_begin(py_i64 timeout);
|
|
|
+/// Reset the watchdog.
|
|
|
+PK_API void py_watchdog_end();
|
|
|
+
|
|
|
+PK_API void py_profiler_begin();
|
|
|
+PK_API void py_profiler_end();
|
|
|
+PK_API void py_profiler_reset();
|
|
|
+PK_API char* py_profiler_report();
|
|
|
+
|
|
|
/************* Others *************/
|
|
|
|
|
|
/// An utility function to read a line from stdin for REPL.
|