summaryrefslogtreecommitdiffstats
path: root/Modules/gcmodule.c
Commit message (Collapse)AuthorAgeFilesLines
...
* bpo-38858: Factorize Py_EndInterpreter() code (GH-17273)Victor Stinner2019-11-201-2/+2
| | | | | | * Factorize code in common between Py_FinalizeEx() and Py_EndInterpreter(). * Py_EndInterpreter() now also calls _PyWarnings_Fini(). * Call _PyExc_Fini() and _PyGC_Fini() later in the finalization.
* bpo-36710: Add PyInterpreterState.runtime field (GH-17270)Victor Stinner2019-11-201-2/+2
| | | | | | | | | | | Add PyInterpreterState.runtime field: reference to the _PyRuntime global variable. This field exists to not have to pass runtime in addition to tstate to a function. Get runtime from tstate: tstate->interp->runtime. Remove "_PyRuntimeState *runtime" parameter from functions already taking a "PyThreadState *tstate" parameter. _PyGC_Init() first parameter becomes "PyThreadState *tstate".
* bpo-36710: Pass tstate parameter to GC collect() (GH-17267)Victor Stinner2019-11-201-37/+50
| | | | Pass tstate parameter (PyThreadState) to GC collect() function and other GC subfunctions.
* bpo-38631: Avoid Py_FatalError() in handle_legacy_finalizers() (GH-17266)Victor Stinner2019-11-201-6/+18
| | | | | * Rename _PyGC_Initialize() to _PyGC_InitializeRuntime() * Add _PyGC_Init(): initialize _PyRuntime.gc.garbage list * Call _PyGC_Init() before _PyTypes_Init()
* Minor fixes to the formatting of the notes of Modules/gcmodule.c (GH-17247)Pablo Galindo2019-11-191-2/+2
|
* Years overdue, explain why unreachable objects are moved. (GH-17030)Tim Peters2019-11-021-1/+38
|
* visit_reachable: replace release-mode test with an assert. (GH-16866)Tim Peters2019-10-211-2/+5
| | | | | | | It should be impossible for an untracked object to have the collecting flag set. Back when state was stored in gc_refs, it obviously was impossible (gc_refs couldn't possibly have a positive & negative value simultaneously). While the _implementation_ of "state" has gotten much more complicated, it's still _logically_ just as impossible.
* validate_list: make flags argument impossible to spell wrongly. (GH-16843)Tim Peters2019-10-191-16/+37
|
* Misc gc code & comment cleanups. (GH-16752)Tim Peters2019-10-131-22/+44
| | | | | | | | | | | | * Misc gc code & comment cleanups. validate_list: there are two temp flags polluting pointers, but this checked only one. Now it checks both, and verifies that the list head's pointers are not polluted. move_unreachable: repaired incoherent comments. Added new comments. Cleared the pollution of the unreachable list head's 'next' pointer (it was expedient while the function was running, but there's no excuse for letting this damage survive the function's end). * Update Modules/gcmodule.c Co-Authored-By: Pablo Galindo <Pablogsal@gmail.com>
* bpo-38379: Don't block collection of unreachable objects when some objects ↵Pablo Galindo2019-10-131-60/+122
| | | | | | | resurrect (GH-16687) Currently if any finalizer invoked during garbage collection resurrects any object, the gc gives up and aborts the collection. Although finalizers are assured to only run once per object, this behaviour of the gc can lead to an ever-increasing memory situation if new resurrecting objects are allocated in every new gc collection. To avoid this, recompute what objects among the unreachable set need to be resurrected and what objects can be safely collected. In this way, resurrecting objects will not block the collection of other objects in the unreachable set.
* bpo-38437: Activate GC_DEBUG when PY_DEBUG is set (GH-16707)Pablo Galindo2019-10-101-2/+5
|
* bpo-38392: Only declare visit_validate() if Py_DEBUG is defined (GH-16689)Victor Stinner2019-10-101-0/+3
| | | | | bpo-38392, bpo-38426: Fix a compiler warning in gcmodule.c. Fix also a typo in PYMEM_DEADBYTE macro comment.
* bpo-38379: don't claim objects are collected when they aren't (#16658)Tim Peters2019-10-091-6/+4
| | | | | | * bpo-38379: when a finalizer resurrects an object, nothing is actually collected in this run of gc. Change the stats to relect that truth.
* bpo-38070: Enhance visit_decref() debug trace (GH-16631)Victor Stinner2019-10-081-4/+5
| | | | | | | | subtract_refs() now pass the parent object to visit_decref() which pass it to _PyObject_ASSERT(). So if the "is freed" assertion fails, the parent is used in debug trace, rather than the freed object. The parent object is more likely to contain useful information. Freed objects cannot be inspected are are displayed as "<object at xxx is freed>" with no other detail.
* bpo-38392: PyObject_GC_Track() validates object in debug mode (GH-16615)Victor Stinner2019-10-071-0/+19
| | | | | | | | In debug mode, PyObject_GC_Track() now calls tp_traverse() of the object type to ensure that the object is valid: test that objects visited by tp_traverse() are valid. Fix pyexpat.c: only track the parser in the GC once the parser is fully initialized.
* bpo-36389: _PyObject_CheckConsistency() available in release mode (GH-16612)Victor Stinner2019-10-071-1/+0
| | | | | | | | | | | | | | | | | | | | | bpo-36389, bpo-38376: The _PyObject_CheckConsistency() function is now also available in release mode. For example, it can be used to debug a crash in the visit_decref() function of the GC. Modify the following functions to also work in release mode: * _PyDict_CheckConsistency() * _PyObject_CheckConsistency() * _PyType_CheckConsistency() * _PyUnicode_CheckConsistency() Other changes: * _PyMem_IsPtrFreed(ptr) now also returns 1 if ptr is NULL (equals to 0). * _PyBytesWriter_CheckConsistency() now returns 1 and is only used with assert(). * Reorder _PyObject_Dump() to write safe fields first, and only attempt to render repr() at the end.
* Clear weakrefs in garbage found by the GC (#16495)Neil Schemenauer2019-09-301-0/+17
| | | | | Fix a bug due to the interaction of weakrefs and the cyclic garbage collector. We must clear any weakrefs in garbage in order to prevent their callbacks from executing and causing a crash.
* bpo-38070: visit_decref() calls _PyObject_IsFreed() (GH-15782)Victor Stinner2019-09-091-0/+2
| | | | | | In debug mode, visit_decref() now calls _PyObject_IsFreed() to ensure that the object is not freed. If it's freed, the program fails with an assertion error and Python dumps informations about the freed object.
* bpo-37990: fix gc stats (GH-15626)Inada Naoki2019-08-311-2/+3
|
* bpo-37729: gc: write stats at once (GH-15050)Inada Naoki2019-08-021-20/+25
| | | | | | | | | | | | | | | gc used several PySys_WriteStderr() calls to write stats. It caused stats mixed up when stderr is shared by multiple processes like this: gc: collecting generation 2... gc: objects in each generation: 0 0gc: collecting generation 2... gc: objects in each generation: 0 0 126077 126077 gc: objects in permanent generation: 0 gc: objects in permanent generation: 0 gc: done, 112575 unreachable, 0 uncollectablegc: done, 112575 unreachable, 0 uncollectable, 0.2223s elapsed , 0.2344s elapsed
* bpo-37483: add _PyObject_CallOneArg() function (#14558)Jeroen Demeyer2019-07-041-1/+1
|
* bpo-32388: Remove cross-version binary compatibility requirement in tp_flags ↵Antoine Pitrou2019-05-291-1/+0
| | | | | | | | (GH-4944) It is now allowed to add new fields at the end of the PyTypeObject struct without having to allocate a dedicated compatibility flag in tp_flags. This will reduce the risk of running out of bits in the 32-bit tp_flags value.
* bpo-36829: Add _PyErr_WriteUnraisableMsg() (GH-13488)Victor Stinner2019-05-271-3/+2
| | | | | * sys.unraisablehook: add 'err_msg' field to UnraisableHookArgs. * Use _PyErr_WriteUnraisableMsg() in _ctypes _DictRemover_call() and gc delete_garbage().
* bpo-36710: Add runtime parameter in gcmodule.c (GH-12958)Victor Stinner2019-04-261-139/+163
| | | | Add 'state' or 'runtime' parameter to functions in gcmodule.c to avoid to rely directly on the global variable _PyRuntime.
* bpo-36710: Add runtime variable to Py_FinalizeEx() (GH-12937)Victor Stinner2019-04-241-2/+3
| | | | | | * Add a 'runtime' variable to Py_FinalizeEx() rather than working directly on the global variable _PyRuntime * Add a 'runtime' parameter to _PyGC_Fini(), _PyGILState_Fini() and call_ll_exitfuncs()
* bpo-36389: Cleanup gc.set_threshold() (GH-12844)Victor Stinner2019-04-151-2/+2
| | | | Don't assign generations[2].threshold to generations[2].threshold: useless operation.
* bpo-36016: Add generation option to gc.getobjects() (GH-11909)Pablo Galindo2019-02-231-5/+39
|
* bpo-35059: Cast void* to PyObject* (GH-10650)Victor Stinner2018-11-221-4/+5
| | | Don't pass void* to Python macros: use _PyObject_CAST().
* bpo-35059: Convert _PyObject_GC_TRACK() to inline function (GH-10643)Victor Stinner2018-11-221-6/+7
| | | | | | | | | | | | | * Add _PyObject_ASSERT_FROM() and _PyObject_ASSERT_FAILED_MSG() macros. * PyObject_GC_Track() now calls _PyObject_ASSERT_FAILED_MSG(), instead of Py_FatalError(), if the object is already tracked, to dump more information on error. * _PyObject_GC_TRACK() no longer checks if the object is already tracked at runtime, use an assertion instead for best performances; PyObject_GC_Track() still checks at runtime. * pycore_object.h now includes pycore_pystate.h. * Convert _PyObject_GC_TRACK() and _PyObject_GC_UNTRACK() macros to inline functions.
* bpo-35081: Add Include/internal/pycore_object.h (GH-10640)Victor Stinner2018-11-211-0/+1
| | | | Move _PyObject_GC_TRACK() and _PyObject_GC_UNTRACK() from Include/objimpl.h to Include/internal/pycore_object.h.
* bpo-35081: Rename internal headers (GH-10275)Victor Stinner2018-11-121-2/+2
| | | | | | | | | | | | | | Rename Include/internal/ headers: * pycore_hash.h -> pycore_pyhash.h * pycore_lifecycle.h -> pycore_pylifecycle.h * pycore_mem.h -> pycore_pymem.h * pycore_state.h -> pycore_pystate.h Add missing headers to Makefile.pre.in and PCbuild: * pycore_condvar.h. * pycore_hamt.h * pycore_pyhash.h
* bpo-35081: Add pycore_ prefix to internal header files (GH-10263)Victor Stinner2018-10-311-3/+3
| | | | | | | | | | | | | | | | | | | | * Rename Include/internal/ header files: * pyatomic.h -> pycore_atomic.h * ceval.h -> pycore_ceval.h * condvar.h -> pycore_condvar.h * context.h -> pycore_context.h * pygetopt.h -> pycore_getopt.h * gil.h -> pycore_gil.h * hamt.h -> pycore_hamt.h * hash.h -> pycore_hash.h * mem.h -> pycore_mem.h * pystate.h -> pycore_state.h * warnings.h -> pycore_warnings.h * PCbuild project, Makefile.pre.in, Modules/Setup: add the Include/internal/ directory to the search paths of header files. * Update includes. For example, replace #include "internal/mem.h" with #include "pycore_mem.h".
* bpo-9263: Use _PyObject_ASSERT() in gcmodule.c (GH-10112)Victor Stinner2018-10-261-46/+56
| | | | | | | | | | Replace assert() with _PyObject_ASSERT() in Modules/gcmodule.c to dump the faulty object on assertion failure to ease debugging. Fix also indentation of a large comment. Initial patch written by David Malcolm. Co-Authored-By: David Malcolm <dmalcolm@redhat.com>
* bpo-9263: Dump Python object on GC assertion failure (GH-10062)Victor Stinner2018-10-251-7/+9
| | | | | | | | | | | | | | | | | | | | | | | Changes: * Add _PyObject_AssertFailed() function. * Add _PyObject_ASSERT() and _PyObject_ASSERT_WITH_MSG() macros. * gc_decref(): replace assert() with _PyObject_ASSERT_WITH_MSG() to dump the faulty object if the assertion fails. _PyObject_AssertFailed() calls: * _PyMem_DumpTraceback(): try to log the traceback where the object memory has been allocated if tracemalloc is enabled. * _PyObject_Dump(): log repr(obj). * Py_FatalError(): log the current Python traceback. _PyObject_AssertFailed() uses _PyObject_IsFreed() heuristic to check if the object memory has been freed by a debug hook on Python memory allocators. Initial patch written by David Malcolm. Co-Authored-By: David Malcolm <dmalcolm@redhat.com>
* Fix typos in comments (GH-9905)Quan Tian2018-10-191-1/+1
|
* bpo-33597: Reduce PyGC_Head size (GH-7043)INADA Naoki2018-07-101-210/+369
|
* bpo-33622: Add checks for exceptions leaks in the garbage collector. (GH-7126)Serhiy Storchaka2018-05-291-4/+23
| | | | | * Failure in adding to gc.garbage is no longer fatal. * An exception in tp_clear() no longer lead to crash (though tp_clear() should not leave exceptions).
* bpo-33622: Fix issues with handling errors in the GC. (GH-7078)Serhiy Storchaka2018-05-241-8/+11
| | | | | | | * Fixed a leak when the GC fails to add an object with __del__ into the gc.garbage list. * PyGC_Collect() can now be called when an exception is set and preserves it. * Fixed an undefined behavior with comparing a dead pointer with NULL.
* bpo-33583: Add note in PyObject_GC_Resize() doc (GH-7021)INADA Naoki2018-05-211-0/+1
|
* Revert "bpo-31356: Add context manager to temporarily disable GC GH-5495Yury Selivanov2018-02-021-106/+0
| | | | | | | This reverts commit 72a0d218dcc94a3cc409a9ef32dfcd5a7bbcb43c. The reverted commit had a few issues so it was unanimously decided to undo it. See the bpo issue for details.
* bpo-31356: Add context manager to temporarily disable GC (GH-4224)Pablo Galindo2018-01-291-0/+106
|
* bpo-32436: Implement PEP 567 (#5027)Yury Selivanov2018-01-231-0/+2
|
* bpo-9566: Fix size_t=>int downcast warnings (#5230)Victor Stinner2018-01-181-3/+3
| | | | * Use wider types (int => Py_ssize_t) to avoid integer overflows. * Fix gc.get_freeze_count(): use Py_ssize_t type rather than int, since gc_list_size() returns a Py_ssize_t.
* Add the const qualifier to "char *" variables that refer to literal strings. ↵Serhiy Storchaka2017-11-111-1/+1
| | | | (#4370)
* bpo-31558: Add gc.freeze() (#3705)brainfvck2017-10-161-1/+63
| | | | | Freeze all the objects tracked by gc - move them to a permanent generation and ignore all the future collections. This can be used before a POSIX fork() call to make the gc copy-on-write friendly or to speed up collection.
* bpo-30860: Consolidate stateful runtime globals. (#3397)Eric Snow2017-09-081-213/+98
| | | | | | | * group the (stateful) runtime globals into various topical structs * consolidate the topical structs under a single top-level _PyRuntimeState struct * add a check-c-globals.py script that helps identify runtime globals Other globals are excluded (see globals.txt and check-c-globals.py).
* Revert "bpo-30860: Consolidate stateful runtime globals." (#3379)Eric Snow2017-09-061-96/+213
| | | Windows buildbots started failing due to include-related errors.
* bpo-30860: Consolidate stateful runtime globals. (#2594)Eric Snow2017-09-061-213/+96
| | | | | | | | | * group the (stateful) runtime globals into various topical structs * consolidate the topical structs under a single top-level _PyRuntimeState struct * add a check-c-globals.py script that helps identify runtime globals Other globals are excluded (see globals.txt and check-c-globals.py).
* Issue #20185: Converted the gc module to Argument Clinic.Serhiy Storchaka2017-02-041-98/+132
|
* Issue #28999: Use Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE whereverSerhiy Storchaka2017-01-231-8/+4
| | | | possible. Patch is writen with Coccinelle.