Cannot return object by value #3329
Unanswered
davideanastasia
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am currently trying to write a wrapper for a simple C++ class. One of the function merges two objects (both const ref) and creates a third object.
Code that creates the function is here: https://github.com/davideanastasia/pyblossom/blob/master/src/bloomfilter.cxx#L46
While binding is defined here: https://github.com/davideanastasia/pyblossom/blob/master/src/bindings.cxx#L28
When I run the associated unit test (https://github.com/davideanastasia/pyblossom/blob/master/tests/test_bloomfilter.py#L27), I am getting this:
`
tests/test_bloomfilter.py::test_merge Fatal Python error: Aborted
Current thread 0x0000ffffb9569010 (most recent call first):
File "/usr/local/lib/python3.6/dist-packages/_pytest/python.py", line 183 in pytest_pyfunc_call
File "/usr/local/lib/python3.6/dist-packages/pluggy/_callers.py", line 39 in _multicall
File "/usr/local/lib/python3.6/dist-packages/pluggy/_manager.py", line 80 in _hookexec
File "/usr/local/lib/python3.6/dist-packages/pluggy/_hooks.py", line 265 in call
File "/usr/local/lib/python3.6/dist-packages/_pytest/python.py", line 1641 in runtest
File "/usr/local/lib/python3.6/dist-packages/_pytest/runner.py", line 162 in pytest_runtest_call
File "/usr/local/lib/python3.6/dist-packages/pluggy/_callers.py", line 39 in _multicall
File "/usr/local/lib/python3.6/dist-packages/pluggy/_manager.py", line 80 in _hookexec
File "/usr/local/lib/python3.6/dist-packages/pluggy/_hooks.py", line 265 in call
File "/usr/local/lib/python3.6/dist-packages/_pytest/runner.py", line 255 in
File "/usr/local/lib/python3.6/dist-packages/_pytest/runner.py", line 311 in from_call
File "/usr/local/lib/python3.6/dist-packages/_pytest/runner.py", line 255 in call_runtest_hook
File "/usr/local/lib/python3.6/dist-packages/_pytest/runner.py", line 215 in call_and_report
File "/usr/local/lib/python3.6/dist-packages/_pytest/runner.py", line 126 in runtestprotocol
File "/usr/local/lib/python3.6/dist-packages/_pytest/runner.py", line 109 in pytest_runtest_protocol
File "/usr/local/lib/python3.6/dist-packages/pluggy/_callers.py", line 39 in _multicall
File "/usr/local/lib/python3.6/dist-packages/pluggy/_manager.py", line 80 in _hookexec
File "/usr/local/lib/python3.6/dist-packages/pluggy/_hooks.py", line 265 in call
File "/usr/local/lib/python3.6/dist-packages/_pytest/main.py", line 348 in pytest_runtestloop
File "/usr/local/lib/python3.6/dist-packages/pluggy/_callers.py", line 39 in _multicall
File "/usr/local/lib/python3.6/dist-packages/pluggy/_manager.py", line 80 in _hookexec
File "/usr/local/lib/python3.6/dist-packages/pluggy/_hooks.py", line 265 in call
File "/usr/local/lib/python3.6/dist-packages/_pytest/main.py", line 323 in _main
File "/usr/local/lib/python3.6/dist-packages/_pytest/main.py", line 269 in wrap_session
File "/usr/local/lib/python3.6/dist-packages/_pytest/main.py", line 316 in pytest_cmdline_main
File "/usr/local/lib/python3.6/dist-packages/pluggy/_callers.py", line 39 in _multicall
File "/usr/local/lib/python3.6/dist-packages/pluggy/_manager.py", line 80 in _hookexec
File "/usr/local/lib/python3.6/dist-packages/pluggy/_hooks.py", line 265 in call
File "/usr/local/lib/python3.6/dist-packages/_pytest/config/init.py", line 163 in main
File "/usr/local/lib/python3.6/dist-packages/_pytest/config/init.py", line 185 in console_main
File "/usr/local/bin/pytest", line 11 in
Makefile:15: recipe for target 'test' failed
make: *** [test] Aborted
`
I have also tried to allocate the object on the heap and return a pointer, and the code passes the associated unit test without any error. It is still not clear to me how python manages the lifecycle of the C++ objects and whether it calls the destructor in the expected way.
Beta Was this translation helpful? Give feedback.
All reactions