Skip to content

Commit 66ba4cf

Browse files
Move _Py_RefTotal to _PyRuntimeState.
1 parent e700f01 commit 66ba4cf

File tree

8 files changed

+32
-3
lines changed

8 files changed

+32
-3
lines changed

Include/internal/pycore_object.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalRefcountErrorFunc(
3737
#define _Py_FatalRefcountError(message) \
3838
_Py_FatalRefcountErrorFunc(__func__, (message))
3939

40+
#ifdef Py_REF_DEBUG
41+
# define _Py_RefTotal (_PyRuntime.object_state.reftotal)
42+
#endif
43+
4044
// Increment reference count by n
4145
static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n)
4246
{
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef Py_INTERNAL_OBJECT_H
2+
#define Py_INTERNAL_OBJECT_H
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
#ifndef Py_BUILD_CORE
8+
# error "this header requires Py_BUILD_CORE define"
9+
#endif
10+
11+
struct _py_object_runtime_state {
12+
#ifdef Py_REF_DEBUG
13+
Py_ssize_t reftotal;
14+
#endif
15+
};
16+
17+
18+
#ifdef __cplusplus
19+
}
20+
#endif
21+
#endif /* !Py_INTERNAL_OBJECT_H */

Include/internal/pycore_runtime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extern "C" {
1717
#include "pycore_global_objects.h" // struct _Py_global_objects
1818
#include "pycore_import.h" // struct _import_runtime_state
1919
#include "pycore_interp.h" // PyInterpreterState
20+
#include "pycore_object_state.h" // struct _py_object_runtime_state
2021
#include "pycore_parser.h" // struct _parser_runtime_state
2122
#include "pycore_pymem.h" // struct _pymem_allocators
2223
#include "pycore_pyhash.h" // struct pyhash_runtime_state
@@ -151,6 +152,7 @@ typedef struct pyruntimestate {
151152
void *open_code_userdata;
152153
_Py_AuditHookEntry *audit_hook_head;
153154

155+
struct _py_object_runtime_state obj_state;
154156
struct _Py_float_runtime_state float_state;
155157
struct _Py_unicode_runtime_state unicode_state;
156158
struct _Py_dict_runtime_state dict_state;

Include/object.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,6 @@ you can count such references to the type object.)
490490
*/
491491

492492
#ifdef Py_REF_DEBUG
493-
PyAPI_DATA(Py_ssize_t) _Py_RefTotal;
494493
PyAPI_FUNC(void) _Py_NegativeRefcount(const char *filename, int lineno,
495494
PyObject *op);
496495
#endif /* Py_REF_DEBUG */

Makefile.pre.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,7 @@ PYTHON_HEADERS= \
16531653
$(srcdir)/Include/internal/pycore_moduleobject.h \
16541654
$(srcdir)/Include/internal/pycore_namespace.h \
16551655
$(srcdir)/Include/internal/pycore_object.h \
1656+
$(srcdir)/Include/internal/pycore_object_state.h \
16561657
$(srcdir)/Include/internal/pycore_obmalloc.h \
16571658
$(srcdir)/Include/internal/pycore_obmalloc_init.h \
16581659
$(srcdir)/Include/internal/pycore_pathconfig.h \

Objects/object.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ _PyObject_CheckConsistency(PyObject *op, int check_content)
5454

5555

5656
#ifdef Py_REF_DEBUG
57-
Py_ssize_t _Py_RefTotal;
58-
5957
Py_ssize_t
6058
_Py_GetRefTotal(void)
6159
{

PCbuild/pythoncore.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@
235235
<ClInclude Include="..\Include\internal\pycore_moduleobject.h" />
236236
<ClInclude Include="..\Include\internal\pycore_namespace.h" />
237237
<ClInclude Include="..\Include\internal\pycore_object.h" />
238+
<ClInclude Include="..\Include\internal\pycore_object_state.h" />
238239
<ClInclude Include="..\Include\internal\pycore_obmalloc.h" />
239240
<ClInclude Include="..\Include\internal\pycore_obmalloc_init.h" />
240241
<ClInclude Include="..\Include\internal\pycore_pathconfig.h" />

PCbuild/pythoncore.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,9 @@
609609
<ClInclude Include="..\Include\internal\pycore_object.h">
610610
<Filter>Include\internal</Filter>
611611
</ClInclude>
612+
<ClInclude Include="..\Include\internal\pycore_object_state.h">
613+
<Filter>Include\internal</Filter>
614+
</ClInclude>
612615
<ClInclude Include="..\Include\internal\pycore_obmalloc.h">
613616
<Filter>Include\internal</Filter>
614617
</ClInclude>

0 commit comments

Comments
 (0)