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

Skip to content

Commit 07e9e38

Browse files
committed
frameobject.c: Use an identifer instead of creating explicitly an interned
string for "__builtins__" literal string
1 parent e8453bc commit 07e9e38

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

Objects/frameobject.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -601,13 +601,13 @@ PyTypeObject PyFrame_Type = {
601601
0, /* tp_dict */
602602
};
603603

604-
static PyObject *builtin_object;
604+
_Py_IDENTIFIER(__builtins__);
605605

606606
int _PyFrame_Init()
607607
{
608-
builtin_object = PyUnicode_InternFromString("__builtins__");
609-
if (builtin_object == NULL)
610-
return 0;
608+
/* Before, PyId___builtins__ was a string created explicitly in
609+
this function. Now there is nothing to initialize anymore, but
610+
the function is kept for backward compatibility. */
611611
return 1;
612612
}
613613

@@ -628,7 +628,7 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals,
628628
}
629629
#endif
630630
if (back == NULL || back->f_globals != globals) {
631-
builtins = PyDict_GetItem(globals, builtin_object);
631+
builtins = _PyDict_GetItemId(globals, &PyId___builtins__);
632632
if (builtins) {
633633
if (PyModule_Check(builtins)) {
634634
builtins = PyModule_GetDict(builtins);
@@ -994,8 +994,6 @@ void
994994
PyFrame_Fini(void)
995995
{
996996
(void)PyFrame_ClearFreeList();
997-
Py_XDECREF(builtin_object);
998-
builtin_object = NULL;
999997
}
1000998

1001999
/* Print summary info about the state of the optimized allocator */

0 commit comments

Comments
 (0)