-
Notifications
You must be signed in to change notification settings - Fork 792
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
Subclassing a #[pyclass] in Python causes segfault during interpreter finalization #220
Comments
Thanks for the report! I've minimized the example: #[pyclass(subclass)]
struct SomeClass {}
#[pymethods]
impl SomeClass {
#[new]
fn __new__(obj: &PyRawObject) -> PyResult<()> {
obj.init(|_| SomeClass {})
}
}
#[pymodinit]
fn word_count(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<SomeClass>()?;
Ok(())
} from word_count import SomeClass
class SomeSubClass(SomeClass):
pass
a = SomeSubClass()
print(a) With python-dbg you get a bit more information:
And with gdb I could get a backtrace:
|
Until PyO3/pyo3#220 is sorted out
@konstin Awesome! Thank you! |
@konstin I'm sorry, but it does not seem like this issue is fixed. Running |
PyO3/pyo3#220 is not fixed yet.
:/ |
I can't reproduce 🤔 |
@joar Did you update to the latest master? |
@konstin I'm pretty sure I did. Here's how I reproduce the error: Extracted and polished commands & output from the terminal recording: $ python --version
Python 3.7.1
$ cargo version
cargo 1.32.0-nightly (5e85ba14a 2018-12-02)
$ rustc --version
rustc 1.32.0-nightly (4a45578bc 2018-12-07)
$ cd rust-csv-py/pyo3 # I'm using the submodule checkout of pyo3 inside my rust-csv-py repo
$ git pull
Updating 26b88ca2..1b4afd11
[...]
$ cd examples/rustapi_module
$ python setup.py develop
[...]
$ python tests/test_subclassing.py
/home/joar/.virtualenvs/rust-csv-py/lib/python3.7/site.py:165: DeprecationWarning: 'U' mode is deprecated
f = open(fullname, "rU")
Debug memory block at address p=0x7f620692bc20: API '�'
5791237713491329024 bytes originally requested
The 7 pad bytes at p-7 are not all FORBIDDENBYTE (0xfb):
at p-7: 0xff *** OUCH
at p-6: 0xff *** OUCH
at p-5: 0xff *** OUCH
at p-4: 0xff *** OUCH
at p-3: 0xff *** OUCH
at p-2: 0xff *** OUCH
at p-1: 0xff *** OUCH
Because memory is corrupted at the start, the count of bytes requested
may be bogus, and checking the trailing pad bytes may segfault.
The 8 pad bytes at tail=0x505f1b666911bc20 are fish: “python tests/test_subclassing.py” terminated by signal SIGSEGV (Address boundary error)
$ gdb -ex r --args (which python) tests/test_subclassing.py
GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/joar/.virtualenvs/rust-csv-py/bin/python...done.
Starting program: /home/joar/.virtualenvs/rust-csv-py/bin/python tests/test_subclassing.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
/home/joar/.virtualenvs/rust-csv-py/lib/python3.7/site.py:165: DeprecationWarning: 'U' mode is deprecated
f = open(fullname, "rU")
Debug memory block at address p=0x7ffff7e72c20: API '�'
6925957840821485568 bytes originally requested
The 7 pad bytes at p-7 are not all FORBIDDENBYTE (0xfb):
at p-7: 0xff *** OUCH
at p-6: 0xff *** OUCH
at p-5: 0xff *** OUCH
at p-4: 0xff *** OUCH
at p-3: 0xff *** OUCH
at p-2: 0xff *** OUCH
at p-1: 0xff *** OUCH
Because memory is corrupted at the start, the count of bytes requested
may be bogus, and checking the trailing pad bytes may segfault.
The 8 pad bytes at tail=0x601e71f5f7662c20 are
Program received signal SIGSEGV, Segmentation fault.
0x000055555560ede2 in _PyObject_DebugDumpAddress (p=p@entry=0x7ffff7e72c20)
at ../Objects/obmalloc.c:2340
2340 ../Objects/obmalloc.c: No such file or directory.
(gdb) bt
#0 0x000055555560ede2 in _PyObject_DebugDumpAddress (p=p@entry=0x7ffff7e72c20)
at ../Objects/obmalloc.c:2340
#1 0x000055555560f14a in _PyMem_DebugCheckAddress (api=<optimized out>,
p=p@entry=0x7ffff7e72c20) at ../Objects/obmalloc.c:2281
#2 0x000055555560f1c7 in _PyMem_DebugRawFree (
ctx=ctx@entry=0x555555bddc60 <_PyMem_Debug+96>, p=p@entry=0x7ffff7e72c20)
at ../Objects/obmalloc.c:2092
#3 0x000055555560f20f in _PyMem_DebugFree (
ctx=0x555555bddc60 <_PyMem_Debug+96>, ptr=0x7ffff7e72c20)
at ../Objects/obmalloc.c:2217
#4 0x0000555555610471 in PyObject_Free (ptr=<optimized out>)
at ../Objects/obmalloc.c:640
#5 0x00007ffff5b6efa3 in pyo3::typeob::PyObjectAlloc::dealloc (py=...,
obj=0x7ffff7e72c20) at /home/joar/git/rust-csv-py/pyo3/src/typeob.rs:227
#6 0x00007ffff5b62d60 in pyo3::typeob::tp_dealloc_callback (
obj=0x7ffff7e72c20) at /home/joar/git/rust-csv-py/pyo3/src/typeob.rs:461
#7 0x0000555555621f20 in subtype_dealloc (self=self@entry=0x7ffff7e72c20)
at ../Objects/typeobject.c:1256
#8 0x000055555560b7ed in _Py_Dealloc (op=0x7ffff7e72c20)
at ../Objects/object.c:1934
#9 0x00005555555f8a6b in free_keys_object (keys=keys@entry=0x555555d12c70)
at ../Objects/dictobject.c:559
#10 0x00005555555fa8e3 in dict_dealloc (mp=mp@entry=0x7ffff7eaa328)
---Type <return> to continue, or q <return> to quit---
at ../Objects/dictobject.c:1913
#11 0x000055555560b7ed in _Py_Dealloc (op=0x7ffff7eaa328)
at ../Objects/object.c:1934
#12 0x000055555560944e in module_dealloc (m=m@entry=0x7ffff7ea57d8)
at ../Objects/moduleobject.c:684
#13 0x000055555560b7ed in _Py_Dealloc (op=0x7ffff7ea57d8)
at ../Objects/object.c:1934
#14 0x00005555555fcf95 in insertdict (mp=mp@entry=0x7ffff7f56e68,
key=key@entry=0x7ffff7eb2580, hash=1016438506669533865,
value=value@entry=0x555555bdd520 <_Py_NoneStruct>)
at ../Objects/dictobject.c:1076
#15 0x00005555555fe5da in PyDict_SetItem (op=0x7ffff7f56e68,
key=0x7ffff7eb2580, value=0x555555bdd520 <_Py_NoneStruct>)
at ../Objects/dictobject.c:1463
#16 0x00005555555ff174 in dict_ass_sub (mp=<optimized out>, v=<optimized out>,
w=<optimized out>) at ../Objects/dictobject.c:2056
#17 0x00005555557c656b in PyObject_SetItem (o=o@entry=0x7ffff7f56e68,
key=<optimized out>, value=0x555555bdd520 <_Py_NoneStruct>)
at ../Objects/abstract.c:198
#18 0x00005555556b0c2e in PyImport_Cleanup () at ../Python/import.c:479
#19 0x00005555556bfa73 in Py_FinalizeEx () at ../Python/pylifecycle.c:1192
#20 0x00005555555c4e9e in pymain_main (pymain=pymain@entry=0x7fffffffd660)
at ../Modules/main.c:2789
---Type <return> to continue, or q <return> to quit---
#21 0x00005555555c4fb1 in _Py_UnixMain (argc=<optimized out>,
argv=<optimized out>) at ../Modules/main.c:2822
#22 0x00005555555bfb73 in main (argc=<optimized out>, argv=<optimized out>)
at ../Programs/python.c:15
(gdb) quit
A debugging session is active.
Inferior 1 [process 22416] will be killed.
Quit anyway? (y or n) y |
EDIT: I opened #322 that should fix this Line 10 in 1b4afd1
However, the The root tox.ini has
|
There's another problem with the tests even once I've fixed the issue in #220 (comment). It seems that |
Should this be closed now that #322 has been merged? |
@pganssle No, I don't believe so. |
🐛 Bug Reports
When reporting a bug, please provide the following information. If this is not a bug report you can just discard this template.
🌍 Environment
venv
rustc --version
):rustc 1.30.0-nightly (2d4e34ca8 2018-09-09)
💥 Reproducing
Check out the branch at https://github.com/joar/pyo3/tree/bug/subclass-causes-sigsegv/examples/word-count
I believe the issue occurs during python's final GC.
The text was updated successfully, but these errors were encountered: