Skip to content

Commit a8c5a07

Browse files
committed
Bug 551254: Allow reviewed+approved STL headers to be included through <foo>. (<algorithm> and <vector> are provisionally in the list because of their use in libpr0n, but need to be reviewed in followup bug 556700 and bug 556701). r=ehsan,ted,zwol
1 parent dc57b86 commit a8c5a07

File tree

16 files changed

+501
-2
lines changed

16 files changed

+501
-2
lines changed

config/Makefile.in

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,26 @@ export::
137137
GARBAGE_DIRS += system_wrappers
138138
endif
139139

140+
ifdef WRAP_STL_INCLUDES
141+
ifdef GCC_VERSION
142+
stl_compiler = gcc
143+
else
144+
stl_compiler = msvc
145+
endif
146+
endif
147+
148+
ifdef stl_compiler
149+
stl-wrappers-sentinel: $(srcdir)/make-stl-wrappers.py $(srcdir)/$(stl_compiler)-stl-wrapper.template.h $(srcdir)/stl-headers $(GLOBAL_DEPS)
150+
$(PYTHON) $(srcdir)/make-stl-wrappers.py stl_wrappers $(stl_compiler) $(srcdir)/$(stl_compiler)-stl-wrapper.template.h $(srcdir)/stl-headers
151+
$(PYTHON) $(srcdir)/nsinstall.py stl_wrappers $(DIST)
152+
touch stl-wrappers-sentinel
153+
154+
export:: stl-wrappers-sentinel
155+
156+
GARBAGE += stl-wrappers-sentinel
157+
GARBAGE_DIRS += stl_wrappers
158+
endif
159+
140160
install::
141161
$(SYSINSTALL) $(IFLAGS1) $(DEPTH)/mozilla-config.h $(DESTDIR)$(includedir)
142162

config/autoconf.mk.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,9 @@ HAVE_GCC3_ABI = @HAVE_GCC3_ABI@
359359
INTEL_CC = @INTEL_CC@
360360
INTEL_CXX = @INTEL_CXX@
361361

362+
STL_FLAGS = @STL_FLAGS@
363+
WRAP_STL_INCLUDES = @WRAP_STL_INCLUDES@
364+
362365
HOST_CC = @HOST_CC@
363366
HOST_CXX = @HOST_CXX@
364367
HOST_CFLAGS = @HOST_CFLAGS@

config/config.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ OS_COMPILE_CMMFLAGS += -fobjc-exceptions
526526
endif
527527

528528
COMPILE_CFLAGS = $(VISIBILITY_FLAGS) $(DEFINES) $(INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(CFLAGS) $(RTL_FLAGS) $(OS_COMPILE_CFLAGS)
529-
COMPILE_CXXFLAGS = $(VISIBILITY_FLAGS) $(DEFINES) $(INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(CXXFLAGS) $(RTL_FLAGS) $(OS_COMPILE_CXXFLAGS)
529+
COMPILE_CXXFLAGS = $(VISIBILITY_FLAGS) $(STL_FLAGS) $(DEFINES) $(INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(CXXFLAGS) $(RTL_FLAGS) $(OS_COMPILE_CXXFLAGS)
530530
COMPILE_CMFLAGS = $(OS_COMPILE_CMFLAGS)
531531
COMPILE_CMMFLAGS = $(OS_COMPILE_CMMFLAGS)
532532

config/gcc-stl-wrapper.template.h

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2+
* vim: sw=2 ts=8 et :
3+
*/
4+
/* ***** BEGIN LICENSE BLOCK *****
5+
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
6+
*
7+
* The contents of this file are subject to the Mozilla Public License Version
8+
* 1.1 (the "License"); you may not use this file except in compliance with
9+
* the License. You may obtain a copy of the License at:
10+
* http://www.mozilla.org/MPL/
11+
*
12+
* Software distributed under the License is distributed on an "AS IS" basis,
13+
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14+
* for the specific language governing rights and limitations under the
15+
* License.
16+
*
17+
* The Original Code is Mozilla Code.
18+
*
19+
* The Initial Developer of the Original Code is
20+
* The Mozilla Foundation
21+
* Portions created by the Initial Developer are Copyright (C) 2010
22+
* the Initial Developer. All Rights Reserved.
23+
*
24+
* Contributor(s):
25+
* Chris Jones <jones.chris.g@gmail.com>
26+
*
27+
* Alternatively, the contents of this file may be used under the terms of
28+
* either the GNU General Public License Version 2 or later (the "GPL"), or
29+
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30+
* in which case the provisions of the GPL or the LGPL are applicable instead
31+
* of those above. If you wish to allow use of your version of this file only
32+
* under the terms of either the GPL or the LGPL, and not to allow others to
33+
* use your version of this file under the terms of the MPL, indicate your
34+
* decision by deleting the provisions above and replace them with the notice
35+
* and other provisions required by the GPL or the LGPL. If you do not delete
36+
* the provisions above, a recipient may use your version of this file under
37+
* the terms of any one of the MPL, the GPL or the LGPL.
38+
*
39+
* ***** END LICENSE BLOCK ***** */
40+
41+
#ifndef mozilla_${HEADER}_h
42+
#define mozilla_${HEADER}_h
43+
44+
#if __EXCEPTIONS
45+
# error "STL code can only be used with -fno-exceptions"
46+
#endif
47+
48+
// See if we're in code that can use mozalloc. NB: this duplicates
49+
// code in nscore.h because nscore.h pulls in prtypes.h, and chromium
50+
// can't build with that being included before base/basictypes.h.
51+
#if !defined(XPCOM_GLUE) && !defined(NS_NO_XPCOM) && !defined(MOZ_NO_MOZALLOC)
52+
# include <new> // to give mozalloc std::bad_alloc
53+
# include <stdlib.h> // to give mozalloc malloc/free decls
54+
# include <string.h>
55+
# include "mozilla/mozalloc.h"
56+
#else
57+
# error "STL code can only be used with infallible ::operator new()"
58+
#endif
59+
60+
#if defined(DEBUG) && !defined(_GLIBCXX_DEBUG)
61+
// Enable checked iterators and other goodies
62+
//
63+
// FIXME/bug 551254: gcc's debug STL implementation requires -frtti.
64+
// Figure out how to resolve this with -fno-rtti. Maybe build with
65+
// -frtti in DEBUG builds?
66+
//
67+
// # define _GLIBCXX_DEBUG 1
68+
#endif
69+
70+
#pragma GCC visibility push(default)
71+
#include_next <${HEADER}>
72+
#pragma GCC visibility pop
73+
74+
// gcc calls a __throw_*() function from bits/functexcept.h when it
75+
// wants to "throw an exception". functexcept exists nominally to
76+
// support -fno-exceptions, but since we'll always use the system
77+
// libstdc++, and it's compiled with exceptions, then in practice
78+
// these __throw_*() functions will always throw exceptions (shades of
79+
// -fshort-wchar). We don't want that and so define our own inlined
80+
// __throw_*().
81+
#ifndef mozilla_functexcept_h
82+
# include "mozilla/functexcept.h"
83+
#endif
84+
85+
#endif // if mozilla_${HEADER}_h

config/make-stl-wrappers.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# ***** BEGIN LICENSE BLOCK *****
2+
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
3+
#
4+
# The contents of this file are subject to the Mozilla Public License Version
5+
# 1.1 (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
# http://www.mozilla.org/MPL/
8+
#
9+
# Software distributed under the License is distributed on an "AS IS" basis,
10+
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11+
# for the specific language governing rights and limitations under the
12+
# License.
13+
#
14+
# The Original Code is mozilla.org code.
15+
#
16+
# The Initial Developer of the Original Code is
17+
# The Mozilla Foundation
18+
# Portions created by the Initial Developer are Copyright (C) 2010
19+
# the Initial Developer. All Rights Reserved.
20+
#
21+
# Contributor(s):
22+
# Chris Jones <jones.chris.g@gmail.com>
23+
#
24+
# Alternatively, the contents of this file may be used under the terms of
25+
# either of the GNU General Public License Version 2 or later (the "GPL"),
26+
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27+
# in which case the provisions of the GPL or the LGPL are applicable instead
28+
# of those above. If you wish to allow use of your version of this file only
29+
# under the terms of either the GPL or the LGPL, and not to allow others to
30+
# use your version of this file under the terms of the MPL, indicate your
31+
# decision by deleting the provisions above and replace them with the notice
32+
# and other provisions required by the GPL or the LGPL. If you do not delete
33+
# the provisions above, a recipient may use your version of this file under
34+
# the terms of any one of the MPL, the GPL or the LGPL.
35+
#
36+
# ***** END LICENSE BLOCK *****
37+
38+
import os, re, string, sys
39+
40+
def find_in_path(file, searchpath):
41+
for dir in searchpath.split(os.pathsep):
42+
f = os.path.join(dir, file)
43+
if os.path.exists(f):
44+
return f
45+
return ''
46+
47+
def header_path(header, compiler):
48+
if compiler == 'gcc':
49+
# we use include_next on gcc
50+
return header
51+
elif compiler == 'msvc':
52+
return find_in_path(header, os.environ.get('INCLUDE', ''))
53+
else:
54+
# hope someone notices this ...
55+
raise NotImplementedError, compiler
56+
57+
def is_comment(line):
58+
return re.match(r'\s*#.*', line)
59+
60+
def main(outdir, compiler, template_file, header_list_file):
61+
if not os.path.isdir(outdir):
62+
os.mkdir(outdir)
63+
64+
template = open(template_file, 'r').read()
65+
66+
for header in open(header_list_file, 'r'):
67+
header = header.rstrip()
68+
if 0 == len(header) or is_comment(header):
69+
continue
70+
71+
path = header_path(header, compiler)
72+
try:
73+
f = open(os.path.join(outdir, header), 'w')
74+
f.write(string.Template(template).substitute(HEADER=header,
75+
HEADER_PATH=path))
76+
finally:
77+
f.close()
78+
79+
80+
if __name__ == '__main__':
81+
if 5 != len(sys.argv):
82+
print >>sys.stderr, """Usage:
83+
python %s OUT_DIR ('msvc'|'gcc') TEMPLATE_FILE HEADER_LIST_FILE
84+
"""% (sys.argv[0])
85+
sys.exit(1)
86+
87+
main(*sys.argv[1:])

config/msvc-stl-wrapper.template.h

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2+
* vim: sw=2 ts=8 et :
3+
*/
4+
/* ***** BEGIN LICENSE BLOCK *****
5+
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
6+
*
7+
* The contents of this file are subject to the Mozilla Public License Version
8+
* 1.1 (the "License"); you may not use this file except in compliance with
9+
* the License. You may obtain a copy of the License at:
10+
* http://www.mozilla.org/MPL/
11+
*
12+
* Software distributed under the License is distributed on an "AS IS" basis,
13+
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14+
* for the specific language governing rights and limitations under the
15+
* License.
16+
*
17+
* The Original Code is Mozilla Code.
18+
*
19+
* The Initial Developer of the Original Code is
20+
* The Mozilla Foundation
21+
* Portions created by the Initial Developer are Copyright (C) 2010
22+
* the Initial Developer. All Rights Reserved.
23+
*
24+
* Contributor(s):
25+
* Chris Jones <jones.chris.g@gmail.com>
26+
*
27+
* Alternatively, the contents of this file may be used under the terms of
28+
* either the GNU General Public License Version 2 or later (the "GPL"), or
29+
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30+
* in which case the provisions of the GPL or the LGPL are applicable instead
31+
* of those above. If you wish to allow use of your version of this file only
32+
* under the terms of either the GPL or the LGPL, and not to allow others to
33+
* use your version of this file under the terms of the MPL, indicate your
34+
* decision by deleting the provisions above and replace them with the notice
35+
* and other provisions required by the GPL or the LGPL. If you do not delete
36+
* the provisions above, a recipient may use your version of this file under
37+
* the terms of any one of the MPL, the GPL or the LGPL.
38+
*
39+
* ***** END LICENSE BLOCK ***** */
40+
41+
#ifndef mozilla_${HEADER}_h
42+
#define mozilla_${HEADER}_h
43+
44+
#if _HAS_EXCEPTIONS
45+
# error "STL code can only be used with -fno-exceptions"
46+
#endif
47+
48+
// See if we're in code that can use mozalloc. NB: this duplicates
49+
// code in nscore.h because nscore.h pulls in prtypes.h, and chromium
50+
// can't build with that being included before base/basictypes.h.
51+
#if !defined(XPCOM_GLUE) && !defined(NS_NO_XPCOM) && !defined(MOZ_NO_MOZALLOC)
52+
# include <new> // to give mozalloc std::bad_alloc
53+
# include <stdlib.h> // to give mozalloc malloc/free decls
54+
# include <string.h>
55+
# include "mozilla/mozalloc.h"
56+
#else
57+
# error "STL code can only be used with infallible ::operator new()"
58+
#endif
59+
60+
#ifdef DEBUG
61+
// From
62+
// http://msdn.microsoft.com/en-us/library/aa985982%28VS.80%29.aspx
63+
// and
64+
// http://msdn.microsoft.com/en-us/library/aa985965%28VS.80%29.aspx
65+
// there appear to be two types of STL container checking. The
66+
// former is enabled by -D_DEBUG (which is implied by -DDEBUG), and
67+
// looks to be full generation/mutation checked iterators as done by
68+
// _GLIBCXX_DEBUG. The latter appears to just be bounds checking, and
69+
// is enabled by the following macros. It appears that the _DEBUG
70+
// iterators subsume _SECURE_SCL, and the following settings are
71+
// default anyway, so we'll just leave this commented out.
72+
//# define _SECURE_SCL 1
73+
//# define _SECURE_SCL_THROWS 0
74+
#else
75+
// Note: _SECURE_SCL iterators are on by default in opt builds. We
76+
// could leave them on, but since gcc doesn't, we might as well
77+
// preserve that behavior for perf reasons. nsTArray is in the same
78+
// camp as gcc. Can revisit later.
79+
//
80+
// FIXME/bug 551254: because we're not wrapping all the STL headers we
81+
// use, undefining this here can cause some headers to be built with
82+
// iterator checking and others not. Turning this off until we have a
83+
// better plan.
84+
//# undef _SECURE_SCL
85+
#endif
86+
87+
// We know that code won't be able to catch exceptions, but that's OK
88+
// because we're not throwing them.
89+
#pragma warning( push )
90+
#pragma warning( disable : 4530 )
91+
92+
#include <${HEADER_PATH}>
93+
94+
#pragma warning( pop )
95+
96+
#endif // if mozilla_${HEADER}_h

config/stl-headers

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# This file contains a list the of STL headers that have been reviewed
3+
# for exception safety and approved. See
4+
#
5+
# https://bugzilla.mozilla.org/show_bug.cgi?id=551254
6+
#
7+
# At build time, each header listed here is converted into a "wrapper
8+
# header" that is installed into dist/stl_includes.
9+
#
10+
# If you would like to request a new STL header <foo> be added, please
11+
# file a Core:XPCOM bug with a title like "STL: Review exception
12+
# safety of <foo> for gcc and MSVC".
13+
#
14+
15+
# FIXME: these headers haven't been reviewed yet, but we use them
16+
# unsafely in modules/libpr0n, so we might as well prevent it from
17+
# throwing exceptions
18+
algorithm
19+
vector

configure.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,9 @@ EOF
759759
AC_DEFINE_UNQUOTED(MOZ_NTDDI_WS03, 0x05020000)
760760
AC_DEFINE_UNQUOTED(MOZ_NTDDI_LONGHORN, 0x06000000)
761761
AC_DEFINE_UNQUOTED(MOZ_NTDDI_WIN7, 0x06010000)
762+
763+
STL_FLAGS='-D_HAS_EXCEPTIONS=0 -I$(DIST)/stl_wrappers'
764+
WRAP_STL_INCLUDES=1
762765
;;
763766
esac
764767

@@ -807,6 +810,9 @@ AC_SUBST(GNU_CXX)
807810
AC_SUBST(INTEL_CC)
808811
AC_SUBST(INTEL_CXX)
809812

813+
AC_SUBST(STL_FLAGS)
814+
AC_SUBST(WRAP_STL_INCLUDES)
815+
810816
dnl ========================================================
811817
dnl Checks for programs.
812818
dnl ========================================================
@@ -3126,6 +3132,8 @@ EOF
31263132
"$ac_cv_have_visibility_class_bug" = "no"; then
31273133
VISIBILITY_FLAGS='-I$(DIST)/system_wrappers -include $(topsrcdir)/config/gcc_hidden.h'
31283134
WRAP_SYSTEM_INCLUDES=1
3135+
STL_FLAGS='-I$(DIST)/stl_wrappers'
3136+
WRAP_STL_INCLUDES=1
31293137
else
31303138
VISIBILITY_FLAGS='-fvisibility=hidden'
31313139
fi # have visibility pragma bug

js/src/config/config.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ OS_COMPILE_CMMFLAGS += -fobjc-exceptions
526526
endif
527527

528528
COMPILE_CFLAGS = $(VISIBILITY_FLAGS) $(DEFINES) $(INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(CFLAGS) $(RTL_FLAGS) $(OS_COMPILE_CFLAGS)
529-
COMPILE_CXXFLAGS = $(VISIBILITY_FLAGS) $(DEFINES) $(INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(CXXFLAGS) $(RTL_FLAGS) $(OS_COMPILE_CXXFLAGS)
529+
COMPILE_CXXFLAGS = $(VISIBILITY_FLAGS) $(STL_FLAGS) $(DEFINES) $(INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(CXXFLAGS) $(RTL_FLAGS) $(OS_COMPILE_CXXFLAGS)
530530
COMPILE_CMFLAGS = $(OS_COMPILE_CMFLAGS)
531531
COMPILE_CMMFLAGS = $(OS_COMPILE_CMMFLAGS)
532532

testing/mochitest/ssltunnel/Makefile.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ VPATH = @srcdir@
4343

4444
include $(DEPTH)/config/autoconf.mk
4545

46+
# This isn't XPCOM code, but it wants to use STL, so disable the STL
47+
# wrappers
48+
STL_FLAGS =
49+
4650
PROGRAM = ssltunnel$(BIN_SUFFIX)
4751

4852
CPPSRCS = ssltunnel.cpp

0 commit comments

Comments
 (0)