]> granicus.if.org Git - python/commitdiff
bpo-35081: Add Include/internal/pycore_object.h (GH-10640)
authorVictor Stinner <vstinner@redhat.com>
Wed, 21 Nov 2018 21:27:47 +0000 (22:27 +0100)
committerGitHub <noreply@github.com>
Wed, 21 Nov 2018 21:27:47 +0000 (22:27 +0100)
Move _PyObject_GC_TRACK() and _PyObject_GC_UNTRACK() from
Include/objimpl.h to Include/internal/pycore_object.h.

34 files changed:
Include/internal/pycore_object.h [new file with mode: 0644]
Include/objimpl.h
Modules/_io/bufferedio.c
Modules/_io/bytesio.c
Modules/_io/fileio.c
Modules/_io/iobase.c
Modules/_io/stringio.c
Modules/_io/textio.c
Modules/_io/winconsoleio.c
Modules/gcmodule.c
Objects/bytearrayobject.c
Objects/bytesobject.c
Objects/call.c
Objects/cellobject.c
Objects/classobject.c
Objects/descrobject.c
Objects/dictobject.c
Objects/exceptions.c
Objects/frameobject.c
Objects/funcobject.c
Objects/genobject.c
Objects/iterobject.c
Objects/listobject.c
Objects/memoryobject.c
Objects/methodobject.c
Objects/odictobject.c
Objects/setobject.c
Objects/sliceobject.c
Objects/tupleobject.c
Objects/typeobject.c
Objects/unicodeobject.c
Python/ceval.c
Python/context.c
Python/hamt.c

diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
new file mode 100644 (file)
index 0000000..a263834
--- /dev/null
@@ -0,0 +1,56 @@
+#ifndef Py_INTERNAL_OBJECT_H
+#define Py_INTERNAL_OBJECT_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
+#  error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN defined"
+#endif
+
+/* Tell the GC to track this object.
+ *
+ * NB: While the object is tracked by the collector, it must be safe to call the
+ * ob_traverse method.
+ *
+ * Internal note: _PyRuntime.gc.generation0->_gc_prev doesn't have any bit flags
+ * because it's not object header.  So we don't use _PyGCHead_PREV() and
+ * _PyGCHead_SET_PREV() for it to avoid unnecessary bitwise operations.
+ *
+ * The PyObject_GC_Track() function is the public version of this macro.
+ */
+#define _PyObject_GC_TRACK(o) do { \
+        PyGC_Head *g = _Py_AS_GC(o); \
+        if (g->_gc_next != 0) { \
+            Py_FatalError("GC object already tracked"); \
+        } \
+        assert((g->_gc_prev & _PyGC_PREV_MASK_COLLECTING) == 0); \
+        PyGC_Head *last = (PyGC_Head*)(_PyRuntime.gc.generation0->_gc_prev); \
+        _PyGCHead_SET_NEXT(last, g); \
+        _PyGCHead_SET_PREV(g, last); \
+        _PyGCHead_SET_NEXT(g, _PyRuntime.gc.generation0); \
+        _PyRuntime.gc.generation0->_gc_prev = (uintptr_t)g; \
+    } while (0);
+
+/* Tell the GC to stop tracking this object.
+ *
+ * Internal note: This may be called while GC.  So _PyGC_PREV_MASK_COLLECTING must
+ * be cleared.  But _PyGC_PREV_MASK_FINALIZED bit is kept.
+ *
+ * The PyObject_GC_UnTrack() function is the public version of this macro.
+ */
+#define _PyObject_GC_UNTRACK(o) do { \
+        PyGC_Head *g = _Py_AS_GC(o); \
+        PyGC_Head *prev = _PyGCHead_PREV(g); \
+        PyGC_Head *next = _PyGCHead_NEXT(g); \
+        assert(next != NULL); \
+        _PyGCHead_SET_NEXT(prev, next); \
+        _PyGCHead_SET_PREV(next, prev); \
+        g->_gc_next = 0; \
+        g->_gc_prev &= _PyGC_PREV_MASK_FINALIZED; \
+    } while (0);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_INTERNAL_OBJECT_H */
index b51b751b9c85fbe9d3ad34f9283ca93b7cd4c014..c455d4bebbdc579932d09d756ac66d6c424a6ab7 100644 (file)
@@ -323,51 +323,6 @@ typedef struct {
     _PyGCHead_SET_FINALIZED(_Py_AS_GC(o))
 #endif   /* !defined(Py_LIMITED_API) */
 
-
-#if defined(Py_BUILD_CORE) || defined(Py_BUILD_CORE_BUILTIN)
-/* Tell the GC to track this object.
- *
- * NB: While the object is tracked by the collector, it must be safe to call the
- * ob_traverse method.
- *
- * Internal note: _PyRuntime.gc.generation0->_gc_prev doesn't have any bit flags
- * because it's not object header.  So we don't use _PyGCHead_PREV() and
- * _PyGCHead_SET_PREV() for it to avoid unnecessary bitwise operations.
- *
- * The PyObject_GC_Track() function is the public version of this macro.
- */
-#define _PyObject_GC_TRACK(o) do { \
-    PyGC_Head *g = _Py_AS_GC(o); \
-    if (g->_gc_next != 0) { \
-        Py_FatalError("GC object already tracked"); \
-    } \
-    assert((g->_gc_prev & _PyGC_PREV_MASK_COLLECTING) == 0); \
-    PyGC_Head *last = (PyGC_Head*)(_PyRuntime.gc.generation0->_gc_prev); \
-    _PyGCHead_SET_NEXT(last, g); \
-    _PyGCHead_SET_PREV(g, last); \
-    _PyGCHead_SET_NEXT(g, _PyRuntime.gc.generation0); \
-    _PyRuntime.gc.generation0->_gc_prev = (uintptr_t)g; \
-    } while (0);
-
-/* Tell the GC to stop tracking this object.
- *
- * Internal note: This may be called while GC.  So _PyGC_PREV_MASK_COLLECTING must
- * be cleared.  But _PyGC_PREV_MASK_FINALIZED bit is kept.
- *
- * The PyObject_GC_UnTrack() function is the public version of this macro.
- */
-#define _PyObject_GC_UNTRACK(o) do { \
-    PyGC_Head *g = _Py_AS_GC(o); \
-    PyGC_Head *prev = _PyGCHead_PREV(g); \
-    PyGC_Head *next = _PyGCHead_NEXT(g); \
-    assert(next != NULL); \
-    _PyGCHead_SET_NEXT(prev, next); \
-    _PyGCHead_SET_PREV(next, prev); \
-    g->_gc_next = 0; \
-    g->_gc_prev &= _PyGC_PREV_MASK_FINALIZED; \
-    } while (0);
-#endif   /* defined(Py_BUILD_CORE) || defined(Py_BUILD_CORE_BUILTIN) */
-
 #ifndef Py_LIMITED_API
 PyAPI_FUNC(PyObject *) _PyObject_GC_Malloc(size_t size);
 PyAPI_FUNC(PyObject *) _PyObject_GC_Calloc(size_t size);
index e1e45dc8fae08e5a0939cea733341467149bce84..6f855b9edd08428f8aaf0f0cfa38463b903d261e 100644 (file)
@@ -9,6 +9,7 @@
 
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
+#include "pycore_object.h"
 #include "pycore_pystate.h"
 #include "structmember.h"
 #include "pythread.h"
index a50add2389e561550bdbbfa509322b63ab2a6d1e..8e54ec8e99c3894f160d3b771fb541816f6e60e1 100644 (file)
@@ -1,4 +1,5 @@
 #include "Python.h"
+#include "pycore_object.h"
 #include "structmember.h"       /* for offsetof() */
 #include "_iomodule.h"
 
index ffcb7301295354d35627d5ceb7619a77d3668b11..c502c430134ef6ccbd2aae9b4247ca4dca469448 100644 (file)
@@ -2,6 +2,7 @@
 
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
+#include "pycore_object.h"
 #include "structmember.h"
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
index 5b71732ef19c652dfa85ea06a885909372205e94..9b063cd372fe9b30cbdb9c1949de300457b60097 100644 (file)
@@ -10,6 +10,7 @@
 
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
+#include "pycore_object.h"
 #include "structmember.h"
 #include "_iomodule.h"
 
index 793fa1ee150b7a0461603d5323829e3d79aa1d70..bb5c3736a77a1c15e0a99759b938ae87b43d4ce1 100644 (file)
@@ -2,6 +2,7 @@
 #include "Python.h"
 #include "structmember.h"
 #include "pycore_accu.h"
+#include "pycore_object.h"
 #include "_iomodule.h"
 
 /* Implementation note: the buffer is always at least one character longer
index 8924834eb81c059ad89d073ee514152af701e8ef..645d7123324c04998cf10c3496cbaef8709ee894 100644 (file)
@@ -8,6 +8,7 @@
 
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
+#include "pycore_object.h"
 #include "structmember.h"
 #include "_iomodule.h"
 
index 148255c354a495a5279f0f80e934c0245e9b1bae..824690ff58d68863e9f14302fe6019e4de8e0c4c 100644 (file)
@@ -8,6 +8,7 @@
 
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
+#include "pycore_object.h"
 
 #ifdef MS_WINDOWS
 
@@ -556,7 +557,7 @@ read_console_w(HANDLE handle, DWORD maxlen, DWORD *readlen) {
     Py_BEGIN_ALLOW_THREADS
     DWORD off = 0;
     while (off < maxlen) {
-        DWORD n = (DWORD)-1; 
+        DWORD n = (DWORD)-1;
         DWORD len = min(maxlen - off, BUFSIZ);
         SetLastError(0);
         BOOL res = ReadConsoleW(handle, &buf[off], len, &n, NULL);
index 48b470006c4a6e3f3781b213eb988eba586b8e73..2cbf73866d1280a3abb943b78d3ad99ed0eb1a59 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "Python.h"
 #include "pycore_context.h"
+#include "pycore_object.h"
 #include "pycore_pymem.h"
 #include "pycore_pystate.h"
 #include "frameobject.h"        /* for PyFrame_ClearFreeList */
index 561b06cdf967a6aa00f5b6cc1fb605b8e39f945e..1442653819437298c0ba3ff567a31da45bfa2869 100644 (file)
@@ -2,6 +2,7 @@
 
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
+#include "pycore_object.h"
 #include "pycore_pymem.h"
 #include "pycore_pystate.h"
 #include "structmember.h"
index fac12f55210e726537cb382fec022b3c3a4ee195..bed75ee49e27cf277bae084b29cfdcde0d73c0ac 100644 (file)
@@ -3,6 +3,7 @@
 #define PY_SSIZE_T_CLEAN
 
 #include "Python.h"
+#include "pycore_object.h"
 #include "pycore_pymem.h"
 #include "pycore_pystate.h"
 
index 7c452b99d1176812b6d712fc0374d026bb59c29f..ce346c2934869d4e82fb8d1b54f378de25fc737d 100644 (file)
@@ -1,4 +1,5 @@
 #include "Python.h"
+#include "pycore_object.h"
 #include "pycore_pystate.h"
 #include "frameobject.h"
 
index 7605bcf7bc9b4a2771b47f48baa04397abb91db4..6b7136c41270607a428f812a6026732337fe117b 100644 (file)
@@ -1,6 +1,7 @@
 /* Cell object implementation */
 
 #include "Python.h"
+#include "pycore_object.h"
 #include "pycore_pymem.h"
 #include "pycore_pystate.h"
 
index 79b0562f7d5f48f95da23bd615e4649b0f846f2e..6d1f05ccd3a9e43907806576828efd1623960637 100644 (file)
@@ -1,6 +1,7 @@
 /* Class object implementation (dead now except for methods) */
 
 #include "Python.h"
+#include "pycore_object.h"
 #include "pycore_pymem.h"
 #include "pycore_pystate.h"
 #include "structmember.h"
index ca814bf78a69dd77e85e3a31c8ad361b3ba29c55..dd3c5014aea79845a997c02b1ae66f4153c545de 100644 (file)
@@ -1,6 +1,7 @@
 /* Descriptors -- a new, flexible way to describe attributes */
 
 #include "Python.h"
+#include "pycore_object.h"
 #include "pycore_pystate.h"
 #include "structmember.h" /* Why is this not included in Python.h? */
 
index df92bfd6a9781658de1a2311ec235cd1434f669c..24561dd42c2ed089fd4ea560402c87c56b2a5bcf 100644 (file)
@@ -111,6 +111,7 @@ converting the dict to the combined table.
 #define PyDict_MINSIZE 8
 
 #include "Python.h"
+#include "pycore_object.h"
 #include "pycore_pystate.h"
 #include "dict-common.h"
 #include "stringlib/eq.h"    /* to get unicode_eq() */
index 5ab127111cafb2bb59c2b32f5737e1fb60955b54..cecbf977a32781c2d5cb788331afedf56c30fd9e 100644 (file)
@@ -6,6 +6,7 @@
 
 #define PY_SSIZE_T_CLEAN
 #include <Python.h>
+#include "pycore_object.h"
 #include "pycore_pymem.h"
 #include "pycore_pystate.h"
 #include "structmember.h"
index 70cf5807130e03af54fee1893bb87f4b3287c693..b1a83d82a398a83c4c06706103bb392bd73f79c6 100644 (file)
@@ -1,6 +1,7 @@
 /* Frame object implementation */
 
 #include "Python.h"
+#include "pycore_object.h"
 #include "pycore_pystate.h"
 
 #include "code.h"
index a8e11a9a2d3d3a7e56818f6299fd217a67cc775e..982df5434d25433afb32dfb29403f0684821a3c5 100644 (file)
@@ -2,6 +2,7 @@
 /* Function object implementation */
 
 #include "Python.h"
+#include "pycore_object.h"
 #include "pycore_pymem.h"
 #include "pycore_pystate.h"
 #include "code.h"
index 716bd6d067bdbd92f9f0a49f029171a7f31c0c4c..3279a0947e8f2c8f5882fa05be39a87babf9f7d8 100644 (file)
@@ -1,6 +1,7 @@
 /* Generator object implementation */
 
 #include "Python.h"
+#include "pycore_object.h"
 #include "pycore_pystate.h"
 #include "frameobject.h"
 #include "structmember.h"
index 64bf92382be4bb91d41c6eb6370b391ffd6b20ca..ada1bdc7e87e61d729a5a637a0c191e48fc8c61b 100644 (file)
@@ -1,6 +1,7 @@
 /* Iterator objects */
 
 #include "Python.h"
+#include "pycore_object.h"
 #include "pycore_pymem.h"
 #include "pycore_pystate.h"
 
index 44160abae6eed4f2f2b455857f7497292efe5e59..6da8391fc27544034c1e02a4f78c61252983ae84 100644 (file)
@@ -1,6 +1,7 @@
 /* List object implementation */
 
 #include "Python.h"
+#include "pycore_object.h"
 #include "pycore_pystate.h"
 #include "pycore_accu.h"
 
index 060ae4dd3cd0f2fa32bfc6dfa298821b06388880..0f528eec68bc41cf01fc07f4c9653dabe4da3c8c 100644 (file)
@@ -1,6 +1,7 @@
 /* Memoryview object implementation */
 
 #include "Python.h"
+#include "pycore_object.h"
 #include "pycore_pymem.h"
 #include "pycore_pystate.h"
 #include "pystrhex.h"
index cfea8cf410d7f39ee685956702b18fa97c406159..23325e2a1b3e2ae88269388506bf516f8ba28505 100644 (file)
@@ -2,6 +2,7 @@
 /* Method object implementation */
 
 #include "Python.h"
+#include "pycore_object.h"
 #include "pycore_pymem.h"
 #include "pycore_pystate.h"
 #include "structmember.h"
index 13bc972039f3ad0130f6e222d64e6b38b53345f3..bdd61080d18b908c5d5f118ba2a1ffd881ae8cb6 100644 (file)
@@ -465,6 +465,7 @@ later:
 */
 
 #include "Python.h"
+#include "pycore_object.h"
 #include "pycore_pystate.h"
 #include "structmember.h"
 #include "dict-common.h"
index b11cb3a58696d505a8b49196ce9c99988d8c843e..c2a1467ba61a8b44ebaad612216fd177553260f2 100644 (file)
@@ -32,6 +32,7 @@
 */
 
 #include "Python.h"
+#include "pycore_object.h"
 #include "pycore_pystate.h"
 #include "structmember.h"
 
index 1f79faa3e6cad5ed6aabfa58cd50c15d06546806..c60483ea949459284ebaa99901a463add5785d21 100644 (file)
@@ -14,6 +14,7 @@ this type and there is exactly one in existence.
 */
 
 #include "Python.h"
+#include "pycore_object.h"
 #include "pycore_pymem.h"
 #include "pycore_pystate.h"
 #include "structmember.h"
index e7ba09d71d33ae796dc749b513be64a2e14e8384..83c63e089c3e4f030d16bb33649b73dba47f6540 100644 (file)
@@ -2,6 +2,7 @@
 /* Tuple object implementation */
 
 #include "Python.h"
+#include "pycore_object.h"
 #include "pycore_pystate.h"
 #include "pycore_accu.h"
 
index 4d599bf516327c4d859d673482a2308d243a5da5..2345b7c07dc5f072572a2ca895b2529ccca67c9e 100644 (file)
@@ -1,6 +1,7 @@
 /* Type object implementation */
 
 #include "Python.h"
+#include "pycore_object.h"
 #include "pycore_pystate.h"
 #include "frameobject.h"
 #include "structmember.h"
index 04ca5f3344470e7b14d72654f60b49a01de99831..d22b277a51c8a77a9b37220b3b32329c13052562 100644 (file)
@@ -41,6 +41,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
 #include "pycore_fileutils.h"
+#include "pycore_object.h"
 #include "pycore_pystate.h"
 #include "ucnhash.h"
 #include "bytes_methods.h"
index 9c0ab0663b14d3b182cb4d9142656551c246ba20..7b2465592a4b998ac4ce5d88ffe8201b68afdbd8 100644 (file)
@@ -10,6 +10,7 @@
 #define PY_LOCAL_AGGRESSIVE
 
 #include "Python.h"
+#include "pycore_object.h"
 #include "pycore_pystate.h"
 
 #include "code.h"
index b548ffee3bc0903271156416fe01197ea3c174da..302f7696bb6b4368889114c61c9e5f7323806dda 100644 (file)
@@ -1,9 +1,10 @@
 #include "Python.h"
 
-#include "structmember.h"
-#include "pycore_pystate.h"
 #include "pycore_context.h"
 #include "pycore_hamt.h"
+#include "pycore_object.h"
+#include "pycore_pystate.h"
+#include "structmember.h"
 
 
 #define CONTEXT_FREELIST_MAXLEN 255
index 3fe70b40fafc345ada28b76edd7dac23b30de636..d734d6ed07fb27578cc09a5a07779eb6d8eedafc 100644 (file)
@@ -1,8 +1,9 @@
 #include "Python.h"
 
-#include "structmember.h"
-#include "pycore_pystate.h"
 #include "pycore_hamt.h"
+#include "pycore_object.h"
+#include "pycore_pystate.h"
+#include "structmember.h"
 
 /*
 This file provides an implemention of an immutable mapping using the