Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 551254: Allow reviewed+approved STL headers to be included throug…
…h <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
- Loading branch information
1 parent
dc57b86
commit a8c5a07
Showing
16 changed files
with
501 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- | ||
* vim: sw=2 ts=8 et : | ||
*/ | ||
/* ***** BEGIN LICENSE BLOCK ***** | ||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 | ||
* | ||
* The contents of this file are subject to the Mozilla Public License Version | ||
* 1.1 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at: | ||
* http://www.mozilla.org/MPL/ | ||
* | ||
* Software distributed under the License is distributed on an "AS IS" basis, | ||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
* for the specific language governing rights and limitations under the | ||
* License. | ||
* | ||
* The Original Code is Mozilla Code. | ||
* | ||
* The Initial Developer of the Original Code is | ||
* The Mozilla Foundation | ||
* Portions created by the Initial Developer are Copyright (C) 2010 | ||
* the Initial Developer. All Rights Reserved. | ||
* | ||
* Contributor(s): | ||
* Chris Jones <jones.chris.g@gmail.com> | ||
* | ||
* Alternatively, the contents of this file may be used under the terms of | ||
* either the GNU General Public License Version 2 or later (the "GPL"), or | ||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | ||
* in which case the provisions of the GPL or the LGPL are applicable instead | ||
* of those above. If you wish to allow use of your version of this file only | ||
* under the terms of either the GPL or the LGPL, and not to allow others to | ||
* use your version of this file under the terms of the MPL, indicate your | ||
* decision by deleting the provisions above and replace them with the notice | ||
* and other provisions required by the GPL or the LGPL. If you do not delete | ||
* the provisions above, a recipient may use your version of this file under | ||
* the terms of any one of the MPL, the GPL or the LGPL. | ||
* | ||
* ***** END LICENSE BLOCK ***** */ | ||
|
||
#ifndef mozilla_${HEADER}_h | ||
#define mozilla_${HEADER}_h | ||
|
||
#if __EXCEPTIONS | ||
# error "STL code can only be used with -fno-exceptions" | ||
#endif | ||
|
||
// See if we're in code that can use mozalloc. NB: this duplicates | ||
// code in nscore.h because nscore.h pulls in prtypes.h, and chromium | ||
// can't build with that being included before base/basictypes.h. | ||
#if !defined(XPCOM_GLUE) && !defined(NS_NO_XPCOM) && !defined(MOZ_NO_MOZALLOC) | ||
# include <new> // to give mozalloc std::bad_alloc | ||
# include <stdlib.h> // to give mozalloc malloc/free decls | ||
# include <string.h> | ||
# include "mozilla/mozalloc.h" | ||
#else | ||
# error "STL code can only be used with infallible ::operator new()" | ||
#endif | ||
|
||
#if defined(DEBUG) && !defined(_GLIBCXX_DEBUG) | ||
// Enable checked iterators and other goodies | ||
// | ||
// FIXME/bug 551254: gcc's debug STL implementation requires -frtti. | ||
// Figure out how to resolve this with -fno-rtti. Maybe build with | ||
// -frtti in DEBUG builds? | ||
// | ||
// # define _GLIBCXX_DEBUG 1 | ||
#endif | ||
|
||
#pragma GCC visibility push(default) | ||
#include_next <${HEADER}> | ||
#pragma GCC visibility pop | ||
|
||
// gcc calls a __throw_*() function from bits/functexcept.h when it | ||
// wants to "throw an exception". functexcept exists nominally to | ||
// support -fno-exceptions, but since we'll always use the system | ||
// libstdc++, and it's compiled with exceptions, then in practice | ||
// these __throw_*() functions will always throw exceptions (shades of | ||
// -fshort-wchar). We don't want that and so define our own inlined | ||
// __throw_*(). | ||
#ifndef mozilla_functexcept_h | ||
# include "mozilla/functexcept.h" | ||
#endif | ||
|
||
#endif // if mozilla_${HEADER}_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# ***** BEGIN LICENSE BLOCK ***** | ||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1 | ||
# | ||
# The contents of this file are subject to the Mozilla Public License Version | ||
# 1.1 (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# http://www.mozilla.org/MPL/ | ||
# | ||
# Software distributed under the License is distributed on an "AS IS" basis, | ||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
# for the specific language governing rights and limitations under the | ||
# License. | ||
# | ||
# The Original Code is mozilla.org code. | ||
# | ||
# The Initial Developer of the Original Code is | ||
# The Mozilla Foundation | ||
# Portions created by the Initial Developer are Copyright (C) 2010 | ||
# the Initial Developer. All Rights Reserved. | ||
# | ||
# Contributor(s): | ||
# Chris Jones <jones.chris.g@gmail.com> | ||
# | ||
# Alternatively, the contents of this file may be used under the terms of | ||
# either of the GNU General Public License Version 2 or later (the "GPL"), | ||
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | ||
# in which case the provisions of the GPL or the LGPL are applicable instead | ||
# of those above. If you wish to allow use of your version of this file only | ||
# under the terms of either the GPL or the LGPL, and not to allow others to | ||
# use your version of this file under the terms of the MPL, indicate your | ||
# decision by deleting the provisions above and replace them with the notice | ||
# and other provisions required by the GPL or the LGPL. If you do not delete | ||
# the provisions above, a recipient may use your version of this file under | ||
# the terms of any one of the MPL, the GPL or the LGPL. | ||
# | ||
# ***** END LICENSE BLOCK ***** | ||
|
||
import os, re, string, sys | ||
|
||
def find_in_path(file, searchpath): | ||
for dir in searchpath.split(os.pathsep): | ||
f = os.path.join(dir, file) | ||
if os.path.exists(f): | ||
return f | ||
return '' | ||
|
||
def header_path(header, compiler): | ||
if compiler == 'gcc': | ||
# we use include_next on gcc | ||
return header | ||
elif compiler == 'msvc': | ||
return find_in_path(header, os.environ.get('INCLUDE', '')) | ||
else: | ||
# hope someone notices this ... | ||
raise NotImplementedError, compiler | ||
|
||
def is_comment(line): | ||
return re.match(r'\s*#.*', line) | ||
|
||
def main(outdir, compiler, template_file, header_list_file): | ||
if not os.path.isdir(outdir): | ||
os.mkdir(outdir) | ||
|
||
template = open(template_file, 'r').read() | ||
|
||
for header in open(header_list_file, 'r'): | ||
header = header.rstrip() | ||
if 0 == len(header) or is_comment(header): | ||
continue | ||
|
||
path = header_path(header, compiler) | ||
try: | ||
f = open(os.path.join(outdir, header), 'w') | ||
f.write(string.Template(template).substitute(HEADER=header, | ||
HEADER_PATH=path)) | ||
finally: | ||
f.close() | ||
|
||
|
||
if __name__ == '__main__': | ||
if 5 != len(sys.argv): | ||
print >>sys.stderr, """Usage: | ||
python %s OUT_DIR ('msvc'|'gcc') TEMPLATE_FILE HEADER_LIST_FILE | ||
"""% (sys.argv[0]) | ||
sys.exit(1) | ||
|
||
main(*sys.argv[1:]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- | ||
* vim: sw=2 ts=8 et : | ||
*/ | ||
/* ***** BEGIN LICENSE BLOCK ***** | ||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 | ||
* | ||
* The contents of this file are subject to the Mozilla Public License Version | ||
* 1.1 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at: | ||
* http://www.mozilla.org/MPL/ | ||
* | ||
* Software distributed under the License is distributed on an "AS IS" basis, | ||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
* for the specific language governing rights and limitations under the | ||
* License. | ||
* | ||
* The Original Code is Mozilla Code. | ||
* | ||
* The Initial Developer of the Original Code is | ||
* The Mozilla Foundation | ||
* Portions created by the Initial Developer are Copyright (C) 2010 | ||
* the Initial Developer. All Rights Reserved. | ||
* | ||
* Contributor(s): | ||
* Chris Jones <jones.chris.g@gmail.com> | ||
* | ||
* Alternatively, the contents of this file may be used under the terms of | ||
* either the GNU General Public License Version 2 or later (the "GPL"), or | ||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | ||
* in which case the provisions of the GPL or the LGPL are applicable instead | ||
* of those above. If you wish to allow use of your version of this file only | ||
* under the terms of either the GPL or the LGPL, and not to allow others to | ||
* use your version of this file under the terms of the MPL, indicate your | ||
* decision by deleting the provisions above and replace them with the notice | ||
* and other provisions required by the GPL or the LGPL. If you do not delete | ||
* the provisions above, a recipient may use your version of this file under | ||
* the terms of any one of the MPL, the GPL or the LGPL. | ||
* | ||
* ***** END LICENSE BLOCK ***** */ | ||
|
||
#ifndef mozilla_${HEADER}_h | ||
#define mozilla_${HEADER}_h | ||
|
||
#if _HAS_EXCEPTIONS | ||
# error "STL code can only be used with -fno-exceptions" | ||
#endif | ||
|
||
// See if we're in code that can use mozalloc. NB: this duplicates | ||
// code in nscore.h because nscore.h pulls in prtypes.h, and chromium | ||
// can't build with that being included before base/basictypes.h. | ||
#if !defined(XPCOM_GLUE) && !defined(NS_NO_XPCOM) && !defined(MOZ_NO_MOZALLOC) | ||
# include <new> // to give mozalloc std::bad_alloc | ||
# include <stdlib.h> // to give mozalloc malloc/free decls | ||
# include <string.h> | ||
# include "mozilla/mozalloc.h" | ||
#else | ||
# error "STL code can only be used with infallible ::operator new()" | ||
#endif | ||
|
||
#ifdef DEBUG | ||
// From | ||
// http://msdn.microsoft.com/en-us/library/aa985982%28VS.80%29.aspx | ||
// and | ||
// http://msdn.microsoft.com/en-us/library/aa985965%28VS.80%29.aspx | ||
// there appear to be two types of STL container checking. The | ||
// former is enabled by -D_DEBUG (which is implied by -DDEBUG), and | ||
// looks to be full generation/mutation checked iterators as done by | ||
// _GLIBCXX_DEBUG. The latter appears to just be bounds checking, and | ||
// is enabled by the following macros. It appears that the _DEBUG | ||
// iterators subsume _SECURE_SCL, and the following settings are | ||
// default anyway, so we'll just leave this commented out. | ||
//# define _SECURE_SCL 1 | ||
//# define _SECURE_SCL_THROWS 0 | ||
#else | ||
// Note: _SECURE_SCL iterators are on by default in opt builds. We | ||
// could leave them on, but since gcc doesn't, we might as well | ||
// preserve that behavior for perf reasons. nsTArray is in the same | ||
// camp as gcc. Can revisit later. | ||
// | ||
// FIXME/bug 551254: because we're not wrapping all the STL headers we | ||
// use, undefining this here can cause some headers to be built with | ||
// iterator checking and others not. Turning this off until we have a | ||
// better plan. | ||
//# undef _SECURE_SCL | ||
#endif | ||
|
||
// We know that code won't be able to catch exceptions, but that's OK | ||
// because we're not throwing them. | ||
#pragma warning( push ) | ||
#pragma warning( disable : 4530 ) | ||
|
||
#include <${HEADER_PATH}> | ||
|
||
#pragma warning( pop ) | ||
|
||
#endif // if mozilla_${HEADER}_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# | ||
# This file contains a list the of STL headers that have been reviewed | ||
# for exception safety and approved. See | ||
# | ||
# https://bugzilla.mozilla.org/show_bug.cgi?id=551254 | ||
# | ||
# At build time, each header listed here is converted into a "wrapper | ||
# header" that is installed into dist/stl_includes. | ||
# | ||
# If you would like to request a new STL header <foo> be added, please | ||
# file a Core:XPCOM bug with a title like "STL: Review exception | ||
# safety of <foo> for gcc and MSVC". | ||
# | ||
|
||
# FIXME: these headers haven't been reviewed yet, but we use them | ||
# unsafely in modules/libpr0n, so we might as well prevent it from | ||
# throwing exceptions | ||
algorithm | ||
vector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.