# HG changeset patch
# User Pádraig Brady
# Date 1277250174 -3600
# Node ID 0e10c7f526c55a4996f2e2aad46985d93a666db6
# Parent be240014a246f225c2b306ba1f6f748ee1fcad44
memmem: rearrange memmem and expand memmem-simple modules
Move all functional checks to memmem-simple so that one has
a fully functional memmem by using just this module.
Restrict the memmem module to performance checks only.
Document exactly how the memmem and memmem-simple modules
relate to each other.
* m4/memmem.m4 (gl_FUNC_MEMMEM_SIMPLE, gl_FUNC_MEMMEM): Move the
empty needle check from the memmem module to memmem-simple.
Also expand the empty needle check to ensure the correct
pointer is returned, not just a non NULL pointer.
In gl_FUNC_MEMMEM, make the cross compilation check only
consider the versions with performance issues.
* doc/glibc-functions/memmem.texi: Rearrange the portability
documentation to correlate with the rearranged checks.
diff --git a/ChangeLog b/ChangeLog
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2010-12-15 Pádraig Brady
+
+ 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
Bruno Haible
diff --git a/doc/glibc-functions/memmem.texi b/doc/glibc-functions/memmem.texi
--- a/doc/glibc-functions/memmem.texi
+++ b/doc/glibc-functions/memmem.texi
@@ -4,6 +4,10 @@
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
@@ -17,18 +21,20 @@
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:
diff --git a/m4/memmem.m4 b/m4/memmem.m4
--- a/m4/memmem.m4
+++ b/m4/memmem.m4
@@ -5,7 +5,7 @@
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 to declare memmem().
@@ -18,6 +18,7 @@
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([[
@@ -25,21 +26,31 @@
#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
- #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__
@@ -63,7 +74,7 @@
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])
@@ -95,26 +106,23 @@
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
#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
- #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