mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-43244: Remove symtable.h header file (GH-24910)
Rename Include/symtable.h to to Include/internal/pycore_symtable.h, don't export symbols anymore (replace PyAPI_FUNC and PyAPI_DATA with extern) and rename functions: * PyST_GetScope() to _PyST_GetScope() * PySymtable_BuildObject() to _PySymtable_Build() * PySymtable_Free() to _PySymtable_Free() Remove PySymtable_Build(), Py_SymtableString() and Py_SymtableStringObject() functions. The Py_SymtableString() function was part the stable ABI by mistake but it could not be used, since the symtable.h header file was excluded from the limited C API. The Python symtable module remains available and is unchanged.
This commit is contained in:
parent
32eba61ea4
commit
28ad12f8fe
15 changed files with 100 additions and 115 deletions
|
@ -25,8 +25,8 @@
|
|||
#include "pycore_ast.h" // _PyAST_GetDocString()
|
||||
#include "pycore_pymem.h" // _PyMem_IsPtrFreed()
|
||||
#include "pycore_long.h" // _PyLong_GetZero()
|
||||
#include "pycore_symtable.h" // PySTEntryObject
|
||||
|
||||
#include "symtable.h" // struct symtable
|
||||
#define NEED_OPCODE_JUMP_TABLES
|
||||
#include "opcode.h" // EXTENDED_ARG
|
||||
#include "wordcode_helpers.h" // instrsize()
|
||||
|
@ -394,7 +394,7 @@ PyAST_CompileObject(mod_ty mod, PyObject *filename, PyCompilerFlags *flags,
|
|||
goto finally;
|
||||
}
|
||||
|
||||
c.c_st = PySymtable_BuildObject(mod, filename, c.c_future);
|
||||
c.c_st = _PySymtable_Build(mod, filename, c.c_future);
|
||||
if (c.c_st == NULL) {
|
||||
if (!PyErr_Occurred())
|
||||
PyErr_SetString(PyExc_SystemError, "no symtable");
|
||||
|
@ -428,7 +428,7 @@ static void
|
|||
compiler_free(struct compiler *c)
|
||||
{
|
||||
if (c->c_st)
|
||||
PySymtable_Free(c->c_st);
|
||||
_PySymtable_Free(c->c_st);
|
||||
if (c->c_future)
|
||||
PyObject_Free(c->c_future);
|
||||
Py_XDECREF(c->c_filename);
|
||||
|
@ -729,7 +729,7 @@ compiler_set_qualname(struct compiler *c)
|
|||
mangled = _Py_Mangle(parent->u_private, u->u_name);
|
||||
if (!mangled)
|
||||
return 0;
|
||||
scope = PyST_GetScope(parent->u_ste, mangled);
|
||||
scope = _PyST_GetScope(parent->u_ste, mangled);
|
||||
Py_DECREF(mangled);
|
||||
assert(scope != GLOBAL_IMPLICIT);
|
||||
if (scope == GLOBAL_EXPLICIT)
|
||||
|
@ -1920,10 +1920,10 @@ get_ref_type(struct compiler *c, PyObject *name)
|
|||
if (c->u->u_scope_type == COMPILER_SCOPE_CLASS &&
|
||||
_PyUnicode_EqualToASCIIString(name, "__class__"))
|
||||
return CELL;
|
||||
scope = PyST_GetScope(c->u->u_ste, name);
|
||||
scope = _PyST_GetScope(c->u->u_ste, name);
|
||||
if (scope == 0) {
|
||||
PyErr_Format(PyExc_SystemError,
|
||||
"PyST_GetScope(name=%R) failed: "
|
||||
"_PyST_GetScope(name=%R) failed: "
|
||||
"unknown scope in unit %S (%R); "
|
||||
"symbols: %R; locals: %R; globals: %R",
|
||||
name,
|
||||
|
@ -3608,7 +3608,7 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
|
|||
|
||||
op = 0;
|
||||
optype = OP_NAME;
|
||||
scope = PyST_GetScope(c->u->u_ste, mangled);
|
||||
scope = _PyST_GetScope(c->u->u_ste, mangled);
|
||||
switch (scope) {
|
||||
case FREE:
|
||||
dict = c->u->u_freevars;
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "token.h" // INDENT
|
||||
#include "errcode.h" // E_EOF
|
||||
#include "code.h" // PyCodeObject
|
||||
#include "symtable.h" // PySymtable_BuildObject()
|
||||
#include "marshal.h" // PyMarshal_ReadLongFromFile()
|
||||
|
||||
#ifdef MS_WINDOWS
|
||||
|
@ -1369,48 +1368,6 @@ _Py_SourceAsString(PyObject *cmd, const char *funcname, const char *what, PyComp
|
|||
return str;
|
||||
}
|
||||
|
||||
struct symtable *
|
||||
Py_SymtableStringObject(const char *str, PyObject *filename, int start)
|
||||
{
|
||||
PyCompilerFlags flags = _PyCompilerFlags_INIT;
|
||||
return _Py_SymtableStringObjectFlags(str, filename, start, &flags);
|
||||
}
|
||||
|
||||
struct symtable *
|
||||
_Py_SymtableStringObjectFlags(const char *str, PyObject *filename, int start, PyCompilerFlags *flags)
|
||||
{
|
||||
struct symtable *st;
|
||||
mod_ty mod;
|
||||
PyArena *arena;
|
||||
|
||||
arena = PyArena_New();
|
||||
if (arena == NULL)
|
||||
return NULL;
|
||||
|
||||
mod = PyParser_ASTFromStringObject(str, filename, start, flags, arena);
|
||||
if (mod == NULL) {
|
||||
PyArena_Free(arena);
|
||||
return NULL;
|
||||
}
|
||||
st = PySymtable_BuildObject(mod, filename, 0);
|
||||
PyArena_Free(arena);
|
||||
return st;
|
||||
}
|
||||
|
||||
struct symtable *
|
||||
Py_SymtableString(const char *str, const char *filename_str, int start)
|
||||
{
|
||||
PyObject *filename;
|
||||
struct symtable *st;
|
||||
|
||||
filename = PyUnicode_DecodeFSDefault(filename_str);
|
||||
if (filename == NULL)
|
||||
return NULL;
|
||||
st = Py_SymtableStringObject(str, filename, start);
|
||||
Py_DECREF(filename);
|
||||
return st;
|
||||
}
|
||||
|
||||
#if defined(USE_STACKCHECK)
|
||||
#if defined(WIN32) && defined(_MSC_VER)
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "Python.h"
|
||||
#include "pycore_pystate.h" // _PyThreadState_GET()
|
||||
#include "symtable.h"
|
||||
#include "pycore_pystate.h" // _PyThreadState_GET()
|
||||
#include "pycore_symtable.h" // PySTEntryObject
|
||||
#undef Yield /* undefine macro conflicting with <winbase.h> */
|
||||
#include "structmember.h" // PyMemberDef
|
||||
|
||||
|
@ -243,7 +243,7 @@ symtable_new(void)
|
|||
st->in_pattern = 0;
|
||||
return st;
|
||||
fail:
|
||||
PySymtable_Free(st);
|
||||
_PySymtable_Free(st);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -260,7 +260,7 @@ symtable_new(void)
|
|||
#define COMPILER_STACK_FRAME_SCALE 3
|
||||
|
||||
struct symtable *
|
||||
PySymtable_BuildObject(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
|
||||
_PySymtable_Build(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
|
||||
{
|
||||
struct symtable *st = symtable_new();
|
||||
asdl_stmt_seq *seq;
|
||||
|
@ -272,7 +272,7 @@ PySymtable_BuildObject(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
|
|||
if (st == NULL)
|
||||
return NULL;
|
||||
if (filename == NULL) {
|
||||
PySymtable_Free(st);
|
||||
_PySymtable_Free(st);
|
||||
return NULL;
|
||||
}
|
||||
Py_INCREF(filename);
|
||||
|
@ -282,7 +282,7 @@ PySymtable_BuildObject(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
|
|||
/* Setup recursion depth check counters */
|
||||
tstate = _PyThreadState_GET();
|
||||
if (!tstate) {
|
||||
PySymtable_Free(st);
|
||||
_PySymtable_Free(st);
|
||||
return NULL;
|
||||
}
|
||||
/* Be careful here to prevent overflow. */
|
||||
|
@ -295,7 +295,7 @@ PySymtable_BuildObject(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
|
|||
/* Make the initial symbol information gathering pass */
|
||||
if (!GET_IDENTIFIER(top) ||
|
||||
!symtable_enter_block(st, top, ModuleBlock, (void *)mod, 0, 0)) {
|
||||
PySymtable_Free(st);
|
||||
_PySymtable_Free(st);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -325,7 +325,7 @@ PySymtable_BuildObject(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
|
|||
goto error;
|
||||
}
|
||||
if (!symtable_exit_block(st)) {
|
||||
PySymtable_Free(st);
|
||||
_PySymtable_Free(st);
|
||||
return NULL;
|
||||
}
|
||||
/* Check that the recursion depth counting balanced correctly */
|
||||
|
@ -333,35 +333,23 @@ PySymtable_BuildObject(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
|
|||
PyErr_Format(PyExc_SystemError,
|
||||
"symtable analysis recursion depth mismatch (before=%d, after=%d)",
|
||||
starting_recursion_depth, st->recursion_depth);
|
||||
PySymtable_Free(st);
|
||||
_PySymtable_Free(st);
|
||||
return NULL;
|
||||
}
|
||||
/* Make the second symbol analysis pass */
|
||||
if (symtable_analyze(st))
|
||||
return st;
|
||||
PySymtable_Free(st);
|
||||
_PySymtable_Free(st);
|
||||
return NULL;
|
||||
error:
|
||||
(void) symtable_exit_block(st);
|
||||
PySymtable_Free(st);
|
||||
_PySymtable_Free(st);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct symtable *
|
||||
PySymtable_Build(mod_ty mod, const char *filename_str, PyFutureFeatures *future)
|
||||
{
|
||||
PyObject *filename;
|
||||
struct symtable *st;
|
||||
filename = PyUnicode_DecodeFSDefault(filename_str);
|
||||
if (filename == NULL)
|
||||
return NULL;
|
||||
st = PySymtable_BuildObject(mod, filename, future);
|
||||
Py_DECREF(filename);
|
||||
return st;
|
||||
}
|
||||
|
||||
void
|
||||
PySymtable_Free(struct symtable *st)
|
||||
_PySymtable_Free(struct symtable *st)
|
||||
{
|
||||
Py_XDECREF(st->st_filename);
|
||||
Py_XDECREF(st->st_blocks);
|
||||
|
@ -402,7 +390,7 @@ _PyST_GetSymbol(PySTEntryObject *ste, PyObject *name)
|
|||
}
|
||||
|
||||
int
|
||||
PyST_GetScope(PySTEntryObject *ste, PyObject *name)
|
||||
_PyST_GetScope(PySTEntryObject *ste, PyObject *name)
|
||||
{
|
||||
long symbol = _PyST_GetSymbol(ste, name);
|
||||
return (symbol >> SCOPE_OFFSET) & SCOPE_MASK;
|
||||
|
@ -1971,3 +1959,26 @@ symtable_visit_dictcomp(struct symtable *st, expr_ty e)
|
|||
e->v.DictComp.key,
|
||||
e->v.DictComp.value);
|
||||
}
|
||||
|
||||
|
||||
struct symtable *
|
||||
_Py_SymtableStringObjectFlags(const char *str, PyObject *filename,
|
||||
int start, PyCompilerFlags *flags)
|
||||
{
|
||||
struct symtable *st;
|
||||
mod_ty mod;
|
||||
PyArena *arena;
|
||||
|
||||
arena = PyArena_New();
|
||||
if (arena == NULL)
|
||||
return NULL;
|
||||
|
||||
mod = PyParser_ASTFromStringObject(str, filename, start, flags, arena);
|
||||
if (mod == NULL) {
|
||||
PyArena_Free(arena);
|
||||
return NULL;
|
||||
}
|
||||
st = _PySymtable_Build(mod, filename, 0);
|
||||
PyArena_Free(arena);
|
||||
return st;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue