Skip to content

bpo-40939: Rename PyPegen* functions to PyParser* #21016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 21, 2020
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
1 change: 1 addition & 0 deletions Include/Python.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
#include "modsupport.h"
#include "compile.h"
#include "pythonrun.h"
#include "parser_interface.h"
#include "pylifecycle.h"
#include "ceval.h"
#include "sysmodule.h"
Expand Down
30 changes: 18 additions & 12 deletions Include/internal/pegen_interface.h → Include/parser_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,49 @@
extern "C" {
#endif

#ifndef Py_BUILD_CORE
# error "this header requires Py_BUILD_CORE define"
#endif

#include "Python.h"
#include "Python-ast.h"

PyAPI_FUNC(mod_ty) PyPegen_ASTFromString(
#ifndef Py_LIMITED_API
PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(
const char *str,
const char *filename,
int mode,
PyCompilerFlags *flags,
PyArena *arena);
PyAPI_FUNC(mod_ty) PyPegen_ASTFromStringObject(
PyAPI_FUNC(struct _mod *) PyParser_ASTFromStringObject(
const char *str,
PyObject* filename,
int mode,
PyCompilerFlags *flags,
PyArena *arena);
PyAPI_FUNC(mod_ty) PyPegen_ASTFromFileObject(
PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(
FILE *fp,
PyObject *filename_ob,
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(mod_ty) PyPegen_ASTFromFilename(
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*/
#endif /* !Py_PEGENINTERFACE */
50 changes: 0 additions & 50 deletions Include/pythonrun.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,57 +32,7 @@ PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(
const char *filename, /* decoded from the filesystem encoding */
PyCompilerFlags *flags);

PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(
const char *s,
const char *filename, /* decoded from the filesystem encoding */
int start,
PyCompilerFlags *flags,
PyArena *arena);
PyAPI_FUNC(struct _mod *) PyParser_ASTFromStringObject(
const char *s,
PyObject *filename,
int start,
PyCompilerFlags *flags,
PyArena *arena);
PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(
FILE *fp,
const char *filename, /* decoded from the filesystem encoding */
const char* enc,
int start,
const char *ps1,
const char *ps2,
PyCompilerFlags *flags,
int *errcode,
PyArena *arena);
PyAPI_FUNC(struct _mod *) PyParser_ASTFromFileObject(
FILE *fp,
PyObject *filename,
const char* enc,
int start,
const char *ps1,
const char *ps2,
PyCompilerFlags *flags,
int *errcode,
PyArena *arena);
#endif

#ifndef PyParser_SimpleParseString
#define PyParser_SimpleParseString(S, B) \
PyParser_SimpleParseStringFlags(S, B, 0)
#define PyParser_SimpleParseFile(FP, S, B) \
PyParser_SimpleParseFileFlags(FP, S, B, 0)
#endif
PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int,
int);
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlagsFilename(const char *,
const char *,
int, int);
#endif
PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *,
int, int);

#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
PyObject *, PyCompilerFlags *);

Expand Down
2 changes: 1 addition & 1 deletion Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ PEGEN_OBJS= \


PEGEN_HEADERS= \
$(srcdir)/Include/internal/pegen_interface.h \
$(srcdir)/Include/parser_interface.h \
$(srcdir)/Parser/pegen.h \
$(srcdir)/Parser/string_parser.h

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +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.
2 changes: 1 addition & 1 deletion PCbuild/pythoncore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@
<ClInclude Include="..\Include\funcobject.h" />
<ClInclude Include="..\Include\genobject.h" />
<ClInclude Include="..\Include\import.h" />
<ClInclude Include="..\Include\internal\pegen_interface.h" />
<ClInclude Include="..\Include\internal\pycore_abstract.h" />
<ClInclude Include="..\Include\internal\pycore_accu.h" />
<ClInclude Include="..\Include\internal\pycore_atomic.h" />
Expand Down Expand Up @@ -213,6 +212,7 @@
<ClInclude Include="..\Include\osdefs.h" />
<ClInclude Include="..\Include\osmodule.h" />
<ClInclude Include="..\Include\patchlevel.h" />
<ClInclude Include="..\Include\parser_interface.h" />
<ClInclude Include="..\Include\picklebufobject.h" />
<ClInclude Include="..\Include\py_curses.h" />
<ClInclude Include="..\Include\pyarena.h" />
Expand Down
29 changes: 22 additions & 7 deletions Parser/peg_api.c
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#include "pegen_interface.h"
#include "parser_interface.h"

#include "tokenizer.h"
#include "pegen.h"

mod_ty
PyPegen_ASTFromString(const char *str, const char *filename, int mode,
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 = PyPegen_ASTFromStringObject(str, filename_ob, mode, flags, arena);
mod_ty result = PyParser_ASTFromStringObject(str, filename_ob, mode, flags, arena);
Py_XDECREF(filename_ob);
return result;
}

mod_ty
PyPegen_ASTFromStringObject(const char *str, PyObject* filename, int mode,
PyParser_ASTFromStringObject(const char *str, PyObject* filename, int mode,
PyCompilerFlags *flags, PyArena *arena)
{
if (PySys_Audit("compile", "yO", str, filename) < 0) {
Expand All @@ -29,7 +29,7 @@ PyPegen_ASTFromStringObject(const char *str, PyObject* filename, int mode,
}

mod_ty
PyPegen_ASTFromFilename(const char *filename, int mode, PyCompilerFlags *flags, PyArena *arena)
PyParser_ASTFromFilename(const char *filename, int mode, PyCompilerFlags *flags, PyArena *arena)
{
PyObject *filename_ob = PyUnicode_FromString(filename);
if (filename_ob == NULL) {
Expand All @@ -42,8 +42,23 @@ PyPegen_ASTFromFilename(const char *filename, int mode, PyCompilerFlags *flags,
}

mod_ty
PyPegen_ASTFromFileObject(FILE *fp, PyObject *filename_ob, int mode,
const char *enc, const char *ps1, const char* ps2,
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)
{
if (PySys_Audit("compile", "OO", Py_None, filename_ob) < 0) {
Expand Down
16 changes: 8 additions & 8 deletions Python/pythonrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "symtable.h" // PySymtable_BuildObject()
#include "marshal.h" // PyMarshal_ReadLongFromFile()

#include "pegen_interface.h" // PyPegen_ASTFrom*
#include "parser_interface.h" // PyParser_ASTFrom*

#ifdef MS_WINDOWS
# include "malloc.h" // alloca()
Expand Down Expand Up @@ -205,8 +205,8 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename,
return -1;
}

mod = PyPegen_ASTFromFileObject(fp, filename, Py_single_input,
enc, ps1, ps2, flags, &errcode, arena);
mod = PyParser_ASTFromFileObject(fp, filename, enc, Py_single_input,
ps1, ps2, flags, &errcode, arena);

Py_XDECREF(v);
Py_XDECREF(w);
Expand Down Expand Up @@ -1026,7 +1026,7 @@ PyRun_StringFlags(const char *str, int start, PyObject *globals,
if (arena == NULL)
return NULL;

mod = PyPegen_ASTFromStringObject(str, filename, start, flags, arena);
mod = PyParser_ASTFromStringObject(str, filename, start, flags, arena);

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

mod = PyPegen_ASTFromFileObject(fp, filename, start, NULL, NULL, NULL,
flags, NULL, arena);
mod = PyParser_ASTFromFileObject(fp, filename, NULL, start, NULL, NULL,
flags, NULL, arena);

if (closeit)
fclose(fp);
Expand Down Expand Up @@ -1200,7 +1200,7 @@ Py_CompileStringObject(const char *str, PyObject *filename, int start,
if (arena == NULL)
return NULL;

mod = PyPegen_ASTFromStringObject(str, filename, start, flags, arena);
mod = PyParser_ASTFromStringObject(str, filename, start, flags, arena);
if (mod == NULL) {
PyArena_Free(arena);
return NULL;
Expand Down Expand Up @@ -1303,7 +1303,7 @@ _Py_SymtableStringObjectFlags(const char *str, PyObject *filename, int start, Py
if (arena == NULL)
return NULL;

mod = PyPegen_ASTFromStringObject(str, filename, start, flags, arena);
mod = PyParser_ASTFromStringObject(str, filename, start, flags, arena);
if (mod == NULL) {
PyArena_Free(arena);
return NULL;
Expand Down