mirror of https://github.com/python/cpython
bpo-43244: Remove parser_interface.h header file (GH-25001)
Remove parser functions using the "struct _mod" type, because the AST C API was removed: * PyParser_ASTFromFile() * PyParser_ASTFromFileObject() * PyParser_ASTFromFilename() * PyParser_ASTFromString() * PyParser_ASTFromStringObject() These functions were undocumented and excluded from the limited C API. Add pycore_parser.h internal header file. Rename functions: * PyParser_ASTFromFileObject() => _PyParser_ASTFromFile() * PyParser_ASTFromStringObject() => _PyParser_ASTFromString() These functions are no longer exported (replace PyAPI_FUNC() with extern). Remove also _PyPegen_run_parser_from_file() function. Update test_peg_generator to use _PyPegen_run_parser_from_file_pointer() instead.
This commit is contained in:
parent
a054f6b2b1
commit
57364ce34e
|
@ -1403,14 +1403,19 @@ Removed
|
|||
Windows ``<winbase.h>`` header. Use the Python :mod:`ast` module instead.
|
||||
(Contributed by Victor Stinner in :issue:`43244`.)
|
||||
|
||||
* Remove the compiler functions using ``struct _mod`` type, because the public
|
||||
AST C API was removed:
|
||||
* Remove the compiler and parser functions using ``struct _mod`` type, because
|
||||
the public AST C API was removed:
|
||||
|
||||
* ``PyAST_Compile()``
|
||||
* ``PyAST_CompileEx()``
|
||||
* ``PyAST_CompileObject()``
|
||||
* ``PyFuture_FromAST()``
|
||||
* ``PyFuture_FromASTObject()``
|
||||
* ``PyParser_ASTFromFile()``
|
||||
* ``PyParser_ASTFromFileObject()``
|
||||
* ``PyParser_ASTFromFilename()``
|
||||
* ``PyParser_ASTFromString()``
|
||||
* ``PyParser_ASTFromStringObject()``
|
||||
|
||||
These functions were undocumented and excluded from the limited C API.
|
||||
(Contributed by Victor Stinner in :issue:`43244`.)
|
||||
|
|
|
@ -141,7 +141,6 @@
|
|||
#include "modsupport.h"
|
||||
#include "compile.h"
|
||||
#include "pythonrun.h"
|
||||
#include "cpython/parser_interface.h"
|
||||
#include "pylifecycle.h"
|
||||
#include "ceval.h"
|
||||
#include "sysmodule.h"
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
#ifndef Py_PEGENINTERFACE
|
||||
#define Py_PEGENINTERFACE
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "Python.h"
|
||||
|
||||
#ifndef Py_LIMITED_API
|
||||
PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(
|
||||
const char *str,
|
||||
const char *filename,
|
||||
int mode,
|
||||
PyCompilerFlags *flags,
|
||||
PyArena *arena);
|
||||
PyAPI_FUNC(struct _mod *) PyParser_ASTFromStringObject(
|
||||
const char *str,
|
||||
PyObject* filename,
|
||||
int mode,
|
||||
PyCompilerFlags *flags,
|
||||
PyArena *arena);
|
||||
PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(
|
||||
FILE *fp,
|
||||
const char *filename,
|
||||
const char* enc,
|
||||
int mode,
|
||||
const char *ps1,
|
||||
const char *ps2,
|
||||
PyCompilerFlags *flags,
|
||||
int *errcode,
|
||||
PyArena *arena);
|
||||
PyAPI_FUNC(struct _mod *) PyParser_ASTFromFileObject(
|
||||
FILE *fp,
|
||||
PyObject *filename_ob,
|
||||
const char *enc,
|
||||
int mode,
|
||||
const char *ps1,
|
||||
const char *ps2,
|
||||
PyCompilerFlags *flags,
|
||||
int *errcode,
|
||||
PyArena *arena);
|
||||
PyAPI_FUNC(struct _mod *) PyParser_ASTFromFilename(
|
||||
const char *filename,
|
||||
int mode,
|
||||
PyCompilerFlags *flags,
|
||||
PyArena *arena);
|
||||
#endif /* !Py_LIMITED_API */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* !Py_PEGENINTERFACE */
|
|
@ -0,0 +1,31 @@
|
|||
#ifndef Py_INTERNAL_PARSER_H
|
||||
#define Py_INTERNAL_PARSER_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef Py_BUILD_CORE
|
||||
# error "this header requires Py_BUILD_CORE define"
|
||||
#endif
|
||||
|
||||
extern struct _mod* _PyParser_ASTFromString(
|
||||
const char *str,
|
||||
PyObject* filename,
|
||||
int mode,
|
||||
PyCompilerFlags *flags,
|
||||
PyArena *arena);
|
||||
extern struct _mod* _PyParser_ASTFromFile(
|
||||
FILE *fp,
|
||||
PyObject *filename_ob,
|
||||
const char *enc,
|
||||
int mode,
|
||||
const char *ps1,
|
||||
const char *ps2,
|
||||
PyCompilerFlags *flags,
|
||||
int *errcode,
|
||||
PyArena *arena);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* !Py_INTERNAL_PARSER_H */
|
|
@ -317,7 +317,7 @@ PEGEN_OBJS= \
|
|||
|
||||
|
||||
PEGEN_HEADERS= \
|
||||
$(srcdir)/Include/cpython/parser_interface.h \
|
||||
$(srcdir)/Include/internal/pycore_parser.h \
|
||||
$(srcdir)/Parser/pegen.h \
|
||||
$(srcdir)/Parser/string_parser.h
|
||||
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
Remove the compiler functions using ``struct _mod`` type, because the public
|
||||
AST C API was removed:
|
||||
Remove the compiler and parser functions using ``struct _mod`` type, because
|
||||
the public AST C API was removed:
|
||||
|
||||
* ``PyAST_Compile()``
|
||||
* ``PyAST_CompileEx()``
|
||||
* ``PyAST_CompileObject()``
|
||||
* ``PyFuture_FromAST()``
|
||||
* ``PyFuture_FromASTObject()``
|
||||
* ``PyParser_ASTFromFile()``
|
||||
* ``PyParser_ASTFromFileObject()``
|
||||
* ``PyParser_ASTFromFilename()``
|
||||
* ``PyParser_ASTFromString()``
|
||||
* ``PyParser_ASTFromStringObject()``
|
||||
|
||||
These functions were undocumented and excluded from the limited C API.
|
||||
Patch by Victor Stinner.
|
||||
|
|
|
@ -4,21 +4,8 @@
|
|||
#include "pegen.h"
|
||||
|
||||
mod_ty
|
||||
PyParser_ASTFromString(const char *str, const char *filename, int mode,
|
||||
PyCompilerFlags *flags, PyArena *arena)
|
||||
{
|
||||
PyObject *filename_ob = PyUnicode_FromString(filename);
|
||||
if (filename_ob == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
mod_ty result = PyParser_ASTFromStringObject(str, filename_ob, mode, flags, arena);
|
||||
Py_XDECREF(filename_ob);
|
||||
return result;
|
||||
}
|
||||
|
||||
mod_ty
|
||||
PyParser_ASTFromStringObject(const char *str, PyObject* filename, int mode,
|
||||
PyCompilerFlags *flags, PyArena *arena)
|
||||
_PyParser_ASTFromString(const char *str, PyObject* filename, int mode,
|
||||
PyCompilerFlags *flags, PyArena *arena)
|
||||
{
|
||||
if (PySys_Audit("compile", "yO", str, filename) < 0) {
|
||||
return NULL;
|
||||
|
@ -29,37 +16,9 @@ PyParser_ASTFromStringObject(const char *str, PyObject* filename, int mode,
|
|||
}
|
||||
|
||||
mod_ty
|
||||
PyParser_ASTFromFilename(const char *filename, int mode, PyCompilerFlags *flags, PyArena *arena)
|
||||
{
|
||||
PyObject *filename_ob = PyUnicode_FromString(filename);
|
||||
if (filename_ob == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mod_ty result = _PyPegen_run_parser_from_file(filename, mode, filename_ob, flags, arena);
|
||||
Py_XDECREF(filename_ob);
|
||||
return result;
|
||||
}
|
||||
|
||||
mod_ty
|
||||
PyParser_ASTFromFile(FILE *fp, const char *filename, const char *enc,
|
||||
int mode, const char *ps1, const char* ps2,
|
||||
PyCompilerFlags *flags, int *errcode, PyArena *arena)
|
||||
{
|
||||
PyObject *filename_ob = PyUnicode_FromString(filename);
|
||||
if (filename_ob == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
mod_ty result = PyParser_ASTFromFileObject(fp, filename_ob, enc, mode,
|
||||
ps1, ps2, flags, errcode, arena);
|
||||
Py_XDECREF(filename_ob);
|
||||
return result;
|
||||
}
|
||||
|
||||
mod_ty
|
||||
PyParser_ASTFromFileObject(FILE *fp, PyObject *filename_ob, const char *enc,
|
||||
int mode, const char *ps1, const char* ps2,
|
||||
PyCompilerFlags *flags, int *errcode, PyArena *arena)
|
||||
_PyParser_ASTFromFile(FILE *fp, PyObject *filename_ob, const char *enc,
|
||||
int mode, const char *ps1, const char* ps2,
|
||||
PyCompilerFlags *flags, int *errcode, PyArena *arena)
|
||||
{
|
||||
if (PySys_Audit("compile", "OO", Py_None, filename_ob) < 0) {
|
||||
return NULL;
|
||||
|
|
|
@ -1321,23 +1321,6 @@ error:
|
|||
return result;
|
||||
}
|
||||
|
||||
mod_ty
|
||||
_PyPegen_run_parser_from_file(const char *filename, int start_rule,
|
||||
PyObject *filename_ob, PyCompilerFlags *flags, PyArena *arena)
|
||||
{
|
||||
FILE *fp = fopen(filename, "rb");
|
||||
if (fp == NULL) {
|
||||
PyErr_SetFromErrnoWithFilename(PyExc_OSError, filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mod_ty result = _PyPegen_run_parser_from_file_pointer(fp, start_rule, filename_ob,
|
||||
NULL, NULL, NULL, flags, NULL, arena);
|
||||
|
||||
fclose(fp);
|
||||
return result;
|
||||
}
|
||||
|
||||
mod_ty
|
||||
_PyPegen_run_parser_from_string(const char *str, int start_rule, PyObject *filename_ob,
|
||||
PyCompilerFlags *flags, PyArena *arena)
|
||||
|
|
|
@ -227,7 +227,6 @@ void _PyPegen_Parser_Free(Parser *);
|
|||
mod_ty _PyPegen_run_parser_from_file_pointer(FILE *, int, PyObject *, const char *,
|
||||
const char *, const char *, PyCompilerFlags *, int *, PyArena *);
|
||||
void *_PyPegen_run_parser(Parser *);
|
||||
mod_ty _PyPegen_run_parser_from_file(const char *, int, PyObject *, PyCompilerFlags *, PyArena *);
|
||||
mod_ty _PyPegen_run_parser_from_string(const char *, int, PyObject *, PyCompilerFlags *, PyArena *);
|
||||
asdl_stmt_seq *_PyPegen_interactive_exit(Parser *);
|
||||
asdl_seq *_PyPegen_singleton_seq(Parser *, void *);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "pycore_compile.h" // _PyAST_Compile()
|
||||
#include "pycore_interp.h" // PyInterpreterState.importlib
|
||||
#include "pycore_object.h" // _PyDebug_PrintTotalRefs()
|
||||
#include "pycore_parser.h" // _PyParser_ASTFromString()
|
||||
#include "pycore_pyerrors.h" // _PyErr_Fetch
|
||||
#include "pycore_pylifecycle.h" // _Py_UnhandledKeyboardInterrupt
|
||||
#include "pycore_pystate.h" // _PyInterpreterState_GET()
|
||||
|
@ -254,8 +255,8 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename,
|
|||
return -1;
|
||||
}
|
||||
|
||||
mod = PyParser_ASTFromFileObject(fp, filename, enc, Py_single_input,
|
||||
ps1, ps2, flags, &errcode, arena);
|
||||
mod = _PyParser_ASTFromFile(fp, filename, enc, Py_single_input,
|
||||
ps1, ps2, flags, &errcode, arena);
|
||||
|
||||
Py_XDECREF(v);
|
||||
Py_XDECREF(w);
|
||||
|
@ -1102,7 +1103,7 @@ PyRun_StringFlags(const char *str, int start, PyObject *globals,
|
|||
if (arena == NULL)
|
||||
return NULL;
|
||||
|
||||
mod = PyParser_ASTFromStringObject(str, filename, start, flags, arena);
|
||||
mod = _PyParser_ASTFromString(str, filename, start, flags, arena);
|
||||
|
||||
if (mod != NULL)
|
||||
ret = run_mod(mod, filename, globals, locals, flags, arena);
|
||||
|
@ -1121,8 +1122,8 @@ pyrun_file(FILE *fp, PyObject *filename, int start, PyObject *globals,
|
|||
}
|
||||
|
||||
mod_ty mod;
|
||||
mod = PyParser_ASTFromFileObject(fp, filename, NULL, start, NULL, NULL,
|
||||
flags, NULL, arena);
|
||||
mod = _PyParser_ASTFromFile(fp, filename, NULL, start, NULL, NULL,
|
||||
flags, NULL, arena);
|
||||
|
||||
if (closeit) {
|
||||
fclose(fp);
|
||||
|
@ -1292,7 +1293,7 @@ Py_CompileStringObject(const char *str, PyObject *filename, int start,
|
|||
if (arena == NULL)
|
||||
return NULL;
|
||||
|
||||
mod = PyParser_ASTFromStringObject(str, filename, start, flags, arena);
|
||||
mod = _PyParser_ASTFromString(str, filename, start, flags, arena);
|
||||
if (mod == NULL) {
|
||||
PyArena_Free(arena);
|
||||
return NULL;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "pycore_ast.h" // identifier, stmt_ty
|
||||
#undef Yield /* undefine macro conflicting with <winbase.h> */
|
||||
#include "pycore_compile.h" // _Py_Mangle()
|
||||
#include "pycore_parser.h" // _PyParser_ASTFromString()
|
||||
#include "pycore_pystate.h" // _PyThreadState_GET()
|
||||
#include "pycore_symtable.h" // PySTEntryObject
|
||||
#include "structmember.h" // PyMemberDef
|
||||
|
@ -1975,7 +1976,7 @@ _Py_SymtableStringObjectFlags(const char *str, PyObject *filename,
|
|||
if (arena == NULL)
|
||||
return NULL;
|
||||
|
||||
mod = PyParser_ASTFromStringObject(str, filename, start, flags, arena);
|
||||
mod = _PyParser_ASTFromString(str, filename, start, flags, arena);
|
||||
if (mod == NULL) {
|
||||
PyArena_Free(arena);
|
||||
return NULL;
|
||||
|
|
|
@ -44,8 +44,17 @@ parse_file(PyObject *self, PyObject *args, PyObject *kwds)
|
|||
goto error;
|
||||
}
|
||||
|
||||
FILE *fp = fopen(filename, "rb");
|
||||
if (fp == NULL) {
|
||||
PyErr_SetFromErrnoWithFilename(PyExc_OSError, filename);
|
||||
goto error;
|
||||
}
|
||||
|
||||
PyCompilerFlags flags = _PyCompilerFlags_INIT;
|
||||
mod_ty res = _PyPegen_run_parser_from_file(filename, Py_file_input, filename_ob, &flags, arena);
|
||||
mod_ty res = _PyPegen_run_parser_from_file_pointer(
|
||||
fp, Py_file_input, filename_ob,
|
||||
NULL, NULL, NULL, &flags, NULL, arena);
|
||||
fclose(fp);
|
||||
if (res == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue