1

i have a c++ class A , it will callback a python function foo(A) , and i want to send a A* pointer to this function , how can i do it ? my code is similar as follow :

PyObject* arg = (PyObject*)(pA);
PyTuple_SetItem(args, 0, arg);
PyObject* pRet = PyObject_CallObject(foo, args);

but it always crash , seems wrap arg from A* is not correct , can anybody help me ?

6
  • You can’t just pretend your A object is a Python object! The cast should be a red flag. Moreover, what do you want the Python function to do with the pointer? Commented Sep 26, 2019 at 12:54
  • function foo is a python function , i callback it from C++ , in foo , the pointer will call some member function , such as A::do_something() Commented Sep 27, 2019 at 2:58
  • how to wrap the pointer ? Commented Sep 27, 2019 at 2:59
  • Possible duplicate of Passing a C pointer around with the Python/C API Commented Sep 27, 2019 at 3:01
  • i already checked that question before , but it can't run correctly Commented Sep 27, 2019 at 3:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.