Le dim. 5 avr. 2020 à 04:02, Skip Montanaro <skip.montanaro@gmail.com> a écrit :
The command is
% PYTHONTRACEMALLOC=5 ./python ./Tools/scripts/run_tests.py -R 5:50:reflog.txt test_rattlesnake (...) FWIW, the register branch of my CPython fork:
gdb traceback: (gdb) where (...) #2 0x000000000056671d in fatal_error_exit (status=-1) at Python/pylifecycle.c:2183 (...) #8 0x000000000047d61e in PyObject_Free (ptr=0x7d3e40 <_Py_FalseStruct>) at Objects/obmalloc.c:709 #9 0x0000000000498a9b in object_dealloc (self=False) at Objects/typeobject.c:3824 #10 0x000000000047c5aa in _Py_Dealloc (op=False) at Objects/object.c:2206 #11 0x00000000005f771c in _Py_DECREF (filename=0x741e7d "./Modules/_io/iobase.c", lineno=275, op=False) at ./Include/object.h:425 #12 0x00000000005f7f16 in iobase_finalize (self=<_io.TextIOWrapper at remote 0x7fffeab2a6e0>) at ./Modules/_io/iobase.c:275 #13 0x0000000000477755 in PyObject_CallFinalizer (self=<_io.TextIOWrapper at remote 0x7fffeab2a6e0>) at Objects/object.c:193 #14 0x00000000004777ea in PyObject_CallFinalizerFromDealloc (self=<_io.TextIOWrapper at remote 0x7fffeab2a6e0>) at Objects/object.c:211 #15 0x00000000005f7fd8 in _PyIOBase_finalize (self=<_io.TextIOWrapper at remote 0x7fffeab2a6e0>) at ./Modules/_io/iobase.c:319 #16 0x0000000000609533 in textiowrapper_dealloc (self=0x7fffeab2a6e0) at ./Modules/_io/textio.c:1433 (...) #48 0x0000000000595fa7 in delete_garbage (tstate=0x82dc80, gcstate=0x82c648, collectable=0x7fffffffd2c0, old=0x82c690) at Modules/gcmodule.c:1005 #49 0x00000000005965c8 in collect (tstate=0x82dc80, generation=2, n_collected=0x0, n_uncollectable=0x0, nofail=1) at Modules/gcmodule.c:1275 #50 0x00000000005980e7 in _PyGC_CollectNoFail () at Modules/gcmodule.c:2099 #51 0x0000000000546da8 in _PyImport_Cleanup (tstate=0x82dc80) at Python/import.c:633 #52 0x0000000000564f89 in Py_FinalizeEx () at Python/pylifecycle.c:1416 #53 0x000000000041ed1b in Py_RunMain () at Modules/main.c:634 #54 0x000000000041ed90 in pymain_main (args=0x7fffffffd500) at Modules/main.c:662 #55 0x000000000041ee0a in Py_BytesMain (argc=6, argv=0x7fffffffd628) at Modules/main.c:686 #56 0x000000000041d786 in main (argc=6, argv=0x7fffffffd628) at ./Programs/python.c:16 (gdb) p *res $6 = { ob_refcnt = 0, ob_type = 0x7d3ca0 <PyBool_Type> } (gdb) p *(PyLongObject*)res $7 = { ob_base = { ob_base = { ob_refcnt = 0, ob_type = 0x7d3ca0 <PyBool_Type> }, ob_size = 0 }, ob_digit = {0} } (gdb) p res == ((PyObject *) &_Py_FalseStruct) $8 = 1 Py_FinalizeEx() cleans up all modules with _PyImport_Cleanup(). When Python destroys a _io.TextIOWrapper instance, Py_False is destroyed... Py_False must never me deallocated: it's statically allocated. Py_False reference counter should not decrease to 0. It seems like your Python changes use Py_False "somewhere" without Py_INCREF(Py_False). -- It seems like you are working on a register-based bytecode, cool. I recall that you told me something like that ;-) It seems like executing the register-based bytecode of the following function is enough to steal one reference to False (use False without INCREF): def _long_block(s, b): if s > b: return s return b Maybe it's COMPARE_OP_REG() which calls SETLOCAL(dst, False). Maybe it's JUMP_IF_FALSE_REG() which has suspicious code: DECREF without clearing GETLOCAL(src). PyObject *cond = GETLOCAL(src); .. Py_DECREF(cond); Maybe SETLOCAL(src, NULL); is need somewhere. Maybe it's something else. Replacing stack-based bytecode with register-based bytecode requires to rethink the lifetime of registers... I had a hard time to fix my old "registervm" project to fix the register lifetime: I added CLEAR_REG bytecode to explicitly clear a register. Using a stack, all "CLEAR_REG" operation are implicit. You have to make them explicit. Hopefully, a compiler can easily reuse registers and remove most CLEAR_REG. -- My old project (2012, OMG, I'm getting old!): https://faster-cpython.readthedocs.io/registervm.html https://hg.python.org/sandbox/registervm/file/tip/REGISTERVM.txt Victor -- Night gathers, and now my watch begins. It shall not end until my death.