8000 gh-106084: Remove _PyObject_HasLen() function (#106103) · python/cpython@6200aaf · GitHub
[go: up one dir, main page]

Skip to content

Commit 6200aaf

Browse files
authored
gh-106084: Remove _PyObject_HasLen() function (#106103)
Remove _PyObject_HasLen() and _PySequence_IterSearch() functions from the public C API: move them to the internal C API (pycore_abstract.h). No longer export these symbols (in libpython). Remove also unused pycore_initconfig.h include in typeobject.c.
1 parent c075a19 commit 6200aaf

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

Include/cpython/abstract.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ _PyObject_CallMethodIdOneArg(PyObject *self, _Py_Identifier *name, PyObject *arg
133133
return _PyObject_VectorcallMethodId(name, args, nargsf, _Py_NULL);
134134
}
135135

136-
PyAPI_FUNC(int) _PyObject_HasLen(PyObject *o);
137-
138136
/* Guess the size of object 'o' using len(o) or o.__length_hint__().
139137
If neither of those return a non-negative value, then return the default
140138
value. If one of the calls fails, this function returns -1. */
@@ -147,24 +145,6 @@ PyAPI_FUNC(Py_ssize_t) PyObject_LengthHint(PyObject *o, Py_ssize_t);
147145
#define PySequence_ITEM(o, i)\
148146
( Py_TYPE(o)->tp_as_sequence->sq_item((o), (i)) )
149147

150-
#define PY_ITERSEARCH_COUNT 1
151-
#define PY_ITERSEARCH_INDEX 2
152-
#define PY_ITERSEARCH_CONTAINS 3
153-
154-
/* Iterate over seq.
155-
156-
Result depends on the operation:
157-
158-
PY_ITERSEARCH_COUNT: return # of times obj appears in seq; -1 if
159-
error.
160-
PY_ITERSEARCH_INDEX: return 0-based index of first occurrence of
161-
obj in seq; set ValueError and return -1 if none found;
162-
also return -1 on error.
163-
PY_ITERSEARCH_CONTAINS: return 1 if obj in seq, else 0; -1 on
164-
error. */
165-
PyAPI_FUNC(Py_ssize_t) _PySequence_IterSearch(PyObject *seq,
166-
PyObject *obj, int operation);
167-
168148
/* === Mapping protocol ================================================= */
169149

170150
PyAPI_FUNC(int) _PyObject_RealIsInstance(PyObject *inst, PyObject *cls);

Include/internal/pycore_abstract.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,28 @@ _PyIndex_Check(PyObject *obj)
1919
PyObject *_PyNumber_PowerNoMod(PyObject *lhs, PyObject *rhs);
2020
PyObject *_PyNumber_InPlacePowerNoMod(PyObject *lhs, PyObject *rhs);
2121

22+
extern int _PyObject_HasLen(PyObject *o);
23+
24+
/* === Sequence protocol ================================================ */
25+
26+
#define PY_ITERSEARCH_COUNT 1
27+
#define PY_ITERSEARCH_INDEX 2
28+
#define PY_ITERSEARCH_CONTAINS 3
29+
30+
/* Iterate over seq.
31+
32+
Result depends on the operation:
33+
34+
PY_ITERSEARCH_COUNT: return # of times obj appears in seq; -1 if
35+
error.
36+
PY_ITERSEARCH_INDEX: return 0-based index of first occurrence of
37+
obj in seq; set ValueError and return -1 if none found;
38+
also return -1 on error.
39+
PY_ITERSEARCH_CONTAINS: return 1 if obj in seq, else 0; -1 on
40+
error. */
41+
extern Py_ssize_t _PySequence_IterSearch(PyObject *seq,
42+
PyObject *obj, int operation);
43+
2244
#ifdef __cplusplus
2345
}
2446
#endif

Objects/iterobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* Iterator objects */
22

33
#include "Python.h"
4+
#include "pycore_abstract.h" // _PyObject_HasLen()
45
#include "pycore_call.h" // _PyObject_CallNoArgs()
56
#include "pycore_object.h" // _PyObject_GC_TRACK()
67

Objects/typeobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* Type object implementation */
22

33
#include "Python.h"
4-
#include "pycore_call.h"
4+
#include "pycore_abstract.h" // _PySequence_IterSearch()
5+
#include "pycore_call.h" // _PyObject_VectorcallTstate()
56
#include "pycore_code.h" // CO_FAST_FREE
67
#include "pycore_dict.h" // _PyDict_KeysSize()
78
#include "pycore_frame.h" // _PyInterpreterFrame
8-
#include "pycore_initconfig.h" // _PyStatus_OK()
99
#include "pycore_long.h" // _PyLong_IsNegative()
1010
#include "pycore_memoryobject.h" // _PyMemoryView_FromBufferProc()
1111
#include "pycore_moduleobject.h" // _PyModule_GetDef()

0 commit comments

Comments
 (0)
0