|
2 | 2 | /* Function object implementation */ |
3 | 3 |
|
4 | 4 | #include "Python.h" |
5 | | -#include "pycore_ceval.h" // _PyEval_BuiltinsFromGlobals() |
6 | 5 | #include "pycore_dict.h" // _Py_INCREF_DICT() |
7 | 6 | #include "pycore_long.h" // _PyLong_GetOne() |
8 | 7 | #include "pycore_modsupport.h" // _PyArg_NoKeywords() |
@@ -115,12 +114,7 @@ _PyFunction_FromConstructor(PyFrameConstructor *constr) |
115 | 114 | } |
116 | 115 | _Py_INCREF_DICT(constr->fc_globals); |
117 | 116 | op->func_globals = constr->fc_globals; |
118 | | - if (PyDict_Check(constr->fc_builtins)) { |
119 | | - _Py_INCREF_DICT(constr->fc_builtins); |
120 | | - } |
121 | | - else { |
122 | | - Py_INCREF(constr->fc_builtins); |
123 | | - } |
| 117 | + _Py_INCREF_BUILTINS(constr->fc_builtins); |
124 | 118 | op->func_builtins = constr->fc_builtins; |
125 | 119 | op->func_name = Py_NewRef(constr->fc_name); |
126 | 120 | op->func_qualname = Py_NewRef(constr->fc_qualname); |
@@ -153,8 +147,6 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname |
153 | 147 | assert(PyDict_Check(globals)); |
154 | 148 | _Py_INCREF_DICT(globals); |
155 | 149 |
|
156 | | - PyThreadState *tstate = _PyThreadState_GET(); |
157 | | - |
158 | 150 | PyCodeObject *code_obj = (PyCodeObject *)code; |
159 | 151 | _Py_INCREF_CODE(code_obj); |
160 | 152 |
|
@@ -188,16 +180,10 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname |
188 | 180 | goto error; |
189 | 181 | } |
190 | 182 |
|
191 | | - builtins = _PyEval_BuiltinsFromGlobals(tstate, globals); // borrowed ref |
| 183 | + builtins = _PyDict_LoadBuiltinsFromGlobals(globals); |
192 | 184 | if (builtins == NULL) { |
193 | 185 | goto error; |
194 | 186 | } |
195 | | - if (PyDict_Check(builtins)) { |
196 | | - _Py_INCREF_DICT(builtins); |
197 | | - } |
198 | | - else { |
199 | | - Py_INCREF(builtins); |
200 | | - } |
201 | 187 |
|
202 | 188 | PyFunctionObject *op = PyObject_GC_New(PyFunctionObject, &PyFunction_Type); |
203 | 189 | if (op == NULL) { |
@@ -1078,12 +1064,7 @@ func_clear(PyObject *self) |
1078 | 1064 | PyObject *builtins = op->func_builtins; |
1079 | 1065 | op->func_builtins = NULL; |
1080 | 1066 | if (builtins != NULL) { |
1081 | | - if (PyDict_Check(builtins)) { |
1082 | | - _Py_DECREF_DICT(builtins); |
1083 | | - } |
1084 | | - else { |
1085 | | - Py_DECREF(builtins); |
1086 | | - } |
| 1067 | + _Py_DECREF_BUILTINS(builtins); |
1087 | 1068 | } |
1088 | 1069 | Py_CLEAR(op->func_module); |
1089 | 1070 | Py_CLEAR(op->func_defaults); |
|
0 commit comments