* m4/memmem.m4 (gl_FUNC_MEMMEM_SIMPLE): New macro.
(gl_FUNC_MEMMEM): Separate performance from presence checks.
* modules/memmem-simple: New file.
* modules/memmem (Description): Tweak.
* MODULES.html.sh (string handling): Mention it.
* doc/functions/memmem.texi (memmem): Distinguish which flaws are
addressed by memmem-simple.
* NEWS: Document the difference.
Signed-off-by: Eric Blake <ebb9@byu.net>
+2008-01-09 Simon Josefsson <simon@josefsson.org>
+ and Eric Blake <ebb9@byu.net>
+
+ Add memmem-simple module.
+ * m4/memmem.m4 (gl_FUNC_MEMMEM_SIMPLE): New macro.
+ (gl_FUNC_MEMMEM): Separate performance from presence checks.
+ * modules/memmem-simple: New file.
+ * modules/memmem (Description): Tweak.
+ * MODULES.html.sh (string handling): Mention new module.
+ * doc/functions/memmem.texi (memmem): Distinguish which flaws are
+ addressed by memmem-simple.
+ * NEWS: Document the difference.
+
2008-01-09 Eric Blake <ebb9@byu.net>
Give gcc some memmem optimization hints.
* build-aux/config.rpath: Likewise.
2008-01-08 Jim Meyering <meyering@redhat.com>
- Bruno Haible <bruno@clisp.org>
+ Bruno Haible <bruno@clisp.org>
* lib/printf-parse.c (PRINTF_PARSE): Handle a size specifier "q"
on MacOS X and a size specifier "I64" on mingw. Needed for PRIdMAX.
#!/bin/sh
#
-# Copyright (C) 2002-2007 Free Software Foundation, Inc.
+# Copyright (C) 2002-2008 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
func_begin_table
func_module bcopy
func_module memmem
+ func_module memmem-simple
func_module mempcpy
func_module memrchr
func_module stpcpy
Date Modules Changes
+2008-01-08 memmem This module now replaces worst-case inefficient
+ implementations; clients that use controlled
+ needles and thus do not care about worst-case
+ efficiency should use the new memmem-simple
+ module instead for smaller code size.
+
2007-12-24 setenv The include file is changed from "setenv.h" to
<stdlib.h>. Also, the unsetenv function is no
longer declared in this module; use the 'unsetenv'
Unspecified by POSIX, but comparable to @code{strstr}.
-Gnulib module: memmem
+Gnulib module: memmem, memmem-simple
Portability problems fixed by Gnulib:
@itemize
@item
This function returns incorrect values in some cases, such as when
-given an empty needle:
+given an empty needle (not fixed in memmem-simple):
glibc <= 2.0, cygwin 1.5.x
@item
This function has quadratic instead of linear complexity on some
-platforms:
+platforms (not fixed in memmem-simple):
glibc <= 2.6.1, cygwin 1.5.x
@item
-# memmem.m4 serial 7
+# memmem.m4 serial 8
dnl Copyright (C) 2002, 2003, 2004, 2007, 2008 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
-AC_DEFUN([gl_FUNC_MEMMEM],
+dnl Check that memmem is present.
+AC_DEFUN([gl_FUNC_MEMMEM_SIMPLE],
[
dnl Persuade glibc <string.h> to declare memmem().
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
AC_CHECK_DECLS_ONCE(memmem)
if test $ac_cv_have_decl_memmem = no; then
HAVE_DECL_MEMMEM=0
- else
+ fi
+ gl_PREREQ_MEMMEM
+]) # gl_FUNC_MEMMEM_SIMPLE
+
+dnl Additionally, check that memmem is efficient and handles empty needles.
+AC_DEFUN([gl_FUNC_MEMMEM],
+[
+ AC_REQUIRE([gl_FUNC_MEMMEM_SIMPLE])
+ if test $ac_cv_have_decl_memmem = yes; then
AC_CACHE_CHECK([whether memmem works in linear time],
[gl_cv_func_memmem_works],
[AC_RUN_IFELSE([AC_LANG_PROGRAM([
/* Failure to compile this test due to missing alarm is okay,
since all such platforms (mingw) also lack memmem. */
alarm (5);
+ /* Check for quadratic performance. */
if (haystack && needle)
{
memset (haystack, 'A', 2 * m);
needle[m] = 'B';
result = memmem (haystack, 2 * m + 1, needle, m + 1);
}
+ /* Check for empty needle behavior. */
return !result || !memmem ("a", 1, 0, 0);]])],
[gl_cv_func_memmem_works=yes], [gl_cv_func_memmem_works=no],
[dnl pessimistically assume the worst, since even glibc 2.6.1
AC_LIBOBJ([memmem])
fi
fi
- gl_PREREQ_MEMMEM
-])
+]) # gl_FUNC_MEMMEM
# Prerequisites of lib/memmem.c.
AC_DEFUN([gl_PREREQ_MEMMEM], [:])
Description:
-memmem() function: locate first substring in a buffer.
+memmem() function: efficiently locate first substring in a buffer.
Files:
lib/memmem.c
--- /dev/null
+Description:
+memmem() function: locate first substring in a buffer.
+
+Files:
+lib/memmem.c
+m4/memmem.m4
+
+Depends-on:
+extensions
+string
+stdint
+memchr
+memcmp
+
+configure.ac:
+gl_FUNC_MEMMEM_SIMPLE
+gl_STRING_MODULE_INDICATOR([memmem])
+
+Makefile.am:
+
+Include:
+<string.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+libc, Eric Blake, Simon Josefsson