Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault (sometimes!) using array::set_module_and_type and Python 3 #75

Closed
martyngigg opened this issue Jul 1, 2016 · 2 comments
Closed
Labels

Comments

@martyngigg
Copy link

The following stripped down example demonstrates the issue.

Module definition:

#include <boost/python/def.hpp>
#include <boost/python/module.hpp>
#include <boost/python/numeric.hpp>

using namespace boost::python;

void pass_array(const numeric::array &) {

}

BOOST_PYTHON_MODULE(test_arrays) {
  numeric::array::set_module_and_type("numpy", "ndarray");
  def("pass_array", pass_array);
}

Running the following produces a segfault but not for every run:

echo; while [ $? == 0 ]; do PYTHONPATH=$PWD /usr/bin/python3 -c "from test_arrays import pass_array; import numpy as np; print('testing'); pass_array(np.arange(100.))"; done

The backtrace from a debug with of Python:

 Program terminated with signal 11, Segmentation fault.
#0  0x0000000000456c9a in dict_dealloc (mp=0x7f62ea20f488) at ../Objects/dictobject.c:1379
(gdb) bt
#0  0x0000000000456c9a in dict_dealloc (mp=0x7f62ea20f488) at ../Objects/dictobject.c:1379
#1  0x000000000046355a in module_dealloc (m=0x7f62ebe40c28) at ../Objects/moduleobject.c:398
#2  0x000000000062aca5 in meth_dealloc (m=0x7f62ea20f548) at ../Objects/methodobject.c:150
#3  0x00007f62eaadf4f9 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#4  0x00007f62eaadf545 in exit () from /lib/x86_64-linux-gnu/libc.so.6
#5  0x00007f62eaac4ecc in __libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6
#6  0x000000000041deb9 in _start ()

I am not certain if it is related to this Python issue: http://bugs.python.org/issue17703

martyngigg added a commit to mantidproject/mantid that referenced this issue Jul 5, 2016
It causes random segfaults on shutdown of the python 3 interpeter. It
appears to be an issue with the statically allocated dict objects -
see boostorg/python#75
@stefanseefeld
Copy link
Member

Just as a FYI: I have just merged a new NumPy C++ API extension into the development branch, and plan to release that with Boost 1.63. (It still lacks integration with Boost's own build system, as I'm mostly just working with Boost.Python's SCons-based build logic nowadays.)
I encourage you to give that a try, as I also plan to deprecate the original "numeric" API.

vargheseg added a commit to ChimeraTK/DeviceAccess-PythonBindings that referenced this issue Apr 10, 2017
Had to drop boost::python::numeric to wrap numpy ndarray; using
bp:numeric causes segfaults on python3 exit:
boostorg/python#75
boostorg/python#79

Work around the problem by defining a custom python object to handle the
numpy array. These links were used as reference to reach this solution:
mantidproject/mantid@7371d12
https://github.com/boostorg/python/blob/352792c90a36ee8d6a520c7602b2dbd03ab19c3f/include/boost/python/numpy/numpy_object_mgr_traits.hpp
@stefanseefeld
Copy link
Member

The numeric module has just been removed as it was obsoleted by the addition of Boost.NumPy. Please adjust your code to use the latter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants