Bug 773014 - Part 2: Mark Static{Auto,Ref}Ptr as global-only; r=jrmuizel

This commit is contained in:
Ehsan Akhgari 2014-12-22 18:10:44 -05:00
Родитель 4f72aaa22b
Коммит d945a5c5ae
3 изменённых файлов: 13 добавлений и 7 удалений

Просмотреть файл

@ -1031,7 +1031,7 @@ imgLoader::imgLoader()
already_AddRefed<imgLoader> already_AddRefed<imgLoader>
imgLoader::GetInstance() imgLoader::GetInstance()
{ {
static StaticRefPtr<imgLoader> singleton; static nsRefPtr<imgLoader> singleton;
if (!singleton) { if (!singleton) {
singleton = imgLoader::Create(); singleton = imgLoader::Create();
if (!singleton) if (!singleton)

Просмотреть файл

@ -495,6 +495,10 @@
* class uses this class, or if another class inherits from this class, then * class uses this class, or if another class inherits from this class, then
* it is considered to be a non-heap class as well, although this attribute * it is considered to be a non-heap class as well, although this attribute
* need not be provided in such cases. * need not be provided in such cases.
* MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS: Applies to all classes that are
* intended to prevent introducing static initializers. This attribute
* currently makes it a compile-time error to instantiate these classes
* anywhere other than at the global scope, or as a static member of a class.
* MOZ_HEAP_ALLOCATOR: Applies to any function. This indicates that the return * MOZ_HEAP_ALLOCATOR: Applies to any function. This indicates that the return
* value is allocated on the heap, and will as a result check such allocations * value is allocated on the heap, and will as a result check such allocations
* during MOZ_STACK_CLASS and MOZ_NONHEAP_CLASS annotation checking. * during MOZ_STACK_CLASS and MOZ_NONHEAP_CLASS annotation checking.
@ -509,6 +513,7 @@
# define MOZ_MUST_OVERRIDE __attribute__((annotate("moz_must_override"))) # define MOZ_MUST_OVERRIDE __attribute__((annotate("moz_must_override")))
# define MOZ_STACK_CLASS __attribute__((annotate("moz_stack_class"))) # define MOZ_STACK_CLASS __attribute__((annotate("moz_stack_class")))
# define MOZ_NONHEAP_CLASS __attribute__((annotate("moz_nonheap_class"))) # define MOZ_NONHEAP_CLASS __attribute__((annotate("moz_nonheap_class")))
# define MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS __attribute__((annotate("moz_global_class")))
# define MOZ_IMPLICIT __attribute__((annotate("moz_implicit"))) # define MOZ_IMPLICIT __attribute__((annotate("moz_implicit")))
# define MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT __attribute__((annotate("moz_no_arith_expr_in_arg"))) # define MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT __attribute__((annotate("moz_no_arith_expr_in_arg")))
/* /*
@ -525,6 +530,7 @@
# define MOZ_MUST_OVERRIDE /* nothing */ # define MOZ_MUST_OVERRIDE /* nothing */
# define MOZ_STACK_CLASS /* nothing */ # define MOZ_STACK_CLASS /* nothing */
# define MOZ_NONHEAP_CLASS /* nothing */ # define MOZ_NONHEAP_CLASS /* nothing */
# define MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS /* nothing */
# define MOZ_IMPLICIT /* nothing */ # define MOZ_IMPLICIT /* nothing */
# define MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT /* nothing */ # define MOZ_NO_ARITHMETIC_EXPR_IN_ARGUMENT /* nothing */
# define MOZ_HEAP_ALLOCATOR /* nothing */ # define MOZ_HEAP_ALLOCATOR /* nothing */

Просмотреть файл

@ -8,6 +8,7 @@
#define mozilla_StaticPtr_h #define mozilla_StaticPtr_h
#include "mozilla/Assertions.h" #include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/NullPtr.h" #include "mozilla/NullPtr.h"
namespace mozilla { namespace mozilla {
@ -25,17 +26,16 @@ namespace mozilla {
* upon destruction. * upon destruction.
* *
* Since the compiler guarantees that all global variables are initialized to * Since the compiler guarantees that all global variables are initialized to
* 0, these trivial constructors are safe, so long as you use * 0, these trivial constructors are safe. Since we rely on this, the clang
* Static{Auto,Ref}Ptr as a global variable. If you use Static{Auto,Ref}Ptr as * plugin, run as part of our "static analysis" builds, makes it a compile-time
* a stack variable or as a class instance variable, you will get what you * error to use Static{Auto,Ref}Ptr as anything except a global variable.
* deserve.
* *
* Static{Auto,Ref}Ptr have a limited interface as compared to ns{Auto,Ref}Ptr; * Static{Auto,Ref}Ptr have a limited interface as compared to ns{Auto,Ref}Ptr;
* this is intentional, since their range of acceptable uses is smaller. * this is intentional, since their range of acceptable uses is smaller.
*/ */
template<class T> template<class T>
class StaticAutoPtr class MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS StaticAutoPtr
{ {
public: public:
// In debug builds, check that mRawPtr is initialized for us as we expect // In debug builds, check that mRawPtr is initialized for us as we expect
@ -87,7 +87,7 @@ private:
}; };
template<class T> template<class T>
class StaticRefPtr class MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS StaticRefPtr
{ {
public: public:
// In debug builds, check that mRawPtr is initialized for us as we expect // In debug builds, check that mRawPtr is initialized for us as we expect