pybind / pybind/pybind11

[BUG] Adding constructor causes segmentation fault / GlobalError::PushToStack()

Open
#2,998 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

Issue description

I am working on esmini-pybind1.
Adding constructor causes segmentation fault / GlobalError::PushToStack()

Reproducible example code

Before defining a constructor
import pyplayerbase
from pyplayerbase import *

x = ScenarioPlayer
print( x )
print( type(x))
print( dir(x))
print( x() )

Results in:

python3 tests/scenarioplayer.py 
<class 'pyplayerbase.ScenarioPlayer'>
<class 'pybind11_builtins.pybind11_type'>
['AddObjectSensor', 'Frame', 'GetFixedTimestep', 'GetOSIFreq', 'GetParameterValue', 'IsQuitRequested', 'ScenarioFrame', 'SetFixedTimestep', 'SetOSIFileStatus', 'SetParameterValue', 'ShowObjectSensors', 'UpdateCSV_Log', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'callback', 'exe_path_', 'maxStepSize', 'minStepSize', 'opt', 'sensor']
Traceback (most recent call last):
  File "tests/scenarioplayer.py", line 12, in <module>
    print( x() )
TypeError: pyplayerbase.ScenarioPlayer: No constructor defined!
After defining an empty constructor

RosettaCommons/binder generates the following this extra bindings:

cl.def( pybind11::init( [](){ return new ScenarioPlayer(); } ) );

The same script crashes when it tries to import the pyplayerbase module:

$ python3 tests/scenarioplayer.py 
Segmentation fault (core dumped)

$ gdb python3 

(gdb) r tests/scenarioplayer.py
Starting program: /usr/bin/python3 tests/scenarioplayer.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00007fffefc812b9 in GlobalError::PushToStack() () from /usr/lib/x86_64-linux-gnu/libapt-pkg.so.5.0
(gdb) bt
#0  0x00007fffefc812b9 in GlobalError::PushToStack() () from /usr/lib/x86_64-linux-gnu/libapt-pkg.so.5.0
#1  0x00007fffefd04fc2 in pkgInitConfig(Configuration&) () from /usr/lib/x86_64-linux-gnu/libapt-pkg.so.5.0
#2  0x00007fffeffa2ed8 in ?? () from /usr/lib/python3/dist-packages/apt_pkg.cpython-36m-x86_64-linux-gnu.so
#3  0x000000000050a22f in ?? ()
#4  0x000000000050bf44 in _PyEval_EvalFrameDefault ()
#5  0x0000000000507cd4 in ?? ()
#6  0x0000000000516129 in ?? ()
#7  0x0000000000566ff2 in PyCFunction_Call ()
#8  0x0000000000510f56 in _PyEval_EvalFrameDefault ()
#9  0x0000000000507cd4 in ?? ()
#10 0x0000000000509a00 in ?? ()
#11 0x000000000050a3fd in ?? ()
#12 0x000000000050bf44 in _PyEval_EvalFrameDefault ()
#13 0x00000000005096c8 in ?? ()
#14 0x000000000050a3fd in ?? ()
#15 0x000000000050bf44 in _PyEval_EvalFrameDefault ()
#16 0x00000000005096c8 in ?? ()
#17 0x000000000050a3fd in ?? ()
#18 0x000000000050bf44 in _PyEval_EvalFrameDefault ()
#19 0x00000000005096c8 in ?? ()
#20 0x000000000050a3fd in ?? ()
#21 0x000000000050bf44 in _PyEval_EvalFrameDefault ()
#22 0x0000000000508dc5 in _PyFunction_FastCallDict ()
#23 0x00000000005a5481 in _PyObject_FastCallDict ()
#24 0x00000000005a64be in _PyObject_CallMethodIdObjArgs ()
#25 0x00000000004f6dbd in PyImport_ImportModuleLevelObject ()
#26 0x000000000050deee in _PyEval_EvalFrameDefault ()
#27 0x0000000000507cd4 in ?? ()
#28 0x0000000000516129 in ?? ()
#29 0x0000000000566ff2 in PyCFunction_Call ()
#30 0x0000000000510f56 in _PyEval_EvalFrameDefault ()
#31 0x0000000000507cd4 in ?? ()
#32 0x0000000000509a00 in ?? ()
#33 0x000000000050a3fd in ?? ()
#34 0x000000000050bf44 in _PyEval_EvalFrameDefault ()
#35 0x00000000005096c8 in ?? ()
#36 0x000000000050a3fd in ?? ()
#37 0x000000000050bf44 in _PyEval_EvalFrameDefault ()
#38 0x00000000005096c8 in ?? ()
#39 0x000000000050a3fd in ?? ()
#40 0x000000000050bf44 in _PyEval_EvalFrameDefault ()
#41 0x00000000005096c8 in ?? ()
#42 0x000000000050a3fd in ?? ()
#43 0x000000000050bf44 in _PyEval_EvalFrameDefault ()
#44 0x0000000000508dc5 in _PyFunction_FastCallDict ()
#45 0x00000000005a5481 in _PyObject_FastCallDict ()
#46 0x00000000005a64be in _PyObject_CallMethodIdObjArgs ()
#47 0x00000000004f6dbd in PyImport_ImportModuleLevelObject ()
#48 0x000000000050deee in _PyEval_EvalFrameDefault ()
#49 0x0000000000507cd4 in ?? ()
#50 0x0000000000516129 in ?? ()
#51 0x0000000000566ff2 in PyCFunction_Call ()
---Type <return> to continue, or q <return> to quit---

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the import crash with tests/scenarioplayer.py and the generated pybind11 constructor binding for ScenarioPlayer. Use the shown gdb backtrace, including GlobalError::PushToStack(), to investigate the failure during pyplayerbase import. Done means the module imports without a segmentation fault and ScenarioPlayer can be constructed.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.