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

Lines changed: 0 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 25 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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" />

0 commit comments

Comments
 (0)