Skip to content

Commit b6b711a

Browse files
authored
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.
1 parent 03642df commit b6b711a

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

Include/cpython/bytesobject.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,3 @@ PyAPI_FUNC(void*) _PyBytesWriter_WriteBytes(_PyBytesWriter *writer,
116116
void *str,
117117
const void *bytes,
118118
Py_ssize_t size);
119-
120-
/* Substring Search.
121-
122-
Returns the index of the first occurence of
123-
a substring ("needle") in a larger text ("haystack").
124-
If the needle is not found, return -1.
125-
If the needle is found, add offset to the index.
126-
*/
127-
128-
PyAPI_FUNC(Py_ssize_t)
129-
_PyBytes_Find(const char *haystack, Py_ssize_t len_haystack,
130-
const char *needle, Py_ssize_t len_needle,
131-
Py_ssize_t offset);
132-
133-
/* Same as above, but search right-to-left */
134-
PyAPI_FUNC(Py_ssize_t)
135-
_PyBytes_ReverseFind(const char *haystack, Py_ssize_t len_haystack,
136-
const char *needle, Py_ssize_t len_needle,
137-
Py_ssize_t offset);

Include/internal/pycore_bytesobject.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,25 @@ extern "C" {
1414
extern PyStatus _PyBytes_InitTypes(PyInterpreterState *);
1515

1616

17+
/* Substring Search.
18+
19+
Returns the index of the first occurence of
20+
a substring ("needle") in a larger text ("haystack").
21+
If the needle is not found, return -1.
22+
If the needle is found, add offset to the index.
23+
*/
24+
25+
PyAPI_FUNC(Py_ssize_t)
26+
_PyBytes_Find(const char *haystack, Py_ssize_t len_haystack,
27+
const char *needle, Py_ssize_t len_needle,
28+
Py_ssize_t offset);
29+
30+
/* Same as above, but search right-to-left */
31+
PyAPI_FUNC(Py_ssize_t)
32+
_PyBytes_ReverseFind(const char *haystack, Py_ssize_t len_haystack,
33+
const char *needle, Py_ssize_t len_needle,
34+
Py_ssize_t offset);
35+
1736
#ifdef __cplusplus
1837
}
1938
#endif

Modules/mmapmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#define PY_SSIZE_T_CLEAN
2626
#include <Python.h>
27+
#include "pycore_bytesobject.h" // _PyBytes_Find()
2728
#include "pycore_fileutils.h" // _Py_stat_struct
2829
#include "structmember.h" // PyMemberDef
2930
#include <stddef.h> // offsetof()

Objects/bytesobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "Python.h"
66
#include "pycore_abstract.h" // _PyIndex_Check()
7+
#include "pycore_bytesobject.h" // _PyBytes_Find()
78
#include "pycore_bytes_methods.h" // _Py_bytes_startswith()
89
#include "pycore_call.h" // _PyObject_CallNoArgs()
910
#include "pycore_format.h" // F_LJUST

0 commit comments

Comments
 (0)