Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions 9 Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1400,14 +1400,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`.)
1 change: 0 additions & 1 deletion 1 Include/Python.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
52 changes: 0 additions & 52 deletions 52 Include/cpython/parser_interface.h

This file was deleted.

31 changes: 31 additions & 0 deletions 31 Include/internal/pycore_parser.h
Original file line number Diff line number Diff line change
@@ -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 */
2 changes: 1 addition & 1 deletion 2 Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
51 changes: 5 additions & 46 deletions 51 Parser/peg_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
17 changes: 0 additions & 17 deletions 17 Parser/pegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1321,23 +1321,6 @@ _PyPegen_run_parser_from_file_pointer(FILE *fp, int start_rule, PyObject *filena
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)
Expand Down
1 change: 0 additions & 1 deletion 1 Parser/pegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
13 changes: 7 additions & 6 deletions 13 Python/pythonrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion 3 Python/symtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion 11 Tools/peg_generator/peg_extension/peg_extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.