]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46848: Move _PyBytes_Find() to internal C API (GH-31642)
authorVictor Stinner <vstinner@python.org>
Wed, 2 Mar 2022 13:15:26 +0000 (14:15 +0100)
committerGitHub <noreply@github.com>
Wed, 2 Mar 2022 13:15:26 +0000 (14:15 +0100)
Move _PyBytes_Find() and _PyBytes_ReverseFind() functions to the
internal C API.

bytesobject.c now includes pycore_bytesobject.h.

Include/cpython/bytesobject.h
Include/internal/pycore_bytesobject.h
Modules/mmapmodule.c
Objects/bytesobject.c

index 38a0fe0af660f882e4ba45bc1c956973e5641e49..6b3f55224fc553313380a6bcc2c56613ac45a835 100644 (file)
@@ -116,22 +116,3 @@ PyAPI_FUNC(void*) _PyBytesWriter_WriteBytes(_PyBytesWriter *writer,
     void *str,
     const void *bytes,
     Py_ssize_t size);
-
-/* Substring Search.
-
-   Returns the index of the first occurence of
-   a substring ("needle") in a larger text ("haystack").
-   If the needle is not found, return -1.
-   If the needle is found, add offset to the index.
-*/
-
-PyAPI_FUNC(Py_ssize_t)
-_PyBytes_Find(const char *haystack, Py_ssize_t len_haystack,
-              const char *needle, Py_ssize_t len_needle,
-              Py_ssize_t offset);
-
-/* Same as above, but search right-to-left */
-PyAPI_FUNC(Py_ssize_t)
-_PyBytes_ReverseFind(const char *haystack, Py_ssize_t len_haystack,
-                     const char *needle, Py_ssize_t len_needle,
-                     Py_ssize_t offset);
index 18d9530aaf41ee08c93f973503ea1c777e2e4b80..8739a759ec36bfdab89a2d1bbd5332f6f6a77072 100644 (file)
@@ -14,6 +14,25 @@ extern "C" {
 extern PyStatus _PyBytes_InitTypes(PyInterpreterState *);
 
 
+/* Substring Search.
+
+   Returns the index of the first occurence of
+   a substring ("needle") in a larger text ("haystack").
+   If the needle is not found, return -1.
+   If the needle is found, add offset to the index.
+*/
+
+PyAPI_FUNC(Py_ssize_t)
+_PyBytes_Find(const char *haystack, Py_ssize_t len_haystack,
+              const char *needle, Py_ssize_t len_needle,
+              Py_ssize_t offset);
+
+/* Same as above, but search right-to-left */
+PyAPI_FUNC(Py_ssize_t)
+_PyBytes_ReverseFind(const char *haystack, Py_ssize_t len_haystack,
+                     const char *needle, Py_ssize_t len_needle,
+                     Py_ssize_t offset);
+
 #ifdef __cplusplus
 }
 #endif
index 6a038e72f93cfc746051228bae52c50f3bb9c49a..ec36465728c3a612feaf566f9700ec508960d27d 100644 (file)
@@ -24,6 +24,7 @@
 
 #define PY_SSIZE_T_CLEAN
 #include <Python.h>
+#include "pycore_bytesobject.h"   // _PyBytes_Find()
 #include "pycore_fileutils.h"     // _Py_stat_struct
 #include "structmember.h"         // PyMemberDef
 #include <stddef.h>               // offsetof()
index 4c67b8f7af213b25e273d116df1466372cce4e8b..c6160aad790bea8ae2cf6ff8cff66c371e53c753 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "Python.h"
 #include "pycore_abstract.h"      // _PyIndex_Check()
+#include "pycore_bytesobject.h"   // _PyBytes_Find()
 #include "pycore_bytes_methods.h" // _Py_bytes_startswith()
 #include "pycore_call.h"          // _PyObject_CallNoArgs()
 #include "pycore_format.h"        // F_LJUST