Update mail/thunderbird to version 45.3.0_2
[dports.git] / mail / thunderbird / files / patch-bug1269171
1
2 # HG changeset patch
3 # User Mike Hommey <mh+mozilla@glandium.org>
4 # Date 1463557039 -32400
5 # Node ID 68da139d0866977c0ada86319fa94388f2255446
6 # Parent  a640e6fa8ab9977fb6c5bcf63dc4daca6699477b
7 Bug 1269171 - Change how mozalloc.h is hooked in STL wrappers. r=froydnj
8
9 Since the introduction of the STL wrappers, they have included
10 mozalloc.h, and multiple times, we've hit header reentrancy problems,
11 and worked around them as best as we could.
12
13 Taking a step back, all mozalloc.h does is:
14 - declare moz_* allocator functions.
15 - define inline implementations of various operator new/delete variants.
16
17 The first only requires the functions to be declared before they are used,
18 so mozalloc.h only needs to be included before anything that would use
19 those functions.
20
21 The second doesn't actually require a specific order, as long as the
22 declaration for those functions comes before their use, and they are
23 either declared in <new> or implicitly by the C++ compiler.
24
25 So all in all, it doesn't matter that mozalloc.h is included before the
26 wrapped STL headers. What matters is that it's included when STL headers
27 are included. So arrange things such that mozalloc.h is included after
28 the first wrapped STL header is fully preprocessed (and all its includes
29 have been included).
30
31
32 diff --git config/gcc-stl-wrapper.template.h config/gcc-stl-wrapper.template.h
33 --- mozilla/config/gcc-stl-wrapper.template.h
34 +++ mozilla/config/gcc-stl-wrapper.template.h
35 @@ -12,56 +12,54 @@
36  // compiling ObjC.
37  #if defined(__EXCEPTIONS) && __EXCEPTIONS && !(__OBJC__ && __GNUC__ && XP_IOS)
38  #  error "STL code can only be used with -fno-exceptions"
39  #endif
40  
41  // Silence "warning: #include_next is a GCC extension"
42  #pragma GCC system_header
43  
44 -// Don't include mozalloc for cstdlib. See bug 1245076.
45 -#ifndef moz_dont_include_mozalloc_for_cstdlib
46 -#  define moz_dont_include_mozalloc_for_cstdlib
47 -#endif
48 -#ifndef moz_dont_include_mozalloc_for_${HEADER}
49 -// mozalloc.h wants <new>; break the cycle by always explicitly
50 -// including <new> here.  NB: this is a tad sneaky.  Sez the gcc docs:
51 -//
52 -//    `#include_next' does not distinguish between <file> and "file"
53 -//    inclusion, nor does it check that the file you specify has the
54 -//    same name as the current file. It simply looks for the file
55 -//    named, starting with the directory in the search path after the
56 -//    one where the current file was found.
57 -#  include_next <new>
58 -
59 -// See if we're in code that can use mozalloc.  NB: this duplicates
60 -// code in nscore.h because nscore.h pulls in prtypes.h, and chromium
61 -// can't build with that being included before base/basictypes.h.
62 -#  if !defined(XPCOM_GLUE) && !defined(NS_NO_XPCOM) && !defined(MOZ_NO_MOZALLOC)
63 -#    include "mozilla/mozalloc.h"
64 -#  else
65 -#    error "STL code can only be used with infallible ::operator new()"
66 -#  endif
67 -
68 -#endif
69 -
70  #if defined(DEBUG) && !defined(_GLIBCXX_DEBUG)
71  // Enable checked iterators and other goodies
72  //
73  // FIXME/bug 551254: gcc's debug STL implementation requires -frtti.
74  // Figure out how to resolve this with -fno-rtti.  Maybe build with
75  // -frtti in DEBUG builds?
76  //
77  //  # define _GLIBCXX_DEBUG 1
78  #endif
79  
80 +// Don't include mozalloc for cstdlib. See bug 1245076.
81 +#ifndef moz_dont_include_mozalloc_for_cstdlib
82 +#  define moz_dont_include_mozalloc_for_cstdlib
83 +#endif
84 +
85 +// Include mozalloc after the STL header and all other headers it includes
86 +// have been preprocessed.
87 +#if !defined(MOZ_INCLUDE_MOZALLOC_H) && \
88 +    !defined(moz_dont_include_mozalloc_for_${HEADER})
89 +#  define MOZ_INCLUDE_MOZALLOC_H
90 +#  define MOZ_INCLUDE_MOZALLOC_H_FROM_${HEADER}
91 +#endif
92 +
93  #pragma GCC visibility push(default)
94  #include_next <${HEADER}>
95  #pragma GCC visibility pop
96  
97 +#ifdef MOZ_INCLUDE_MOZALLOC_H_FROM_${HEADER}
98 +// See if we're in code that can use mozalloc.  NB: this duplicates
99 +// code in nscore.h because nscore.h pulls in prtypes.h, and chromium
100 +// can't build with that being included before base/basictypes.h.
101 +#  if !defined(XPCOM_GLUE) && !defined(NS_NO_XPCOM) && !defined(MOZ_NO_MOZALLOC)
102 +#    include "mozilla/mozalloc.h"
103 +#  else
104 +#    error "STL code can only be used with infallible ::operator new()"
105 +#  endif
106 +#endif
107 +
108  // gcc calls a __throw_*() function from bits/functexcept.h when it
109  // wants to "throw an exception".  functexcept exists nominally to
110  // support -fno-exceptions, but since we'll always use the system
111  // libstdc++, and it's compiled with exceptions, then in practice
112  // these __throw_*() functions will always throw exceptions (shades of
113  // -fshort-wchar).  We don't want that and so define our own inlined
114  // __throw_*().
115  #ifndef mozilla_throw_gcc_h
116 diff --git config/make-stl-wrappers.py config/make-stl-wrappers.py
117 --- mozilla/config/make-stl-wrappers.py
118 +++ mozilla/config/make-stl-wrappers.py
119 @@ -25,28 +25,26 @@ def header_path(header, compiler):
120  def is_comment(line):
121      return re.match(r'\s*#.*', line)
122  
123  def main(outdir, compiler, template_file, header_list_file):
124      if not os.path.isdir(outdir):
125          os.mkdir(outdir)
126  
127      template = open(template_file, 'r').read()
128 -    path_to_new = header_path('new', compiler)
129  
130      for header in open(header_list_file, 'r'):
131          header = header.rstrip()
132          if 0 == len(header) or is_comment(header):
133              continue
134  
135          path = header_path(header, compiler)
136          with FileAvoidWrite(os.path.join(outdir, header)) as f:
137              f.write(string.Template(template).substitute(HEADER=header,
138 -                                                         HEADER_PATH=path,
139 -                                                         NEW_HEADER_PATH=path_to_new))
140 +                                                         HEADER_PATH=path))
141  
142  
143  if __name__ == '__main__':
144      if 5 != len(sys.argv):
145          print("""Usage:
146    python {0} OUT_DIR ('msvc'|'gcc') TEMPLATE_FILE HEADER_LIST_FILE
147  """.format(sys.argv[0]), file=sys.stderr)
148          sys.exit(1)
149 diff --git config/msvc-stl-wrapper.template.h config/msvc-stl-wrapper.template.h
150 --- mozilla/config/msvc-stl-wrapper.template.h
151 +++ mozilla/config/msvc-stl-wrapper.template.h
152 @@ -3,45 +3,33 @@
153   */
154  /* This Source Code Form is subject to the terms of the Mozilla Public
155   * License, v. 2.0. If a copy of the MPL was not distributed with this
156   * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
157  
158  #ifndef mozilla_${HEADER}_h
159  #define mozilla_${HEADER}_h
160  
161 -#ifndef MOZ_HAVE_INCLUDED_ALLOC
162 -#define MOZ_HAVE_INCLUDED_ALLOC
163 -
164  #if _HAS_EXCEPTIONS
165  #  error "STL code can only be used with -fno-exceptions"
166  #endif
167  
168 +// Include mozalloc after the STL header and all other headers it includes
169 +// have been preprocessed.
170 +#if !defined(MOZ_INCLUDE_MOZALLOC_H)
171 +#  define MOZ_INCLUDE_MOZALLOC_H
172 +#  define MOZ_INCLUDE_MOZALLOC_H_FROM_${HEADER}
173 +#endif
174 +
175  // Code built with !_HAS_EXCEPTIONS calls std::_Throw(), but the win2k
176  // CRT doesn't export std::_Throw().  So we define it.
177  #ifndef mozilla_Throw_h
178  #  include "mozilla/throw_msvc.h"
179  #endif
180  
181 -// Code might include <new> before other wrapped headers, but <new>
182 -// includes <exception> and so we want to wrap it.  But mozalloc.h
183 -// wants <new> also, so we break the cycle by always explicitly
184 -// including <new> here.
185 -#include <${NEW_HEADER_PATH}>
186 -
187 -// See if we're in code that can use mozalloc.  NB: this duplicates
188 -// code in nscore.h because nscore.h pulls in prtypes.h, and chromium
189 -// can't build with that being included before base/basictypes.h.
190 -#if !defined(XPCOM_GLUE) && !defined(NS_NO_XPCOM) && !defined(MOZ_NO_MOZALLOC)
191 -#  include "mozilla/mozalloc.h"
192 -#else
193 -#  error "STL code can only be used with infallible ::operator new()"
194 -#endif
195 -#endif /* MOZ_HAVE_INCLUDED_ALLOC */
196 -
197  #ifdef _DEBUG
198  // From
199  //   http://msdn.microsoft.com/en-us/library/aa985982%28VS.80%29.aspx
200  // and
201  //   http://msdn.microsoft.com/en-us/library/aa985965%28VS.80%29.aspx
202  // there appear to be two types of STL container checking.  The
203  // former is enabled by -D_DEBUG (which is implied by -MDd or -MTd), and
204  // looks to be full generation/mutation checked iterators as done by
205 @@ -70,9 +58,20 @@
206  //        but that's OK because we're not throwing them.
207  #pragma warning( push )
208  #pragma warning( disable : 4275 4530 )
209  
210  #include <${HEADER_PATH}>
211  
212  #pragma warning( pop )
213  
214 +#ifdef MOZ_INCLUDE_MOZALLOC_H_FROM_${HEADER}
215 +// See if we're in code that can use mozalloc.  NB: this duplicates
216 +// code in nscore.h because nscore.h pulls in prtypes.h, and chromium
217 +// can't build with that being included before base/basictypes.h.
218 +#  if !defined(XPCOM_GLUE) && !defined(NS_NO_XPCOM) && !defined(MOZ_NO_MOZALLOC)
219 +#    include "mozilla/mozalloc.h"
220 +#  else
221 +#    error "STL code can only be used with infallible ::operator new()"
222 +#  endif
223 +#endif
224 +
225  #endif  // if mozilla_${HEADER}_h
226 diff --git memory/mozalloc/mozalloc.h memory/mozalloc/mozalloc.h
227 --- mozilla/memory/mozalloc/mozalloc.h
228 +++ mozilla/memory/mozalloc/mozalloc.h
229 @@ -7,20 +7,27 @@
230  
231  #ifndef mozilla_mozalloc_h
232  #define mozilla_mozalloc_h
233  
234  /*
235   * https://bugzilla.mozilla.org/show_bug.cgi?id=427099
236   */
237  
238 -#include <stdlib.h>
239 -#include <string.h>
240  #if defined(__cplusplus)
241  #  include <new>
242 +// Since libstdc++ 6, including the C headers (e.g. stdlib.h) instead of the
243 +// corresponding C++ header (e.g. cstdlib) can cause confusion in C++ code
244 +// using things defined there. Specifically, with stdlib.h, the use of abs()
245 +// in gfx/graphite2/src/inc/UtfCodec.h somehow ends up picking the wrong abs()
246 +#  include <cstdlib>
247 +#  include <cstring>
248 +#else
249 +#  include <stdlib.h>
250 +#  include <string.h>
251  #endif
252  
253  #if defined(__cplusplus)
254  #include "mozilla/fallible.h"
255  #include "mozilla/TemplateLib.h"
256  #endif
257  #include "mozilla/Attributes.h"
258  #include "mozilla/Types.h"