Provide a fallback implementation of memrchr

Move the local fallback out of string.c so other source files can use
memrchr on platforms that do not provide it.
This commit is contained in:
Nobuyoshi Nakada authored and Nobuyoshi Nakada committed 2026-07-15 13:28:39 +09:00
1 parent b9a50a0b81
commit 4b638eecd1
5 files changed
+18 -15
Notes: git 2026-07-15 04:29:37 +00:00

No files matched your search

+1 -1
View File
@@ -2131,6 +2131,7 @@ AC_REPLACE_FUNCS(flock)
AC_REPLACE_FUNCS(hypot)
AC_REPLACE_FUNCS(lgamma_r)
AC_REPLACE_FUNCS(memmove)
AC_REPLACE_FUNCS(memrchr)
AC_REPLACE_FUNCS(nan)
AC_REPLACE_FUNCS(nextafter)
AC_REPLACE_FUNCS(setproctitle)
@@ -2246,7 +2247,6 @@ AC_CHECK_FUNCS(mblen)
AC_CHECK_FUNCS(memalign)
AC_CHECK_FUNCS(memset_s)
AC_CHECK_FUNCS(writev)
AC_CHECK_FUNCS(memrchr)
AC_CHECK_FUNCS(memmem)
AC_CHECK_FUNCS(mkfifo)
AC_CHECK_FUNCS(mknod)
+4
View File
@@ -183,6 +183,10 @@ RUBY_EXTERN int memcmp(const void *, const void *, size_t);
RUBY_EXTERN void *memmove(void *, const void *, size_t);
#endif
#ifndef HAVE_MEMRCHR
RUBY_EXTERN void *memrchr(const void *, int, size_t);
#endif
/*
#ifndef HAVE_MODF
RUBY_EXTERN double modf(double, double *);
+12
View File
@@ -0,0 +1,12 @@
#include "ruby/missing.h"
void *
memrchr(const void *ptr, int ch, size_t len)
{
const unsigned char *p = (const unsigned char *)ptr + len;
while (p > (const unsigned char *)ptr) {
if (*--p == (unsigned char)ch) return (void *)p;
}
return NULL;
}
-13
View File
@@ -4763,19 +4763,6 @@ rb_str_byteindex_m(int argc, VALUE *argv, VALUE str)
return Qnil;
}
#ifndef HAVE_MEMRCHR
static void*
memrchr(const char *search_str, int chr, long search_len)
{
const char *ptr = search_str + search_len;
while (ptr > search_str) {
if ((unsigned char)*(--ptr) == chr) return (void *)ptr;
}
return ((void *)0);
}
#endif
static long
str_rindex(VALUE str, VALUE sub, const char *s, rb_encoding *enc)
{
+1 -1
View File
@@ -320,7 +320,7 @@ LIBS = $(LIBS) imagehlp.lib shlwapi.lib bcrypt.lib $(EXTLIBS)
!endif
!if !defined(MISSING)
MISSING = crypt.obj ffs.obj langinfo.obj lgamma_r.obj strlcat.obj strlcpy.obj win32/win32.obj win32/file.obj setproctitle.obj
MISSING = $(MISSING) explicit_bzero.obj
MISSING = $(MISSING) explicit_bzero.obj memrchr.obj
!endif
DLNOBJ = dln.obj