Skip to content

Commit 5e4af2a

Browse files
authored
gh-106320: Move private _PySet API to the internal API (#107041)
* Add pycore_setobject.h header file. * Move the following API to the internal C API: * _PySet_Dummy * _PySet_NextEntry() * _PySet_Update()
1 parent c92ef6f commit 5e4af2a

18 files changed

+53
-16
lines changed

Include/cpython/setobject.h

-5
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,3 @@ static inline Py_ssize_t PySet_GET_SIZE(PyObject *so) {
6565
return _PySet_CAST(so)->used;
6666
}
6767
#define PySet_GET_SIZE(so) PySet_GET_SIZE(_PyObject_CAST(so))
68-
69-
PyAPI_DATA(PyObject *) _PySet_Dummy;
70-
71-
PyAPI_FUNC(int) _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash);
72-
PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable);

Include/internal/pycore_pymem.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,4 @@ PyAPI_FUNC(int) _PyMem_SetupAllocators(PyMemAllocatorName allocator);
9595
#ifdef __cplusplus
9696
}
9797
#endif
98-
#endif /* !Py_INTERNAL_PYMEM_H */
98+
#endif // !Py_INTERNAL_PYMEM_H

Include/internal/pycore_setobject.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef Py_INTERNAL_SETOBJECT_H
2+
#define Py_INTERNAL_SETOBJECT_H
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
#ifndef Py_BUILD_CORE
8+
# error "this header requires Py_BUILD_CORE define"
9+
#endif
10+
11+
// _pickle shared extension uses _PySet_NextEntry() and _PySet_Update()
12+
PyAPI_FUNC(int) _PySet_NextEntry(
13+
PyObject *set,
14+
Py_ssize_t *pos,
15+
PyObject **key,
16+
Py_hash_t *hash);
17+
PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable);
18+
19+
// Export _PySet_Dummy for the gdb plugin's benefit
20+
PyAPI_DATA(PyObject *) _PySet_Dummy;
21+
22+
#ifdef __cplusplus
23+
}
24+
#endif
25+
#endif // !Py_INTERNAL_SETOBJECT_H

Makefile.pre.in

+1
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,7 @@ PYTHON_HEADERS= \
17981798
$(srcdir)/Include/internal/pycore_runtime.h \
17991799
$(srcdir)/Include/internal/pycore_runtime_init_generated.h \
18001800
$(srcdir)/Include/internal/pycore_runtime_init.h \
1801+
$(srcdir)/Include/internal/pycore_setobject.h \
18011802
$(srcdir)/Include/internal/pycore_signal.h \
18021803
$(srcdir)/Include/internal/pycore_sliceobject.h \
18031804
$(srcdir)/Include/internal/pycore_strhex.h \

Modules/_abc.c

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "pycore_moduleobject.h" // _PyModule_GetState()
88
#include "pycore_object.h" // _PyType_GetSubclasses()
99
#include "pycore_runtime.h" // _Py_ID()
10+
#include "pycore_setobject.h" // _PySet_NextEntry()
1011
#include "pycore_typeobject.h" // _PyType_GetMRO()
1112
#include "pycore_weakref.h" // _PyWeakref_GET_REF()
1213
#include "clinic/_abc.c.h"

Modules/_pickle.c

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "pycore_object.h" // _PyNone_Type
1616
#include "pycore_pystate.h" // _PyThreadState_GET()
1717
#include "pycore_runtime.h" // _Py_ID()
18+
#include "pycore_setobject.h" // _PySet_NextEntry()
1819
#include "structmember.h" // PyMemberDef
1920

2021
#include <stdlib.h> // strtol()

Objects/codeobject.c

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "pycore_interp.h" // PyInterpreterState.co_extra_freefuncs
99
#include "pycore_opcode.h" // _PyOpcode_Deopt
1010
#include "pycore_pystate.h" // _PyInterpreterState_GET()
11+
#include "pycore_setobject.h" // _PySet_NextEntry()
1112
#include "pycore_tuple.h" // _PyTuple_ITEMS()
1213
#include "clinic/codeobject.c.h"
1314

Objects/dictobject.c

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ As a consequence of this, split keys have a maximum size of 16.
121121
#include "pycore_object.h" // _PyObject_GC_TRACK()
122122
#include "pycore_pyerrors.h" // _PyErr_GetRaisedException()
123123
#include "pycore_pystate.h" // _PyThreadState_GET()
124+
#include "pycore_setobject.h" // _PySet_NextEntry()
124125
#include "stringlib/eq.h" // unicode_eq()
125126

126127
#include <stdbool.h>

Objects/setobject.c

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "Python.h"
3535
#include "pycore_modsupport.h" // _PyArg_NoKwnames()
3636
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
37+
#include "pycore_setobject.h" // _PySet_NextEntry() definition
3738
#include <stddef.h> // offsetof()
3839

3940
/* Object used as dummy key to fill deleted entries */

PCbuild/pythoncore.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@
261261
<ClInclude Include="..\Include\internal\pycore_runtime.h" />
262262
<ClInclude Include="..\Include\internal\pycore_runtime_init.h" />
263263
<ClInclude Include="..\Include\internal\pycore_runtime_init_generated.h" />
264+
<ClInclude Include="..\Include\internal\pycore_setobject.h" />
264265
<ClInclude Include="..\Include\internal\pycore_signal.h" />
265266
<ClInclude Include="..\Include\internal\pycore_sliceobject.h" />
266267
<ClInclude Include="..\Include\internal\pycore_strhex.h" />

PCbuild/pythoncore.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,9 @@
687687
<ClInclude Include="..\Include\internal\pycore_runtime_init_generated.h">
688688
<Filter>Include\internal</Filter>
689689
</ClInclude>
690+
<ClInclude Include="..\Include\internal\pycore_setobject.h">
691+
<Filter>Include\internal</Filter>
692+
</ClInclude>
690693
<ClInclude Include="..\Include\internal\pycore_signal.h">
691694
<Filter>Include\internal</Filter>
692695
</ClInclude>

Python/ast_opt.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* AST Optimizer */
22
#include "Python.h"
33
#include "pycore_ast.h" // _PyAST_GetDocString()
4-
#include "pycore_long.h" // _PyLong
5-
#include "pycore_pystate.h" // _PyThreadState_GET()
64
#include "pycore_format.h" // F_LJUST
5+
#include "pycore_long.h" // _PyLong
6+
#include "pycore_pystate.h" // _PyThreadState_GET()
7+
#include "pycore_setobject.h" // _PySet_NextEntry()
78

89

910
typedef struct {

Python/bytecodes.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,24 @@
1010
#include "pycore_abstract.h" // _PyIndex_Check()
1111
#include "pycore_ceval.h" // _PyEval_SignalAsyncExc()
1212
#include "pycore_code.h"
13+
#include "pycore_emscripten_signal.h" // _Py_CHECK_EMSCRIPTEN_SIGNALS
1314
#include "pycore_function.h"
15+
#include "pycore_instruments.h"
1416
#include "pycore_intrinsics.h"
1517
#include "pycore_long.h" // _PyLong_GetZero()
16-
#include "pycore_instruments.h"
17-
#include "pycore_object.h" // _PyObject_GC_TRACK()
1818
#include "pycore_moduleobject.h" // PyModuleObject
19+
#include "pycore_object.h" // _PyObject_GC_TRACK()
1920
#include "pycore_opcode.h" // EXTRA_CASES
2021
#include "pycore_opcode_metadata.h" // uop names
2122
#include "pycore_opcode_utils.h" // MAKE_FUNCTION_*
2223
#include "pycore_pyerrors.h" // _PyErr_GetRaisedException()
2324
#include "pycore_pystate.h" // _PyInterpreterState_GET()
2425
#include "pycore_range.h" // _PyRangeIterObject
26+
#include "pycore_setobject.h" // _PySet_NextEntry()
2527
#include "pycore_sliceobject.h" // _PyBuildSlice_ConsumeRefs
2628
#include "pycore_sysmodule.h" // _PySys_Audit()
2729
#include "pycore_tuple.h" // _PyTuple_ITEMS()
2830
#include "pycore_typeobject.h" // _PySuper_Lookup()
29-
#include "pycore_emscripten_signal.h" // _Py_CHECK_EMSCRIPTEN_SIGNALS
3031

3132
#include "pycore_dict.h"
3233
#include "dictobject.h"

Python/ceval.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,25 @@
77
#include "pycore_call.h" // _PyObject_CallNoArgs()
88
#include "pycore_ceval.h" // _PyEval_SignalAsyncExc()
99
#include "pycore_code.h"
10+
#include "pycore_emscripten_signal.h" // _Py_CHECK_EMSCRIPTEN_SIGNALS
1011
#include "pycore_function.h"
12+
#include "pycore_instruments.h"
1113
#include "pycore_intrinsics.h"
1214
#include "pycore_long.h" // _PyLong_GetZero()
13-
#include "pycore_instruments.h"
14-
#include "pycore_object.h" // _PyObject_GC_TRACK()
1515
#include "pycore_moduleobject.h" // PyModuleObject
16+
#include "pycore_object.h" // _PyObject_GC_TRACK()
1617
#include "pycore_opcode.h" // EXTRA_CASES
1718
#include "pycore_opcode_metadata.h"
1819
#include "pycore_opcode_utils.h" // MAKE_FUNCTION_*
1920
#include "pycore_pyerrors.h" // _PyErr_GetRaisedException()
2021
#include "pycore_pystate.h" // _PyInterpreterState_GET()
2122
#include "pycore_range.h" // _PyRangeIterObject
23+
#include "pycore_setobject.h" // _PySet_Update()
2224
#include "pycore_sliceobject.h" // _PyBuildSlice_ConsumeRefs
2325
#include "pycore_sysmodule.h" // _PySys_Audit()
2426
#include "pycore_tuple.h" // _PyTuple_ITEMS()
2527
#include "pycore_typeobject.h" // _PySuper_Lookup()
2628
#include "pycore_uops.h" // _PyUOpExecutorObject
27-
#include "pycore_emscripten_signal.h" // _Py_CHECK_EMSCRIPTEN_SIGNALS
2829

2930
#include "pycore_dict.h"
3031
#include "dictobject.h"

Python/compile.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828
#define NEED_OPCODE_TABLES
2929
#include "pycore_opcode_utils.h"
3030
#undef NEED_OPCODE_TABLES
31-
#include "pycore_flowgraph.h"
3231
#include "pycore_code.h" // _PyCode_New()
3332
#include "pycore_compile.h"
33+
#include "pycore_flowgraph.h"
3434
#include "pycore_intrinsics.h"
3535
#include "pycore_long.h" // _PyLong_GetZero()
3636
#include "pycore_pystate.h" // _Py_GetConfig()
37+
#include "pycore_setobject.h" // _PySet_NextEntry()
3738
#include "pycore_symtable.h" // PySTEntryObject, _PyFuture_FromAST()
3839

3940
#define NEED_OPCODE_METADATA

Python/executor.c

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "pycore_opcode_utils.h"
1212
#include "pycore_pyerrors.h"
1313
#include "pycore_range.h"
14+
#include "pycore_setobject.h" // _PySet_Update()
1415
#include "pycore_sliceobject.h"
1516
#include "pycore_uops.h"
1617

Python/marshal.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
#include "Python.h"
1010
#include "pycore_call.h" // _PyObject_CallNoArgs()
1111
#include "pycore_code.h" // _PyCode_New()
12-
#include "pycore_long.h" // _PyLong_DigitCount
1312
#include "pycore_hashtable.h" // _Py_hashtable_t
13+
#include "pycore_long.h" // _PyLong_DigitCount
14+
#include "pycore_setobject.h" // _PySet_NextEntry()
1415
#include "marshal.h" // Py_MARSHAL_VERSION
1516

1617
/*[clinic input]

Python/pylifecycle.c

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "pycore_pystate.h" // _PyThreadState_GET()
2525
#include "pycore_runtime.h" // _Py_ID()
2626
#include "pycore_runtime_init.h" // _PyRuntimeState_INIT
27+
#include "pycore_setobject.h" // _PySet_NextEntry()
2728
#include "pycore_sliceobject.h" // _PySlice_Fini()
2829
#include "pycore_sysmodule.h" // _PySys_ClearAuditHooks()
2930
#include "pycore_traceback.h" // _Py_DumpTracebackThreads()

0 commit comments

Comments
 (0)