]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106084: Remove _PyObject_HasLen() function (#106103)
authorVictor Stinner <vstinner@python.org>
Mon, 26 Jun 2023 13:02:43 +0000 (15:02 +0200)
committerGitHub <noreply@github.com>
Mon, 26 Jun 2023 13:02:43 +0000 (13:02 +0000)
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.

Include/cpython/abstract.h
Include/internal/pycore_abstract.h
Objects/iterobject.c
Objects/typeobject.c

index 5d2d2afdd4e7512c2345e2aba2154ee4d12a77f4..cba0f4c31309213a1bc36ec5b2c13ff2da19cdcc 100644 (file)
@@ -133,8 +133,6 @@ _PyObject_CallMethodIdOneArg(PyObject *self, _Py_Identifier *name, PyObject *arg
     return _PyObject_VectorcallMethodId(name, args, nargsf, _Py_NULL);
 }
 
-PyAPI_FUNC(int) _PyObject_HasLen(PyObject *o);
-
 /* Guess the size of object 'o' using len(o) or o.__length_hint__().
    If neither of those return a non-negative value, then return the default
    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);
 #define PySequence_ITEM(o, i)\
     ( Py_TYPE(o)->tp_as_sequence->sq_item((o), (i)) )
 
-#define PY_ITERSEARCH_COUNT    1
-#define PY_ITERSEARCH_INDEX    2
-#define PY_ITERSEARCH_CONTAINS 3
-
-/* Iterate over seq.
-
-   Result depends on the operation:
-
-   PY_ITERSEARCH_COUNT:  return # of times obj appears in seq; -1 if
-     error.
-   PY_ITERSEARCH_INDEX:  return 0-based index of first occurrence of
-     obj in seq; set ValueError and return -1 if none found;
-     also return -1 on error.
-   PY_ITERSEARCH_CONTAINS:  return 1 if obj in seq, else 0; -1 on
-     error. */
-PyAPI_FUNC(Py_ssize_t) _PySequence_IterSearch(PyObject *seq,
-                                              PyObject *obj, int operation);
-
 /* === Mapping protocol ================================================= */
 
 PyAPI_FUNC(int) _PyObject_RealIsInstance(PyObject *inst, PyObject *cls);
index b1afb2dc7be65e6442da153b051689f5b7e96ad8..9ba27487f5bbf1bbd5ea1aaaa9e75afb52fa884b 100644 (file)
@@ -19,6 +19,28 @@ _PyIndex_Check(PyObject *obj)
 PyObject *_PyNumber_PowerNoMod(PyObject *lhs, PyObject *rhs);
 PyObject *_PyNumber_InPlacePowerNoMod(PyObject *lhs, PyObject *rhs);
 
+extern int _PyObject_HasLen(PyObject *o);
+
+/* === Sequence protocol ================================================ */
+
+#define PY_ITERSEARCH_COUNT    1
+#define PY_ITERSEARCH_INDEX    2
+#define PY_ITERSEARCH_CONTAINS 3
+
+/* Iterate over seq.
+
+   Result depends on the operation:
+
+   PY_ITERSEARCH_COUNT:  return # of times obj appears in seq; -1 if
+     error.
+   PY_ITERSEARCH_INDEX:  return 0-based index of first occurrence of
+     obj in seq; set ValueError and return -1 if none found;
+     also return -1 on error.
+   PY_ITERSEARCH_CONTAINS:  return 1 if obj in seq, else 0; -1 on
+     error. */
+extern Py_ssize_t _PySequence_IterSearch(PyObject *seq,
+                                         PyObject *obj, int operation);
+
 #ifdef __cplusplus
 }
 #endif
index 7cb17a6ca4ab56a5d9abb9f8df7f092f2855b50f..cf7cb8af52a274c55d97b7318220352c03b0a95a 100644 (file)
@@ -1,6 +1,7 @@
 /* Iterator objects */
 
 #include "Python.h"
+#include "pycore_abstract.h"      // _PyObject_HasLen()
 #include "pycore_call.h"          // _PyObject_CallNoArgs()
 #include "pycore_object.h"        // _PyObject_GC_TRACK()
 
index 9aba53df157910bac3e64dfdc3a0e0dc6689c911..e3769cee2c39725ab3f802ebc1b6d70bec39ff47 100644 (file)
@@ -1,11 +1,11 @@
 /* Type object implementation */
 
 #include "Python.h"
-#include "pycore_call.h"
+#include "pycore_abstract.h"      // _PySequence_IterSearch()
+#include "pycore_call.h"          // _PyObject_VectorcallTstate()
 #include "pycore_code.h"          // CO_FAST_FREE
 #include "pycore_dict.h"          // _PyDict_KeysSize()
 #include "pycore_frame.h"         // _PyInterpreterFrame
-#include "pycore_initconfig.h"    // _PyStatus_OK()
 #include "pycore_long.h"          // _PyLong_IsNegative()
 #include "pycore_memoryobject.h"  // _PyMemoryView_FromBufferProc()
 #include "pycore_moduleobject.h"  // _PyModule_GetDef()