diff --git a/include/pocketpy/vm.h b/include/pocketpy/vm.h index 72e6ba9d..2f10c573 100644 --- a/include/pocketpy/vm.h +++ b/include/pocketpy/vm.h @@ -460,7 +460,7 @@ public: // new style binding api PyObject* bind(PyObject*, const char*, const char*, NativeFuncC, UserData userdata={}, BindType bt=BindType::DEFAULT); PyObject* bind(PyObject*, const char*, NativeFuncC, UserData userdata={}, BindType bt=BindType::DEFAULT); - PyObject* bind_property(PyObject*, Str, NativeFuncC fget, NativeFuncC fset=nullptr); + PyObject* bind_property(PyObject*, const char*, NativeFuncC fget, NativeFuncC fset=nullptr); template Type _find_type_in_cxx_typeid_map(){ diff --git a/src/vm.cpp b/src/vm.cpp index 94dde907..ef6724ae 100644 --- a/src/vm.cpp +++ b/src/vm.cpp @@ -1204,14 +1204,15 @@ PyObject* VM::bind(PyObject* obj, const char* sig, const char* docstring, Native return f_obj; } -PyObject* VM::bind_property(PyObject* obj, Str name, NativeFuncC fget, NativeFuncC fset){ +PyObject* VM::bind_property(PyObject* obj, const char* name, NativeFuncC fget, NativeFuncC fset){ PyObject* _0 = heap.gcnew(tp_native_func, fget, 1, false); PyObject* _1 = vm->None; if(fset != nullptr) _1 = heap.gcnew(tp_native_func, fset, 2, false); - int pos = name.index(":"); - if(pos > 0) name = name.substr(0, pos).strip(); + std::string_view name_sv(name); + int pos = name_sv.find(':'); + if(pos > 0) name_sv = name_sv.substr(0, pos); PyObject* prop = VAR(Property(_0, _1)); - obj->attr().set(name, prop); + obj->attr().set(StrName(name_sv), prop); return prop; }