Coverage Report

Created: 2026-03-23 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Parser/tokenizer/utf8_tokenizer.c
Line
Count
Source
1
#include "Python.h"
2
#include "errcode.h"
3
4
#include "helpers.h"
5
#include "../lexer/state.h"
6
7
static int
8
152k
tok_underflow_string(struct tok_state *tok) {
9
152k
    char *end = strchr(tok->inp, '\n');
10
152k
    if (end != NULL) {
11
78.2k
        end++;
12
78.2k
    }
13
74.3k
    else {
14
74.3k
        end = strchr(tok->inp, '\0');
15
74.3k
        if (end == tok->inp) {
16
74.0k
            tok->done = E_EOF;
17
74.0k
            return 0;
18
74.0k
        }
19
74.3k
    }
20
78.4k
    if (tok->start == NULL) {
21
78.4k
        tok->buf = tok->cur;
22
78.4k
    }
23
78.4k
    tok->line_start = tok->cur;
24
78.4k
    ADVANCE_LINENO();
25
78.4k
    tok->inp = end;
26
78.4k
    return 1;
27
152k
}
28
29
/* Set up tokenizer for UTF-8 string */
30
struct tok_state *
31
_PyTokenizer_FromUTF8(const char *str, int exec_input, int preserve_crlf)
32
74.0k
{
33
74.0k
    struct tok_state *tok = _PyTokenizer_tok_new();
34
74.0k
    char *translated;
35
74.0k
    if (tok == NULL)
36
0
        return NULL;
37
74.0k
    tok->input = translated = _PyTokenizer_translate_newlines(str, exec_input, preserve_crlf, tok);
38
74.0k
    if (translated == NULL) {
39
0
        _PyTokenizer_Free(tok);
40
0
        return NULL;
41
0
    }
42
74.0k
    tok->decoding_state = STATE_NORMAL;
43
74.0k
    tok->enc = NULL;
44
74.0k
    tok->str = translated;
45
74.0k
    tok->encoding = _PyTokenizer_new_string("utf-8", 5, tok);
46
74.0k
    if (!tok->encoding) {
47
0
        _PyTokenizer_Free(tok);
48
0
        return NULL;
49
0
    }
50
51
74.0k
    tok->buf = tok->cur = tok->inp = translated;
52
74.0k
    tok->end = translated;
53
74.0k
    tok->underflow = &tok_underflow_string;
54
74.0k
    return tok;
55
74.0k
}