[Python-checkins] bpo-46848: Move _PyBytes_Find() to internal C API (GH-31642)

vstinner webhook-mailer at python.org
Wed Mar 2 08:15:31 EST 2022


https://github.com/python/cpython/commit/b6b711a1aa233001c1874af1d920e459b6bf962c
commit: b6b711a1aa233001c1874af1d920e459b6bf962c
branch: main
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2022-03-02T14:15:26+01:00
summary:

bpo-46848: Move _PyBytes_Find() to internal C API (GH-31642)

Move _PyBytes_Find() and _PyBytes_ReverseFind() functions to the
internal C API.

bytesobject.c now includes pycore_bytesobject.h.

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

diff --git a/Include/cpython/bytesobject.h b/Include/cpython/bytesobject.h
index 38a0fe0af660f..6b3f55224fc55 100644
--- a/Include/cpython/bytesobject.h
+++ b/Include/cpython/bytesobject.h
@@ -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);
diff --git a/Include/internal/pycore_bytesobject.h b/Include/internal/pycore_bytesobject.h
index 18d9530aaf41e..8739a759ec36b 100644
--- a/Include/internal/pycore_bytesobject.h
+++ b/Include/internal/pycore_bytesobject.h
@@ -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
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index 6a038e72f93cf..ec36465728c3a 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -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()
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index 4c67b8f7af213..c6160aad790be 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -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



More information about the Python-checkins mailing list