mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
bpo-30860: Consolidate stateful runtime globals. (#3397)
* 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).
This commit is contained in:
parent
bab21faded
commit
2ebc5ce42a
72 changed files with 2746 additions and 1312 deletions
|
@ -1,6 +1,7 @@
|
|||
/* Abstract Object Interface (many thanks to Jim Fulton) */
|
||||
|
||||
#include "Python.h"
|
||||
#include "internal/pystate.h"
|
||||
#include <ctype.h>
|
||||
#include "structmember.h" /* we need the offsetof() macro from there */
|
||||
#include "longintrepr.h"
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#define PY_SSIZE_T_CLEAN
|
||||
#include "Python.h"
|
||||
#include "internal/mem.h"
|
||||
#include "internal/pystate.h"
|
||||
#include "structmember.h"
|
||||
#include "bytes_methods.h"
|
||||
#include "bytesobject.h"
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#define PY_SSIZE_T_CLEAN
|
||||
|
||||
#include "Python.h"
|
||||
#include "internal/mem.h"
|
||||
#include "internal/pystate.h"
|
||||
|
||||
#include "bytes_methods.h"
|
||||
#include "pystrhex.h"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "Python.h"
|
||||
#include "internal/pystate.h"
|
||||
#include "frameobject.h"
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
/* Cell object implementation */
|
||||
|
||||
#include "Python.h"
|
||||
#include "internal/mem.h"
|
||||
#include "internal/pystate.h"
|
||||
|
||||
PyObject *
|
||||
PyCell_New(PyObject *obj)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
/* Class object implementation (dead now except for methods) */
|
||||
|
||||
#include "Python.h"
|
||||
#include "internal/mem.h"
|
||||
#include "internal/pystate.h"
|
||||
#include "structmember.h"
|
||||
|
||||
#define TP_DESCR_GET(t) ((t)->tp_descr_get)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* Descriptors -- a new, flexible way to describe attributes */
|
||||
|
||||
#include "Python.h"
|
||||
#include "internal/pystate.h"
|
||||
#include "structmember.h" /* Why is this not included in Python.h? */
|
||||
|
||||
/*[clinic input]
|
||||
|
|
|
@ -111,6 +111,7 @@ converting the dict to the combined table.
|
|||
#define PyDict_MINSIZE 8
|
||||
|
||||
#include "Python.h"
|
||||
#include "internal/pystate.h"
|
||||
#include "dict-common.h"
|
||||
#include "stringlib/eq.h" /* to get unicode_eq() */
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#define PY_SSIZE_T_CLEAN
|
||||
#include <Python.h>
|
||||
#include "internal/mem.h"
|
||||
#include "internal/pystate.h"
|
||||
#include "structmember.h"
|
||||
#include "osdefs.h"
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* Frame object implementation */
|
||||
|
||||
#include "Python.h"
|
||||
#include "internal/pystate.h"
|
||||
|
||||
#include "code.h"
|
||||
#include "frameobject.h"
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
/* Function object implementation */
|
||||
|
||||
#include "Python.h"
|
||||
#include "internal/mem.h"
|
||||
#include "internal/pystate.h"
|
||||
#include "code.h"
|
||||
#include "structmember.h"
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* Generator object implementation */
|
||||
|
||||
#include "Python.h"
|
||||
#include "internal/pystate.h"
|
||||
#include "frameobject.h"
|
||||
#include "structmember.h"
|
||||
#include "opcode.h"
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
/* Iterator objects */
|
||||
|
||||
#include "Python.h"
|
||||
#include "internal/mem.h"
|
||||
#include "internal/pystate.h"
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* List object implementation */
|
||||
|
||||
#include "Python.h"
|
||||
#include "internal/pystate.h"
|
||||
#include "accu.h"
|
||||
|
||||
#ifdef STDC_HEADERS
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
/* Memoryview object implementation */
|
||||
|
||||
#include "Python.h"
|
||||
#include "internal/mem.h"
|
||||
#include "internal/pystate.h"
|
||||
#include "pystrhex.h"
|
||||
#include <stddef.h>
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
/* Method object implementation */
|
||||
|
||||
#include "Python.h"
|
||||
#include "internal/mem.h"
|
||||
#include "internal/pystate.h"
|
||||
#include "structmember.h"
|
||||
|
||||
/* Free list for method objects to safe malloc/free overhead
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
/* Module object implementation */
|
||||
|
||||
#include "Python.h"
|
||||
#include "internal/pystate.h"
|
||||
#include "structmember.h"
|
||||
|
||||
static Py_ssize_t max_module_number;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
/* Generic object operations; and implementation of None */
|
||||
|
||||
#include "Python.h"
|
||||
#include "internal/pystate.h"
|
||||
#include "frameobject.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -2022,14 +2023,6 @@ finally:
|
|||
|
||||
/* Trashcan support. */
|
||||
|
||||
/* Current call-stack depth of tp_dealloc calls. */
|
||||
int _PyTrash_delete_nesting = 0;
|
||||
|
||||
/* List of objects that still need to be cleaned up, singly linked via their
|
||||
* gc headers' gc_prev pointers.
|
||||
*/
|
||||
PyObject *_PyTrash_delete_later = NULL;
|
||||
|
||||
/* Add op to the _PyTrash_delete_later list. Called when the current
|
||||
* call-stack depth gets large. op must be a currently untracked gc'ed
|
||||
* object, with refcount 0. Py_DECREF must already have been called on it.
|
||||
|
@ -2040,8 +2033,8 @@ _PyTrash_deposit_object(PyObject *op)
|
|||
assert(PyObject_IS_GC(op));
|
||||
assert(_PyGC_REFS(op) == _PyGC_REFS_UNTRACKED);
|
||||
assert(op->ob_refcnt == 0);
|
||||
_Py_AS_GC(op)->gc.gc_prev = (PyGC_Head *)_PyTrash_delete_later;
|
||||
_PyTrash_delete_later = op;
|
||||
_Py_AS_GC(op)->gc.gc_prev = (PyGC_Head *)_PyRuntime.gc.trash_delete_later;
|
||||
_PyRuntime.gc.trash_delete_later = op;
|
||||
}
|
||||
|
||||
/* The equivalent API, using per-thread state recursion info */
|
||||
|
@ -2062,11 +2055,11 @@ _PyTrash_thread_deposit_object(PyObject *op)
|
|||
void
|
||||
_PyTrash_destroy_chain(void)
|
||||
{
|
||||
while (_PyTrash_delete_later) {
|
||||
PyObject *op = _PyTrash_delete_later;
|
||||
while (_PyRuntime.gc.trash_delete_later) {
|
||||
PyObject *op = _PyRuntime.gc.trash_delete_later;
|
||||
destructor dealloc = Py_TYPE(op)->tp_dealloc;
|
||||
|
||||
_PyTrash_delete_later =
|
||||
_PyRuntime.gc.trash_delete_later =
|
||||
(PyObject*) _Py_AS_GC(op)->gc.gc_prev;
|
||||
|
||||
/* Call the deallocator directly. This used to try to
|
||||
|
@ -2076,9 +2069,9 @@ _PyTrash_destroy_chain(void)
|
|||
* up distorting allocation statistics.
|
||||
*/
|
||||
assert(op->ob_refcnt == 0);
|
||||
++_PyTrash_delete_nesting;
|
||||
++_PyRuntime.gc.trash_delete_nesting;
|
||||
(*dealloc)(op);
|
||||
--_PyTrash_delete_nesting;
|
||||
--_PyRuntime.gc.trash_delete_nesting;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -470,6 +470,7 @@ later:
|
|||
*/
|
||||
|
||||
#include "Python.h"
|
||||
#include "internal/pystate.h"
|
||||
#include "structmember.h"
|
||||
#include "dict-common.h"
|
||||
#include <stddef.h>
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
*/
|
||||
|
||||
#include "Python.h"
|
||||
#include "internal/pystate.h"
|
||||
#include "structmember.h"
|
||||
|
||||
/* Object used as dummy key to fill deleted entries */
|
||||
|
|
|
@ -14,6 +14,8 @@ this type and there is exactly one in existence.
|
|||
*/
|
||||
|
||||
#include "Python.h"
|
||||
#include "internal/mem.h"
|
||||
#include "internal/pystate.h"
|
||||
#include "structmember.h"
|
||||
|
||||
static PyObject *
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
/* Tuple object implementation */
|
||||
|
||||
#include "Python.h"
|
||||
#include "internal/pystate.h"
|
||||
#include "accu.h"
|
||||
|
||||
/*[clinic input]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* Type object implementation */
|
||||
|
||||
#include "Python.h"
|
||||
#include "internal/pystate.h"
|
||||
#include "frameobject.h"
|
||||
#include "structmember.h"
|
||||
|
||||
|
@ -1157,10 +1158,10 @@ subtype_dealloc(PyObject *self)
|
|||
/* UnTrack and re-Track around the trashcan macro, alas */
|
||||
/* See explanation at end of function for full disclosure */
|
||||
PyObject_GC_UnTrack(self);
|
||||
++_PyTrash_delete_nesting;
|
||||
++_PyRuntime.gc.trash_delete_nesting;
|
||||
++ tstate->trash_delete_nesting;
|
||||
Py_TRASHCAN_SAFE_BEGIN(self);
|
||||
--_PyTrash_delete_nesting;
|
||||
--_PyRuntime.gc.trash_delete_nesting;
|
||||
-- tstate->trash_delete_nesting;
|
||||
|
||||
/* Find the nearest base with a different tp_dealloc */
|
||||
|
@ -1254,10 +1255,10 @@ subtype_dealloc(PyObject *self)
|
|||
Py_DECREF(type);
|
||||
|
||||
endlabel:
|
||||
++_PyTrash_delete_nesting;
|
||||
++_PyRuntime.gc.trash_delete_nesting;
|
||||
++ tstate->trash_delete_nesting;
|
||||
Py_TRASHCAN_SAFE_END(self);
|
||||
--_PyTrash_delete_nesting;
|
||||
--_PyRuntime.gc.trash_delete_nesting;
|
||||
-- tstate->trash_delete_nesting;
|
||||
|
||||
/* Explanation of the weirdness around the trashcan macros:
|
||||
|
@ -1297,7 +1298,7 @@ subtype_dealloc(PyObject *self)
|
|||
a subtle disaster.
|
||||
|
||||
Q. Why the bizarre (net-zero) manipulation of
|
||||
_PyTrash_delete_nesting around the trashcan macros?
|
||||
_PyRuntime.trash_delete_nesting around the trashcan macros?
|
||||
|
||||
A. Some base classes (e.g. list) also use the trashcan mechanism.
|
||||
The following scenario used to be possible:
|
||||
|
|
|
@ -40,6 +40,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
#define PY_SSIZE_T_CLEAN
|
||||
#include "Python.h"
|
||||
#include "internal/pystate.h"
|
||||
#include "ucnhash.h"
|
||||
#include "bytes_methods.h"
|
||||
#include "stringlib/eq.h"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue