summaryrefslogtreecommitdiff
path: root/memory/fallible
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /memory/fallible
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloaduxp-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
Add m-esr52 at 52.6.0
Diffstat (limited to 'memory/fallible')
-rw-r--r--memory/fallible/fallible.cpp11
-rw-r--r--memory/fallible/fallible.h68
-rw-r--r--memory/fallible/moz.build34
3 files changed, 113 insertions, 0 deletions
diff --git a/memory/fallible/fallible.cpp b/memory/fallible/fallible.cpp
new file mode 100644
index 0000000000..5a449bc80e
--- /dev/null
+++ b/memory/fallible/fallible.cpp
@@ -0,0 +1,11 @@
+/* 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/. */
+
+#include "fallible.h"
+
+namespace mozilla {
+
+const fallible_t fallible = {};
+
+} // namespace mozilla
diff --git a/memory/fallible/fallible.h b/memory/fallible/fallible.h
new file mode 100644
index 0000000000..c028360b14
--- /dev/null
+++ b/memory/fallible/fallible.h
@@ -0,0 +1,68 @@
+/* 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/. */
+
+#ifndef mozilla_fallible_h
+#define mozilla_fallible_h
+
+#if defined(__cplusplus)
+
+/* Explicit fallible allocation
+ *
+ * Memory allocation (normally) defaults to abort in case of failed
+ * allocation. That is, it never returns NULL, and crashes instead.
+ *
+ * Code can explicitely request for fallible memory allocation thanks
+ * to the declarations below.
+ *
+ * The typical use of the mozilla::fallible const is with placement new,
+ * like the following:
+ *
+ * foo = new (mozilla::fallible) Foo();
+ *
+ * The following forms, or derivatives, are also possible but deprecated:
+ *
+ * foo = new ((mozilla::fallible_t())) Foo();
+ *
+ * const mozilla::fallible_t fallible = mozilla::fallible_t();
+ * bar = new (f) Bar();
+ *
+ * It is also possible to declare method overloads with fallible allocation
+ * alternatives, like so:
+ *
+ * class Foo {
+ * public:
+ * void Method(void *);
+ * void Method(void *, const mozilla::fallible_t&);
+ * };
+ *
+ * Foo foo;
+ * foo.Method(nullptr, mozilla::fallible);
+ *
+ * If that last method call is in a method that itself takes a const
+ * fallible_t& argument, it is recommended to propagate that argument
+ * instead of using mozilla::fallible:
+ *
+ * void Func(Foo &foo, const mozilla::fallible_t& aFallible) {
+ * foo.Method(nullptr, aFallible);
+ * }
+ *
+ */
+namespace mozilla {
+
+struct fallible_t { };
+
+/* This symbol is kept unexported, such that in corner cases where the
+ * compiler can't remove its use (essentially, cross compilation-unit
+ * calls), the smallest machine code is used.
+ * Depending how the linker packs symbols, it will consume between 1 and
+ * 8 bytes of read-only data in each executable or shared library, but
+ * only in those where it's actually not optimized out by the compiler.
+ */
+extern const fallible_t fallible;
+
+} // namespace mozilla
+
+#endif
+
+#endif // mozilla_fallible_h
diff --git a/memory/fallible/moz.build b/memory/fallible/moz.build
new file mode 100644
index 0000000000..581a394b47
--- /dev/null
+++ b/memory/fallible/moz.build
@@ -0,0 +1,34 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+EXPORTS.mozilla += [
+ 'fallible.h',
+]
+
+Library('fallible')
+
+SOURCES += [
+ 'fallible.cpp',
+]
+
+if CONFIG['_MSC_VER']:
+ # MSVC normally adds linker directives relative to the CRT in a .drectve
+ # section in .obj files. Then, when linking objects, it adds those
+ # directives as if they were given as command line arguments. This can
+ # lead to trying to include link CRTs because different objects are
+ # compiled with different CRT options (i.e. -MT vs. -MD), and failing.
+ # The only source in this directory doesn't expose anything that depends
+ # on a CRT, so it doesn't need to be bound to a specific one.
+ # Adding the -Zl option makes MSVC not store linker directives in the
+ # object. This allows to link fallible.obj to binaries independently of
+ # the CRT they use.
+ CXXFLAGS += [
+ '-Zl',
+ ]
+
+ # This further prevents the CRT name from getting into the .obj file,
+ # by avoiding pulling in a bunch of string code that uses the CRT.
+ DEFINES['mozilla_Char16_h'] = True