Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -559,14 +559,10 @@ ]) ], [ AC_MSG_RESULT(no) ]) -AC_CHECK_FUNC(madvise, [ - AC_DEFINE(HAVE_MADVISE, 1, [Whether we have madvise]) -]) - AS_IF([test x"$objc_runtime" = x"Apple"], [ AC_CHECK_HEADER(Foundation/NSObject.h, [ AC_SUBST(FOUNDATION_COMPAT_M, "foundation-compat.m") ]) ]) Index: src/OFMutableString.m ================================================================== --- src/OFMutableString.m +++ src/OFMutableString.m @@ -20,16 +20,10 @@ #include #include #include #include -#ifdef HAVE_MADVISE -# include -#else -# define madvise(addr, len, advise) -#endif - #import "OFString.h" #import "OFAutoreleasePool.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" @@ -287,44 +281,36 @@ - (void)reverse { size_t i, j; - madvise(s->cString, s->cStringLength, MADV_SEQUENTIAL); - /* We reverse all bytes and restore UTF-8 later, if necessary */ for (i = 0, j = s->cStringLength - 1; i < s->cStringLength / 2; i++, j--) { s->cString[i] ^= s->cString[j]; s->cString[j] ^= s->cString[i]; s->cString[i] ^= s->cString[j]; } - if (!s->UTF8) { - madvise(s->cString, s->cStringLength, MADV_NORMAL); + if (!s->UTF8) return; - } for (i = 0; i < s->cStringLength; i++) { /* ASCII */ if (OF_LIKELY(!(s->cString[i] & 0x80))) continue; /* A start byte can't happen first as we reversed everything */ - if (OF_UNLIKELY(s->cString[i] & 0x40)) { - madvise(s->cString, s->cStringLength, MADV_NORMAL); + if (OF_UNLIKELY(s->cString[i] & 0x40)) @throw [OFInvalidEncodingException exceptionWithClass: isa]; - } /* Next byte must not be ASCII */ if (OF_UNLIKELY(s->cStringLength < i + 1 || - !(s->cString[i + 1] & 0x80))) { - madvise(s->cString, s->cStringLength, MADV_NORMAL); + !(s->cString[i + 1] & 0x80))) @throw [OFInvalidEncodingException exceptionWithClass: isa]; - } /* Next byte is the start byte */ if (OF_LIKELY(s->cString[i + 1] & 0x40)) { s->cString[i] ^= s->cString[i + 1]; s->cString[i + 1] ^= s->cString[i]; @@ -334,15 +320,13 @@ continue; } /* Second next byte must not be ASCII */ if (OF_UNLIKELY(s->cStringLength < i + 2 || - !(s->cString[i + 2] & 0x80))) { - madvise(s->cString, s->cStringLength, MADV_NORMAL); + !(s->cString[i + 2] & 0x80))) @throw [OFInvalidEncodingException exceptionWithClass: isa]; - } /* Second next byte is the start byte */ if (OF_LIKELY(s->cString[i + 2] & 0x40)) { s->cString[i] ^= s->cString[i + 2]; s->cString[i + 2] ^= s->cString[i]; @@ -352,15 +336,13 @@ continue; } /* Third next byte must not be ASCII */ if (OF_UNLIKELY(s->cStringLength < i + 3 || - !(s->cString[i + 3] & 0x80))) { - madvise(s->cString, s->cStringLength, MADV_NORMAL); + !(s->cString[i + 3] & 0x80))) @throw [OFInvalidEncodingException exceptionWithClass: isa]; - } /* Third next byte is the start byte */ if (OF_LIKELY(s->cString[i + 3] & 0x40)) { s->cString[i] ^= s->cString[i + 3]; s->cString[i + 3] ^= s->cString[i]; @@ -373,15 +355,12 @@ i += 3; continue; } /* UTF-8 does not allow more than 4 bytes per character */ - madvise(s->cString, s->cStringLength, MADV_NORMAL); @throw [OFInvalidEncodingException exceptionWithClass: isa]; } - - madvise(s->cString, s->cStringLength, MADV_NORMAL); } - (void)upper { [self _applyTable: of_unicode_upper_table Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -22,15 +22,10 @@ #include #include #include #include -#ifdef HAVE_MADVISE -# include -#else -# define madvise(addr, len, advise) -#endif #import "OFString.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFFile.h" @@ -86,37 +81,29 @@ of_string_check_utf8(const char *cString, size_t cStringLength, size_t *length) { size_t i, tmpLength = cStringLength; int UTF8 = 0; - madvise((void*)cString, cStringLength, MADV_SEQUENTIAL); - for (i = 0; i < cStringLength; i++) { /* No sign of UTF-8 here */ if (OF_LIKELY(!(cString[i] & 0x80))) continue; UTF8 = 1; /* We're missing a start byte here */ - if (OF_UNLIKELY(!(cString[i] & 0x40))) { - madvise((void*)cString, cStringLength, MADV_NORMAL); + if (OF_UNLIKELY(!(cString[i] & 0x40))) return -1; - } /* 2 byte sequences for code points 0 - 127 are forbidden */ - if (OF_UNLIKELY((cString[i] & 0x7E) == 0x40)) { - madvise((void*)cString, cStringLength, MADV_NORMAL); + if (OF_UNLIKELY((cString[i] & 0x7E) == 0x40)) return -1; - } /* We have at minimum a 2 byte character -> check next byte */ if (OF_UNLIKELY(cStringLength <= i + 1 || - (cString[i + 1] & 0xC0) != 0x80)) { - madvise((void*)cString, cStringLength, MADV_NORMAL); + (cString[i + 1] & 0xC0) != 0x80)) return -1; - } /* Check if we have at minimum a 3 byte character */ if (OF_LIKELY(!(cString[i] & 0x20))) { i++; tmpLength--; @@ -123,14 +110,12 @@ continue; } /* We have at minimum a 3 byte char -> check second next byte */ if (OF_UNLIKELY(cStringLength <= i + 2 || - (cString[i + 2] & 0xC0) != 0x80)) { - madvise((void*)cString, cStringLength, MADV_NORMAL); + (cString[i + 2] & 0xC0) != 0x80)) return -1; - } /* Check if we have a 4 byte character */ if (OF_LIKELY(!(cString[i] & 0x10))) { i += 2; tmpLength -= 2; @@ -137,30 +122,24 @@ continue; } /* We have a 4 byte character -> check third next byte */ if (OF_UNLIKELY(cStringLength <= i + 3 || - (cString[i + 3] & 0xC0) != 0x80)) { - madvise((void*)cString, cStringLength, MADV_NORMAL); + (cString[i + 3] & 0xC0) != 0x80)) return -1; - } /* * Just in case, check if there's a 5th character, which is * forbidden by UTF-8 */ - if (OF_UNLIKELY(cString[i] & 0x08)) { - madvise((void*)cString, cStringLength, MADV_NORMAL); + if (OF_UNLIKELY(cString[i] & 0x08)) return -1; - } i += 3; tmpLength -= 3; } - madvise((void*)cString, cStringLength, MADV_NORMAL); - if (length != NULL) *length = tmpLength; return UTF8; }