mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-24 13:30:18 +00:00
fix c binding bug
This commit is contained in:
parent
6778d29ffa
commit
1003f3a6df
@ -7,14 +7,9 @@
|
||||
void check_impl(pkpy_vm* vm, bool result, int lineno) {
|
||||
if (!result) {
|
||||
printf("ERROR: failed where it should have succeed at line %i\n", lineno);
|
||||
char* message;
|
||||
if (!pkpy_clear_error(vm, &message)) {
|
||||
if (!pkpy_clear_error(vm, NULL)) {
|
||||
printf("clear error reported everything was fine\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("%s\n", message);
|
||||
free(message);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,7 +190,12 @@ T& lambda_get_userdata(PyObject** p){
|
||||
if(p[-1] != PY_NULL) ud = &PK_OBJ_GET(NativeFunc, p[-1])._userdata;
|
||||
else ud = &PK_OBJ_GET(NativeFunc, p[-2])._userdata;
|
||||
T* out;
|
||||
if(!any_cast(*ud, &out)) throw std::runtime_error("lambda_get_userdata: any_cast failed");
|
||||
if(!any_cast(*ud, &out)){
|
||||
const char* expected = typeid(T).name();
|
||||
const char* actual = ud->type_id().name();
|
||||
Str error = _S("lambda_get_userdata: any_cast failed: expected ", expected, ", got ", actual);
|
||||
throw std::runtime_error(error.c_str());
|
||||
}
|
||||
return *out;
|
||||
}
|
||||
|
||||
|
||||
@ -5,8 +5,6 @@
|
||||
|
||||
using namespace pkpy;
|
||||
|
||||
typedef int (*LuaStyleFuncC)(VM*);
|
||||
|
||||
#define PK_ASSERT_N_EXTRA_ELEMENTS(n) \
|
||||
int __ex_count = count_extra_elements(vm, n); \
|
||||
if(__ex_count < n){ \
|
||||
@ -334,12 +332,12 @@ struct TempViewPopper{
|
||||
|
||||
// function
|
||||
static PyObject* c_function_wrapper(VM* vm, ArgsView args) {
|
||||
LuaStyleFuncC f = lambda_get_userdata<LuaStyleFuncC>(args.begin());
|
||||
pkpy_CFunction f = lambda_get_userdata<pkpy_CFunction>(args.begin());
|
||||
PyObject** curr_sp = vm->s_data._sp;
|
||||
|
||||
vm->__c.s_view.push(args);
|
||||
TempViewPopper _tvp(vm);
|
||||
int retc = f(vm); // may raise, _tvp will handle this via RAII
|
||||
int retc = f((pkpy_vm*)vm); // may raise, _tvp will handle this via RAII
|
||||
_tvp.restore();
|
||||
|
||||
// propagate_if_errored
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user