Backout 48213b973bfb (bug 695515) due to suspected OSX orange.
authorRyan VanderMeulen <ryanvm@gmail.com>
Tue, 24 Apr 2012 20:51:53 -0400
changeset 96417 314adec5e5151f8b6e978d2faa7dc1341c114589
parent 96416 931678f97b3a01af8d47d8bfd42a662c76eeb032
child 96418 f124e0fb56047fbe1f809b96fdb3653ee61c790b
push idunknown
push userunknown
push dateunknown
bugs695515
milestone14.0a1
backs out48213b973bfbe23f980e45c80bb6f6deac9e6221
Backout 48213b973bfb (bug 695515) due to suspected OSX orange.
configure.in
xpcom/ds/nsCRT.cpp
xpcom/ds/nsCRT.h
--- a/configure.in
+++ b/configure.in
@@ -3342,17 +3342,17 @@ case $target in
     AC_SEARCH_LIBS(dlopen, dl,
         MOZ_CHECK_HEADER(dlfcn.h,
         AC_DEFINE(HAVE_DLOPEN)))
     ;;
 esac
 
 _SAVE_CFLAGS="$CFLAGS"
 CFLAGS="$CFLAGS -D_GNU_SOURCE"
-AC_CHECK_FUNC(dladdr)
+AC_CHECK_FUNCS(dladdr memmem)
 CFLAGS="$_SAVE_CFLAGS"
 
 if test ! "$GNU_CXX"; then
 
     case $target in
     *-aix*)
 	AC_CHECK_LIB(C_r, demangle)
 	;;
--- a/xpcom/ds/nsCRT.cpp
+++ b/xpcom/ds/nsCRT.cpp
@@ -154,16 +154,38 @@ PRInt32 nsCRT::strncmp(const PRUnichar* 
           return 1;
         }
       } while (--n != 0);
     }
   }
   return 0;
 }
 
+const char* nsCRT::memmem(const char* haystack, PRUint32 haystackLen,
+                          const char* needle, PRUint32 needleLen)
+{
+  // Sanity checking
+  if (!(haystack && needle && haystackLen && needleLen &&
+        needleLen <= haystackLen))
+    return NULL;
+
+#ifdef HAVE_MEMMEM
+  return (const char*)::memmem(haystack, haystackLen, needle, needleLen);
+#else
+  // No memmem means we need to roll our own.  This isn't really optimized
+  // for performance ... if that becomes an issue we can take some inspiration
+  // from the js string compare code in jsstr.cpp
+  for (PRInt32 i = 0; i < haystackLen - needleLen; i++) {
+    if (!memcmp(haystack + i, needle, needleLen))
+      return haystack + i;
+  }
+#endif
+  return NULL;
+}
+
 PRUnichar* nsCRT::strdup(const PRUnichar* str)
 {
   PRUint32 len = nsCRT::strlen(str);
   return strndup(str, len);
 }
 
 PRUnichar* nsCRT::strndup(const PRUnichar* str, PRUint32 len)
 {
--- a/xpcom/ds/nsCRT.h
+++ b/xpcom/ds/nsCRT.h
@@ -205,16 +205,22 @@ public:
   }
 
   /// Like strcmp except for ucs2 strings
   static PRInt32 strcmp(const PRUnichar* s1, const PRUnichar* s2);
   /// Like strcmp except for ucs2 strings
   static PRInt32 strncmp(const PRUnichar* s1, const PRUnichar* s2,
                          PRUint32 aMaxLen);
 
+  // The GNU libc has memmem, which is strstr except for binary data
+  // This is our own implementation that uses memmem on platforms
+  // where it's available.
+  static const char* memmem(const char* haystack, PRUint32 haystackLen,
+                            const char* needle, PRUint32 needleLen);
+
   // You must use nsCRT::free(PRUnichar*) to free memory allocated
   // by nsCRT::strdup(PRUnichar*).
   static PRUnichar* strdup(const PRUnichar* str);
 
   // You must use nsCRT::free(PRUnichar*) to free memory allocated
   // by strndup(PRUnichar*, PRUint32).
   static PRUnichar* strndup(const PRUnichar* str, PRUint32 len);