Skip to content

Commit 28ad12f

Browse files
authored
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.
1 parent 32eba61 commit 28ad12f

File tree

15 files changed

+100
-115
lines changed

15 files changed

+100
-115
lines changed

Doc/data/stable_abi.dat

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,6 @@ Py_SetPath
776776
Py_SetProgramName
777777
Py_SetPythonHome
778778
Py_SetRecursionLimit
779-
Py_SymtableString
780779
Py_UTF8Mode
781780
Py_VaBuildValue
782781
Py_XNewRef

Doc/whatsnew/3.10.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,3 +1364,19 @@ Removed
13641364
AST object (``mod_ty`` type) with the public C API. The function was already
13651365
excluded from the limited C API (:pep:`384`).
13661366
(Contributed by Victor Stinner in :issue:`43244`.)
1367+
1368+
* Remove the ``symtable.h`` header file and the undocumented functions:
1369+
1370+
* ``PyST_GetScope()``
1371+
* ``PySymtable_Build()``
1372+
* ``PySymtable_BuildObject()``
1373+
* ``PySymtable_Free()``
1374+
* ``Py_SymtableString()``
1375+
* ``Py_SymtableStringObject()``
1376+
1377+
The ``Py_SymtableString()`` function was part the stable ABI by mistake but
1378+
it could not be used, because the ``symtable.h`` header file was excluded
1379+
from the limited C API.
1380+
1381+
The Python :mod:`symtable` module remains available and is unchanged.
1382+
(Contributed by Victor Stinner in :issue:`43244`.)

Include/cpython/pythonrun.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,6 @@ PyAPI_FUNC(const char *) _Py_SourceAsString(
7777
PyCompilerFlags *cf,
7878
PyObject **cmd_copy);
7979

80-
PyAPI_FUNC(struct symtable *) Py_SymtableStringObject(
81-
const char *str,
82-
PyObject *filename,
83-
int start);
84-
85-
PyAPI_FUNC(struct symtable *) _Py_SymtableStringObjectFlags(
86-
const char *str,
87-
PyObject *filename,
88-
int start,
89-
PyCompilerFlags *flags);
90-
9180

9281
/* A function flavor is also exported by libpython. It is required when
9382
libpython is accessed directly rather than using header files which defines

Include/symtable.h renamed to Include/internal/pycore_symtable.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
#ifndef Py_LIMITED_API
2-
#ifndef Py_SYMTABLE_H
3-
#define Py_SYMTABLE_H
1+
#ifndef Py_INTERNAL_SYMTABLE_H
2+
#define Py_INTERNAL_SYMTABLE_H
43
#ifdef __cplusplus
54
extern "C" {
65
#endif
76

8-
#include "Python-ast.h" /* mod_ty */
7+
#ifndef Py_BUILD_CORE
8+
# error "this header requires Py_BUILD_CORE define"
9+
#endif
910

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

1413
typedef enum _block_type { FunctionBlock, ClassBlock, ModuleBlock }
1514
_Py_block_ty;
@@ -68,23 +67,19 @@ typedef struct _symtable_entry {
6867
struct symtable *ste_table;
6968
} PySTEntryObject;
7069

71-
PyAPI_DATA(PyTypeObject) PySTEntry_Type;
70+
extern PyTypeObject PySTEntry_Type;
7271

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

75-
PyAPI_FUNC(int) PyST_GetScope(PySTEntryObject *, PyObject *);
74+
extern int _PyST_GetScope(PySTEntryObject *, PyObject *);
7675

77-
PyAPI_FUNC(struct symtable *) PySymtable_Build(
78-
mod_ty mod,
79-
const char *filename, /* decoded from the filesystem encoding */
80-
PyFutureFeatures *future);
81-
PyAPI_FUNC(struct symtable *) PySymtable_BuildObject(
76+
extern struct symtable* _PySymtable_Build(
8277
mod_ty mod,
8378
PyObject *filename,
8479
PyFutureFeatures *future);
8580
PyAPI_FUNC(PySTEntryObject *) PySymtable_Lookup(struct symtable *, void *);
8681

87-
PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
82+
extern void _PySymtable_Free(struct symtable *);
8883

8984
/* Flags for def-use information */
9085

@@ -117,8 +112,14 @@ PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
117112
#define GENERATOR 1
118113
#define GENERATOR_EXPRESSION 2
119114

115+
// Used by symtablemodule.c
116+
extern struct symtable* _Py_SymtableStringObjectFlags(
117+
const char *str,
118+
PyObject *filename,
119+
int start,
120+
PyCompilerFlags *flags);
121+
120122
#ifdef __cplusplus
121123
}
122124
#endif
123-
#endif /* !Py_SYMTABLE_H */
124-
#endif /* !Py_LIMITED_API */
125+
#endif /* !Py_INTERNAL_SYMTABLE_H */

Include/pythonrun.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ extern "C" {
99

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

12-
PyAPI_FUNC(struct symtable *) Py_SymtableString(
13-
const char *str,
14-
const char *filename, /* decoded from the filesystem encoding */
15-
int start);
16-
1712
PyAPI_FUNC(void) PyErr_Print(void);
1813
PyAPI_FUNC(void) PyErr_PrintEx(int);
1914
PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);

Makefile.pre.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,6 @@ PYTHON_HEADERS= \
10871087
$(srcdir)/Include/sliceobject.h \
10881088
$(srcdir)/Include/structmember.h \
10891089
$(srcdir)/Include/structseq.h \
1090-
$(srcdir)/Include/symtable.h \
10911090
$(srcdir)/Include/sysmodule.h \
10921091
$(srcdir)/Include/token.h \
10931092
$(srcdir)/Include/traceback.h \
@@ -1167,6 +1166,7 @@ PYTHON_HEADERS= \
11671166
$(srcdir)/Include/internal/pycore_pymem.h \
11681167
$(srcdir)/Include/internal/pycore_pystate.h \
11691168
$(srcdir)/Include/internal/pycore_runtime.h \
1169+
$(srcdir)/Include/internal/pycore_symtable.h \
11701170
$(srcdir)/Include/internal/pycore_sysmodule.h \
11711171
$(srcdir)/Include/internal/pycore_traceback.h \
11721172
$(srcdir)/Include/internal/pycore_tuple.h \
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Remove the ``symtable.h`` header file and the undocumented functions:
2+
3+
* ``PyST_GetScope()``
4+
* ``PySymtable_Build()``
5+
* ``PySymtable_BuildObject()``
6+
* ``PySymtable_Free()``
7+
* ``Py_SymtableString()``
8+
* ``Py_SymtableStringObject()``
9+
10+
The ``Py_SymtableString()`` function was part the stable ABI by mistake but it
11+
could not be used, because the ``symtable.h`` header file was excluded from the
12+
limited C API.
13+
14+
The Python :mod:`symtable` module remains available and is unchanged.
15+
16+
Patch by Victor Stinner.

Modules/symtablemodule.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#include "Python.h"
22

3-
#include "code.h"
43
#include "Python-ast.h"
5-
#include "symtable.h"
4+
#include "pycore_symtable.h" // struct symtable
65

76
#include "clinic/symtablemodule.c.h"
87
/*[clinic input]
@@ -62,7 +61,7 @@ _symtable_symtable_impl(PyObject *module, PyObject *source,
6261
t = (PyObject *)st->st_top;
6362
Py_INCREF(t);
6463
PyMem_Free((void *)st->st_future);
65-
PySymtable_Free(st);
64+
_PySymtable_Free(st);
6665
return t;
6766
}
6867

PC/python3dll.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ EXPORT_FUNC(Py_SetPath)
8080
EXPORT_FUNC(Py_SetProgramName)
8181
EXPORT_FUNC(Py_SetPythonHome)
8282
EXPORT_FUNC(Py_SetRecursionLimit)
83-
EXPORT_FUNC(Py_SymtableString)
8483
EXPORT_FUNC(Py_VaBuildValue)
8584
EXPORT_FUNC(Py_XNewRef)
8685
EXPORT_FUNC(PyArg_Parse)

PCbuild/pythoncore.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@
208208
<ClInclude Include="..\Include\internal\pycore_pystate.h" />
209209
<ClInclude Include="..\Include\internal\pycore_runtime.h" />
210210
<ClInclude Include="..\Include\internal\pycore_sysmodule.h" />
211+
<ClInclude Include="..\Include\internal\pycore_symtable.h" />
211212
<ClInclude Include="..\Include\internal\pycore_traceback.h" />
212213
<ClInclude Include="..\Include\internal\pycore_tuple.h" />
213214
<ClInclude Include="..\Include\internal\pycore_ucnhash.h" />

0 commit comments

Comments
 (0)