python - CPython - How to create and add a method attribute to an object with __dict__? -


this can tricky question...

in short creating , adding method follows:

static pyobject *ret_arg(pybvhtree *self, pyobject *arg) {     /* demonstrate */     return arg; } static pymethoddef my_meth = {"ret_arg", (pycfunction)ret_arg, meth_o, 0};         ...     pyobject* func = pycfunction_new(&my_meth, my_object);     py_decref(my_object);     pyobject_setattrstring(my_object, "ret_arg", func);     py_decref(func);     return my_object; } 

it works! having problems :(

eg.:

  • if del my_object. , use new method, crash.
  • when close program python. error: exception_access_violation. , no problem refcount

so question is:

what correct way this?


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -