From 8b08edab66472a4cc951d874654aa6b511be7015 Mon Sep 17 00:00:00 2001 From: Michael Layzell Date: Wed, 12 Aug 2015 10:46:42 -0400 Subject: [PATCH] Bug 1192130 - Part 2: Use MOZ_NON_AUTOABLE to validate the usage of already_AddRefed, r=ehsan --- mfbt/AlreadyAddRefed.h | 2 +- mfbt/Attributes.h | 8 +++++++- toolkit/devtools/server/HeapSnapshot.cpp | 7 +++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/mfbt/AlreadyAddRefed.h b/mfbt/AlreadyAddRefed.h index faf1f4c3d69..d141bc6420d 100644 --- a/mfbt/AlreadyAddRefed.h +++ b/mfbt/AlreadyAddRefed.h @@ -29,7 +29,7 @@ struct unused_t; * because of the sheer number of usages of already_AddRefed. */ template -struct MOZ_MUST_USE already_AddRefed +struct MOZ_MUST_USE MOZ_NON_AUTOABLE already_AddRefed { /* * We want to allow returning nullptr from functions returning diff --git a/mfbt/Attributes.h b/mfbt/Attributes.h index 2fafa731e93..aa31d172910 100644 --- a/mfbt/Attributes.h +++ b/mfbt/Attributes.h @@ -475,6 +475,10 @@ * declarations where an instance of the template should be considered, for * static analysis purposes, to inherit any type annotations (such as * MOZ_MUST_USE and MOZ_STACK_CLASS) from its template arguments. + * MOZ_NON_AUTOABLE: Applies to class declarations. Makes it a compile time error to + * use `auto` in place of this type in variable declarations. This is intended to + * be used with types which are intended to be implicitly constructed into other + * other types before being assigned to variables. */ #ifdef MOZ_CLANG_PLUGIN # define MOZ_MUST_OVERRIDE __attribute__((annotate("moz_must_override"))) @@ -499,8 +503,9 @@ # define MOZ_NEEDS_NO_VTABLE_TYPE __attribute__((annotate("moz_needs_no_vtable_type"))) # define MOZ_NON_MEMMOVABLE __attribute__((annotate("moz_non_memmovable"))) # define MOZ_NEEDS_MEMMOVABLE_TYPE __attribute__((annotate("moz_needs_memmovable_type"))) -# define MOZ_INHERIT_TYPE_ANNOTATIONS_FROM_TEMPLATE_ARGS \ +# define MOZ_INHERIT_TYPE_ANNOTATIONS_FROM_TEMPLATE_ARGS \ __attribute__((annotate("moz_inherit_type_annotations_from_template_args"))) +# define MOZ_NON_AUTOABLE __attribute__((annotate("moz_non_autoable"))) /* * It turns out that clang doesn't like void func() __attribute__ {} without a * warning, so use pragmas to disable the warning. This code won't work on GCC @@ -530,6 +535,7 @@ # define MOZ_NON_MEMMOVABLE /* nothing */ # define MOZ_NEEDS_MEMMOVABLE_TYPE /* nothing */ # define MOZ_INHERIT_TYPE_ANNOTATIONS_FROM_TEMPLATE_ARGS /* nothing */ +# define MOZ_NON_AUTOABLE /* nothing */ #endif /* MOZ_CLANG_PLUGIN */ /* diff --git a/toolkit/devtools/server/HeapSnapshot.cpp b/toolkit/devtools/server/HeapSnapshot.cpp index 0f4343e4ee8..4568f74fa0c 100644 --- a/toolkit/devtools/server/HeapSnapshot.cpp +++ b/toolkit/devtools/server/HeapSnapshot.cpp @@ -649,15 +649,14 @@ ThreadSafeChromeUtils::ReadHeapSnapshot(GlobalObject& global, if (rv.Failed()) return nullptr; - auto snapshot = HeapSnapshot::Create(cx, global, - reinterpret_cast(mm.address()), - mm.size(), rv); + nsRefPtr snapshot = HeapSnapshot::Create( + cx, global, reinterpret_cast(mm.address()), mm.size(), rv); if (!rv.Failed()) Telemetry::AccumulateTimeDelta(Telemetry::DEVTOOLS_READ_HEAP_SNAPSHOT_MS, start); - return snapshot; + return snapshot.forget(); } } // namespace dom