GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-108634: Py_TRACE_REFS uses a hash table (#108663) · 2union/ircpython@13a0007

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Doc
    • c-api
      • typeobj.rst
    • using
      • configure.rst
    • whatsnew
      • 3.13.rst
  • Include
    • internal
      • pycore_object.h
      • pycore_object_state.h
      • pycore_runtime_init.h
    • modsupport.h
    • object.h
    • pyport.h
  • Lib/test
    • support
      • __init__.py
    • test_capi
      • test_mem.py
    • test_exceptions.py
    • test_import
      • __init__.py
    • test_repl.py
    • test_sys.py
    • test_tracemalloc.py
  • Misc
    • NEWS.d/next
      • Build
        • 2023-08-30-02-52-52.gh-issue-108634.3dpBvf.rst
      • C API
        • 2023-08-30-02-54-06.gh-issue-108634.oV3Xzk.rst
    • SpecialBuilds.txt
  • Modules/_testcapi
    • parts.h
  • Objects
    • object.c
    • setobject.c
    • sliceobject.c
    • structseq.c
    • typeobject.c
  • Python
    • bltinmodule.c
    • hashtable.c
    • pylifecycle.c
    • pystate.c
  • configure.ac
  • configure
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Doc/c-api/typeobj.rst‎

Copy file name to clipboardExpand all lines: Doc/c-api/typeobj.rst
-22Lines changed: 0 additions & 22 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -528,28 +528,6 @@ type objects) *must* have the :c:member:`~PyVarObject.ob_size` field.
528528
This field is inherited by subtypes.
529529

530530

531-
.. c:member:: PyObject* PyObject._ob_next
532-
PyObject* PyObject._ob_prev
533-
534-
These fields are only present when the macro ``Py_TRACE_REFS`` is defined
535-
(see the :option:`configure --with-trace-refs option <--with-trace-refs>`).
536-
537-
Their initialization to ``NULL`` is taken care of by the
538-
``PyObject_HEAD_INIT`` macro. For :ref:`statically allocated objects
539-
<static-types>`, these fields always remain ``NULL``. For :ref:`dynamically
540-
allocated objects <heap-types>`, these two fields are used to link the
541-
object into a doubly linked list of *all* live objects on the heap.
542-
543-
This could be used for various debugging purposes; currently the only uses
544-
are the :func:`sys.getobjects` function and to print the objects that are
545-
still alive at the end of a run when the environment variable
546-
:envvar:`PYTHONDUMPREFS` is set.
547-
548-
**Inheritance:**
549-
550-
These fields are not inherited by subtypes.
551-
552-
553531
PyVarObject Slots
554532
-----------------
555533

Collapse file

‎Doc/using/configure.rst‎

Copy file name to clipboardExpand all lines: Doc/using/configure.rst
+9-4Lines changed: 9 additions & 4 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,7 @@ See also the :ref:`Python Development Mode <devmode>` and the
425425
.. versionchanged:: 3.8
426426
Release builds and debug builds are now ABI compatible: defining the
427427
``Py_DEBUG`` macro no longer implies the ``Py_TRACE_REFS`` macro (see the
428-
:option:`--with-trace-refs` option), which introduces the only ABI
429-
incompatibility.
428+
:option:`--with-trace-refs` option).
430429

431430

432431
Debug options
@@ -447,8 +446,14 @@ Debug options
447446
* Add :func:`sys.getobjects` function.
448447
* Add :envvar:`PYTHONDUMPREFS` environment variable.
449448

450-
This build is not ABI compatible with release build (default build) or debug
451-
build (``Py_DEBUG`` and ``Py_REF_DEBUG`` macros).
449+
The :envvar:`PYTHONDUMPREFS` environment variable can be used to dump
450+
objects and reference counts still alive at Python exit.
451+
452+
:ref:`Statically allocated objects <static-types>` are not traced.
453+
454+
.. versionchanged:: 3.13
455+
This build is now ABI compatible with release build and :ref:`debug build
456+
<debug-build>`.
452457

453458
.. versionadded:: 3.8
454459

Collapse file

‎Doc/whatsnew/3.13.rst‎

Copy file name to clipboardExpand all lines: Doc/whatsnew/3.13.rst
+9Lines changed: 9 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,11 @@ Build Changes
828828
* SQLite 3.15.2 or newer is required to build the :mod:`sqlite3` extension module.
829829
(Contributed by Erlend Aasland in :gh:`105875`.)
830830

831+
* Python built with :file:`configure` :option:`--with-trace-refs` (tracing
832+
references) is now ABI compatible with Python release build and
833+
:ref:`debug build <debug-build>`.
834+
(Contributed by Victor Stinner in :gh:`108634`.)
835+
831836

832837
C API Changes
833838
=============
@@ -900,6 +905,10 @@ New Features
900905
(with an underscore prefix).
901906
(Contributed by Victor Stinner in :gh:`108014`.)
902907

908+
* Python built with :file:`configure` :option:`--with-trace-refs` (tracing
909+
references) now supports the :ref:`Limited API <limited-c-api>`.
910+
(Contributed by Victor Stinner in :gh:`108634`.)
911+
903912
Porting to Python 3.13
904913
----------------------
905914

Collapse file

‎Include/internal/pycore_object.h‎

Copy file name to clipboardExpand all lines: Include/internal/pycore_object.h
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *);
5555
backwards compatible solution */
5656
#define _PyObject_HEAD_INIT(type) \
5757
{ \
58-
_PyObject_EXTRA_INIT \
5958
.ob_refcnt = _Py_IMMORTAL_REFCNT, \
6059
.ob_type = (type) \
6160
},
@@ -184,6 +183,8 @@ _PyType_HasFeature(PyTypeObject *type, unsigned long feature) {
184183
extern void _PyType_InitCache(PyInterpreterState *interp);
185184

186185
extern void _PyObject_InitState(PyInterpreterState *interp);
186+
extern void _PyObject_FiniState(PyInterpreterState *interp);
187+
extern bool _PyRefchain_IsTraced(PyInterpreterState *interp, PyObject *obj);
187188

188189
/* Inline functions trading binary compatibility for speed:
189190
_PyObject_Init() is the fast version of PyObject_Init(), and
@@ -302,7 +303,7 @@ extern void _PyDebug_PrintTotalRefs(void);
302303
#endif
303304

304305
#ifdef Py_TRACE_REFS
305-
extern void _Py_AddToAllObjects(PyObject *op, int force);
306+
extern void _Py_AddToAllObjects(PyObject *op);
306307
extern void _Py_PrintReferences(PyInterpreterState *, FILE *);
307308
extern void _Py_PrintReferenceAddresses(PyInterpreterState *, FILE *);
308309
#endif
Collapse file

‎Include/internal/pycore_object_state.h‎

Copy file name to clipboardExpand all lines: Include/internal/pycore_object_state.h
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11+
#include "pycore_hashtable.h" // _Py_hashtable_t
12+
1113
struct _py_object_runtime_state {
1214
#ifdef Py_REF_DEBUG
1315
Py_ssize_t interpreter_leaks;
@@ -20,11 +22,10 @@ struct _py_object_state {
2022
Py_ssize_t reftotal;
2123
#endif
2224
#ifdef Py_TRACE_REFS
23-
/* Head of circular doubly-linked list of all objects. These are linked
24-
* together via the _ob_prev and _ob_next members of a PyObject, which
25-
* exist only in a Py_TRACE_REFS build.
26-
*/
27-
PyObject refchain;
25+
// Hash table storing all objects. The key is the object pointer
26+
// (PyObject*) and the value is always the number 1 (as uintptr_t).
27+
// See _PyRefchain_IsTraced() and _PyRefchain_Trace() functions.
28+
_Py_hashtable_t *refchain;
2829
#endif
2930
int _not_used;
3031
};
Collapse file

‎Include/internal/pycore_runtime_init.h‎

Copy file name to clipboardExpand all lines: Include/internal/pycore_runtime_init.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ extern PyTypeObject _PyExc_MemoryError;
192192
#ifdef Py_TRACE_REFS
193193
# define _py_object_state_INIT(INTERP) \
194194
{ \
195-
.refchain = {&INTERP.object_state.refchain, &INTERP.object_state.refchain}, \
195+
.refchain = NULL, \
196196
}
197197
#else
198198
# define _py_object_state_INIT(INTERP) \
Collapse file

‎Include/modsupport.h‎

Copy file name to clipboardExpand all lines: Include/modsupport.h
-8Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,6 @@ PyAPI_FUNC(int) PyModule_ExecDef(PyObject *module, PyModuleDef *def);
111111
#define PYTHON_ABI_VERSION 3
112112
#define PYTHON_ABI_STRING "3"
113113

114-
#ifdef Py_TRACE_REFS
115-
/* When we are tracing reference counts, rename module creation functions so
116-
modules compiled with incompatible settings will generate a
117-
link-time error. */
118-
#define PyModule_Create2 PyModule_Create2TraceRefs
119-
#define PyModule_FromDefAndSpec2 PyModule_FromDefAndSpec2TraceRefs
120-
#endif
121-
122114
PyAPI_FUNC(PyObject *) PyModule_Create2(PyModuleDef*, int apiver);
123115

124116
#ifdef Py_LIMITED_API
Collapse file

‎Include/object.h‎

Copy file name to clipboardExpand all lines: Include/object.h
-21Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,6 @@ whose size is determined when the object is allocated.
5858
# define Py_REF_DEBUG
5959
#endif
6060

61-
#if defined(Py_LIMITED_API) && defined(Py_TRACE_REFS)
62-
# error Py_LIMITED_API is incompatible with Py_TRACE_REFS
63-
#endif
64-
65-
#ifdef Py_TRACE_REFS
66-
/* Define pointers to support a doubly-linked list of all live heap objects. */
67-
#define _PyObject_HEAD_EXTRA \
68-
PyObject *_ob_next; \
69-
PyObject *_ob_prev;
70-
71-
#define _PyObject_EXTRA_INIT _Py_NULL, _Py_NULL,
72-
73-
#else
74-
# define _PyObject_HEAD_EXTRA
75-
# define _PyObject_EXTRA_INIT
76-
#endif
77-
7861
/* PyObject_HEAD defines the initial segment of every PyObject. */
7962
#define PyObject_HEAD PyObject ob_base;
8063

@@ -130,14 +113,12 @@ check by comparing the reference count field to the immortality reference count.
130113
#ifdef Py_BUILD_CORE
131114
#define PyObject_HEAD_INIT(type) \
132115
{ \
133-
_PyObject_EXTRA_INIT \
134116
{ _Py_IMMORTAL_REFCNT }, \
135117
(type) \
136118
},
137119
#else
138120
#define PyObject_HEAD_INIT(type) \
139121
{ \
140-
_PyObject_EXTRA_INIT \
141122
{ 1 }, \
142123
(type) \
143124
},
@@ -164,8 +145,6 @@ check by comparing the reference count field to the immortality reference count.
164145
* in addition, be cast to PyVarObject*.
165146
*/
166147
struct _object {
167-
_PyObject_HEAD_EXTRA
168-
169148
#if (defined(__GNUC__) || defined(__clang__)) \
170149
&& !(defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L)
171150
// On C99 and older, anonymous union is a GCC and clang extension
Collapse file

‎Include/pyport.h‎

Copy file name to clipboardExpand all lines: Include/pyport.h
-6Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -684,12 +684,6 @@ extern char * _getpty(int *, int, mode_t, int);
684684
# endif
685685
#endif
686686

687-
/* Check that ALT_SOABI is consistent with Py_TRACE_REFS:
688-
./configure --with-trace-refs should must be used to define Py_TRACE_REFS */
689-
#if defined(ALT_SOABI) && defined(Py_TRACE_REFS)
690-
# error "Py_TRACE_REFS ABI is not compatible with release and debug ABI"
691-
#endif
692-
693687
#if defined(__ANDROID__) || defined(__VXWORKS__)
694688
// Use UTF-8 as the locale encoding, ignore the LC_CTYPE locale.
695689
// See _Py_GetLocaleEncoding(), PyUnicode_DecodeLocale()
Collapse file

‎Lib/test/support/__init__.py‎

Copy file name to clipboardExpand all lines: Lib/test/support/__init__.py
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -779,9 +779,6 @@ def python_is_optimized():
779779

780780
_header = 'nP'
781781
_align = '0n'
782-
if hasattr(sys, "getobjects"):
783-
_header = '2P' + _header
784-
_align = '0P'
785782
_vheader = _header + 'n'
786783

787784
def calcobjsize(fmt):
@@ -2469,3 +2466,5 @@ def adjust_int_max_str_digits(max_digits):
24692466
#Windows doesn't have os.uname() but it doesn't support s390x.
24702467
skip_on_s390x = unittest.skipIf(hasattr(os, 'uname') and os.uname().machine == 's390x',
24712468
'skipped on s390x')
2469+
2470+
Py_TRACE_REFS = hasattr(sys, 'getobjects')

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.