rpms/dietlibc/devel dietlibc-0.31.20080212-strlen.patch,1.1,1.2
Enrico Scholz (ensc)
fedora-extras-commits at redhat.com
Thu Feb 14 19:04:01 UTC 2008
Author: ensc
Update of /cvs/extras/rpms/dietlibc/devel
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv26345
Modified Files:
dietlibc-0.31.20080212-strlen.patch
Log Message:
fixed strlen patch
dietlibc-0.31.20080212-strlen.patch:
Index: dietlibc-0.31.20080212-strlen.patch
===================================================================
RCS file: /cvs/extras/rpms/dietlibc/devel/dietlibc-0.31.20080212-strlen.patch,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- dietlibc-0.31.20080212-strlen.patch 14 Feb 2008 16:31:20 -0000 1.1
+++ dietlibc-0.31.20080212-strlen.patch 14 Feb 2008 19:03:48 -0000 1.2
@@ -5,31 +5,42 @@
-#include "alpha/strlen.c"
diff -upN dietlibc-0.31.20080212/test/string/strlen.c.strlen dietlibc-0.31.20080212/test/string/strlen.c
--- dietlibc-0.31.20080212/test/string/strlen.c.strlen 2003-12-15 14:07:42.000000000 +0100
-+++ dietlibc-0.31.20080212/test/string/strlen.c 2008-02-14 17:23:25.000000000 +0100
-@@ -2,9 +2,24 @@
++++ dietlibc-0.31.20080212/test/string/strlen.c 2008-02-14 18:32:57.000000000 +0100
+@@ -1,10 +1,35 @@
+ #include <assert.h>
#include <string.h>
++#include <endian.h>
++
++/* make it large enough to test all possible alignments, number of trailing
++ * bytes and word sizes */
++#define BUFLEN (__WORDSIZE/8 * 4)
int main() {
- const char* x="foo bar baz";
-+ /* make it large enough to test all possible alignments, number of trailing
-+ * bytes and word sizes */
-+ char x[33]= { [0] = '\0' };
++ /* will hold the string, the trailing zero and a test pattern */
++ char buf[BUFLEN + 1 + __WORDSIZE/8];
++ size_t len;
+
-+ size_t i, j, k;
assert(strlen("")==0);
- assert(strlen(x)==11);
- assert(strlen(x+5)==6);
+
-+ /* run it twice; during first run, all trailing bytes are \0. In second run,
-+ * they are initialized to non \0 */
-+ for (k=0; k<2; ++k) {
-+ for (j=0; j<32; ++j) {
-+ x[j] = j%10 + '0';
-+ x[j+1] = '\0';
++ for (len=0; len<BUFLEN; ++len) {
++ unsigned int mask;
+
-+ for (i=0; i<=j; ++i)
-+ assert(strlen(x+i)==j+1-i);
-+ }
++ buf[len] = len%10 + '0';
++ buf[len+1] = '\0';
++
++ for (mask=0; mask<(1u<<__WORDSIZE/8); ++mask) {
++ size_t bit;
++ size_t i;
++
++ for (bit=0; bit<__WORDSIZE/8; ++bit)
++ buf[len+2+bit] = (mask & (1u<<bit)) ? 0xff : 0;
++
++ for (i=0; i<=len; ++i)
++ assert(strlen(buf+i)==len+1-i);
++ }
+ }
+
return 0;
@@ -51,7 +62,7 @@
-}
diff -upN dietlibc-0.31.20080212/test/Makefile.strlen dietlibc-0.31.20080212/test/Makefile
--- dietlibc-0.31.20080212/test/Makefile.strlen 2003-12-15 14:07:42.000000000 +0100
-+++ dietlibc-0.31.20080212/test/Makefile 2008-02-14 17:24:12.000000000 +0100
++++ dietlibc-0.31.20080212/test/Makefile 2008-02-14 17:26:39.000000000 +0100
@@ -13,7 +13,7 @@ gethostbyname_r getmntent getopt getpass
glob grent hasmntopt hello iconv if_nameindex ltostr malloc-debugger md5_testharness \
memccpy memchr memcmp memcpy memrchr memusage mktime mmap_test pipe printf printftest \
@@ -63,7 +74,7 @@
test: $(TESTPROGRAMS)
diff -upN dietlibc-0.31.20080212/test/runtests.sh.strlen dietlibc-0.31.20080212/test/runtests.sh
--- dietlibc-0.31.20080212/test/runtests.sh.strlen 2003-12-15 14:07:42.000000000 +0100
-+++ dietlibc-0.31.20080212/test/runtests.sh 2008-02-14 17:24:01.000000000 +0100
++++ dietlibc-0.31.20080212/test/runtests.sh 2008-02-14 17:26:39.000000000 +0100
@@ -1,6 +1,6 @@
SUBDIRS="dirent inet stdio string stdlib time"
@@ -84,7 +95,7 @@
-#include "alpha/strlen.c"
diff -upN dietlibc-0.31.20080212/lib/strstr.c.strlen dietlibc-0.31.20080212/lib/strstr.c
--- dietlibc-0.31.20080212/lib/strstr.c.strlen 2003-08-19 21:34:18.000000000 +0200
-+++ dietlibc-0.31.20080212/lib/strstr.c 2008-02-14 16:40:23.000000000 +0100
++++ dietlibc-0.31.20080212/lib/strstr.c 2008-02-14 17:26:39.000000000 +0100
@@ -4,7 +4,7 @@
char *strstr(const char *haystack, const char *needle) {
size_t nl=strlen(needle);
@@ -96,7 +107,7 @@
for (i=hl-nl+1; __likely(i); --i) {
diff -upN dietlibc-0.31.20080212/lib/strlen.c.strlen dietlibc-0.31.20080212/lib/strlen.c
--- dietlibc-0.31.20080212/lib/strlen.c.strlen 2003-08-19 21:34:18.000000000 +0200
-+++ dietlibc-0.31.20080212/lib/strlen.c 2008-02-14 17:06:39.000000000 +0100
++++ dietlibc-0.31.20080212/lib/strlen.c 2008-02-14 19:59:19.000000000 +0100
@@ -1,6 +1,7 @@
#include <endian.h>
#include "dietfeatures.h"
@@ -105,7 +116,7 @@
#ifdef WANT_SMALL_STRING_ROUTINES
size_t strlen(const char *s) {
-@@ -10,38 +11,64 @@ size_t strlen(const char *s) {
+@@ -10,38 +11,83 @@ size_t strlen(const char *s) {
return i;
}
#else
@@ -126,8 +137,10 @@
const char *t = s;
- unsigned long word;
+ word_t word;
++ word_t mask;
- if (!s) return 0;
+- if (!s) return 0;
++ if (__unlikely(!s)) return 0;
/* Byte compare up until word boundary */
- for (; ((unsigned long) t & 3); t++)
@@ -148,44 +161,60 @@
- word += (word << 8) + (word << 16);
- t += word >> 26;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
-+
-+ if (sizeof(word)==8) {
++ switch (sizeof(word)) {
++ case 8:
+ /* word & 0x8080808080808080 == word */
+ word = (word - 1) & (magic << 8);
+ word += (word << 32);
+ word += (word << 16);
+ word += (word << 8);
+ t += word >> 56;
-+ } else if (sizeof(word)==4) {
++ break;
++
++ case 4:
+ /* word & 0x80808080 == word */
+ word = (word - 1) & (magic << 10);
+ word += (word << 8) + (word << 16);
+ t += word >> 26;
++ break;
+ }
-+
#else
- if ((word & 0x80800000) == 0) {
- word <<= 16;
+- t += 2;
++ /* results into 0x8080 0000 or 0x80808080 00000000 */
++ mask = (magic << 7) & ~((1u<<(sizeof(magic)*8/2))-1);
++
++ if (sizeof(word)>=8) {
++ if ((word & mask) == 0) {
++ t += 4;
++ word <<= 4*8;
++ }
++
++ mask <<= 2*8;
++ }
+
-+ if (sizeof(word)>=8 && (word & 0x8080808000000000ull) == 0)
-+ t += 4;
++ if (sizeof(word)>=4) {
++ if ((word & mask) == 0) {
++ t += 2;
++ word <<= 2*8;
++ }
++
++ mask <<= 1*8;
++ }
+
-+ if (sizeof(word)>=4 && (word & 0x80800000u) == 0)
- t += 2;
-- }
++ if (sizeof(word)>=2) {
++ if ((word & mask) == 0) {
++ t += 1;
++ word <<= 1*8;
++ }
+ }
- if ((word & 0x80000000) == 0) t += 1;
--#endif
+ #endif
- return ((const char *) t) - 4 - s;
-+
-+ if (sizeof(word)>=2 && (word & 0x8000u) == 0)
-+ t += 1;
-+
-+#endif /* __BYTE_ORDER */
-+
+ return t - sizeof(word) - s;
}
--#endif
-+#endif /* WANT_SMALL_STRING_ROUTINES */
+ #endif
diff -upN dietlibc-0.31.20080212/ia64/strlen.c.strlen dietlibc-0.31.20080212/ia64/strlen.c
--- dietlibc-0.31.20080212/ia64/strlen.c.strlen 2007-10-04 18:19:15.000000000 +0200
+++ dietlibc-0.31.20080212/ia64/strlen.c 1970-01-01 01:00:00.000000000 +0100
More information about the fedora-extras-commits
mailing list