@@ -196,17 +196,6 @@ intern_strings(PyObject *tuple)
196196 return 0 ;
197197}
198198
199- static inline PyObject *
200- get_interned_string (PyObject * interned_dict , PyObject * s ) {
201- PyObject * existing = PyDict_GetItemWithError (interned_dict , s );
202- if (existing == NULL ) {
203- if (PyErr_Occurred ()) {
204- return NULL ;
205- }
206- return NULL ;
207- }
208- return existing ;
209- }
210199
211200/* Intern constants. In the default build, this interns selected string
212201 constants. In the free-threaded build, this also interns non-string
@@ -216,13 +205,17 @@ intern_constants(PyObject *tuple, int *modified)
216205{
217206 PyInterpreterState * interp = _PyInterpreterState_GET ();
218207 PyObject * interned_dict = _Py_INTERP_CACHED_OBJECT (interp , interned_strings );
208+ Py_INCREF (interned_dict );
219209 for (Py_ssize_t i = PyTuple_GET_SIZE (tuple ); -- i >= 0 ; ) {
220210 PyObject * v = PyTuple_GET_ITEM (tuple , i );
221211 if (PyUnicode_CheckExact (v ) && PyUnicode_GET_LENGTH (v ) > 1 ) {
222212 if (PyUnicode_CHECK_INTERNED (v ) != 0 ) {
223213 continue ;
224214 }
225- PyObject * interned = get_interned_string (interned_dict , v );
215+ PyObject * interned = PyDict_GetItemWithError (interned_dict , v );
216+ if (interned == NULL && PyErr_Occurred ()) {
217+ goto error ;
218+ }
226219 if (interned != NULL && interned != v ) {
227220 Py_INCREF (interned );
228221 PyTuple_SET_ITEM (tuple , i , interned );
@@ -243,25 +236,25 @@ intern_constants(PyObject *tuple, int *modified)
243236 }
244237 else if (PyTuple_CheckExact (v )) {
245238 if (intern_constants (v , NULL ) < 0 ) {
246- return -1 ;
239+ goto error ;
247240 }
248241 }
249242 else if (PyFrozenSet_CheckExact (v )) {
250243 PyObject * w = v ;
251244 PyObject * tmp = PySequence_Tuple (v );
252245 if (tmp == NULL ) {
253- return -1 ;
246+ goto error ;
254247 }
255248 int tmp_modified = 0 ;
256249 if (intern_constants (tmp , & tmp_modified ) < 0 ) {
257250 Py_DECREF (tmp );
258- return -1 ;
251+ goto error ;
259252 }
260253 if (tmp_modified ) {
261254 v = PyFrozenSet_New (tmp );
262255 if (v == NULL ) {
263256 Py_DECREF (tmp );
264- return -1 ;
257+ goto error ;
265258 }
266259
267260 PyTuple_SET_ITEM (tuple , i , v );
@@ -277,23 +270,23 @@ intern_constants(PyObject *tuple, int *modified)
277270 PySliceObject * slice = (PySliceObject * )v ;
278271 PyObject * tmp = PyTuple_New (3 );
279272 if (tmp == NULL ) {
280- return -1 ;
273+ goto error ;
281274 }
282275 PyTuple_SET_ITEM (tmp , 0 , Py_NewRef (slice -> start ));
283276 PyTuple_SET_ITEM (tmp , 1 , Py_NewRef (slice -> stop ));
284277 PyTuple_SET_ITEM (tmp , 2 , Py_NewRef (slice -> step ));
285278 int tmp_modified = 0 ;
286279 if (intern_constants (tmp , & tmp_modified ) < 0 ) {
287280 Py_DECREF (tmp );
288- return -1 ;
281+ goto error ;
289282 }
290283 if (tmp_modified ) {
291284 v = PySlice_New (PyTuple_GET_ITEM (tmp , 0 ),
292285 PyTuple_GET_ITEM (tmp , 1 ),
293286 PyTuple_GET_ITEM (tmp , 2 ));
294287 if (v == NULL ) {
295288 Py_DECREF (tmp );
296- return -1 ;
289+ goto error ;
297290 }
298291 PyTuple_SET_ITEM (tuple , i , v );
299292 Py_DECREF (slice );
@@ -312,7 +305,7 @@ intern_constants(PyObject *tuple, int *modified)
312305 {
313306 PyObject * interned = intern_one_constant (v );
314307 if (interned == NULL ) {
315- return -1 ;
308+ goto error ;
316309 }
317310 else if (interned != v ) {
318311 PyTuple_SET_ITEM (tuple , i , interned );
@@ -324,7 +317,12 @@ intern_constants(PyObject *tuple, int *modified)
324317 }
325318#endif
326319 }
320+ Py_DECREF (interned_dict );
327321 return 0 ;
322+
323+ error :
324+ Py_DECREF (interned_dict );
325+ return -1 ;
328326}
329327
330328/* Return a shallow copy of a tuple that is
0 commit comments