Bug 1192043 - Fix compile errors in Natives.h; r=snorp

This patch fixes a compile error when using WeakPtr, where Impl* was
expected but SupportsWeakPtr<Impl>* was given.

This patch also fixes a compile error when using the DisposeNative
implementation provided by the autogenerated Natives class. e.g.,

> struct Foo : Bar::Natives<Foo> {
>     using Bar::Natives<Foo>::DisposeNative;
> };

This uses a default implementation of DisposeNative instead of a custom
implementation, and resulted in a compile error that this patch fixes.
This commit is contained in:
Jim Chen 2015-08-25 14:52:16 -04:00
Родитель 8323512edf
Коммит b8013723d5
1 изменённых файлов: 17 добавлений и 2 удалений

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

@ -147,7 +147,7 @@ struct NativePtr<Impl, /* UseWeakPtr = */ true>
}
template<class LocalRef>
static void Set(const LocalRef& instance, SupportsWeakPtr<Impl>* ptr)
static void Set(const LocalRef& instance, Impl* ptr)
{
Clear(instance);
SetNativeHandle(instance.Env(), instance.Get(),
@ -172,6 +172,8 @@ struct NativePtr<Impl, /* UseWeakPtr = */ true>
} // namespace
template<class Cls, class Impl> class NativeImpl;
namespace detail {
// Wrapper methods that convert arguments from the JNI types to the native
@ -259,6 +261,19 @@ public:
(impl->*Method)(self, TypeAdapter<Args>::ToNative(env, args)...);
self.Forget();
}
// Overload for DisposeNative
template<void (NativeImpl<Owner, Impl>::*Method) (const typename Owner::LocalRef&)>
static void Wrap(JNIEnv* env, jobject instance)
{
Impl* const impl = NativePtr<Impl>::Get(env, instance);
if (!impl) {
return;
}
auto self = Owner::LocalRef::Adopt(env, instance);
(impl->*Method)(self);
self.Forget();
}
};
// Specialization for static methods with non-void return type
@ -369,7 +384,7 @@ protected:
{
static_assert(mozilla::IsBaseOf<SupportsWeakPtr<Impl>, Impl>::value,
"Attach with UniquePtr&& when not using WeakPtr");
return NativePtr<Impl>::Set(instance, ptr);
return NativePtr<Impl>::Set(instance, static_cast<Impl*>(ptr));
}
static void AttachNative(const typename Cls::LocalRef& instance,