Bug 1296186 part 1 - Make borrowed type just alias of corresponding pointer type. r?bholley
Compilers would complain about using user-defined type as return type
of extern "C" functions. A struct is considered a user-defined type if
there is any non-trivial constructor.
Having a type without non-trivial constructor for borrowed type would
be very inconvenient. Actually the currently borrowed type doesn't seem
to provide any additional safety / benefit over a plain pointer.
MozReview-Commit-ID: ncxmCEWCkv
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -21,26 +21,28 @@
#include "nsStyleStruct.h"
#include "nsStyleUtil.h"
#include "nsTArray.h"
#include "mozilla/EventStates.h"
#include "mozilla/ServoElementSnapshot.h"
#include "mozilla/dom/Element.h"
-#define IMPL_STRONG_REF_TYPE(name, T) \
- already_AddRefed<T> name::Consume() { \
- RefPtr<T> result = dont_AddRef(mPtr); \
- mPtr = nullptr; \
- return result.forget(); \
- };
+#define IMPL_STRONG_REF_TYPE_FOR(type_) \
+ already_AddRefed<type_> \
+ type_##Strong::Consume() { \
+ RefPtr<type_> result; \
+ result.swap(mPtr); \
+ return result.forget(); \
+ }
+IMPL_STRONG_REF_TYPE_FOR(ServoComputedValues)
+IMPL_STRONG_REF_TYPE_FOR(RawServoStyleSheet)
-IMPL_STRONG_REF_TYPE(ServoComputedValuesStrong, ServoComputedValues);
-IMPL_STRONG_REF_TYPE(RawServoStyleSheetStrong, RawServoStyleSheet);
+#undef IMPL_STRONG_REF_TYPE_FOR
uint32_t
Gecko_ChildrenCount(RawGeckoNode* aNode)
{
return aNode->GetChildCount();
}
bool
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -11,34 +11,16 @@
#include "mozilla/css/SheetParsingMode.h"
#include "nsChangeHint.h"
#include "nsColor.h"
#include "nsProxyRelease.h"
#include "nsStyleCoord.h"
#include "nsStyleStruct.h"
#include "stdint.h"
-#define DECL_STRONG_REF_TYPE(name, T) \
- struct MOZ_MUST_USE_TYPE name { \
- T* mPtr; \
- already_AddRefed<T> Consume(); \
- }
-
-#define DECL_BORROWED_REF_TYPE(name, T) \
- struct name { \
- T* mPtr; \
- MOZ_IMPLICIT \
- name(T* x): mPtr(x) {}; \
- MOZ_IMPLICIT \
- name(const RefPtr<T>& aPtr) : mPtr(aPtr.get()) {}; \
- operator T*() const & { \
- return mPtr; \
- } \
- }
-
/*
* API for Servo to access Gecko data structures. This file must compile as valid
* C code in order for the binding generator to parse it.
*
* Functions beginning with Gecko_ are implemented in Gecko and invoked from Servo.
* Functions beginning with Servo_ are implemented in Servo and invoked from Gecko.
*/
@@ -57,31 +39,40 @@ using mozilla::FontFamilyList;
using mozilla::FontFamilyType;
using mozilla::dom::Element;
using mozilla::ServoElementSnapshot;
typedef mozilla::dom::Element RawGeckoElement;
class nsIDocument;
typedef nsIDocument RawGeckoDocument;
struct ServoNodeData;
struct ServoComputedValues;
-DECL_STRONG_REF_TYPE(ServoComputedValuesStrong, ServoComputedValues);
-DECL_BORROWED_REF_TYPE(ServoComputedValuesBorrowed, ServoComputedValues);
struct RawServoStyleSheet;
-DECL_STRONG_REF_TYPE(RawServoStyleSheetStrong, RawServoStyleSheet);
-DECL_BORROWED_REF_TYPE(RawServoStyleSheetBorrowed, RawServoStyleSheet);
struct RawServoStyleSet;
class nsHTMLCSSStyleSheet;
struct nsStyleList;
struct nsStyleImage;
struct nsStyleGradientStop;
class nsStyleGradient;
class nsStyleCoord;
struct nsStyleDisplay;
struct ServoDeclarationBlock;
+#define DECL_REF_TYPE_FOR(type_) \
+ typedef type_* type_##Borrowed; \
+ struct MOZ_MUST_USE_TYPE type_##Strong \
+ { \
+ type_* mPtr; \
+ already_AddRefed<type_> Consume(); \
+ };
+
+DECL_REF_TYPE_FOR(ServoComputedValues)
+DECL_REF_TYPE_FOR(RawServoStyleSheet)
+
+#undef DECL_REF_TYPE_FOR
+
#define NS_DECL_THREADSAFE_FFI_REFCOUNTING(class_, name_) \
void Gecko_AddRef##name_##ArbitraryThread(class_* aPtr); \
void Gecko_Release##name_##ArbitraryThread(class_* aPtr);
#define NS_IMPL_THREADSAFE_FFI_REFCOUNTING(class_, name_) \
static_assert(class_::HasThreadSafeRefCnt::value, \
"NS_DECL_THREADSAFE_FFI_REFCOUNTING can only be used with " \
"classes that have thread-safe refcounting"); \
void Gecko_AddRef##name_##ArbitraryThread(class_* aPtr) \