[issue38609] Trashcan mechanism segfault during interpreter finalization in Python 3.7.5

2019-11-13 Thread ysnt27


ysnt27  added the comment:

Thanks for making the issue clear.

My understanding is that,
all C++ destructors have to check Python interpreter before Py_DECREF,
like this.

``` cplusplus
  ~something() {
// PyThreadState *_tstate = PyThreadState_GET();
PyThreadState *_tstate = _PyThreadState_UncheckedGet();
if (_tstate) {
  Py_DECREF(somelist);
}
  }
```

Is this right?

--

___
Python tracker 
<https://bugs.python.org/issue38609>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38609] Trashcan mechanism segfault during interpreter finalization in Python 3.7.5

2019-10-27 Thread ysnt27


New submission from ysnt27 :

My original issue was reported to Boost.Python,
https://github.com/boostorg/python/issues/248
And I found similar issue
https://bugs.python.org/issue17703

It seems root cause exists in Python not Boost.Python.
As the issue #17703 is already closed, I want to open a new issue.

I attached a sample source code, "sample1.cc".
With the code, I can reproduce segmantation fault, like this.

% gdb /usr/local/python375/bin/python3.7dm
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-115.el7
Copyright (C) 2013 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-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/local/python375/bin/python3.7dm...done.
(gdb) run
Starting program: /usr/local/python375/bin/python3.7dm 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Python 3.7.5 (default, Oct 25 2019, 16:11:10) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sample1
something called
>>> sample1.dummy()
[1]
>>> exit()
~something called

Program received signal SIGSEGV, Segmentation fault.
0x0044602a in list_dealloc (op=op@entry=0x77f4b360)
at ../Objects/listobject.c:316
316 Py_TRASHCAN_SAFE_BEGIN(op)
(gdb) p _PyRuntime.gilstate.tstate_current
$1 = {_value = 0}
(gdb) where
#0  0x0044602a in list_dealloc (op=op@entry=0x77f4b360)
at ../Objects/listobject.c:316
#1  0x00466452 in _Py_Dealloc (op=0x77f4b360)
at ../Objects/object.c:1971
#2  0x7051cc28 in something::~something (this=0x7071e140 , 
__in_chrg=) at sample1.cc:26
#3  0x76eeac99 in __run_exit_handlers (status=status@entry=0, 
listp=0x772786c8 <__exit_funcs>, 
run_list_atexit=run_list_atexit@entry=true) at exit.c:77
#4  0x76eeace7 in __GI_exit (status=status@entry=0) at exit.c:99
#5  0x005178e4 in Py_Exit (sts=sts@entry=0)
at ../Python/pylifecycle.c:2292
#6  0x0051faf4 in handle_system_exit () at ../Python/pythonrun.c:636
#7  0x00520d88 in PyErr_PrintEx (
set_sys_last_vars=set_sys_last_vars@entry=1) at ../Python/pythonrun.c:646
#8  0x0052115f in PyErr_Print () at ../Python/pythonrun.c:542
#9  0x00521d1a in PyRun_InteractiveLoopFlags (
fp=fp@entry=0x77279640 <_IO_2_1_stdin_>, 
filename_str=filename_str@entry=0x5e55b2 "", 
flags=flags@entry=0x7fffe2f0) at ../Python/pythonrun.c:134
#10 0x005223d8 in PyRun_AnyFileExFlags (
fp=fp@entry=0x77279640 <_IO_2_1_stdin_>, filename=0x5e55b2 "", 
closeit=closeit@entry=0, flags=flags@entry=0x7fffe2f0)
---Type  to continue, or q  to quit---
at ../Python/pythonrun.c:78
#11 0x00422023 in pymain_run_file (fp=0x77279640 <_IO_2_1_stdin_>, 
filename=0x0, p_cf=p_cf@entry=0x7fffe2f0) at ../Modules/main.c:427
#12 0x004220e5 in pymain_run_filename (
pymain=pymain@entry=0x7fffe320, cf=cf@entry=0x7fffe2f0)
at ../Modules/main.c:1606
#13 0x004221d8 in pymain_run_python (pymain=pymain@entry=0x7fffe320)
at ../Modules/main.c:2867
#14 0x0042550f in pymain_main (pymain=pymain@entry=0x7fffe320)
at ../Modules/main.c:3028
#15 0x00425589 in _Py_UnixMain (argc=, 
argv=) at ../Modules/main.c:3063
#16 0x0041f116 in main (argc=, argv=)
at ../Programs/python.c:15
(gdb) l
311 static void
312 list_dealloc(PyListObject *op)
313 {
314 Py_ssize_t i;
315 PyObject_GC_UnTrack(op);
316 Py_TRASHCAN_SAFE_BEGIN(op)
317 if (op->ob_item != NULL) {
318 /* Do it backwards, for Christian Tismer.
319There's a simple test case where somehow this reduces
320thrashing when a *very* large list is created and
(gdb)

--
components: Interpreter Core
files: sample1.cc
messages: 355510
nosy: ysnt27
priority: normal
severity: normal
status: open
title: Trashcan mechanism segfault during interpreter finalization in Python 
3.7.5
type: crash
versions: Python 3.7
Added file: https://bugs.python.org/file48681/sample1.cc

___
Python tracker 
<https://bugs.python.org/issue38609>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com