Skip to content

bpo-43244: Remove symtable.h header file #24910

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 1 commit into from
Mar 19, 2021
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: 0 additions & 1 deletion Doc/data/stable_abi.dat
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,6 @@ Py_SetPath
Py_SetProgramName
Py_SetPythonHome
Py_SetRecursionLimit
Py_SymtableString
Py_UTF8Mode
Py_VaBuildValue
Py_XNewRef
16 changes: 16 additions & 0 deletions Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1358,3 +1358,19 @@ Removed
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`.)

* Remove the ``symtable.h`` header file and the undocumented functions:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this should be here, as it was never documented

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, I didn't document such changes, but there is always one project sleeping somewhere which relies on the modified/removed function, and then it's painful to understand why the project is broken. Even if a function is very well hidden and not documented, there is always a secret project relying on it :-)


* ``PyST_GetScope()``
* ``PySymtable_Build()``
* ``PySymtable_BuildObject()``
* ``PySymtable_Free()``
* ``Py_SymtableString()``
* ``Py_SymtableStringObject()``

The ``Py_SymtableString()`` function was part the stable ABI by mistake but
it could not be used, because the ``symtable.h`` header file was excluded
from the limited C API.

The Python :mod:`symtable` module remains available and is unchanged.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove this, we are in the C-API changes section already.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to say that the function remains available, it's just that the low-level C API is no longer available. It's possible to use the symtable module in C.

(Contributed by Victor Stinner in :issue:`43244`.)
11 changes: 0 additions & 11 deletions Include/cpython/pythonrun.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,6 @@ PyAPI_FUNC(const char *) _Py_SourceAsString(
PyCompilerFlags *cf,
PyObject **cmd_copy);

PyAPI_FUNC(struct symtable *) Py_SymtableStringObject(
const char *str,
PyObject *filename,
int start);

PyAPI_FUNC(struct symtable *) _Py_SymtableStringObjectFlags(
const char *str,
PyObject *filename,
int start,
PyCompilerFlags *flags);


/* A function flavor is also exported by libpython. It is required when
libpython is accessed directly rather than using header files which defines
Expand Down
35 changes: 18 additions & 17 deletions Include/symtable.h → Include/internal/pycore_symtable.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#ifndef Py_LIMITED_API
#ifndef Py_SYMTABLE_H
#define Py_SYMTABLE_H
#ifndef Py_INTERNAL_SYMTABLE_H
#define Py_INTERNAL_SYMTABLE_H
#ifdef __cplusplus
extern "C" {
#endif

#include "Python-ast.h" /* mod_ty */
#ifndef Py_BUILD_CORE
# error "this header requires Py_BUILD_CORE define"
#endif

/* XXX(ncoghlan): This is a weird mix of public names and interpreter internal
* names.
*/
#include "Python-ast.h" /* mod_ty */

typedef enum _block_type { FunctionBlock, ClassBlock, ModuleBlock }
_Py_block_ty;
Expand Down Expand Up @@ -68,23 +67,19 @@ typedef struct _symtable_entry {
struct symtable *ste_table;
} PySTEntryObject;

PyAPI_DATA(PyTypeObject) PySTEntry_Type;
extern PyTypeObject PySTEntry_Type;

#define PySTEntry_Check(op) Py_IS_TYPE(op, &PySTEntry_Type)

PyAPI_FUNC(int) PyST_GetScope(PySTEntryObject *, PyObject *);
extern int _PyST_GetScope(PySTEntryObject *, PyObject *);

PyAPI_FUNC(struct symtable *) PySymtable_Build(
mod_ty mod,
const char *filename, /* decoded from the filesystem encoding */
PyFutureFeatures *future);
PyAPI_FUNC(struct symtable *) PySymtable_BuildObject(
extern struct symtable* _PySymtable_Build(
mod_ty mod,
PyObject *filename,
PyFutureFeatures *future);
PyAPI_FUNC(PySTEntryObject *) PySymtable_Lookup(struct symtable *, void *);

PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
extern void _PySymtable_Free(struct symtable *);

/* Flags for def-use information */

Expand Down Expand Up @@ -117,8 +112,14 @@ PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
#define GENERATOR 1
#define GENERATOR_EXPRESSION 2

// Used by symtablemodule.c
extern struct symtable* _Py_SymtableStringObjectFlags(
const char *str,
PyObject *filename,
int start,
PyCompilerFlags *flags);

#ifdef __cplusplus
}
#endif
#endif /* !Py_SYMTABLE_H */
#endif /* !Py_LIMITED_API */
#endif /* !Py_INTERNAL_SYMTABLE_H */
5 changes: 0 additions & 5 deletions Include/pythonrun.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ extern "C" {

PyAPI_FUNC(PyObject *) Py_CompileString(const char *, const char *, int);

PyAPI_FUNC(struct symtable *) Py_SymtableString(
const char *str,
const char *filename, /* decoded from the filesystem encoding */
int start);

PyAPI_FUNC(void) PyErr_Print(void);
PyAPI_FUNC(void) PyErr_PrintEx(int);
PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);
Expand Down
2 changes: 1 addition & 1 deletion Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,6 @@ PYTHON_HEADERS= \
$(srcdir)/Include/sliceobject.h \
$(srcdir)/Include/structmember.h \
$(srcdir)/Include/structseq.h \
$(srcdir)/Include/symtable.h \
$(srcdir)/Include/sysmodule.h \
$(srcdir)/Include/token.h \
$(srcdir)/Include/traceback.h \
Expand Down Expand Up @@ -1166,6 +1165,7 @@ PYTHON_HEADERS= \
$(srcdir)/Include/internal/pycore_pymem.h \
$(srcdir)/Include/internal/pycore_pystate.h \
$(srcdir)/Include/internal/pycore_runtime.h \
$(srcdir)/Include/internal/pycore_symtable.h \
$(srcdir)/Include/internal/pycore_sysmodule.h \
$(srcdir)/Include/internal/pycore_traceback.h \
$(srcdir)/Include/internal/pycore_tuple.h \
Expand Down
16 changes: 16 additions & 0 deletions Misc/NEWS.d/next/C API/2021-03-17-23-53-14.bpo-43244.kfPqA_.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Remove the ``symtable.h`` header file and the undocumented functions:

* ``PyST_GetScope()``
* ``PySymtable_Build()``
* ``PySymtable_BuildObject()``
* ``PySymtable_Free()``
* ``Py_SymtableString()``
* ``Py_SymtableStringObject()``

The ``Py_SymtableString()`` function was part the stable ABI by mistake but it
could not be used, because the ``symtable.h`` header file was excluded from the
limited C API.

The Python :mod:`symtable` module remains available and is unchanged.

Patch by Victor Stinner.
5 changes: 2 additions & 3 deletions Modules/symtablemodule.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "Python.h"

#include "code.h"
#include "Python-ast.h"
#include "symtable.h"
#include "pycore_symtable.h" // struct symtable

#include "clinic/symtablemodule.c.h"
/*[clinic input]
Expand Down Expand Up @@ -62,7 +61,7 @@ _symtable_symtable_impl(PyObject *module, PyObject *source,
t = (PyObject *)st->st_top;
Py_INCREF(t);
PyMem_Free((void *)st->st_future);
PySymtable_Free(st);
_PySymtable_Free(st);
return t;
}

Expand Down
1 change: 0 additions & 1 deletion PC/python3dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ EXPORT_FUNC(Py_SetPath)
EXPORT_FUNC(Py_SetProgramName)
EXPORT_FUNC(Py_SetPythonHome)
EXPORT_FUNC(Py_SetRecursionLimit)
EXPORT_FUNC(Py_SymtableString)
EXPORT_FUNC(Py_VaBuildValue)
EXPORT_FUNC(Py_XNewRef)
EXPORT_FUNC(PyArg_Parse)
Expand Down
1 change: 1 addition & 0 deletions PCbuild/pythoncore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
<ClInclude Include="..\Include\internal\pycore_pystate.h" />
<ClInclude Include="..\Include\internal\pycore_runtime.h" />
<ClInclude Include="..\Include\internal\pycore_sysmodule.h" />
<ClInclude Include="..\Include\internal\pycore_symtable.h" />
<ClInclude Include="..\Include\internal\pycore_traceback.h" />
<ClInclude Include="..\Include\internal\pycore_tuple.h" />
<ClInclude Include="..\Include\internal\pycore_ucnhash.h" />
Expand Down
3 changes: 3 additions & 0 deletions PCbuild/pythoncore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,9 @@
<ClInclude Include="..\Include\internal\pycore_sysmodule.h">
<Filter>Include\internal</Filter>
</ClInclude>
<ClInclude Include="..\Include\internal\pycore_symtable.h">
<Filter>Include\internal</Filter>
</ClInclude>
<ClInclude Include="..\Include\internal\pycore_traceback.h">
<Filter>Include\internal</Filter>
</ClInclude>
Expand Down
14 changes: 7 additions & 7 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
43 changes: 0 additions & 43 deletions Python/pythonrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
Loading