@@ -256,11 +256,18 @@ check_coding_spec(const char* line, int size, struct tok_state *tok,
256256 strcmp (cs , "iso-8859-1" ) == 0 ) {
257257 tok -> encoding = cs ;
258258 } else {
259+ #ifdef Py_USING_UNICODE
259260 r = set_readline (tok , cs );
260261 if (r ) {
261262 tok -> encoding = cs ;
262263 tok -> decoding_state = -1 ;
263264 }
265+ #else
266+ /* Without Unicode support, we cannot
267+ process the coding spec. Since there
268+ won't be any Unicode literals, that
269+ won't matter. */
270+ #endif
264271 }
265272 } else { /* then, compare cs with BOM */
266273 r = (strcmp (tok -> encoding , cs ) == 0 );
@@ -317,6 +324,10 @@ check_bom(int get_char(struct tok_state *),
317324static char *
318325fp_readl (char * s , int size , struct tok_state * tok )
319326{
327+ #ifndef Py_USING_UNICODE
328+ /* In a non-Unicode built, this should never be called. */
329+ abort ();
330+ #else
320331 PyObject * utf8 ;
321332 PyObject * buf = tok -> decoding_buffer ;
322333 if (buf == NULL ) {
@@ -338,6 +349,7 @@ fp_readl(char *s, int size, struct tok_state *tok)
338349 if (s [0 ] == '\0' ) return NULL ; /* EOF */
339350 return s ;
340351 }
352+ #endif
341353}
342354
343355/* Set the readline function for TOK to a StreamReader's
@@ -487,6 +499,7 @@ static int buf_setreadl(struct tok_state *tok, const char* enc) {
487499/* Return a UTF-8 encoding Python string object from the
488500 C byte string STR, which is encoded with ENC. */
489501
502+ #ifdef Py_USING_UNICODE
490503static PyObject *
491504translate_into_utf8 (const char * str , const char * enc ) {
492505 PyObject * utf8 ;
@@ -497,6 +510,7 @@ translate_into_utf8(const char* str, const char* enc) {
497510 Py_DECREF (buf );
498511 return utf8 ;
499512}
513+ #endif
500514
501515/* Decode a byte string STR for use as the buffer of TOK.
502516 Look for encoding declarations inside STR, and record them
@@ -514,12 +528,14 @@ decode_str(const char *str, struct tok_state *tok)
514528 return NULL ;
515529 str = tok -> str ; /* string after BOM if any */
516530 assert (str );
531+ #ifdef Py_USING_UNICODE
517532 if (tok -> enc != NULL ) {
518533 utf8 = translate_into_utf8 (str , tok -> enc );
519534 if (utf8 == NULL )
520535 return NULL ;
521536 str = PyString_AsString (utf8 );
522537 }
538+ #endif
523539 for (s = str ;; s ++ ) {
524540 if (* s == '\0' ) break ;
525541 else if (* s == '\n' ) {
@@ -530,13 +546,15 @@ decode_str(const char *str, struct tok_state *tok)
530546 tok -> enc = NULL ;
531547 if (!check_coding_spec (str , s - str , tok , buf_setreadl ))
532548 return NULL ;
549+ #ifdef Py_USING_UNICODE
533550 if (tok -> enc != NULL ) {
534551 assert (utf8 == NULL );
535552 utf8 = translate_into_utf8 (str , tok -> enc );
536553 if (utf8 == NULL )
537554 return NULL ;
538555 str = PyString_AsString (utf8 );
539556 }
557+ #endif
540558 assert (tok -> decoding_buffer == NULL );
541559 tok -> decoding_buffer = utf8 ; /* CAUTION */
542560 return str ;
0 commit comments