+2010-12-15 Pádraig Brady <P@draigBrady.com>
+
+ memmem, memmem-simple: reorganize and expand empty needle check
+ * m4/memmem.m4 (gl_FUNC_MEMMEM_SIMPLE, gl_FUNC_MEMMEM): Move all
+ functional checks to memmem-simple so that one has a fully functional
+ memmem by using just this module.
+ Restrict the performance only check to the memmem module.
+ Also expand the empty needle check to ensure the correct
+ pointer is returned, not just a non NULL pointer.
+ * doc/glibc-functions/memmem.texi: Rearrange the portability
+ documentation to correlate with the rearranged checks.
+ Clarify exactly how the memmem and memmem-simple modules
+ relate to each other.
+
2010-12-15 Pádraig Brady <P@draigBrady.com>
Bruno Haible <bruno@clisp.org>
Gnulib module: memmem or memmem-simple
+Both modules implement the same replacement for the @code{memmem} function
+with the memmem module providing a replacement on more platforms where
+the existing @code{memmem} function has a quadratic worst-case complexity.
+
Portability problems fixed by either Gnulib module @code{memmem-simple}
or @code{memmem}:
@itemize
This function can trigger false positives for long periodic needles on
some platforms:
glibc 2.12, Cygwin 1.7.7.
-@end itemize
-Portability problems fixed by Gnulib module @code{memmem}:
-@itemize
@item
This function returns incorrect values in some cases, such as when
given an empty needle:
glibc <= 2.0, Cygwin 1.5.x.
+@end itemize
+
+Performance problems fixed by Gnulib module @code{memmem}:
+@itemize
@item
This function has quadratic instead of linear worst-case complexity on some
platforms:
glibc 2.8, FreeBSD 6.2, NetBSD 5.0, AIX 5.1, Solaris 11 2010-11, Cygwin 1.5.x.
+Note for small needles the replacement may be slower.
@end itemize
Portability problems not fixed by Gnulib:
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
-dnl Check that memmem is present.
+dnl Check that memmem is present and functional.
AC_DEFUN([gl_FUNC_MEMMEM_SIMPLE],
[
dnl Persuade glibc <string.h> to declare memmem().
HAVE_DECL_MEMMEM=0
else
dnl Detect http://sourceware.org/bugzilla/show_bug.cgi?id=12092.
+ dnl Also check that we handle empty needles correctly.
AC_CACHE_CHECK([whether memmem works],
[gl_cv_func_memmem_works_always],
[AC_RUN_IFELSE([AC_LANG_PROGRAM([[
#define P "_EF_BF_BD"
#define HAYSTACK "F_BD_CE_BD" P P P P "_C3_88_20" P P P "_C3_A7_20" P
#define NEEDLE P P P P P
-]], [[return !!memmem (HAYSTACK, strlen (HAYSTACK), NEEDLE, strlen (NEEDLE));
+]], [[
+ int result = 0;
+ if (memmem (HAYSTACK, strlen (HAYSTACK), NEEDLE, strlen (NEEDLE)))
+ result |= 1;
+ /* Check for empty needle behavior. */
+ {
+ char* haystack="AAA";
+ if (memmem (haystack, 3, 0, 0) != haystack)
+ result |= 2;
+ }
+ return result;
]])],
[gl_cv_func_memmem_works_always=yes],
[gl_cv_func_memmem_works_always=no],
- [dnl glibc 2.12 and cygwin 1.7.7 have a known bug. uClibc is not
- dnl affected, since it uses different source code for memmem than
- dnl glibc.
- dnl Assume that it works on all other platforms, even if it is not
- dnl linear.
+ [dnl glibc 2.12 and cygwin 1.7.7 have issue #12092 above.
+ dnl Also empty needles work on glibc >= 2.1 and cygwin >= 1.7.0
+ dnl uClibc is not affected, since it uses different source code.
+ dnl Assume that it works on all other platforms (even if not linear).
AC_EGREP_CPP([Lucky user],
[
#ifdef __GNU_LIBRARY__
#include <features.h>
- #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ > 12) || (__GLIBC__ > 2)) \
- || defined __UCLIBC__
+ #if ((__GLIBC__ == 2 && ((__GLIBC_MINOR > 0 && __GLIBC_MINOR__ < 9) \
+ || __GLIBC_MINOR__ > 12)) \
+ || (__GLIBC__ > 2)) || defined __UCLIBC__
Lucky user
#endif
#elif defined __CYGWIN__
gl_PREREQ_MEMMEM
]) # gl_FUNC_MEMMEM_SIMPLE
-dnl Additionally, check that memmem is efficient and handles empty needles.
+dnl Additionally, check that memmem has linear performance characteristics
AC_DEFUN([gl_FUNC_MEMMEM],
[
AC_REQUIRE([gl_FUNC_MEMMEM_SIMPLE])
if (!memmem (haystack, 2 * m + 1, needle, m + 1))
result |= 1;
}
- /* Check for empty needle behavior. */
- if (!memmem ("a", 1, 0, 0))
- result |= 2;
return result;
]])],
[gl_cv_func_memmem_works_fast=yes], [gl_cv_func_memmem_works_fast=no],
- [dnl Only glibc > 2.12 and cygwin > 1.7.7 are known to have a
- dnl bug-free memmem that works in linear time.
+ [dnl Only glibc >= 2.9 and cygwin > 1.7.0 are known to have a
+ dnl memmem that works in linear time.
AC_EGREP_CPP([Lucky user],
[
#include <features.h>
#ifdef __GNU_LIBRARY__
- #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ > 12) || (__GLIBC__ > 2)) \
+ #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 9) || (__GLIBC__ > 2)) \
&& !defined __UCLIBC__
Lucky user
#endif
#endif
#ifdef __CYGWIN__
#include <cygwin/version.h>
- #if CYGWIN_VERSION_DLL_COMBINED > CYGWIN_VERSION_DLL_MAKE_COMBINED (1007, 7)
+ #if CYGWIN_VERSION_DLL_COMBINED > CYGWIN_VERSION_DLL_MAKE_COMBINED (1007, 0)
Lucky user
#endif
#endif