@@ -162,18 +162,21 @@ _tokenizer_error(struct tok_state *tok)
162162static PyObject *
163163tokenizeriter_next (tokenizeriterobject * it )
164164{
165+ PyObject * result = NULL ;
165166 struct token token ;
167+ _PyToken_Init (& token );
168+
166169 int type = _PyTokenizer_Get (it -> tok , & token );
167170 if (type == ERRORTOKEN ) {
168171 if (!PyErr_Occurred ()) {
169172 _tokenizer_error (it -> tok );
170173 assert (PyErr_Occurred ());
171174 }
172- return NULL ;
175+ goto exit ;
173176 }
174177 if (type == ERRORTOKEN || type == ENDMARKER ) {
175178 PyErr_SetString (PyExc_StopIteration , "EOF" );
176- return NULL ;
179+ goto exit ;
177180 }
178181 PyObject * str = NULL ;
179182 if (token .start == NULL || token .end == NULL ) {
@@ -183,14 +186,14 @@ tokenizeriter_next(tokenizeriterobject *it)
183186 str = PyUnicode_FromStringAndSize (token .start , token .end - token .start );
184187 }
185188 if (str == NULL ) {
186- return NULL ;
189+ goto exit ;
187190 }
188191
189192 Py_ssize_t size = it -> tok -> inp - it -> tok -> buf ;
190193 PyObject * line = PyUnicode_DecodeUTF8 (it -> tok -> buf , size , "replace" );
191194 if (line == NULL ) {
192195 Py_DECREF (str );
193- return NULL ;
196+ goto exit ;
194197 }
195198 const char * line_start = ISSTRINGLIT (type ) ? it -> tok -> multi_line_start : it -> tok -> line_start ;
196199 Py_ssize_t lineno = ISSTRINGLIT (type ) ? it -> tok -> first_lineno : it -> tok -> lineno ;
@@ -204,7 +207,10 @@ tokenizeriter_next(tokenizeriterobject *it)
204207 end_col_offset = _PyPegen_byte_offset_to_character_offset (line , token .end - it -> tok -> line_start );
205208 }
206209
207- return Py_BuildValue ("(NinnnnN)" , str , type , lineno , end_lineno , col_offset , end_col_offset , line );
210+ result = Py_BuildValue ("(NinnnnN)" , str , type , lineno , end_lineno , col_offset , end_col_offset , line );
211+ exit :
212+ _PyToken_Free (& token );
213+ return result ;
208214}
209215
210216static void
0 commit comments