mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 12:00:18 +00:00
remove set_userdata
This commit is contained in:
parent
6e9e25ca34
commit
4ef2e9d156
@ -97,8 +97,7 @@ PyObject* VM::bind_field(PyObject* obj, const char* name, F T::*field){
|
|||||||
F T::*field = lambda_get_userdata<F T::*>(args.begin());
|
F T::*field = lambda_get_userdata<F T::*>(args.begin());
|
||||||
return VAR(self.*field);
|
return VAR(self.*field);
|
||||||
};
|
};
|
||||||
PyObject* _0 = heap.gcnew<NativeFunc>(tp_native_func, fget, 1);
|
PyObject* _0 = heap.gcnew<NativeFunc>(tp_native_func, fget, 1, field);
|
||||||
PK_OBJ_GET(NativeFunc, _0).set_userdata(field);
|
|
||||||
PyObject* _1 = vm->None;
|
PyObject* _1 = vm->None;
|
||||||
if constexpr (!ReadOnly){
|
if constexpr (!ReadOnly){
|
||||||
auto fset = [](VM* vm, ArgsView args){
|
auto fset = [](VM* vm, ArgsView args){
|
||||||
@ -107,8 +106,7 @@ PyObject* VM::bind_field(PyObject* obj, const char* name, F T::*field){
|
|||||||
self.*field = py_cast<F>(vm, args[1]);
|
self.*field = py_cast<F>(vm, args[1]);
|
||||||
return vm->None;
|
return vm->None;
|
||||||
};
|
};
|
||||||
_1 = heap.gcnew<NativeFunc>(tp_native_func, fset, 2);
|
_1 = heap.gcnew<NativeFunc>(tp_native_func, fset, 2, field);
|
||||||
PK_OBJ_GET(NativeFunc, _1).set_userdata(field);
|
|
||||||
}
|
}
|
||||||
PyObject* prop = VAR(Property(_0, _1));
|
PyObject* prop = VAR(Property(_0, _1));
|
||||||
obj->attr().set(StrName(name_sv), prop);
|
obj->attr().set(StrName(name_sv), prop);
|
||||||
|
@ -123,24 +123,12 @@ struct FuncDecl {
|
|||||||
|
|
||||||
struct NativeFunc {
|
struct NativeFunc {
|
||||||
NativeFuncC f;
|
NativeFuncC f;
|
||||||
|
int argc; // old style argc-based call
|
||||||
// old style argc-based call
|
FuncDecl_ decl; // new style decl-based call
|
||||||
int argc;
|
|
||||||
|
|
||||||
// new style decl-based call
|
|
||||||
FuncDecl_ decl;
|
|
||||||
|
|
||||||
any _userdata;
|
any _userdata;
|
||||||
|
|
||||||
void set_userdata(any&& data) {
|
NativeFunc(NativeFuncC f, int argc, any userdata={}): f(f), argc(argc), decl(nullptr), _userdata(std::move(userdata)) {}
|
||||||
if(_userdata){
|
NativeFunc(NativeFuncC f, FuncDecl_ decl, any userdata={}): f(f), argc(-1), decl(decl), _userdata(std::move(userdata)) {}
|
||||||
throw std::runtime_error("NativeFunc userdata already set");
|
|
||||||
}
|
|
||||||
_userdata = std::move(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
NativeFunc(NativeFuncC f, int argc): f(f), argc(argc) {}
|
|
||||||
NativeFunc(NativeFuncC f, FuncDecl_ decl): f(f), argc(-1), decl(decl) {}
|
|
||||||
|
|
||||||
void check_size(VM* vm, ArgsView args) const;
|
void check_size(VM* vm, ArgsView args) const;
|
||||||
PyObject* call(VM* vm, ArgsView args) const { return f(vm, args); }
|
PyObject* call(VM* vm, ArgsView args) const { return f(vm, args); }
|
||||||
|
@ -1303,8 +1303,7 @@ void VM::setattr(PyObject* obj, StrName name, PyObject* value){
|
|||||||
}
|
}
|
||||||
|
|
||||||
PyObject* VM::bind_func(PyObject* obj, StrName name, int argc, NativeFuncC fn, any userdata, BindType bt) {
|
PyObject* VM::bind_func(PyObject* obj, StrName name, int argc, NativeFuncC fn, any userdata, BindType bt) {
|
||||||
PyObject* nf = VAR(NativeFunc(fn, argc));
|
PyObject* nf = VAR(NativeFunc(fn, argc, std::move(userdata)));
|
||||||
PK_OBJ_GET(NativeFunc, nf).set_userdata(std::move(userdata));
|
|
||||||
switch(bt){
|
switch(bt){
|
||||||
case BindType::DEFAULT: break;
|
case BindType::DEFAULT: break;
|
||||||
case BindType::STATICMETHOD: nf = VAR(StaticMethod(nf)); break;
|
case BindType::STATICMETHOD: nf = VAR(StaticMethod(nf)); break;
|
||||||
@ -1331,8 +1330,7 @@ PyObject* VM::bind(PyObject* obj, const char* sig, const char* docstring, Native
|
|||||||
}
|
}
|
||||||
FuncDecl_ decl = co->func_decls[0];
|
FuncDecl_ decl = co->func_decls[0];
|
||||||
decl->docstring = docstring;
|
decl->docstring = docstring;
|
||||||
PyObject* f_obj = VAR(NativeFunc(fn, decl));
|
PyObject* f_obj = VAR(NativeFunc(fn, decl, std::move(userdata)));
|
||||||
PK_OBJ_GET(NativeFunc, f_obj).set_userdata(std::move(userdata));
|
|
||||||
|
|
||||||
switch(bt){
|
switch(bt){
|
||||||
case BindType::STATICMETHOD:
|
case BindType::STATICMETHOD:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user