mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
add function wrapper for malloc/free
This commit is contained in:
parent
39958a92d2
commit
9c2b96e572
@ -127,6 +127,13 @@ PK_API int py_gc_collect();
|
|||||||
/// Setup the callbacks for the current VM.
|
/// Setup the callbacks for the current VM.
|
||||||
PK_API py_Callbacks* py_callbacks();
|
PK_API py_Callbacks* py_callbacks();
|
||||||
|
|
||||||
|
/// Wrapper for `PK_MALLOC(size)`.
|
||||||
|
PK_API void* py_malloc(size_t size);
|
||||||
|
/// Wrapper for `PK_REALLOC(ptr, size)`.
|
||||||
|
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.
|
/// Begin the watchdog with `timeout` in milliseconds.
|
||||||
/// `PK_ENABLE_WATCHDOG` must be defined to `1` to use this feature.
|
/// `PK_ENABLE_WATCHDOG` must be defined to `1` to use this feature.
|
||||||
/// You need to call `py_watchdog_end()` later.
|
/// You need to call `py_watchdog_end()` later.
|
||||||
|
@ -14,7 +14,7 @@ public:
|
|||||||
// get the python exception object
|
// get the python exception object
|
||||||
object& exception() { return m_exception; }
|
object& exception() { return m_exception; }
|
||||||
|
|
||||||
~python_error() { std::free(m_what); }
|
~python_error() { py_free(m_what); }
|
||||||
|
|
||||||
bool match(py_Type type) const { return py_isinstance(m_exception.ptr(), type); }
|
bool match(py_Type type) const { return py_isinstance(m_exception.ptr(), type); }
|
||||||
|
|
||||||
|
@ -47,6 +47,18 @@ void py_initialize() {
|
|||||||
pk_initialized = true;
|
pk_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* py_malloc(size_t size) {
|
||||||
|
return PK_MALLOC(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void* py_realloc(void* ptr, size_t size) {
|
||||||
|
return PK_REALLOC(ptr, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void py_free(void* ptr) {
|
||||||
|
PK_FREE(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
py_GlobalRef py_True() { return &_True; }
|
py_GlobalRef py_True() { return &_True; }
|
||||||
|
|
||||||
py_GlobalRef py_False() { return &_False; }
|
py_GlobalRef py_False() { return &_False; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user