summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-03-18 13:57:49 (GMT)
committerGitHub <noreply@github.com>2021-03-18 13:57:49 (GMT)
commiteec8e61992fb654d4cf58de4d727c18622b8303e (patch)
treecfd8c8904ff2d67c496eadc133e698963d6d7723
parentfc980e0be19776ee05dfc5380eb5d6a8092935cb (diff)
downloadcpython-eec8e61992fb654d4cf58de4d727c18622b8303e.zip
cpython-eec8e61992fb654d4cf58de4d727c18622b8303e.tar.gz
cpython-eec8e61992fb654d4cf58de4d727c18622b8303e.tar.bz2
bpo-43244: Remove the PyAST_Validate() function (GH-24911)
Remove the PyAST_Validate() function. It is no longer possible to build a AST object (mod_ty type) with the public C API. The function was already excluded from the limited C API (PEP 384). Rename PyAST_Validate() function to _PyAST_Validate(), move it to the internal C API, and don't export it anymore (replace PyAPI_FUNC with extern). The function was added in bpo-12575 by the commit 832bfe2ebd5ecfa92031cd40c8b41835ba90487f.
-rw-r--r--Doc/whatsnew/3.10.rst5
-rw-r--r--Include/ast.h2
-rw-r--r--Include/internal/pycore_ast.h2
-rw-r--r--Misc/NEWS.d/next/C API/2021-03-17-23-20-07.bpo-43244.diyn2C.rst3
-rw-r--r--Parser/pegen.c3
-rw-r--r--Python/ast.c2
-rw-r--r--Python/bltinmodule.c3
7 files changed, 15 insertions, 5 deletions
diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst
index 00b0f98..25f71c4 100644
--- a/Doc/whatsnew/3.10.rst
+++ b/Doc/whatsnew/3.10.rst
@@ -1353,3 +1353,8 @@ Removed
Python already implicitly installs signal handlers: see
:c:member:`PyConfig.install_signal_handlers`.
(Contributed by Victor Stinner in :issue:`41713`.)
+
+* Remove the ``PyAST_Validate()`` function. It is no longer possible to build a
+ AST object (``mod_ty`` type) with the public C API. The function was already
+ excluded from the limited C API (:pep:`384`).
+ (Contributed by Victor Stinner in :issue:`43244`.)
diff --git a/Include/ast.h b/Include/ast.h
index 2f19b1a..82bfa48 100644
--- a/Include/ast.h
+++ b/Include/ast.h
@@ -7,8 +7,6 @@ extern "C" {
#include "Python-ast.h" /* mod_ty */
-PyAPI_FUNC(int) PyAST_Validate(mod_ty);
-
#ifdef __cplusplus
}
#endif
diff --git a/Include/internal/pycore_ast.h b/Include/internal/pycore_ast.h
index 38c9212..6cc0b9b 100644
--- a/Include/internal/pycore_ast.h
+++ b/Include/internal/pycore_ast.h
@@ -10,6 +10,8 @@ extern "C" {
#include "Python-ast.h" // expr_ty
+extern int _PyAST_Validate(mod_ty);
+
/* _PyAST_ExprAsUnicode is defined in ast_unparse.c */
extern PyObject* _PyAST_ExprAsUnicode(expr_ty);
diff --git a/Misc/NEWS.d/next/C API/2021-03-17-23-20-07.bpo-43244.diyn2C.rst b/Misc/NEWS.d/next/C API/2021-03-17-23-20-07.bpo-43244.diyn2C.rst
new file mode 100644
index 0000000..6632ace
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2021-03-17-23-20-07.bpo-43244.diyn2C.rst
@@ -0,0 +1,3 @@
+Remove the ``PyAST_Validate()`` function. It is no longer possible to build a
+AST object (``mod_ty`` type) with the public C API. The function was already
+excluded from the limited C API (:pep:`384`). Patch by Victor Stinner.
diff --git a/Parser/pegen.c b/Parser/pegen.c
index 84bdf8d..24aa3af 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -1,4 +1,5 @@
#include <Python.h>
+#include "pycore_ast.h" // _PyAST_Validate()
#include <errcode.h>
#include "tokenizer.h"
@@ -1271,7 +1272,7 @@ _PyPegen_run_parser(Parser *p)
p->start_rule == Py_file_input ||
p->start_rule == Py_eval_input)
{
- if (!PyAST_Validate(res)) {
+ if (!_PyAST_Validate(res)) {
return NULL;
}
}
diff --git a/Python/ast.c b/Python/ast.c
index c58b4a6..8ac2e60 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -551,7 +551,7 @@ validate_exprs(asdl_expr_seq *exprs, expr_context_ty ctx, int null_ok)
}
int
-PyAST_Validate(mod_ty mod)
+_PyAST_Validate(mod_ty mod)
{
int res = 0;
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 52591c4..4683103 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -4,6 +4,7 @@
#include <ctype.h>
#include "ast.h"
#undef Yield /* undefine macro conflicting with <winbase.h> */
+#include "pycore_ast.h" // _PyAST_Validate()
#include "pycore_object.h" // _Py_AddToAllObjects()
#include "pycore_pyerrors.h" // _PyErr_NoMemory()
#include "pycore_pystate.h" // _PyThreadState_GET()
@@ -835,7 +836,7 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
PyArena_Free(arena);
goto error;
}
- if (!PyAST_Validate(mod)) {
+ if (!_PyAST_Validate(mod)) {
PyArena_Free(arena);
goto error;
}