#include "Python.h"
#include "pycore_call.h"
#include "pycore_import.h"
#include "pycore_fileutils.h"
#include "errcode.h"
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include "helpers.h"
#include "../lexer/state.h"
#include "../lexer/lexer.h"
#include "../lexer/buffer.h"
static int
tok_concatenate_interactive_new_line(struct tok_state *tok, const char *line) { … }
static int
tok_readline_raw(struct tok_state *tok)
{ … }
static int
tok_readline_recode(struct tok_state *tok) { … }
static int fp_getc(struct tok_state *tok) { … }
static void fp_ungetc(int c, struct tok_state *tok) { … }
static int
fp_setreadl(struct tok_state *tok, const char* enc)
{ … }
static int
tok_underflow_interactive(struct tok_state *tok) { … }
static int
tok_underflow_file(struct tok_state *tok) { … }
struct tok_state *
_PyTokenizer_FromFile(FILE *fp, const char* enc,
const char *ps1, const char *ps2)
{ … }
#if defined(__wasi__) || (defined(__EMSCRIPTEN__) && (__EMSCRIPTEN_major__ >= 3))
typedef union {
void *cookie;
int fd;
} borrowed;
static ssize_t
borrow_read(void *cookie, char *buf, size_t size)
{
borrowed b = {.cookie = cookie};
return read(b.fd, (void *)buf, size);
}
static FILE *
fdopen_borrow(int fd) {
cookie_io_functions_t io_cb = {borrow_read, NULL, NULL, NULL};
borrowed b = {.fd = fd};
return fopencookie(b.cookie, "r", io_cb);
}
#else
static FILE *
fdopen_borrow(int fd) { … }
#endif
char *
_PyTokenizer_FindEncodingFilename(int fd, PyObject *filename)
{ … }