Commit [r9541] Maximize Restore History

* pumped character encoding detection to recent Mozilla releases

mortenmacfly 2014-01-07

added /trunk/src/include/mozilla_chardet/mfbt/mozilla/Compiler.h.org
added /trunk/src/include/mozilla_chardet/mfbt/mozilla/TypedEnum.h
added /trunk/src/include/mozilla_chardet/mfbt/mozilla/NullPtr.h.org
changed /trunk/src/include/mozilla_chardet/xpcom/glue/nsDebug.h.org
changed /trunk/src/include/mozilla_chardet/mfbt/mozilla/NullPtr.h
changed /trunk/src/include/mozilla_chardet/mfbt/mozilla/Types.h
changed /trunk/src/sdk/mozilla_chardet/src/nsUniversalDetector.cpp.org
changed /trunk/src/include/mozilla_chardet/xpcom/glue/nsDebug.h
changed /trunk/src/include/mozilla_chardet/mfbt/mozilla/Compiler.h
changed /trunk/src/include/mozilla_chardet/mfbt/mozilla/Util.h
changed /trunk/src/include/mozilla_chardet/xpcom/base/nscore.h.org
changed /trunk/src/include/mozilla_chardet/xpcom/base/nsError.h.org
changed /trunk/src/include/mozilla_chardet/xpcom/glue/nsMemory.h.org
changed /trunk/src/include/Makefile.am
changed /trunk/src/include/mozilla_chardet/nsSBCSGroupProber.h
changed /trunk/src/sdk/mozilla_chardet/src/nsUniversalDetector.cpp
changed /trunk/src/include/mozilla_chardet/xpcom/base/ErrorList.h
changed /trunk/src/include/mozilla_chardet/mfbt/mozilla/Attributes.h
changed /trunk/src/include/mozilla_chardet/mfbt/mozilla/Likely.h
changed /trunk/src/include/mozilla_chardet/mfbt/mozilla/Assertions.h
changed /trunk/src/include/mozilla_chardet/xpcom/base/nscore.h
changed /trunk/src/include/mozilla_chardet/xpcom/base/nsError.h
changed /trunk/src/include/mozilla_chardet/xpcom/glue/nsMemory.h
copied /trunk/src/include/mozilla_chardet/mfbt/mozilla/StandardInteger.h -> /trunk/src/include/mozilla_chardet/mfbt/mozilla/Alignment.h
/trunk/src/include/mozilla_chardet/mfbt/mozilla/Compiler.h.org Diff Switch to side-by-side view
Loading...
/trunk/src/include/mozilla_chardet/mfbt/mozilla/TypedEnum.h Diff Switch to side-by-side view
Loading...
/trunk/src/include/mozilla_chardet/mfbt/mozilla/NullPtr.h.org Diff Switch to side-by-side view
Loading...
/trunk/src/include/mozilla_chardet/xpcom/glue/nsDebug.h.org Diff Switch to side-by-side view
Loading...
/trunk/src/include/mozilla_chardet/mfbt/mozilla/NullPtr.h Diff Switch to side-by-side view
Loading...
/trunk/src/include/mozilla_chardet/mfbt/mozilla/Types.h Diff Switch to side-by-side view
Loading...
/trunk/src/sdk/mozilla_chardet/src/nsUniversalDetector.cpp.org Diff Switch to side-by-side view
Loading...
/trunk/src/include/mozilla_chardet/xpcom/glue/nsDebug.h Diff Switch to side-by-side view
Loading...
/trunk/src/include/mozilla_chardet/mfbt/mozilla/Compiler.h Diff Switch to side-by-side view
Loading...
/trunk/src/include/mozilla_chardet/mfbt/mozilla/Util.h Diff Switch to side-by-side view
Loading...
/trunk/src/include/mozilla_chardet/xpcom/base/nscore.h.org Diff Switch to side-by-side view
Loading...
/trunk/src/include/mozilla_chardet/xpcom/base/nsError.h.org Diff Switch to side-by-side view
Loading...
/trunk/src/include/mozilla_chardet/xpcom/glue/nsMemory.h.org Diff Switch to side-by-side view
Loading...
/trunk/src/include/Makefile.am Diff Switch to side-by-side view
Loading...
/trunk/src/include/mozilla_chardet/nsSBCSGroupProber.h Diff Switch to side-by-side view
Loading...
/trunk/src/sdk/mozilla_chardet/src/nsUniversalDetector.cpp Diff Switch to side-by-side view
Loading...
/trunk/src/include/mozilla_chardet/xpcom/base/ErrorList.h Diff Switch to side-by-side view
Loading...
/trunk/src/include/mozilla_chardet/mfbt/mozilla/Attributes.h Diff Switch to side-by-side view
Loading...
/trunk/src/include/mozilla_chardet/mfbt/mozilla/Likely.h Diff Switch to side-by-side view
Loading...
/trunk/src/include/mozilla_chardet/mfbt/mozilla/Assertions.h Diff Switch to side-by-side view
Loading...
/trunk/src/include/mozilla_chardet/xpcom/base/nscore.h Diff Switch to side-by-side view
Loading...
/trunk/src/include/mozilla_chardet/xpcom/base/nsError.h Diff Switch to side-by-side view
Loading...
/trunk/src/include/mozilla_chardet/xpcom/glue/nsMemory.h Diff Switch to side-by-side view
Loading...
/trunk/src/include/mozilla_chardet/mfbt/mozilla/StandardInteger.h to /trunk/src/include/mozilla_chardet/mfbt/mozilla/Alignment.h
--- a/trunk/src/include/mozilla_chardet/mfbt/mozilla/StandardInteger.h
+++ b/trunk/src/include/mozilla_chardet/mfbt/mozilla/Alignment.h
@@ -1,43 +1,137 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-/* Implements the C99 <stdint.h> interface for C and C++ code. */
+/* Functionality related to memory alignment. */
 
-#ifndef mozilla_StandardInteger_h_
-#define mozilla_StandardInteger_h_
+#ifndef mozilla_Alignment_h
+#define mozilla_Alignment_h
+
+#include <stddef.h>
+#include <stdint.h>
+
+namespace mozilla {
 
 /*
- * The C99 standard header <stdint.h> exposes typedefs for common fixed-width
- * integer types.  It would be feasible to simply #include <stdint.h>, but
- * MSVC++ versions prior to 2010 don't provide <stdint.h>.  We could solve this
- * by reimplementing <stdint.h> for MSVC++ 2008 and earlier.  But then we reach
- * a second problem: our custom <stdint.h> might conflict with a <stdint.h>
- * defined by an embedder already looking to work around the MSVC++ <stdint.h>
- * absence.
+ * This class, and the corresponding macro MOZ_ALIGNOF, figures out how many
+ * bytes of alignment a given type needs.
+ */
+template<typename T>
+class AlignmentFinder
+{
+    struct Aligner
+    {
+        char c;
+        T t;
+    };
+
+  public:
+    static const size_t alignment = sizeof(Aligner) - sizeof(T);
+};
+
+#define MOZ_ALIGNOF(T) mozilla::AlignmentFinder<T>::alignment
+
+/*
+ * Declare the MOZ_ALIGNED_DECL macro for declaring aligned types.
  *
- * We address these issues in this manner:
+ * For instance,
  *
- *   1. If the preprocessor macro MOZ_CUSTOM_STDINT_H is defined to a path to a
- *      custom <stdint.h> implementation, we will #include it.  Embedders using
- *      a custom <stdint.h> must define this macro to an implementation that
- *      will work with their embedding.
- *   2. Otherwise, if we are compiling with a an MSVC++ version without
- *      <stdint.h>, #include our custom <stdint.h> reimplementation.
- *   3. Otherwise, #include the standard <stdint.h> provided by the compiler.
+ *   MOZ_ALIGNED_DECL(char arr[2], 8);
  *
- * Note that we can't call this file "stdint.h" or something case-insensitively
- * equal to "stdint.h" because then MSVC (and other compilers on
- * case-insensitive file systems) will include this file, rather than the system
- * stdint.h, when we ask for <stdint.h> below.
+ * will declare a two-character array |arr| aligned to 8 bytes.
  */
-#if defined(MOZ_CUSTOM_STDINT_H)
-#  include MOZ_CUSTOM_STDINT_H
-#elif defined(_MSC_VER) && _MSC_VER < 1600
-#  include "mozilla/MSStdInt.h"
+
+#if defined(__GNUC__)
+#  define MOZ_ALIGNED_DECL(_type, _align) \
+     _type __attribute__((aligned(_align)))
+#elif defined(_MSC_VER)
+#  define MOZ_ALIGNED_DECL(_type, _align) \
+     __declspec(align(_align)) _type
 #else
-#  include <stdint.h>
+#  warning "We don't know how to align variables on this compiler."
+#  define MOZ_ALIGNED_DECL(_type, _align) _type
 #endif
 
-#endif  /* mozilla_StandardInteger_h_ */
+/*
+ * AlignedElem<N> is a structure whose alignment is guaranteed to be at least N
+ * bytes.
+ *
+ * We support 1, 2, 4, 8, and 16-bit alignment.
+ */
+template<size_t Align>
+struct AlignedElem;
+
+/*
+ * We have to specialize this template because GCC doesn't like __attribute__((aligned(foo))) where
+ * foo is a template parameter.
+ */
+
+template<>
+struct AlignedElem<1>
+{
+    MOZ_ALIGNED_DECL(uint8_t elem, 1);
+};
+
+template<>
+struct AlignedElem<2>
+{
+    MOZ_ALIGNED_DECL(uint8_t elem, 2);
+};
+
+template<>
+struct AlignedElem<4>
+{
+    MOZ_ALIGNED_DECL(uint8_t elem, 4);
+};
+
+template<>
+struct AlignedElem<8>
+{
+    MOZ_ALIGNED_DECL(uint8_t elem, 8);
+};
+
+template<>
+struct AlignedElem<16>
+{
+    MOZ_ALIGNED_DECL(uint8_t elem, 16);
+};
+
+/*
+ * This utility pales in comparison to Boost's aligned_storage. The utility
+ * simply assumes that uint64_t is enough alignment for anyone. This may need
+ * to be extended one day...
+ *
+ * As an important side effect, pulling the storage into this template is
+ * enough obfuscation to confuse gcc's strict-aliasing analysis into not giving
+ * false negatives when we cast from the char buffer to whatever type we've
+ * constructed using the bytes.
+ */
+template<size_t Nbytes>
+struct AlignedStorage
+{
+    union U {
+      char bytes[Nbytes];
+      uint64_t _;
+    } u;
+
+    const void* addr() const { return u.bytes; }
+    void* addr() { return u.bytes; }
+};
+
+template<typename T>
+struct AlignedStorage2
+{
+    union U {
+      char bytes[sizeof(T)];
+      uint64_t _;
+    } u;
+
+    const T* addr() const { return reinterpret_cast<const T*>(u.bytes); }
+    T* addr() { return static_cast<T*>(static_cast<void*>(u.bytes)); }
+};
+
+} /* namespace mozilla */
+
+#endif /* mozilla_Alignment_h */