mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-43244: Remove Yield macro from pycore_ast.h (GH-25243)
* pycore_ast.h no longer defines the Yield macro. * Fix a compiler warning on Windows: "warning C4005: 'Yield': macro redefinition". * Python-ast.c now defines directly functions with their real _Py_xxx() name, rather than xxx(). * Remove "#undef Yield" in C files including pycore_ast.h.
This commit is contained in:
parent
67969f5eb8
commit
d36d6a9c18
8 changed files with 320 additions and 326 deletions
|
@ -325,8 +325,12 @@ class PrototypeVisitor(EmitVisitor):
|
|||
margs = "a0"
|
||||
for i in range(1, len(args)+1):
|
||||
margs += ", a%d" % i
|
||||
self.emit("#define %s(%s) _Py_%s(%s)" % (name, margs, name, margs), 0,
|
||||
reflow=False)
|
||||
# bpo-43244: <winbase.h> defines Yield macro. Don't redefine it in
|
||||
# pycore_ast.h: it is not needed outside Python-ast.c which calls
|
||||
# directly _Py_Yield().
|
||||
if name != "Yield":
|
||||
self.emit("#define %s(%s) _Py_%s(%s)" % (name, margs, name, margs), 0,
|
||||
reflow=False)
|
||||
self.emit("%s _Py_%s(%s);" % (ctype, name, argstr), False)
|
||||
|
||||
def visitProduct(self, prod, name):
|
||||
|
@ -336,6 +340,10 @@ class PrototypeVisitor(EmitVisitor):
|
|||
union=False)
|
||||
|
||||
|
||||
def pyfunc_name(name):
|
||||
return f"_Py_{name}"
|
||||
|
||||
|
||||
class FunctionVisitor(PrototypeVisitor):
|
||||
"""Visitor to generate constructor functions for AST."""
|
||||
|
||||
|
@ -349,7 +357,7 @@ class FunctionVisitor(PrototypeVisitor):
|
|||
else:
|
||||
argstr = "PyArena *arena"
|
||||
self.emit("%s" % ctype, 0)
|
||||
emit("%s(%s)" % (name, argstr))
|
||||
emit("%s(%s)" % (pyfunc_name(name), argstr))
|
||||
emit("{")
|
||||
emit("%s p;" % ctype, 1)
|
||||
for argtype, argname, opt in args:
|
||||
|
@ -488,7 +496,7 @@ class Obj2ModVisitor(PickleVisitor):
|
|||
for f in t.fields:
|
||||
self.visitField(f, t.name, sum=sum, depth=2)
|
||||
args = [f.name for f in t.fields] + [a.name for a in sum.attributes]
|
||||
self.emit("*out = %s(%s);" % (t.name, self.buildArgs(args)), 2)
|
||||
self.emit("*out = %s(%s);" % (pyfunc_name(t.name), self.buildArgs(args)), 2)
|
||||
self.emit("if (*out == NULL) goto failed;", 2)
|
||||
self.emit("return 0;", 2)
|
||||
self.emit("}", 1)
|
||||
|
@ -521,7 +529,7 @@ class Obj2ModVisitor(PickleVisitor):
|
|||
self.visitField(a, name, prod=prod, depth=1)
|
||||
args = [f.name for f in prod.fields]
|
||||
args.extend([a.name for a in prod.attributes])
|
||||
self.emit("*out = %s(%s);" % (name, self.buildArgs(args)), 1)
|
||||
self.emit("*out = %s(%s);" % (pyfunc_name(name), self.buildArgs(args)), 1)
|
||||
self.emit("return 0;", 1)
|
||||
self.emit("failed:", 0)
|
||||
self.emit("Py_XDECREF(tmp);", 1)
|
||||
|
@ -1423,34 +1431,29 @@ def generate_module_def(mod, f, internal_h):
|
|||
|
||||
generate_ast_state(module_state, internal_h)
|
||||
|
||||
print(textwrap.dedent(f"""
|
||||
print(textwrap.dedent("""
|
||||
#include "Python.h"
|
||||
#include "pycore_ast.h"
|
||||
#include "pycore_ast_state.h" // struct ast_state
|
||||
#include "pycore_interp.h" // _PyInterpreterState.ast
|
||||
#include "pycore_pystate.h" // _PyInterpreterState_GET()
|
||||
""").rstrip(), file=f)
|
||||
|
||||
f.write("""
|
||||
// Forward declaration
|
||||
static int init_types(struct ast_state *state);
|
||||
|
||||
static struct ast_state*
|
||||
get_ast_state(void)
|
||||
{
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
struct ast_state *state = &interp->ast;
|
||||
if (!init_types(state)) {
|
||||
return NULL;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
""")
|
||||
|
||||
print(textwrap.dedent("""
|
||||
// Include pycore_ast.h after pycore_interp.h to avoid conflicts
|
||||
// with the Yield macro redefined by <winbase.h>
|
||||
#include "pycore_ast.h"
|
||||
#include "structmember.h"
|
||||
""").rstrip(), file=f)
|
||||
#include <stddef.h>
|
||||
|
||||
// Forward declaration
|
||||
static int init_types(struct ast_state *state);
|
||||
|
||||
static struct ast_state*
|
||||
get_ast_state(void)
|
||||
{
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
struct ast_state *state = &interp->ast;
|
||||
if (!init_types(state)) {
|
||||
return NULL;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
""").strip(), file=f)
|
||||
|
||||
generate_ast_fini(module_state, f)
|
||||
|
||||
|
@ -1477,8 +1480,6 @@ def write_header(mod, f):
|
|||
|
||||
#include "pycore_asdl.h"
|
||||
|
||||
#undef Yield /* undefine macro conflicting with <winbase.h> */
|
||||
|
||||
""").lstrip())
|
||||
c = ChainOfVisitors(TypeDefVisitor(f),
|
||||
SequenceDefVisitor(f),
|
||||
|
@ -1534,12 +1535,6 @@ def write_internal_h_footer(mod, f):
|
|||
|
||||
|
||||
def write_source(mod, f, internal_h_file):
|
||||
print(textwrap.dedent(f"""
|
||||
#include <stddef.h>
|
||||
|
||||
#include "Python.h"
|
||||
"""), file=f)
|
||||
|
||||
generate_module_def(mod, f, internal_h_file)
|
||||
|
||||
v = ChainOfVisitors(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue