On 19.02.2016 08:10, Sampsa Riikonen wrote: > Dear List, > > I am unable to solve an issue with the python c api (python 2.7). > > Namely, I am trying to pass a python object to c++, where the python > object is then passed to a c++ class that calls the python object's > method.. I only get segmentation faults. > > No one has been able to help with me with this problem, so I thought > that a guru from this mailing list / community might know the answer. > > The question, with setup.py, source code, etc. has been posted here: > > http://stackoverflow.com/questions/35466991/calling-python-objects-method-from-c > > > .. it is a few-liner, testing the concept of passing around python > objects within c++.
Hi Sampsa, there are many stylistic issues with your code, and solving those would make the bug obvious. The bug is really in your testclass constructor: testclass(int* i, PyObject* po) { std::cerr << "testclass constructor! \n"; i=i; po=po; } You think you are assigning the two arguments 'i' and 'po' to the two member variables 'i', 'po', but you are not. You are assigning the variables to themselves. (The compiler may even chose to optimize away these as no-ops !) I don't know swig, but for rich mapping between Python and C++ I would suggest you consider Boost.Python, which is way more powerful. Stefan -- ...ich hab' noch einen Koffer in Berlin... _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org https://mail.python.org/mailman/listinfo/cplusplus-sig