Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 49c75a8

Browse files
authored
bpo-35064 prefix smelly symbols that appear with COUNT_ALLOCS with _Py_ (GH-10152)
Configuring python with ./configure --with-pydebug CFLAGS="-D COUNT_ALLOCS -O0" makes "make smelly" fail as some symbols were being exported without the "Py_" or "_Py" prefixes.
1 parent 6015cc5 commit 49c75a8

File tree

7 files changed

+31
-31
lines changed

7 files changed

+31
-31
lines changed

Include/object.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -752,10 +752,10 @@ PyAPI_FUNC(void) _PyDebug_PrintTotalRefs(void);
752752
#endif /* Py_REF_DEBUG */
753753

754754
#ifdef COUNT_ALLOCS
755-
PyAPI_FUNC(void) inc_count(PyTypeObject *);
756-
PyAPI_FUNC(void) dec_count(PyTypeObject *);
757-
#define _Py_INC_TPALLOCS(OP) inc_count(Py_TYPE(OP))
758-
#define _Py_INC_TPFREES(OP) dec_count(Py_TYPE(OP))
755+
PyAPI_FUNC(void) _Py_inc_count(PyTypeObject *);
756+
PyAPI_FUNC(void) _Py_dec_count(PyTypeObject *);
757+
#define _Py_INC_TPALLOCS(OP) _Py_inc_count(Py_TYPE(OP))
758+
#define _Py_INC_TPFREES(OP) _Py_dec_count(Py_TYPE(OP))
759759
#define _Py_DEC_TPFREES(OP) Py_TYPE(OP)->tp_frees--
760760
#define _Py_COUNT_ALLOCS_COMMA ,
761761
#else

Objects/bytesobject.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class bytes "PyBytesObject *" "&PyBytes_Type"
1818
#include "clinic/bytesobject.c.h"
1919

2020
#ifdef COUNT_ALLOCS
21-
Py_ssize_t null_strings, one_strings;
21+
Py_ssize_t _Py_null_strings, _Py_one_strings;
2222
#endif
2323

2424
static PyBytesObject *characters[UCHAR_MAX + 1];
@@ -66,7 +66,7 @@ _PyBytes_FromSize(Py_ssize_t size, int use_calloc)
6666

6767
if (size == 0 && (op = nullstring) != NULL) {
6868
#ifdef COUNT_ALLOCS
69-
null_strings++;
69+
_Py_null_strings++;
7070
#endif
7171
Py_INCREF(op);
7272
return (PyObject *)op;
@@ -110,7 +110,7 @@ PyBytes_FromStringAndSize(const char *str, Py_ssize_t size)
110110
(op = characters[*str & UCHAR_MAX]) != NULL)
111111
{
112112
#ifdef COUNT_ALLOCS
113-
one_strings++;
113+
_Py_one_strings++;
114114
#endif
115115
Py_INCREF(op);
116116
return (PyObject *)op;
@@ -146,14 +146,14 @@ PyBytes_FromString(const char *str)
146146
}
147147
if (size == 0 && (op = nullstring) != NULL) {
148148
#ifdef COUNT_ALLOCS
149-
null_strings++;
149+
_Py_null_strings++;
150150
#endif
151151
Py_INCREF(op);
152152
return (PyObject *)op;
153153
}
154154
if (size == 1 && (op = characters[*str & UCHAR_MAX]) != NULL) {
155155
#ifdef COUNT_ALLOCS
156-
one_strings++;
156+
_Py_one_strings++;
157157
#endif
158158
Py_INCREF(op);
159159
return (PyObject *)op;

Objects/longobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ PyObject *_PyLong_One = NULL;
4242
*/
4343
static PyLongObject small_ints[NSMALLNEGINTS + NSMALLPOSINTS];
4444
#ifdef COUNT_ALLOCS
45-
Py_ssize_t quick_int_allocs, quick_neg_int_allocs;
45+
Py_ssize_t _Py_quick_int_allocs, _Py_quick_neg_int_allocs;
4646
#endif
4747

4848
static PyObject *
@@ -54,9 +54,9 @@ get_small_int(sdigit ival)
5454
Py_INCREF(v);
5555
#ifdef COUNT_ALLOCS
5656
if (ival >= 0)
57-
quick_int_allocs++;
57+
_Py_quick_int_allocs++;
5858
else
59-
quick_neg_int_allocs++;
59+
_Py_quick_neg_int_allocs++;
6060
#endif
6161
return v;
6262
}

Objects/object.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ static PyTypeObject *type_list;
9393
is set, they will be removed from the type_list
9494
once the last object is deallocated. */
9595
static int unlist_types_without_objects;
96-
extern Py_ssize_t tuple_zero_allocs, fast_tuple_allocs;
97-
extern Py_ssize_t quick_int_allocs, quick_neg_int_allocs;
98-
extern Py_ssize_t null_strings, one_strings;
96+
extern Py_ssize_t _Py_tuple_zero_allocs, _Py_fast_tuple_allocs;
97+
extern Py_ssize_t _Py_quick_int_allocs, _Py_quick_neg_int_allocs;
98+
extern Py_ssize_t _Py_null_strings, _Py_one_strings;
9999
void
100-
dump_counts(FILE* f)
100+
_Py_dump_counts(FILE* f)
101101
{
102102
PyInterpreterState *interp = _PyInterpreterState_Get();
103103
if (!interp->core_config.show_alloc_count) {
@@ -113,17 +113,17 @@ dump_counts(FILE* f)
113113
tp->tp_maxalloc);
114114
fprintf(f, "fast tuple allocs: %" PY_FORMAT_SIZE_T "d, "
115115
"empty: %" PY_FORMAT_SIZE_T "d\n",
116-
fast_tuple_allocs, tuple_zero_allocs);
116+
_Py_fast_tuple_allocs, _Py_tuple_zero_allocs);
117117
fprintf(f, "fast int allocs: pos: %" PY_FORMAT_SIZE_T "d, "
118118
"neg: %" PY_FORMAT_SIZE_T "d\n",
119-
quick_int_allocs, quick_neg_int_allocs);
119+
_Py_quick_int_allocs, _Py_quick_neg_int_allocs);
120120
fprintf(f, "null strings: %" PY_FORMAT_SIZE_T "d, "
121121
"1-strings: %" PY_FORMAT_SIZE_T "d\n",
122-
null_strings, one_strings);
122+
_Py_null_strings, _Py_one_strings);
123123
}
124124

125125
PyObject *
126-
get_counts(void)
126+
_Py_get_counts(void)
127127
{
128128
PyTypeObject *tp;
129129
PyObject *result;
@@ -150,12 +150,12 @@ get_counts(void)
150150
}
151151

152152
void
153-
inc_count(PyTypeObject *tp)
153+
_Py_inc_count(PyTypeObject *tp)
154154
{
155155
if (tp->tp_next == NULL && tp->tp_prev == NULL) {
156156
/* first time; insert in linked list */
157157
if (tp->tp_next != NULL) /* sanity check */
158-
Py_FatalError("XXX inc_count sanity check");
158+
Py_FatalError("XXX _Py_inc_count sanity check");
159159
if (type_list)
160160
type_list->tp_prev = tp;
161161
tp->tp_next = type_list;
@@ -181,7 +181,7 @@ inc_count(PyTypeObject *tp)
181181
tp->tp_maxalloc = tp->tp_allocs - tp->tp_frees;
182182
}
183183

184-
void dec_count(PyTypeObject *tp)
184+
void _Py_dec_count(PyTypeObject *tp)
185185
{
186186
tp->tp_frees++;
187187
if (unlist_types_without_objects &&

Objects/tupleobject.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ static PyTupleObject *free_list[PyTuple_MAXSAVESIZE];
2828
static int numfree[PyTuple_MAXSAVESIZE];
2929
#endif
3030
#ifdef COUNT_ALLOCS
31-
Py_ssize_t fast_tuple_allocs;
32-
Py_ssize_t tuple_zero_allocs;
31+
Py_ssize_t _Py_fast_tuple_allocs;
32+
Py_ssize_t _Py_tuple_zero_allocs;
3333
#endif
3434

3535
/* Debug statistic to count GC tracking of tuples.
@@ -89,15 +89,15 @@ PyTuple_New(Py_ssize_t size)
8989
op = free_list[0];
9090
Py_INCREF(op);
9191
#ifdef COUNT_ALLOCS
92-
tuple_zero_allocs++;
92+
_Py_tuple_zero_allocs++;
9393
#endif
9494
return (PyObject *) op;
9595
}
9696
if (size < PyTuple_MAXSAVESIZE && (op = free_list[size]) != NULL) {
9797
free_list[size] = (PyTupleObject *) op->ob_item[0];
9898
numfree[size]--;
9999
#ifdef COUNT_ALLOCS
100-
fast_tuple_allocs++;
100+
_Py_fast_tuple_allocs++;
101101
#endif
102102
/* Inline PyObject_InitVar */
103103
#ifdef Py_TRACE_REFS

Python/pylifecycle.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ Py_Initialize(void)
929929

930930

931931
#ifdef COUNT_ALLOCS
932-
extern void dump_counts(FILE*);
932+
extern void _Py_dump_counts(FILE*);
933933
#endif
934934

935935
/* Flush stdout and stderr */
@@ -1112,7 +1112,7 @@ Py_FinalizeEx(void)
11121112

11131113
/* Debugging stuff */
11141114
#ifdef COUNT_ALLOCS
1115-
dump_counts(stderr);
1115+
_Py_dump_counts(stderr);
11161116
#endif
11171117
/* dump hash stats */
11181118
_PyHash_Fini();

Python/sysmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,9 +1340,9 @@ size."
13401340
static PyObject *
13411341
sys_getcounts(PyObject *self)
13421342
{
1343-
extern PyObject *get_counts(void);
1343+
extern PyObject *_Py_get_counts(void);
13441344

1345-
return get_counts();
1345+
return _Py_get_counts();
13461346
}
13471347
#endif
13481348

0 commit comments

Comments
 (0)