]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43244: Remove the PyAST_Validate() function (GH-24911)
authorVictor Stinner <vstinner@python.org>
Thu, 18 Mar 2021 13:57:49 +0000 (14:57 +0100)
committerGitHub <noreply@github.com>
Thu, 18 Mar 2021 13:57:49 +0000 (14:57 +0100)
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.

Doc/whatsnew/3.10.rst
Include/ast.h
Include/internal/pycore_ast.h
Misc/NEWS.d/next/C API/2021-03-17-23-20-07.bpo-43244.diyn2C.rst [new file with mode: 0644]
Parser/pegen.c
Python/ast.c
Python/bltinmodule.c

index 00b0f985e33868668397f5d10299d4c14733a027..25f71c4253d84c33a2de07ce8692971ab3260639 100644 (file)
@@ -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`.)
index 2f19b1a870dac1ee758221c39caba937d5d1301d..82bfa4800cdd55bbaf8b64e5c94841f4273110cf 100644 (file)
@@ -7,8 +7,6 @@ extern "C" {
 
 #include "Python-ast.h"   /* mod_ty */
 
-PyAPI_FUNC(int) PyAST_Validate(mod_ty);
-
 #ifdef __cplusplus
 }
 #endif
index 38c9212b07ca003ef22daca3382822e5d4124156..6cc0b9b3b000fd4cd5dd81d5546330a96212a600 100644 (file)
@@ -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 (file)
index 0000000..6632ace
--- /dev/null
@@ -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.
index 84bdf8dd3f89e244db1e652cfbf74590a8b1082b..24aa3af336c34747b0d4aea1895bf3dbc9474aac 100644 (file)
@@ -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;
         }
     }
index c58b4a69b1e3213c1d09d7a81c48ecbcc7952a23..8ac2e60c92fde7fe4993e6416d391bf6f3b75b30 100644 (file)
@@ -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;
 
index 52591c4a46f3dbbd41206814172d6ff0db34e39d..4683103e09437ea7b030e41cecb81094d740ee51 100644 (file)
@@ -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;
             }