@@ -29,8 +29,9 @@ _PyLexer_refill(struct tok_state *tok)
2929#if defined(Py_DEBUG )
3030 if (tok -> debug ) {
3131 fprintf (stderr , "line[%d] = " , tok -> lineno );
32- _PyTokenizer_print_escape (stderr , _PyLexer_BufferPointer (tok , tok -> cur ),
33- tok -> inp - tok -> cur );
32+ _PyTokenizer_print_escape (
33+ stderr , _PyTok_SourcePointer (& tok -> source , tok -> cur ),
34+ tok -> inp - tok -> cur );
3435 fprintf (stderr , " tok->done = %d\n" , tok -> done );
3536 }
3637#endif
@@ -39,7 +40,7 @@ _PyLexer_refill(struct tok_state *tok)
3940 return 0 ;
4041 }
4142 tok -> line_start = tok -> cur ;
42- if (contains_null_bytes (_PyLexer_BufferPointer ( tok , tok -> line_start ),
43+ if (contains_null_bytes (_PyTok_SourcePointer ( & tok -> source , tok -> line_start ),
4344 tok -> inp - tok -> line_start )) {
4445 _PyTokenizer_syntaxerror (tok , "source code cannot contain null bytes" );
4546 tok -> cur = tok -> inp ;
@@ -56,7 +57,8 @@ _PyLexer_backup(struct tok_state *tok, int c)
5657 if (-- tok -> cur < tok -> buf_offset ) {
5758 Py_FatalError ("tokenizer beginning of buffer" );
5859 }
59- if ((int )(unsigned char )* _PyLexer_BufferPointer (tok , tok -> cur ) != Py_CHARMASK (c )) {
60+ const char * cur = _PyTok_SourcePointer (& tok -> source , tok -> cur );
61+ if ((int )(unsigned char )* cur != Py_CHARMASK (c )) {
6062 Py_FatalError ("tok_backup: wrong character" );
6163 }
6264 }
@@ -74,7 +76,8 @@ verify_identifier(struct tok_state *tok)
7476 PyObject * s ;
7577 if (tok_failed (tok ))
7678 return 0 ;
77- s = PyUnicode_DecodeUTF8 (_PyLexer_BufferPointer (tok , tok -> start ), tok -> cur - tok -> start , NULL );
79+ s = PyUnicode_DecodeUTF8 (_PyTok_SourcePointer (& tok -> source , tok -> start ),
80+ tok -> cur - tok -> start , NULL );
7881 if (s == NULL ) {
7982 if (PyErr_ExceptionMatches (PyExc_UnicodeDecodeError )) {
8083 tok -> done = E_DECODE ;
@@ -105,13 +108,13 @@ verify_identifier(struct tok_state *tok)
105108 Py_DECREF (s );
106109 if (Py_UNICODE_ISPRINTABLE (ch )) {
107110 _PyTokenizer_syntaxerror_at (
108- tok , _PyLexer_BufferPointer ( tok , tok -> line_start ),
111+ tok , _PyTok_SourcePointer ( & tok -> source , tok -> line_start ),
109112 error_cursor - tok -> line_start , tok -> lineno , -1 , -1 ,
110113 "invalid character '%c' (U+%04X)" , ch , ch );
111114 }
112115 else {
113116 _PyTokenizer_syntaxerror_at (
114- tok , _PyLexer_BufferPointer ( tok , tok -> line_start ),
117+ tok , _PyTok_SourcePointer ( & tok -> source , tok -> line_start ),
115118 error_cursor - tok -> line_start , tok -> lineno , -1 , -1 ,
116119 "invalid non-printable character U+%04X" , ch );
117120 }
@@ -193,14 +196,14 @@ _PyLexer_get_normal(struct tok_state *tok, ftstring_state *current, struct token
193196 }
194197
195198 if (tok -> tok_extra_tokens ) {
196- p = _PyLexer_BufferPointer ( tok , tok -> start );
199+ p = _PyTok_SourcePointer ( & tok -> source , tok -> start );
197200 }
198201
199202 if (tok -> type_comments ) {
200- p = _PyLexer_BufferPointer ( tok , tok -> start );
203+ p = _PyTok_SourcePointer ( & tok -> source , tok -> start );
201204 current_starting_col_offset = tok -> start_loc .byte_col ;
202205 prefix = type_comment_prefix ;
203- while (* prefix && p < _PyLexer_BufferPointer ( tok , tok -> cur )) {
206+ while (* prefix && p < _PyTok_SourcePointer ( & tok -> source , tok -> cur )) {
204207 if (* prefix == ' ' ) {
205208 while (* p == ' ' || * p == '\t' ) {
206209 p ++ ;
@@ -229,24 +232,25 @@ _PyLexer_get_normal(struct tok_state *tok, ftstring_state *current, struct token
229232 /* A TYPE_IGNORE is "type: ignore" followed by the end of the token
230233 * or anything ASCII and non-alphanumeric. */
231234 is_type_ignore = (
232- _PyLexer_BufferPointer (tok , tok -> cur ) >= ignore_end && memcmp (p , "ignore" , 6 ) == 0
233- && !(_PyLexer_BufferPointer (tok , tok -> cur ) > ignore_end
235+ _PyTok_SourcePointer (& tok -> source , tok -> cur ) >= ignore_end
236+ && memcmp (p , "ignore" , 6 ) == 0
237+ && !(_PyTok_SourcePointer (& tok -> source , tok -> cur ) > ignore_end
234238 && ((unsigned char )ignore_end [0 ] >= 128 || Py_ISALNUM (ignore_end [0 ]))));
235239
236240 int type = is_type_ignore ? TYPE_IGNORE : TYPE_COMMENT ;
237241 int start_col_offset = is_type_ignore
238242 ? ignore_end_col_offset : current_starting_col_offset ;
239243 p_end = tok -> cur ;
240244 if (is_type_ignore ) {
241- p_start = _PyLexer_BufferOffset ( tok , ignore_end );
245+ p_start = _PyTok_SourceOffset ( & tok -> source , ignore_end );
242246
243247 /* If this type ignore is the only thing on the line, consume the newline also. */
244248 if (blankline ) {
245249 tok_nextc (tok );
246250 tok -> layout .at_bol = 1 ;
247251 }
248252 } else {
249- p_start = _PyLexer_BufferOffset ( tok , type_start );
253+ p_start = _PyTok_SourceOffset ( & tok -> source , type_start );
250254 }
251255 _PyLexer_token_setup (tok , token , type , p_start , p_end );
252256 token -> start_loc = (_PyTok_Loc ){tok -> lineno , start_col_offset };
@@ -257,7 +261,7 @@ _PyLexer_get_normal(struct tok_state *tok, ftstring_state *current, struct token
257261 }
258262 if (tok -> tok_extra_tokens ) {
259263 tok_backup (tok , c ); /* don't eat the newline or EOF */
260- p_start = _PyLexer_BufferOffset ( tok , p );
264+ p_start = _PyTok_SourceOffset ( & tok -> source , p );
261265 p_end = tok -> cur ;
262266 tok -> layout .comment_newline = blankline ;
263267 return MAKE_TOKEN (COMMENT );
0 commit comments