summaryrefslogtreecommitdiffstats
path: root/Modules/_tracemalloc.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2022-02-23 00:23:51 (GMT)
committerGitHub <noreply@github.com>2022-02-23 00:23:51 (GMT)
commit1f455361ecfb1892e375bdbee813cdf095b6cfb8 (patch)
treed7def4d5d167965a45c4b0e30bb5a1a0bb5c3b4a /Modules/_tracemalloc.c
parentcff4d5c5d29528299ec1ac5b3b3a6f7735577c01 (diff)
downloadcpython-1f455361ecfb1892e375bdbee813cdf095b6cfb8.zip
cpython-1f455361ecfb1892e375bdbee813cdf095b6cfb8.tar.gz
cpython-1f455361ecfb1892e375bdbee813cdf095b6cfb8.tar.bz2
bpo-46765: Replace Locally Cached Strings with Statically Initialized Objects (gh-31366)
https://bugs.python.org/issue46765
Diffstat (limited to 'Modules/_tracemalloc.c')
-rw-r--r--Modules/_tracemalloc.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c
index 14bad00..53e3299 100644
--- a/Modules/_tracemalloc.c
+++ b/Modules/_tracemalloc.c
@@ -3,6 +3,7 @@
#include "pycore_gc.h" // PyGC_Head
#include "pycore_hashtable.h" // _Py_hashtable_t
#include "pycore_pymem.h" // _Py_tracemalloc_config
+#include "pycore_runtime.h" // _Py_ID()
#include "pycore_traceback.h"
#include <pycore_frame.h>
@@ -15,6 +16,8 @@ module _tracemalloc
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=708a98302fc46e5f]*/
+_Py_DECLARE_STR(anon_unknown, "<unknown>");
+
/* Trace memory blocks allocated by PyMem_RawMalloc() */
#define TRACE_RAW_MALLOC
@@ -91,7 +94,6 @@ typedef struct {
static const unsigned long MAX_NFRAME = Py_MIN(UINT16_MAX, ((SIZE_MAX - sizeof(traceback_t)) / sizeof(frame_t) + 1));
-static PyObject *unknown_filename = NULL;
static traceback_t tracemalloc_empty_traceback;
/* Trace of a memory block */
@@ -305,7 +307,7 @@ hashtable_compare_traceback(const void *key1, const void *key2)
static void
tracemalloc_get_frame(InterpreterFrame *pyframe, frame_t *frame)
{
- frame->filename = unknown_filename;
+ frame->filename = &_Py_STR(anon_unknown);
int lineno = PyCode_Addr2Line(pyframe->f_code, pyframe->f_lasti*sizeof(_Py_CODEUNIT));
if (lineno < 0) {
lineno = 0;
@@ -905,15 +907,10 @@ tracemalloc_init(void)
return -1;
}
- unknown_filename = PyUnicode_FromString("<unknown>");
- if (unknown_filename == NULL)
- return -1;
- PyUnicode_InternInPlace(&unknown_filename);
-
tracemalloc_empty_traceback.nframe = 1;
tracemalloc_empty_traceback.total_nframe = 1;
/* borrowed reference */
- tracemalloc_empty_traceback.frames[0].filename = unknown_filename;
+ tracemalloc_empty_traceback.frames[0].filename = &_Py_STR(anon_unknown);
tracemalloc_empty_traceback.frames[0].lineno = 0;
tracemalloc_empty_traceback.hash = traceback_hash(&tracemalloc_empty_traceback);
@@ -947,8 +944,6 @@ tracemalloc_deinit(void)
#ifdef REENTRANT_THREADLOCAL
PyThread_tss_delete(&tracemalloc_reentrant_key);
#endif
-
- Py_XDECREF(unknown_filename);
}