diff options
author | Simon Josefsson <simon@josefsson.org> | 2008-11-03 18:53:36 +0100 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2008-11-03 18:53:36 +0100 |
commit | 1d83818cd6d204bf8990af0e5dee4ba33b88675b (patch) | |
tree | ae458ee3bf08fa58771c9d1970a3fcc3f3865689 | |
parent | 56ca79c9212420c0ec7b2406a7d743931cb540c6 (diff) | |
download | gnutls-1d83818cd6d204bf8990af0e5dee4ba33b88675b.tar.gz |
Update gnulib files.
-rw-r--r-- | lib/gl/Makefile.am | 18 | ||||
-rw-r--r-- | lib/gl/m4/gnulib-comp.m4 | 8 | ||||
-rw-r--r-- | lib/gl/m4/memchr.m4 | 18 | ||||
-rw-r--r-- | lib/gl/m4/memcmp.m4 | 31 | ||||
-rw-r--r-- | lib/gl/memchr.c | 172 | ||||
-rw-r--r-- | lib/gl/memcmp.c | 361 | ||||
-rw-r--r-- | lib/gl/tests/Makefile.am | 16 | ||||
-rw-r--r-- | lib/gl/tests/test-memchr.c | 100 | ||||
-rw-r--r-- | lib/gl/tests/test-memcmp.c | 82 | ||||
-rw-r--r-- | maint.mk | 2 |
10 files changed, 1 insertions, 807 deletions
diff --git a/lib/gl/Makefile.am b/lib/gl/Makefile.am index 523703e538..4d8272ab26 100644 --- a/lib/gl/Makefile.am +++ b/lib/gl/Makefile.am @@ -181,24 +181,6 @@ EXTRA_liblgnu_la_SOURCES += lseek.c ## end gnulib module lseek -## begin gnulib module memchr - - -EXTRA_DIST += memchr.c - -EXTRA_liblgnu_la_SOURCES += memchr.c - -## end gnulib module memchr - -## begin gnulib module memcmp - - -EXTRA_DIST += memcmp.c - -EXTRA_liblgnu_la_SOURCES += memcmp.c - -## end gnulib module memcmp - ## begin gnulib module memmem-simple diff --git a/lib/gl/m4/gnulib-comp.m4 b/lib/gl/m4/gnulib-comp.m4 index 7b1404e4af..ab92dc2fdb 100644 --- a/lib/gl/m4/gnulib-comp.m4 +++ b/lib/gl/m4/gnulib-comp.m4 @@ -56,8 +56,6 @@ AC_DEFUN([lgl_INIT], AC_SUBST([LTLIBINTL]) gl_FUNC_LSEEK gl_UNISTD_MODULE_INDICATOR([lseek]) - gl_FUNC_MEMCHR - gl_FUNC_MEMCMP gl_FUNC_MEMMEM_SIMPLE gl_STRING_MODULE_INDICATOR([memmem]) gl_FUNC_MEMMOVE @@ -243,8 +241,6 @@ AC_DEFUN([lgl_FILE_LIST], [ lib/fseeko.c lib/gettext.h lib/lseek.c - lib/memchr.c - lib/memcmp.c lib/memmem.c lib/memmove.c lib/minmax.h @@ -312,8 +308,6 @@ AC_DEFUN([lgl_FILE_LIST], [ m4/longlong.m4 m4/lseek.m4 m4/malloc.m4 - m4/memchr.m4 - m4/memcmp.m4 m4/memmem.m4 m4/memmove.m4 m4/minmax.m4 @@ -362,8 +356,6 @@ AC_DEFUN([lgl_FILE_LIST], [ tests/test-func.c tests/test-lseek.c tests/test-lseek.sh - tests/test-memchr.c - tests/test-memcmp.c tests/test-netdb.c tests/test-read-file.c tests/test-snprintf.c diff --git a/lib/gl/m4/memchr.m4 b/lib/gl/m4/memchr.m4 deleted file mode 100644 index 91b8636eb8..0000000000 --- a/lib/gl/m4/memchr.m4 +++ /dev/null @@ -1,18 +0,0 @@ -# memchr.m4 serial 4 -dnl Copyright (C) 2002, 2003, 2004 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_MEMCHR], -[ - AC_REPLACE_FUNCS(memchr) - if test $ac_cv_func_memchr = no; then - gl_PREREQ_MEMCHR - fi -]) - -# Prerequisites of lib/memchr.c. -AC_DEFUN([gl_PREREQ_MEMCHR], [ - AC_CHECK_HEADERS(bp-sym.h) -]) diff --git a/lib/gl/m4/memcmp.m4 b/lib/gl/m4/memcmp.m4 deleted file mode 100644 index c995a32987..0000000000 --- a/lib/gl/m4/memcmp.m4 +++ /dev/null @@ -1,31 +0,0 @@ -# memcmp.m4 serial 13 -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_MEMCMP], -[ - if test $cross_compiling != no; then - # AC_FUNC_MEMCMP as of 2.62 defaults to 'no' when cross compiling. - # We default to yes if memcmp appears to exist, which works - # better for MinGW. - AC_CACHE_CHECK([whether cross-compiling target has memcmp], - [ac_cv_func_memcmp_working], - [AC_LINK_IFELSE([ - AC_LANG_PROGRAM([[#include <string.h> - ]], [[int ret = memcmp ("foo", "bar", 0);]])], - [ac_cv_func_memcmp_working=yes], - [ac_cv_func_memcmp_working=no])]) - fi - AC_FUNC_MEMCMP - dnl Note: AC_FUNC_MEMCMP does AC_LIBOBJ(memcmp). - if test $ac_cv_func_memcmp_working = no; then - AC_DEFINE(memcmp, rpl_memcmp, - [Define to rpl_memcmp if the replacement function should be used.]) - gl_PREREQ_MEMCMP - fi -]) - -# Prerequisites of lib/memcmp.c. -AC_DEFUN([gl_PREREQ_MEMCMP], [:]) diff --git a/lib/gl/memchr.c b/lib/gl/memchr.c deleted file mode 100644 index a57179d52f..0000000000 --- a/lib/gl/memchr.c +++ /dev/null @@ -1,172 +0,0 @@ -/* Copyright (C) 1991, 1993, 1996, 1997, 1999, 2000, 2003, 2004, 2006, 2008 - Free Software Foundation, Inc. - - Based on strlen implementation by Torbjorn Granlund (tege@sics.se), - with help from Dan Sahlin (dan@sics.se) and - commentary by Jim Blandy (jimb@ai.mit.edu); - adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu), - and implemented by Roland McGrath (roland@ai.mit.edu). - -NOTE: The canonical source of this file is maintained with the GNU C Library. -Bugs can be reported to bug-glibc@prep.ai.mit.edu. - -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU Lesser General Public License as published by the -Free Software Foundation; either version 2.1 of the License, or any -later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with this program. If not, see <http://www.gnu.org/licenses/>. */ - -#ifndef _LIBC -# include <config.h> -#endif - -#include <string.h> - -#include <stddef.h> - -#if defined _LIBC -# include <memcopy.h> -#else -# define reg_char char -#endif - -#include <limits.h> - -#if HAVE_BP_SYM_H || defined _LIBC -# include <bp-sym.h> -#else -# define BP_SYM(sym) sym -#endif - -#undef __memchr -#ifdef _LIBC -# undef memchr -#endif - -#ifndef weak_alias -# define __memchr memchr -#endif - -/* Search no more than N bytes of S for C. */ -void * -__memchr (void const *s, int c_in, size_t n) -{ - /* On 32-bit hardware, choosing longword to be a 32-bit unsigned - long instead of a 64-bit uintmax_t tends to give better - performance. On 64-bit hardware, unsigned long is generally 64 - bits already. Change this typedef to experiment with - performance. */ - typedef unsigned long int longword; - - const unsigned char *char_ptr; - const longword *longword_ptr; - longword repeated_one; - longword repeated_c; - unsigned reg_char c; - - c = (unsigned char) c_in; - - /* Handle the first few bytes by reading one byte at a time. - Do this until CHAR_PTR is aligned on a longword boundary. */ - for (char_ptr = (const unsigned char *) s; - n > 0 && (size_t) char_ptr % sizeof (longword) != 0; - --n, ++char_ptr) - if (*char_ptr == c) - return (void *) char_ptr; - - longword_ptr = (const longword *) char_ptr; - - /* All these elucidatory comments refer to 4-byte longwords, - but the theory applies equally well to any size longwords. */ - - /* Compute auxiliary longword values: - repeated_one is a value which has a 1 in every byte. - repeated_c has c in every byte. */ - repeated_one = 0x01010101; - repeated_c = c | (c << 8); - repeated_c |= repeated_c << 16; - if (0xffffffffU < (longword) -1) - { - repeated_one |= repeated_one << 31 << 1; - repeated_c |= repeated_c << 31 << 1; - if (8 < sizeof (longword)) - { - size_t i; - - for (i = 64; i < sizeof (longword) * 8; i *= 2) - { - repeated_one |= repeated_one << i; - repeated_c |= repeated_c << i; - } - } - } - - /* Instead of the traditional loop which tests each byte, we will test a - longword at a time. The tricky part is testing if *any of the four* - bytes in the longword in question are equal to c. We first use an xor - with repeated_c. This reduces the task to testing whether *any of the - four* bytes in longword1 is zero. - - We compute tmp = - ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7). - That is, we perform the following operations: - 1. Subtract repeated_one. - 2. & ~longword1. - 3. & a mask consisting of 0x80 in every byte. - Consider what happens in each byte: - - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff, - and step 3 transforms it into 0x80. A carry can also be propagated - to more significant bytes. - - If a byte of longword1 is nonzero, let its lowest 1 bit be at - position k (0 <= k <= 7); so the lowest k bits are 0. After step 1, - the byte ends in a single bit of value 0 and k bits of value 1. - After step 2, the result is just k bits of value 1: 2^k - 1. After - step 3, the result is 0. And no carry is produced. - So, if longword1 has only non-zero bytes, tmp is zero. - Whereas if longword1 has a zero byte, call j the position of the least - significant zero byte. Then the result has a zero at positions 0, ..., - j-1 and a 0x80 at position j. We cannot predict the result at the more - significant bytes (positions j+1..3), but it does not matter since we - already have a non-zero bit at position 8*j+7. - - So, the test whether any byte in longword1 is zero is equivalent to - testing whether tmp is nonzero. */ - - while (n >= sizeof (longword)) - { - longword longword1 = *longword_ptr ^ repeated_c; - - if ((((longword1 - repeated_one) & ~longword1) - & (repeated_one << 7)) != 0) - break; - longword_ptr++; - n -= sizeof (longword); - } - - char_ptr = (const unsigned char *) longword_ptr; - - /* At this point, we know that either n < sizeof (longword), or one of the - sizeof (longword) bytes starting at char_ptr is == c. On little-endian - machines, we could determine the first such byte without any further - memory accesses, just by looking at the tmp result from the last loop - iteration. But this does not work on big-endian machines. Choose code - that works in both cases. */ - - for (; n > 0; --n, ++char_ptr) - { - if (*char_ptr == c) - return (void *) char_ptr; - } - - return NULL; -} -#ifdef weak_alias -weak_alias (__memchr, BP_SYM (memchr)) -#endif diff --git a/lib/gl/memcmp.c b/lib/gl/memcmp.c deleted file mode 100644 index fa340631f4..0000000000 --- a/lib/gl/memcmp.c +++ /dev/null @@ -1,361 +0,0 @@ -/* Copyright (C) 1991, 1993, 1995, 1997, 1998, 2003, 2006 Free Software - Foundation, Inc. - - Contributed by Torbjorn Granlund (tege@sics.se). - - NOTE: The canonical source of this file is maintained with the GNU C Library. - Bugs can be reported to bug-glibc@prep.ai.mit.edu. - - This program is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation; either version 2.1 of the License, or any - later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. */ - -#ifndef _LIBC -# include <config.h> -#endif - -#include <string.h> - -#undef memcmp - -#ifdef _LIBC - -# include <memcopy.h> -# include <endian.h> - -# if __BYTE_ORDER == __BIG_ENDIAN -# define WORDS_BIGENDIAN -# endif - -#else /* Not in the GNU C library. */ - -# include <sys/types.h> - -/* Type to use for aligned memory operations. - This should normally be the biggest type supported by a single load - and store. Must be an unsigned type. */ -# define op_t unsigned long int -# define OPSIZ (sizeof(op_t)) - -/* Threshold value for when to enter the unrolled loops. */ -# define OP_T_THRES 16 - -/* Type to use for unaligned operations. */ -typedef unsigned char byte; - -# ifndef WORDS_BIGENDIAN -# define MERGE(w0, sh_1, w1, sh_2) (((w0) >> (sh_1)) | ((w1) << (sh_2))) -# else -# define MERGE(w0, sh_1, w1, sh_2) (((w0) << (sh_1)) | ((w1) >> (sh_2))) -# endif - -#endif /* In the GNU C library. */ - -#ifdef WORDS_BIGENDIAN -# define CMP_LT_OR_GT(a, b) ((a) > (b) ? 1 : -1) -#else -# define CMP_LT_OR_GT(a, b) memcmp_bytes ((a), (b)) -#endif - -/* BE VERY CAREFUL IF YOU CHANGE THIS CODE! */ - -/* The strategy of this memcmp is: - - 1. Compare bytes until one of the block pointers is aligned. - - 2. Compare using memcmp_common_alignment or - memcmp_not_common_alignment, regarding the alignment of the other - block after the initial byte operations. The maximum number of - full words (of type op_t) are compared in this way. - - 3. Compare the few remaining bytes. */ - -#ifndef WORDS_BIGENDIAN -/* memcmp_bytes -- Compare A and B bytewise in the byte order of the machine. - A and B are known to be different. - This is needed only on little-endian machines. */ - -# ifdef __GNUC__ -__inline -# endif -static int -memcmp_bytes (long unsigned int a, long unsigned int b) -{ - long int srcp1 = (long int) &a; - long int srcp2 = (long int) &b; - op_t a0, b0; - - do - { - a0 = ((byte *) srcp1)[0]; - b0 = ((byte *) srcp2)[0]; - srcp1 += 1; - srcp2 += 1; - } - while (a0 == b0); - return a0 - b0; -} -#endif - -/* memcmp_common_alignment -- Compare blocks at SRCP1 and SRCP2 with LEN `op_t' - objects (not LEN bytes!). Both SRCP1 and SRCP2 should be aligned for - memory operations on `op_t's. */ -#ifdef __GNUC__ -__inline -#endif -static int -memcmp_common_alignment (long int srcp1, long int srcp2, size_t len) -{ - op_t a0, a1; - op_t b0, b1; - - switch (len % 4) - { - default: /* Avoid warning about uninitialized local variables. */ - case 2: - a0 = ((op_t *) srcp1)[0]; - b0 = ((op_t *) srcp2)[0]; - srcp1 -= 2 * OPSIZ; - srcp2 -= 2 * OPSIZ; - len += 2; - goto do1; - case 3: - a1 = ((op_t *) srcp1)[0]; - b1 = ((op_t *) srcp2)[0]; - srcp1 -= OPSIZ; - srcp2 -= OPSIZ; - len += 1; - goto do2; - case 0: - if (OP_T_THRES <= 3 * OPSIZ && len == 0) - return 0; - a0 = ((op_t *) srcp1)[0]; - b0 = ((op_t *) srcp2)[0]; - goto do3; - case 1: - a1 = ((op_t *) srcp1)[0]; - b1 = ((op_t *) srcp2)[0]; - srcp1 += OPSIZ; - srcp2 += OPSIZ; - len -= 1; - if (OP_T_THRES <= 3 * OPSIZ && len == 0) - goto do0; - /* Fall through. */ - } - - do - { - a0 = ((op_t *) srcp1)[0]; - b0 = ((op_t *) srcp2)[0]; - if (a1 != b1) - return CMP_LT_OR_GT (a1, b1); - - do3: - a1 = ((op_t *) srcp1)[1]; - b1 = ((op_t *) srcp2)[1]; - if (a0 != b0) - return CMP_LT_OR_GT (a0, b0); - - do2: - a0 = ((op_t *) srcp1)[2]; - b0 = ((op_t *) srcp2)[2]; - if (a1 != b1) - return CMP_LT_OR_GT (a1, b1); - - do1: - a1 = ((op_t *) srcp1)[3]; - b1 = ((op_t *) srcp2)[3]; - if (a0 != b0) - return CMP_LT_OR_GT (a0, b0); - - srcp1 += 4 * OPSIZ; - srcp2 += 4 * OPSIZ; - len -= 4; - } - while (len != 0); - - /* This is the right position for do0. Please don't move - it into the loop. */ - do0: - if (a1 != b1) - return CMP_LT_OR_GT (a1, b1); - return 0; -} - -/* memcmp_not_common_alignment -- Compare blocks at SRCP1 and SRCP2 with LEN - `op_t' objects (not LEN bytes!). SRCP2 should be aligned for memory - operations on `op_t', but SRCP1 *should be unaligned*. */ -#ifdef __GNUC__ -__inline -#endif -static int -memcmp_not_common_alignment (long int srcp1, long int srcp2, size_t len) -{ - op_t a0, a1, a2, a3; - op_t b0, b1, b2, b3; - op_t x; - int shl, shr; - - /* Calculate how to shift a word read at the memory operation - aligned srcp1 to make it aligned for comparison. */ - - shl = 8 * (srcp1 % OPSIZ); - shr = 8 * OPSIZ - shl; - - /* Make SRCP1 aligned by rounding it down to the beginning of the `op_t' - it points in the middle of. */ - srcp1 &= -OPSIZ; - - switch (len % 4) - { - default: /* Avoid warning about uninitialized local variables. */ - case 2: - a1 = ((op_t *) srcp1)[0]; - a2 = ((op_t *) srcp1)[1]; - b2 = ((op_t *) srcp2)[0]; - srcp1 -= 1 * OPSIZ; - srcp2 -= 2 * OPSIZ; - len += 2; - goto do1; - case 3: - a0 = ((op_t *) srcp1)[0]; - a1 = ((op_t *) srcp1)[1]; - b1 = ((op_t *) srcp2)[0]; - srcp2 -= 1 * OPSIZ; - len += 1; - goto do2; - case 0: - if (OP_T_THRES <= 3 * OPSIZ && len == 0) - return 0; - a3 = ((op_t *) srcp1)[0]; - a0 = ((op_t *) srcp1)[1]; - b0 = ((op_t *) srcp2)[0]; - srcp1 += 1 * OPSIZ; - goto do3; - case 1: - a2 = ((op_t *) srcp1)[0]; - a3 = ((op_t *) srcp1)[1]; - b3 = ((op_t *) srcp2)[0]; - srcp1 += 2 * OPSIZ; - srcp2 += 1 * OPSIZ; - len -= 1; - if (OP_T_THRES <= 3 * OPSIZ && len == 0) - goto do0; - /* Fall through. */ - } - - do - { - a0 = ((op_t *) srcp1)[0]; - b0 = ((op_t *) srcp2)[0]; - x = MERGE(a2, shl, a3, shr); - if (x != b3) - return CMP_LT_OR_GT (x, b3); - - do3: - a1 = ((op_t *) srcp1)[1]; - b1 = ((op_t *) srcp2)[1]; - x = MERGE(a3, shl, a0, shr); - if (x != b0) - return CMP_LT_OR_GT (x, b0); - - do2: - a2 = ((op_t *) srcp1)[2]; - b2 = ((op_t *) srcp2)[2]; - x = MERGE(a0, shl, a1, shr); - if (x != b1) - return CMP_LT_OR_GT (x, b1); - - do1: - a3 = ((op_t *) srcp1)[3]; - b3 = ((op_t *) srcp2)[3]; - x = MERGE(a1, shl, a2, shr); - if (x != b2) - return CMP_LT_OR_GT (x, b2); - - srcp1 += 4 * OPSIZ; - srcp2 += 4 * OPSIZ; - len -= 4; - } - while (len != 0); - - /* This is the right position for do0. Please don't move - it into the loop. */ - do0: - x = MERGE(a2, shl, a3, shr); - if (x != b3) - return CMP_LT_OR_GT (x, b3); - return 0; -} - -int -rpl_memcmp (const void *s1, const void *s2, size_t len) -{ - op_t a0; - op_t b0; - long int srcp1 = (long int) s1; - long int srcp2 = (long int) s2; - op_t res; - - if (len >= OP_T_THRES) - { - /* There are at least some bytes to compare. No need to test - for LEN == 0 in this alignment loop. */ - while (srcp2 % OPSIZ != 0) - { - a0 = ((byte *) srcp1)[0]; - b0 = ((byte *) srcp2)[0]; - srcp1 += 1; - srcp2 += 1; - res = a0 - b0; - if (res != 0) - return res; - len -= 1; - } - - /* SRCP2 is now aligned for memory operations on `op_t'. - SRCP1 alignment determines if we can do a simple, - aligned compare or need to shuffle bits. */ - - if (srcp1 % OPSIZ == 0) - res = memcmp_common_alignment (srcp1, srcp2, len / OPSIZ); - else - res = memcmp_not_common_alignment (srcp1, srcp2, len / OPSIZ); - if (res != 0) - return res; - - /* Number of bytes remaining in the interval [0..OPSIZ-1]. */ - srcp1 += len & -OPSIZ; - srcp2 += len & -OPSIZ; - len %= OPSIZ; - } - - /* There are just a few bytes to compare. Use byte memory operations. */ - while (len != 0) - { - a0 = ((byte *) srcp1)[0]; - b0 = ((byte *) srcp2)[0]; - srcp1 += 1; - srcp2 += 1; - res = a0 - b0; - if (res != 0) - return res; - len -= 1; - } - - return 0; -} - -#ifdef weak_alias -# undef bcmp -weak_alias (memcmp, bcmp) -#endif diff --git a/lib/gl/tests/Makefile.am b/lib/gl/tests/Makefile.am index af0783b562..363bb76a4d 100644 --- a/lib/gl/tests/Makefile.am +++ b/lib/gl/tests/Makefile.am @@ -111,22 +111,6 @@ EXTRA_DIST += test-lseek.c test-lseek.sh ## end gnulib module lseek-tests -## begin gnulib module memchr-tests - -TESTS += test-memchr -check_PROGRAMS += test-memchr -EXTRA_DIST += test-memchr.c - -## end gnulib module memchr-tests - -## begin gnulib module memcmp-tests - -TESTS += test-memcmp -check_PROGRAMS += test-memcmp -EXTRA_DIST += test-memcmp.c - -## end gnulib module memcmp-tests - ## begin gnulib module netdb-tests TESTS += test-netdb diff --git a/lib/gl/tests/test-memchr.c b/lib/gl/tests/test-memchr.c deleted file mode 100644 index ebf3cfcdc5..0000000000 --- a/lib/gl/tests/test-memchr.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2008 Free Software Foundation - * Written by Eric Blake and Bruno Haible - * - * 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 - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ - -#include <config.h> - -#include <string.h> - -#include <stdio.h> -#include <stdlib.h> - -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ - while (0) - -/* Calculating void * + int is not portable, so this wrapper converts - to char * to make the tests easier to write. */ -#define MEMCHR (char *) memchr - -int -main () -{ - void *nil = NULL; /* Use to avoid gcc attribute((nonnull)) warnings. */ - - size_t n = 0x100000; - char *input = malloc (n); - ASSERT (input); - - input[0] = 'a'; - input[1] = 'b'; - memset (input + 2, 'c', 1024); - memset (input + 1026, 'd', n - 1028); - input[n - 2] = 'e'; - input[n - 1] = 'a'; - - /* Basic behavior tests. */ - ASSERT (MEMCHR (input, 'a', n) == input); - - ASSERT (MEMCHR (input, 'a', 0) == NULL); - ASSERT (MEMCHR (nil, 'a', 0) == NULL); - - ASSERT (MEMCHR (input, 'b', n) == input + 1); - ASSERT (MEMCHR (input, 'c', n) == input + 2); - ASSERT (MEMCHR (input, 'd', n) == input + 1026); - - ASSERT (MEMCHR (input + 1, 'a', n - 1) == input + n - 1); - ASSERT (MEMCHR (input + 1, 'e', n - 1) == input + n - 2); - - ASSERT (MEMCHR (input, 'f', n) == NULL); - ASSERT (MEMCHR (input, '\0', n) == NULL); - - /* Check that a very long haystack is handled quickly if the byte is - found near the beginning. */ - { - size_t repeat = 10000; - for (; repeat > 0; repeat--) - { - ASSERT (MEMCHR (input, 'c', n) == input + 2); - } - } - - /* Alignment tests. */ - { - int i, j; - for (i = 0; i < 32; i++) - { - for (j = 0; j < 256; j++) - input[i + j] = j; - for (j = 0; j < 256; j++) - { - ASSERT (MEMCHR (input + i, j, 256) == input + i + j); - } - } - } - - free (input); - - return 0; -} diff --git a/lib/gl/tests/test-memcmp.c b/lib/gl/tests/test-memcmp.c deleted file mode 100644 index 50342cb968..0000000000 --- a/lib/gl/tests/test-memcmp.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2008 Free Software Foundation - * Written by Simon Josefsson - * - * 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 - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ - -#include <config.h> - -#include <string.h> - -#include <stdio.h> -#include <stdlib.h> - -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ - while (0) - -int -main (void) -{ - void *nil = NULL; /* Use to avoid gcc attribute((nonnull)) warnings. */ - - /* Test equal / not equal distinction. */ - ASSERT (memcmp (nil, nil, 0) == 0); - ASSERT (memcmp ("foo", "foobar", 2) == 0); - ASSERT (memcmp ("foo", "foobar", 3) == 0); - ASSERT (memcmp ("foo", "foobar", 4) != 0); - ASSERT (memcmp ("foo", "bar", 1) != 0); - ASSERT (memcmp ("foo", "bar", 3) != 0); - - /* Test less / equal / greater distinction. */ - ASSERT (memcmp ("foo", "moo", 4) < 0); - ASSERT (memcmp ("moo", "foo", 4) > 0); - ASSERT (memcmp ("oomph", "oops", 3) < 0); - ASSERT (memcmp ("oops", "oomph", 3) > 0); - ASSERT (memcmp ("foo", "foobar", 4) < 0); - ASSERT (memcmp ("foobar", "foo", 4) > 0); - - /* Some old versions of memcmp were not 8-bit clean. */ - ASSERT (memcmp ("\100", "\201", 1) < 0); - ASSERT (memcmp ("\201", "\100", 1) > 0); - ASSERT (memcmp ("\200", "\201", 1) < 0); - ASSERT (memcmp ("\201", "\200", 1) > 0); - - /* The Next x86 OpenStep bug shows up only when comparing 16 bytes - or more and with at least one buffer not starting on a 4-byte boundary. - William Lewis provided this test program. */ - { - char foo[21]; - char bar[21]; - int i; - for (i = 0; i < 4; i++) - { - char *a = foo + i; - char *b = bar + i; - strcpy (a, "--------01111111"); - strcpy (b, "--------10000000"); - ASSERT (memcmp (a, b, 16) < 0); - } - } - - return 0; -} @@ -111,7 +111,7 @@ init-coverage: make clean lcov --directory . --zerocounters -COVERAGE_CCOPTS ?= "-g -fprofile-arcs -ftest-coverage" +COVERAGE_CCOPTS ?= "-g --coverage" COVERAGE_OUT ?= doc/coverage build-coverage: |