@@ -35,7 +35,7 @@ _PyLexer_nextc(struct tok_state *tok)
3535 return EOF ;
3636 }
3737 tok -> col_offset ++ ;
38- return Py_CHARMASK (* tok -> cur ++ ); /* Fast path */
38+ return Py_CHARMASK (tok -> source . bytes [ tok -> cur ++ - tok -> source . base_offset ] ); /* Fast path */
3939 }
4040 if (tok -> done != E_OK ) {
4141 return EOF ;
@@ -44,7 +44,7 @@ _PyLexer_nextc(struct tok_state *tok)
4444#if defined(Py_DEBUG )
4545 if (tok -> debug ) {
4646 fprintf (stderr , "line[%d] = " , tok -> lineno );
47- _PyTokenizer_print_escape (stderr , tok -> cur , tok -> inp - tok -> cur );
47+ _PyTokenizer_print_escape (stderr , _PyLexer_BufferPointer ( tok , tok -> cur ) , tok -> inp - tok -> cur );
4848 fprintf (stderr , " tok->done = %d\n" , tok -> done );
4949 }
5050#endif
@@ -54,7 +54,7 @@ _PyLexer_nextc(struct tok_state *tok)
5454 }
5555 tok -> line_start = tok -> cur ;
5656
57- if (contains_null_bytes (tok -> line_start , tok -> inp - tok -> line_start )) {
57+ if (contains_null_bytes (_PyLexer_BufferPointer ( tok , tok -> line_start ) , tok -> inp - tok -> line_start )) {
5858 _PyTokenizer_syntaxerror (tok , "source code cannot contain null bytes" );
5959 tok -> cur = tok -> inp ;
6060 return EOF ;
6868_PyLexer_backup (struct tok_state * tok , int c )
6969{
7070 if (c != EOF ) {
71- if (-- tok -> cur < tok -> buf ) {
71+ if (-- tok -> cur < tok -> buf_offset ) {
7272 Py_FatalError ("tokenizer beginning of buffer" );
7373 }
74- if ((int )(unsigned char )* tok -> cur != Py_CHARMASK (c )) {
74+ if ((int )(unsigned char )* _PyLexer_BufferPointer ( tok , tok -> cur ) != Py_CHARMASK (c )) {
7575 Py_FatalError ("tok_backup: wrong character" );
7676 }
7777 tok -> col_offset -- ;
@@ -90,7 +90,7 @@ verify_identifier(struct tok_state *tok)
9090 PyObject * s ;
9191 if (tok -> input_error )
9292 return 0 ;
93- s = PyUnicode_DecodeUTF8 (tok -> start , tok -> cur - tok -> start , NULL );
93+ s = PyUnicode_DecodeUTF8 (_PyLexer_BufferPointer ( tok , tok -> start ) , tok -> cur - tok -> start , NULL );
9494 if (s == NULL ) {
9595 if (PyErr_ExceptionMatches (PyExc_UnicodeDecodeError )) {
9696 tok -> done = E_DECODE ;
@@ -115,7 +115,7 @@ verify_identifier(struct tok_state *tok)
115115 tok -> done = E_ERROR ;
116116 return 0 ;
117117 }
118- tok -> cur = ( char * ) tok -> start + PyBytes_GET_SIZE (s );
118+ tok -> cur = tok -> start + PyBytes_GET_SIZE (s );
119119 }
120120 Py_DECREF (s );
121121 if (Py_UNICODE_ISPRINTABLE (ch )) {
@@ -161,10 +161,10 @@ _PyLexer_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, str
161161 int c ;
162162 int blankline , nonascii ;
163163
164- const char * p_start = NULL ;
165- const char * p_end = NULL ;
164+ _PyTok_Off p_start = -1 ;
165+ _PyTok_Off p_end = -1 ;
166166 nextline :
167- tok -> start = NULL ;
167+ tok -> start = -1 ;
168168 tok -> starting_col_offset = -1 ;
169169 blankline = 0 ;
170170
@@ -283,7 +283,7 @@ _PyLexer_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, str
283283 }
284284 else {
285285 if (tok -> tok_extra_tokens ) {
286- p_start = tok -> buf ;
286+ p_start = tok -> buf_offset ;
287287 p_end = tok -> cur ;
288288 }
289289 tok -> pendin -- ;
@@ -296,14 +296,14 @@ _PyLexer_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, str
296296 tok_backup (tok , c );
297297
298298 again :
299- tok -> start = NULL ;
299+ tok -> start = -1 ;
300300 /* Skip spaces */
301301 do {
302302 c = tok_nextc (tok );
303303 } while (c == ' ' || c == '\t' || c == '\014' );
304304
305305 /* Set start of current token */
306- tok -> start = tok -> cur == NULL ? NULL : tok -> cur - 1 ;
306+ tok -> start = tok -> cur - 1 ;
307307 tok -> starting_col_offset = tok -> col_offset - 1 ;
308308
309309 /* Skip comment, unless it's a type comment */
@@ -318,14 +318,14 @@ _PyLexer_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, str
318318 }
319319
320320 if (tok -> tok_extra_tokens ) {
321- p = tok -> start ;
321+ p = _PyLexer_BufferPointer ( tok , tok -> start ) ;
322322 }
323323
324324 if (tok -> type_comments ) {
325- p = tok -> start ;
325+ p = _PyLexer_BufferPointer ( tok , tok -> start ) ;
326326 current_starting_col_offset = tok -> starting_col_offset ;
327327 prefix = type_comment_prefix ;
328- while (* prefix && p < tok -> cur ) {
328+ while (* prefix && p < _PyLexer_BufferPointer ( tok , tok -> cur ) ) {
329329 if (* prefix == ' ' ) {
330330 while (* p == ' ' || * p == '\t' ) {
331331 p ++ ;
@@ -354,24 +354,24 @@ _PyLexer_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, str
354354 /* A TYPE_IGNORE is "type: ignore" followed by the end of the token
355355 * or anything ASCII and non-alphanumeric. */
356356 is_type_ignore = (
357- tok -> cur >= ignore_end && memcmp (p , "ignore" , 6 ) == 0
358- && !(tok -> cur > ignore_end
357+ _PyLexer_BufferPointer ( tok , tok -> cur ) >= ignore_end && memcmp (p , "ignore" , 6 ) == 0
358+ && !(_PyLexer_BufferPointer ( tok , tok -> cur ) > ignore_end
359359 && ((unsigned char )ignore_end [0 ] >= 128 || Py_ISALNUM (ignore_end [0 ]))));
360360
361361 int type = is_type_ignore ? TYPE_IGNORE : TYPE_COMMENT ;
362362 int start_col_offset = is_type_ignore
363363 ? ignore_end_col_offset : current_starting_col_offset ;
364364 p_end = tok -> cur ;
365365 if (is_type_ignore ) {
366- p_start = ignore_end ;
366+ p_start = _PyLexer_BufferOffset ( tok , ignore_end ) ;
367367
368368 /* If this type ignore is the only thing on the line, consume the newline also. */
369369 if (blankline ) {
370370 tok_nextc (tok );
371371 tok -> atbol = 1 ;
372372 }
373373 } else {
374- p_start = type_start ;
374+ p_start = _PyLexer_BufferOffset ( tok , type_start ) ;
375375 }
376376 _PyLexer_token_setup (tok , token , type , p_start , p_end );
377377 token -> start_loc = (_PyTok_Loc ){tok -> lineno , start_col_offset };
@@ -381,7 +381,7 @@ _PyLexer_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, str
381381 }
382382 if (tok -> tok_extra_tokens ) {
383383 tok_backup (tok , c ); /* don't eat the newline or EOF */
384- p_start = p ;
384+ p_start = _PyLexer_BufferOffset ( tok , p ) ;
385385 p_end = tok -> cur ;
386386 tok -> comment_newline = blankline ;
387387 return MAKE_TOKEN (COMMENT );
0 commit comments