1
1
#include <Python.h>
2
2
3
+
4
+ /*
5
+ * memrchr not available on some systems, so reimplement.
6
+ */
7
+ const char * _memrchr (const char * s , int c , size_t n ) {
8
+ for (const char * p = s + n - 1 ; p >= s ; -- p ) {
9
+ if (* p == c )
10
+ return p ;
11
+ }
12
+ return NULL ;
13
+ }
14
+
15
+
16
+
3
17
struct cstring {
4
18
PyObject_VAR_HEAD
5
19
Py_hash_t hash ;
@@ -10,7 +24,6 @@ struct cstring {
10
24
#define CSTRING_VALUE (self ) (((struct cstring *)self)->value)
11
25
#define CSTRING_VALUE_AT (self , i ) (&CSTRING_VALUE(self)[(i)])
12
26
13
-
14
27
static PyObject * _cstring_new (PyTypeObject * type , const char * value , size_t len ) {
15
28
struct cstring * new = (struct cstring * )type -> tp_alloc (type , len + 1 );
16
29
new -> hash = -1 ;
@@ -268,7 +281,7 @@ static const char *_substr_params_str(const struct _substr_params *params) {
268
281
static const char * _substr_params_rstr (const struct _substr_params * params ) {
269
282
const char * p = params -> end - params -> substr_len + 1 ;
270
283
for (;;) {
271
- p = memrchr (params -> start , * params -> substr , p - params -> start );
284
+ p = _memrchr (params -> start , * params -> substr , p - params -> start );
272
285
if (!p )
273
286
goto done ;
274
287
if (memcmp (p , params -> substr , params -> substr_len ) == 0 )
@@ -316,6 +329,7 @@ PyObject *cstring_rfind(PyObject *self, PyObject *args) {
316
329
return NULL ;
317
330
318
331
const char * p = _substr_params_rstr (& params );
332
+
319
333
if (!p )
320
334
return PyLong_FromLong (-1 );
321
335
0 commit comments