Skip to content

Commit 57364ce

Browse files
authored
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.
1 parent a054f6b commit 57364ce

File tree

12 files changed

+70
-130
lines changed

12 files changed

+70
-130
lines changed

Doc/whatsnew/3.10.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,14 +1403,19 @@ Removed
14031403
Windows ``<winbase.h>`` header. Use the Python :mod:`ast` module instead.
14041404
(Contributed by Victor Stinner in :issue:`43244`.)
14051405
1406-
* Remove the compiler functions using ``struct _mod`` type, because the public
1407-
AST C API was removed:
1406+
* Remove the compiler and parser functions using ``struct _mod`` type, because
1407+
the public AST C API was removed:
14081408
14091409
* ``PyAST_Compile()``
14101410
* ``PyAST_CompileEx()``
14111411
* ``PyAST_CompileObject()``
14121412
* ``PyFuture_FromAST()``
14131413
* ``PyFuture_FromASTObject()``
1414+
* ``PyParser_ASTFromFile()``
1415+
* ``PyParser_ASTFromFileObject()``
1416+
* ``PyParser_ASTFromFilename()``
1417+
* ``PyParser_ASTFromString()``
1418+
* ``PyParser_ASTFromStringObject()``
14141419
14151420
These functions were undocumented and excluded from the limited C API.
14161421
(Contributed by Victor Stinner in :issue:`43244`.)

Include/Python.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@
141141
#include "modsupport.h"
142142
#include "compile.h"
143143
#include "pythonrun.h"
144-
#include "cpython/parser_interface.h"
145144
#include "pylifecycle.h"
146145
#include "ceval.h"
147146
#include "sysmodule.h"

Include/cpython/parser_interface.h

Lines changed: 0 additions & 52 deletions
This file was deleted.

Include/internal/pycore_parser.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef Py_INTERNAL_PARSER_H
2+
#define Py_INTERNAL_PARSER_H
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
#ifndef Py_BUILD_CORE
8+
# error "this header requires Py_BUILD_CORE define"
9+
#endif
10+
11+
extern struct _mod* _PyParser_ASTFromString(
12+
const char *str,
13+
PyObject* filename,
14+
int mode,
15+
PyCompilerFlags *flags,
16+
PyArena *arena);
17+
extern struct _mod* _PyParser_ASTFromFile(
18+
FILE *fp,
19+
PyObject *filename_ob,
20+
const char *enc,
21+
int mode,
22+
const char *ps1,
23+
const char *ps2,
24+
PyCompilerFlags *flags,
25+
int *errcode,
26+
PyArena *arena);
27+
28+
#ifdef __cplusplus
29+
}
30+
#endif
31+
#endif /* !Py_INTERNAL_PARSER_H */

Makefile.pre.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ PEGEN_OBJS= \
317317

318318

319319
PEGEN_HEADERS= \
320-
$(srcdir)/Include/cpython/parser_interface.h \
320+
$(srcdir)/Include/internal/pycore_parser.h \
321321
$(srcdir)/Parser/pegen.h \
322322
$(srcdir)/Parser/string_parser.h
323323

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
Remove the compiler functions using ``struct _mod`` type, because the public
2-
AST C API was removed:
1+
Remove the compiler and parser functions using ``struct _mod`` type, because
2+
the public AST C API was removed:
33

44
* ``PyAST_Compile()``
55
* ``PyAST_CompileEx()``
66
* ``PyAST_CompileObject()``
77
* ``PyFuture_FromAST()``
88
* ``PyFuture_FromASTObject()``
9+
* ``PyParser_ASTFromFile()``
10+
* ``PyParser_ASTFromFileObject()``
11+
* ``PyParser_ASTFromFilename()``
12+
* ``PyParser_ASTFromString()``
13+
* ``PyParser_ASTFromStringObject()``
914

1015
These functions were undocumented and excluded from the limited C API.
1116
Patch by Victor Stinner.

Parser/peg_api.c

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,8 @@
44
#include "pegen.h"
55

66
mod_ty
7-
PyParser_ASTFromString(const char *str, const char *filename, int mode,
8-
PyCompilerFlags *flags, PyArena *arena)
9-
{
10-
PyObject *filename_ob = PyUnicode_FromString(filename);
11-
if (filename_ob == NULL) {
12-
return NULL;
13-
}
14-
mod_ty result = PyParser_ASTFromStringObject(str, filename_ob, mode, flags, arena);
15-
Py_XDECREF(filename_ob);
16-
return result;
17-
}
18-
19-
mod_ty
20-
PyParser_ASTFromStringObject(const char *str, PyObject* filename, int mode,
21-
PyCompilerFlags *flags, PyArena *arena)
7+
_PyParser_ASTFromString(const char *str, PyObject* filename, int mode,
8+
PyCompilerFlags *flags, PyArena *arena)
229
{
2310
if (PySys_Audit("compile", "yO", str, filename) < 0) {
2411
return NULL;
@@ -29,37 +16,9 @@ PyParser_ASTFromStringObject(const char *str, PyObject* filename, int mode,
2916
}
3017

3118
mod_ty
32-
PyParser_ASTFromFilename(const char *filename, int mode, PyCompilerFlags *flags, PyArena *arena)
33-
{
34-
PyObject *filename_ob = PyUnicode_FromString(filename);
35-
if (filename_ob == NULL) {
36-
return NULL;
37-
}
38-
39-
mod_ty result = _PyPegen_run_parser_from_file(filename, mode, filename_ob, flags, arena);
40-
Py_XDECREF(filename_ob);
41-
return result;
42-
}
43-
44-
mod_ty
45-
PyParser_ASTFromFile(FILE *fp, const char *filename, const char *enc,
46-
int mode, const char *ps1, const char* ps2,
47-
PyCompilerFlags *flags, int *errcode, PyArena *arena)
48-
{
49-
PyObject *filename_ob = PyUnicode_FromString(filename);
50-
if (filename_ob == NULL) {
51-
return NULL;
52-
}
53-
mod_ty result = PyParser_ASTFromFileObject(fp, filename_ob, enc, mode,
54-
ps1, ps2, flags, errcode, arena);
55-
Py_XDECREF(filename_ob);
56-
return result;
57-
}
58-
59-
mod_ty
60-
PyParser_ASTFromFileObject(FILE *fp, PyObject *filename_ob, const char *enc,
61-
int mode, const char *ps1, const char* ps2,
62-
PyCompilerFlags *flags, int *errcode, PyArena *arena)
19+
_PyParser_ASTFromFile(FILE *fp, PyObject *filename_ob, const char *enc,
20+
int mode, const char *ps1, const char* ps2,
21+
PyCompilerFlags *flags, int *errcode, PyArena *arena)
6322
{
6423
if (PySys_Audit("compile", "OO", Py_None, filename_ob) < 0) {
6524
return NULL;

Parser/pegen.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,23 +1321,6 @@ _PyPegen_run_parser_from_file_pointer(FILE *fp, int start_rule, PyObject *filena
13211321
return result;
13221322
}
13231323

1324-
mod_ty
1325-
_PyPegen_run_parser_from_file(const char *filename, int start_rule,
1326-
PyObject *filename_ob, PyCompilerFlags *flags, PyArena *arena)
1327-
{
1328-
FILE *fp = fopen(filename, "rb");
1329-
if (fp == NULL) {
1330-
PyErr_SetFromErrnoWithFilename(PyExc_OSError, filename);
1331-
return NULL;
1332-
}
1333-
1334-
mod_ty result = _PyPegen_run_parser_from_file_pointer(fp, start_rule, filename_ob,
1335-
NULL, NULL, NULL, flags, NULL, arena);
1336-
1337-
fclose(fp);
1338-
return result;
1339-
}
1340-
13411324
mod_ty
13421325
_PyPegen_run_parser_from_string(const char *str, int start_rule, PyObject *filename_ob,
13431326
PyCompilerFlags *flags, PyArena *arena)

Parser/pegen.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ void _PyPegen_Parser_Free(Parser *);
227227
mod_ty _PyPegen_run_parser_from_file_pointer(FILE *, int, PyObject *, const char *,
228228
const char *, const char *, PyCompilerFlags *, int *, PyArena *);
229229
void *_PyPegen_run_parser(Parser *);
230-
mod_ty _PyPegen_run_parser_from_file(const char *, int, PyObject *, PyCompilerFlags *, PyArena *);
231230
mod_ty _PyPegen_run_parser_from_string(const char *, int, PyObject *, PyCompilerFlags *, PyArena *);
232231
asdl_stmt_seq *_PyPegen_interactive_exit(Parser *);
233232
asdl_seq *_PyPegen_singleton_seq(Parser *, void *);

Python/pythonrun.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "pycore_compile.h" // _PyAST_Compile()
1717
#include "pycore_interp.h" // PyInterpreterState.importlib
1818
#include "pycore_object.h" // _PyDebug_PrintTotalRefs()
19+
#include "pycore_parser.h" // _PyParser_ASTFromString()
1920
#include "pycore_pyerrors.h" // _PyErr_Fetch
2021
#include "pycore_pylifecycle.h" // _Py_UnhandledKeyboardInterrupt
2122
#include "pycore_pystate.h" // _PyInterpreterState_GET()
@@ -254,8 +255,8 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename,
254255
return -1;
255256
}
256257

257-
mod = PyParser_ASTFromFileObject(fp, filename, enc, Py_single_input,
258-
ps1, ps2, flags, &errcode, arena);
258+
mod = _PyParser_ASTFromFile(fp, filename, enc, Py_single_input,
259+
ps1, ps2, flags, &errcode, arena);
259260

260261
Py_XDECREF(v);
261262
Py_XDECREF(w);
@@ -1102,7 +1103,7 @@ PyRun_StringFlags(const char *str, int start, PyObject *globals,
11021103
if (arena == NULL)
11031104
return NULL;
11041105

1105-
mod = PyParser_ASTFromStringObject(str, filename, start, flags, arena);
1106+
mod = _PyParser_ASTFromString(str, filename, start, flags, arena);
11061107

11071108
if (mod != NULL)
11081109
ret = run_mod(mod, filename, globals, locals, flags, arena);
@@ -1121,8 +1122,8 @@ pyrun_file(FILE *fp, PyObject *filename, int start, PyObject *globals,
11211122
}
11221123

11231124
mod_ty mod;
1124-
mod = PyParser_ASTFromFileObject(fp, filename, NULL, start, NULL, NULL,
1125-
flags, NULL, arena);
1125+
mod = _PyParser_ASTFromFile(fp, filename, NULL, start, NULL, NULL,
1126+
flags, NULL, arena);
11261127

11271128
if (closeit) {
11281129
fclose(fp);
@@ -1292,7 +1293,7 @@ Py_CompileStringObject(const char *str, PyObject *filename, int start,
12921293
if (arena == NULL)
12931294
return NULL;
12941295

1295-
mod = PyParser_ASTFromStringObject(str, filename, start, flags, arena);
1296+
mod = _PyParser_ASTFromString(str, filename, start, flags, arena);
12961297
if (mod == NULL) {
12971298
PyArena_Free(arena);
12981299
return NULL;

0 commit comments

Comments
 (0)