mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 03:50:16 +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());
|
||||
return VAR(self.*field);
|
||||
};
|
||||
PyObject* _0 = heap.gcnew<NativeFunc>(tp_native_func, fget, 1);
|
||||
PK_OBJ_GET(NativeFunc, _0).set_userdata(field);
|
||||
PyObject* _0 = heap.gcnew<NativeFunc>(tp_native_func, fget, 1, field);
|
||||
PyObject* _1 = vm->None;
|
||||
if constexpr (!ReadOnly){
|
||||
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]);
|
||||
return vm->None;
|
||||
};
|
||||
_1 = heap.gcnew<NativeFunc>(tp_native_func, fset, 2);
|
||||
PK_OBJ_GET(NativeFunc, _1).set_userdata(field);
|
||||
_1 = heap.gcnew<NativeFunc>(tp_native_func, fset, 2, field);
|
||||
}
|
||||
PyObject* prop = VAR(Property(_0, _1));
|
||||
obj->attr().set(StrName(name_sv), prop);
|
||||
|
@ -123,24 +123,12 @@ struct FuncDecl {
|
||||
|
||||
struct NativeFunc {
|
||||
NativeFuncC f;
|
||||
|
||||
// old style argc-based call
|
||||
int argc;
|
||||
|
||||
// new style decl-based call
|
||||
FuncDecl_ decl;
|
||||
|
||||
int argc; // old style argc-based call
|
||||
FuncDecl_ decl; // new style decl-based call
|
||||
any _userdata;
|
||||
|
||||
void set_userdata(any&& data) {
|
||||
if(_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) {}
|
||||
NativeFunc(NativeFuncC f, int argc, any userdata={}): f(f), argc(argc), decl(nullptr), _userdata(std::move(userdata)) {}
|
||||
NativeFunc(NativeFuncC f, FuncDecl_ decl, any userdata={}): f(f), argc(-1), decl(decl), _userdata(std::move(userdata)) {}
|
||||
|
||||
void check_size(VM* vm, ArgsView args) const;
|
||||
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* nf = VAR(NativeFunc(fn, argc));
|
||||
PK_OBJ_GET(NativeFunc, nf).set_userdata(std::move(userdata));
|
||||
PyObject* nf = VAR(NativeFunc(fn, argc, std::move(userdata)));
|
||||
switch(bt){
|
||||
case BindType::DEFAULT: 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];
|
||||
decl->docstring = docstring;
|
||||
PyObject* f_obj = VAR(NativeFunc(fn, decl));
|
||||
PK_OBJ_GET(NativeFunc, f_obj).set_userdata(std::move(userdata));
|
||||
PyObject* f_obj = VAR(NativeFunc(fn, decl, std::move(userdata)));
|
||||
|
||||
switch(bt){
|
||||
case BindType::STATICMETHOD:
|
||||
|
Loading…
x
Reference in New Issue
Block a user