Skip to content

Commit 564cd18

Browse files
authored
bpo-40939: Rename PyPegen* functions to PyParser* (GH-21016)
Rename PyPegen* functions to PyParser*, so that we can remove the old set of PyParser* functions that were using the old parser.
1 parent 6989af0 commit 564cd18

File tree

8 files changed

+52
-79
lines changed

8 files changed

+52
-79
lines changed

Include/Python.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
#include "modsupport.h"
142142
#include "compile.h"
143143
#include "pythonrun.h"
144+
#include "parser_interface.h"
144145
#include "pylifecycle.h"
145146
#include "ceval.h"
146147
#include "sysmodule.h"

Include/internal/pegen_interface.h renamed to Include/parser_interface.h

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,49 @@
44
extern "C" {
55
#endif
66

7-
#ifndef Py_BUILD_CORE
8-
# error "this header requires Py_BUILD_CORE define"
9-
#endif
10-
117
#include "Python.h"
12-
#include "Python-ast.h"
138

14-
PyAPI_FUNC(mod_ty) PyPegen_ASTFromString(
9+
#ifndef Py_LIMITED_API
10+
PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(
1511
const char *str,
1612
const char *filename,
1713
int mode,
1814
PyCompilerFlags *flags,
1915
PyArena *arena);
20-
PyAPI_FUNC(mod_ty) PyPegen_ASTFromStringObject(
16+
PyAPI_FUNC(struct _mod *) PyParser_ASTFromStringObject(
2117
const char *str,
2218
PyObject* filename,
2319
int mode,
2420
PyCompilerFlags *flags,
2521
PyArena *arena);
26-
PyAPI_FUNC(mod_ty) PyPegen_ASTFromFileObject(
22+
PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(
2723
FILE *fp,
28-
PyObject *filename_ob,
24+
const char *filename,
25+
const char* enc,
2926
int mode,
27+
const char *ps1,
28+
const char *ps2,
29+
PyCompilerFlags *flags,
30+
int *errcode,
31+
PyArena *arena);
32+
PyAPI_FUNC(struct _mod *) PyParser_ASTFromFileObject(
33+
FILE *fp,
34+
PyObject *filename_ob,
3035
const char *enc,
36+
int mode,
3137
const char *ps1,
3238
const char *ps2,
3339
PyCompilerFlags *flags,
3440
int *errcode,
3541
PyArena *arena);
36-
PyAPI_FUNC(mod_ty) PyPegen_ASTFromFilename(
42+
PyAPI_FUNC(struct _mod *) PyParser_ASTFromFilename(
3743
const char *filename,
3844
int mode,
3945
PyCompilerFlags *flags,
4046
PyArena *arena);
41-
47+
#endif /* !Py_LIMITED_API */
4248

4349
#ifdef __cplusplus
4450
}
4551
#endif
46-
#endif /* !Py_PEGENINTERFACE*/
52+
#endif /* !Py_PEGENINTERFACE */

Include/pythonrun.h

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -32,57 +32,7 @@ PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(
3232
const char *filename, /* decoded from the filesystem encoding */
3333
PyCompilerFlags *flags);
3434

35-
PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(
36-
const char *s,
37-
const char *filename, /* decoded from the filesystem encoding */
38-
int start,
39-
PyCompilerFlags *flags,
40-
PyArena *arena);
41-
PyAPI_FUNC(struct _mod *) PyParser_ASTFromStringObject(
42-
const char *s,
43-
PyObject *filename,
44-
int start,
45-
PyCompilerFlags *flags,
46-
PyArena *arena);
47-
PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(
48-
FILE *fp,
49-
const char *filename, /* decoded from the filesystem encoding */
50-
const char* enc,
51-
int start,
52-
const char *ps1,
53-
const char *ps2,
54-
PyCompilerFlags *flags,
55-
int *errcode,
56-
PyArena *arena);
57-
PyAPI_FUNC(struct _mod *) PyParser_ASTFromFileObject(
58-
FILE *fp,
59-
PyObject *filename,
60-
const char* enc,
61-
int start,
62-
const char *ps1,
63-
const char *ps2,
64-
PyCompilerFlags *flags,
65-
int *errcode,
66-
PyArena *arena);
67-
#endif
6835

69-
#ifndef PyParser_SimpleParseString
70-
#define PyParser_SimpleParseString(S, B) \
71-
PyParser_SimpleParseStringFlags(S, B, 0)
72-
#define PyParser_SimpleParseFile(FP, S, B) \
73-
PyParser_SimpleParseFileFlags(FP, S, B, 0)
74-
#endif
75-
PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int,
76-
int);
77-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
78-
PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlagsFilename(const char *,
79-
const char *,
80-
int, int);
81-
#endif
82-
PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *,
83-
int, int);
84-
85-
#ifndef Py_LIMITED_API
8636
PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
8737
PyObject *, PyCompilerFlags *);
8838

Makefile.pre.in

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

308308

309309
PEGEN_HEADERS= \
310-
$(srcdir)/Include/internal/pegen_interface.h \
310+
$(srcdir)/Include/parser_interface.h \
311311
$(srcdir)/Parser/pegen.h \
312312
$(srcdir)/Parser/string_parser.h
313313

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Rename `PyPegen*` functions to `PyParser*`, so that we can remove the old set of `PyParser*` functions that were using the old parser, but keep everything backwards-compatible.

PCbuild/pythoncore.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@
162162
<ClInclude Include="..\Include\funcobject.h" />
163163
<ClInclude Include="..\Include\genobject.h" />
164164
<ClInclude Include="..\Include\import.h" />
165-
<ClInclude Include="..\Include\internal\pegen_interface.h" />
166165
<ClInclude Include="..\Include\internal\pycore_abstract.h" />
167166
<ClInclude Include="..\Include\internal\pycore_accu.h" />
168167
<ClInclude Include="..\Include\internal\pycore_atomic.h" />
@@ -213,6 +212,7 @@
213212
<ClInclude Include="..\Include\osdefs.h" />
214213
<ClInclude Include="..\Include\osmodule.h" />
215214
<ClInclude Include="..\Include\patchlevel.h" />
215+
<ClInclude Include="..\Include\parser_interface.h" />
216216
<ClInclude Include="..\Include\picklebufobject.h" />
217217
<ClInclude Include="..\Include\py_curses.h" />
218218
<ClInclude Include="..\Include\pyarena.h" />

Parser/peg_api.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
#include "pegen_interface.h"
1+
#include "parser_interface.h"
22

33
#include "tokenizer.h"
44
#include "pegen.h"
55

66
mod_ty
7-
PyPegen_ASTFromString(const char *str, const char *filename, int mode,
7+
PyParser_ASTFromString(const char *str, const char *filename, int mode,
88
PyCompilerFlags *flags, PyArena *arena)
99
{
1010
PyObject *filename_ob = PyUnicode_FromString(filename);
1111
if (filename_ob == NULL) {
1212
return NULL;
1313
}
14-
mod_ty result = PyPegen_ASTFromStringObject(str, filename_ob, mode, flags, arena);
14+
mod_ty result = PyParser_ASTFromStringObject(str, filename_ob, mode, flags, arena);
1515
Py_XDECREF(filename_ob);
1616
return result;
1717
}
1818

1919
mod_ty
20-
PyPegen_ASTFromStringObject(const char *str, PyObject* filename, int mode,
20+
PyParser_ASTFromStringObject(const char *str, PyObject* filename, int mode,
2121
PyCompilerFlags *flags, PyArena *arena)
2222
{
2323
if (PySys_Audit("compile", "yO", str, filename) < 0) {
@@ -29,7 +29,7 @@ PyPegen_ASTFromStringObject(const char *str, PyObject* filename, int mode,
2929
}
3030

3131
mod_ty
32-
PyPegen_ASTFromFilename(const char *filename, int mode, PyCompilerFlags *flags, PyArena *arena)
32+
PyParser_ASTFromFilename(const char *filename, int mode, PyCompilerFlags *flags, PyArena *arena)
3333
{
3434
PyObject *filename_ob = PyUnicode_FromString(filename);
3535
if (filename_ob == NULL) {
@@ -42,8 +42,23 @@ PyPegen_ASTFromFilename(const char *filename, int mode, PyCompilerFlags *flags,
4242
}
4343

4444
mod_ty
45-
PyPegen_ASTFromFileObject(FILE *fp, PyObject *filename_ob, int mode,
46-
const char *enc, const char *ps1, const char* ps2,
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,
4762
PyCompilerFlags *flags, int *errcode, PyArena *arena)
4863
{
4964
if (PySys_Audit("compile", "OO", Py_None, filename_ob) < 0) {

Python/pythonrun.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "symtable.h" // PySymtable_BuildObject()
2727
#include "marshal.h" // PyMarshal_ReadLongFromFile()
2828

29-
#include "pegen_interface.h" // PyPegen_ASTFrom*
29+
#include "parser_interface.h" // PyParser_ASTFrom*
3030

3131
#ifdef MS_WINDOWS
3232
# include "malloc.h" // alloca()
@@ -205,8 +205,8 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename,
205205
return -1;
206206
}
207207

208-
mod = PyPegen_ASTFromFileObject(fp, filename, Py_single_input,
209-
enc, ps1, ps2, flags, &errcode, arena);
208+
mod = PyParser_ASTFromFileObject(fp, filename, enc, Py_single_input,
209+
ps1, ps2, flags, &errcode, arena);
210210

211211
Py_XDECREF(v);
212212
Py_XDECREF(w);
@@ -1026,7 +1026,7 @@ PyRun_StringFlags(const char *str, int start, PyObject *globals,
10261026
if (arena == NULL)
10271027
return NULL;
10281028

1029-
mod = PyPegen_ASTFromStringObject(str, filename, start, flags, arena);
1029+
mod = PyParser_ASTFromStringObject(str, filename, start, flags, arena);
10301030

10311031
if (mod != NULL)
10321032
ret = run_mod(mod, filename, globals, locals, flags, arena);
@@ -1051,8 +1051,8 @@ PyRun_FileExFlags(FILE *fp, const char *filename_str, int start, PyObject *globa
10511051
if (arena == NULL)
10521052
goto exit;
10531053

1054-
mod = PyPegen_ASTFromFileObject(fp, filename, start, NULL, NULL, NULL,
1055-
flags, NULL, arena);
1054+
mod = PyParser_ASTFromFileObject(fp, filename, NULL, start, NULL, NULL,
1055+
flags, NULL, arena);
10561056

10571057
if (closeit)
10581058
fclose(fp);
@@ -1200,7 +1200,7 @@ Py_CompileStringObject(const char *str, PyObject *filename, int start,
12001200
if (arena == NULL)
12011201
return NULL;
12021202

1203-
mod = PyPegen_ASTFromStringObject(str, filename, start, flags, arena);
1203+
mod = PyParser_ASTFromStringObject(str, filename, start, flags, arena);
12041204
if (mod == NULL) {
12051205
PyArena_Free(arena);
12061206
return NULL;
@@ -1303,7 +1303,7 @@ _Py_SymtableStringObjectFlags(const char *str, PyObject *filename, int start, Py
13031303
if (arena == NULL)
13041304
return NULL;
13051305

1306-
mod = PyPegen_ASTFromStringObject(str, filename, start, flags, arena);
1306+
mod = PyParser_ASTFromStringObject(str, filename, start, flags, arena);
13071307
if (mod == NULL) {
13081308
PyArena_Free(arena);
13091309
return NULL;

0 commit comments

Comments
 (0)