Bug 1251541: Replace |nsAutoArrayPtr<>| with |UniquePtr<[]>| in Bluetooth interfaces, r=shuang

This patch replaces all instances of |nsAutoArrayPtr<>| in the Bluetooth
interfaces with |UniquePtr<[]>|.

In contrast to |nsAutoArrayPtr<>|, |UniquePtr<[]>| doesn't convert to the
underlying pointer type implicitly. This is a problem for the daemon-socket
runnable, which depend on this feature when calling their operations. To
solve this issue, the patch adds |ConvertArg| for each arguemnt, which does
the conversion explicitly.
This commit is contained in:
Thomas Zimmermann 2016-02-29 12:15:08 +01:00
parent 83da4d603d
commit 0fc8c3e5a1
8 changed files with 101 additions and 46 deletions

View File

@ -550,7 +550,7 @@ public:
nsresult
operator () (uint8_t& aArg1,
nsAutoArrayPtr<BluetoothAvrcpPlayerAttribute>& aArg2) const
UniquePtr<BluetoothAvrcpPlayerAttribute[]>& aArg2) const
{
DaemonSocketPDU& pdu = GetPDU();
@ -591,7 +591,7 @@ public:
nsresult
operator () (uint8_t& aArg1,
nsAutoArrayPtr<BluetoothAvrcpPlayerAttribute>& aArg2) const
UniquePtr<BluetoothAvrcpPlayerAttribute[]>& aArg2) const
{
DaemonSocketPDU& pdu = GetPDU();
@ -632,7 +632,7 @@ public:
nsresult
operator () (uint8_t& aArg1, uint8_t& aArg2,
nsAutoArrayPtr<uint8_t>& aArg3) const
UniquePtr<uint8_t[]>& aArg3) const
{
DaemonSocketPDU& pdu = GetPDU();
@ -687,7 +687,7 @@ public:
nsresult
operator () (uint8_t& aArg1,
nsAutoArrayPtr<BluetoothAvrcpMediaAttribute>& aArg2) const
UniquePtr<BluetoothAvrcpMediaAttribute[]>& aArg2) const
{
DaemonSocketPDU& pdu = GetPDU();

View File

@ -199,19 +199,19 @@ protected:
typedef mozilla::ipc::DaemonNotificationRunnable2<
NotificationHandlerWrapper, void, uint8_t,
nsAutoArrayPtr<BluetoothAvrcpPlayerAttribute>,
UniquePtr<BluetoothAvrcpPlayerAttribute[]>,
uint8_t, const BluetoothAvrcpPlayerAttribute*>
GetPlayerAppValueNotification;
typedef mozilla::ipc::DaemonNotificationRunnable2<
NotificationHandlerWrapper, void, uint8_t,
nsAutoArrayPtr<BluetoothAvrcpPlayerAttribute>,
UniquePtr<BluetoothAvrcpPlayerAttribute[]>,
uint8_t, const BluetoothAvrcpPlayerAttribute*>
GetPlayerAppAttrsTextNotification;
typedef mozilla::ipc::DaemonNotificationRunnable3<
NotificationHandlerWrapper, void, uint8_t, uint8_t,
nsAutoArrayPtr<uint8_t>, uint8_t, uint8_t, const uint8_t*>
UniquePtr<uint8_t[]>, uint8_t, uint8_t, const uint8_t*>
GetPlayerAppValuesTextNotification;
typedef mozilla::ipc::DaemonNotificationRunnable1<
@ -221,7 +221,7 @@ protected:
typedef mozilla::ipc::DaemonNotificationRunnable2<
NotificationHandlerWrapper, void, uint8_t,
nsAutoArrayPtr<BluetoothAvrcpMediaAttribute>,
UniquePtr<BluetoothAvrcpMediaAttribute[]>,
uint8_t, const BluetoothAvrcpMediaAttribute*>
GetElementAttrNotification;

View File

@ -796,7 +796,7 @@ public:
nsresult
operator () (BluetoothStatus& aArg1, int& aArg2,
nsAutoArrayPtr<BluetoothProperty>& aArg3) const
UniquePtr<BluetoothProperty[]>& aArg3) const
{
DaemonSocketPDU& pdu = GetPDU();
@ -845,7 +845,7 @@ public:
nsresult
operator () (BluetoothStatus& aArg1, BluetoothAddress& aArg2, int& aArg3,
nsAutoArrayPtr<BluetoothProperty>& aArg4) const
UniquePtr<BluetoothProperty[]>& aArg4) const
{
DaemonSocketPDU& pdu = GetPDU();
@ -899,7 +899,7 @@ public:
{ }
nsresult
operator () (int& aArg1, nsAutoArrayPtr<BluetoothProperty>& aArg2) const
operator () (int& aArg1, UniquePtr<BluetoothProperty[]>& aArg2) const
{
DaemonSocketPDU& pdu = GetPDU();
@ -986,7 +986,7 @@ public:
{ }
nsresult
operator () (uint16_t& aArg1, nsAutoArrayPtr<uint8_t>& aArg2,
operator () (uint16_t& aArg1, UniquePtr<uint8_t[]>& aArg2,
uint8_t& aArg3) const
{
DaemonSocketPDU& pdu = GetPDU();

View File

@ -244,18 +244,18 @@ private:
typedef mozilla::ipc::DaemonNotificationRunnable3<
NotificationHandlerWrapper, void, BluetoothStatus, int,
nsAutoArrayPtr<BluetoothProperty>, BluetoothStatus, int,
UniquePtr<BluetoothProperty[]>, BluetoothStatus, int,
const BluetoothProperty*>
AdapterPropertiesNotification;
typedef mozilla::ipc::DaemonNotificationRunnable4<
NotificationHandlerWrapper, void, BluetoothStatus, BluetoothAddress, int,
nsAutoArrayPtr<BluetoothProperty>, BluetoothStatus,
UniquePtr<BluetoothProperty[]>, BluetoothStatus,
const BluetoothAddress&, int, const BluetoothProperty*>
RemoteDevicePropertiesNotification;
typedef mozilla::ipc::DaemonNotificationRunnable2<
NotificationHandlerWrapper, void, int, nsAutoArrayPtr<BluetoothProperty>,
NotificationHandlerWrapper, void, int, UniquePtr<BluetoothProperty[]>,
int, const BluetoothProperty*>
DeviceFoundNotification;
@ -288,7 +288,7 @@ private:
AclStateChangedNotification;
typedef mozilla::ipc::DaemonNotificationRunnable3<
NotificationHandlerWrapper, void, uint16_t, nsAutoArrayPtr<uint8_t>,
NotificationHandlerWrapper, void, uint16_t, UniquePtr<uint8_t[]>,
uint8_t, uint16_t, const uint8_t*>
DutModeRecvNotification;

View File

@ -1972,7 +1972,7 @@ public:
BluetoothAttributeHandle& aArg4,
int& aArg5,
int& aArg6,
nsAutoArrayPtr<uint8_t>& aArg7,
UniquePtr<uint8_t[]>& aArg7,
bool& aArg8,
bool& aArg9) const
{

View File

@ -653,7 +653,7 @@ protected:
typedef mozilla::ipc::DaemonNotificationRunnable9<
NotificationHandlerWrapper, void,
int, int, BluetoothAddress, BluetoothAttributeHandle,
int, int, nsAutoArrayPtr<uint8_t>, bool, bool,
int, int, UniquePtr<uint8_t[]>, bool, bool,
int, int, const BluetoothAddress&, const BluetoothAttributeHandle&,
int, int, const uint8_t*, bool, bool>
ServerRequestWriteNotification;

View File

@ -8,11 +8,35 @@
#define mozilla_ipc_DaemonRunnables_h
#include "mozilla/unused.h"
#include "mozilla/UniquePtr.h"
#include "nsThreadUtils.h"
namespace mozilla {
namespace ipc {
namespace details {
class DaemonRunnable : public nsRunnable
{
protected:
DaemonRunnable() = default;
virtual ~DaemonRunnable() = default;
template<typename Out, typename In>
static Out& ConvertArg(In& aArg)
{
return aArg;
}
template<typename Out, typename In>
static Out ConvertArg(UniquePtr<In>& aArg)
{
return aArg.get();
}
};
} // namespace detail
//
// Result handling
//
@ -30,7 +54,7 @@ namespace ipc {
//
template <typename Obj, typename Res>
class DaemonResultRunnable0 final : public nsRunnable
class DaemonResultRunnable0 final : public details::DaemonRunnable
{
public:
typedef DaemonResultRunnable0<Obj, Res> SelfType;
@ -86,7 +110,7 @@ private:
};
template <typename Obj, typename Res, typename Tin1, typename Arg1>
class DaemonResultRunnable1 final : public nsRunnable
class DaemonResultRunnable1 final : public details::DaemonRunnable
{
public:
typedef DaemonResultRunnable1<Obj, Res, Tin1, Arg1> SelfType;
@ -118,7 +142,7 @@ public:
NS_IMETHODIMP Run() override
{
((*mObj).*mMethod)(mArg1);
((*mObj).*mMethod)(ConvertArg<Arg1>(mArg1));
return NS_OK;
}
@ -145,7 +169,7 @@ private:
template <typename Obj, typename Res,
typename Tin1, typename Tin2, typename Tin3,
typename Arg1, typename Arg2, typename Arg3>
class DaemonResultRunnable3 final : public nsRunnable
class DaemonResultRunnable3 final : public details::DaemonRunnable
{
public:
typedef DaemonResultRunnable3<Obj, Res,
@ -181,7 +205,9 @@ public:
NS_IMETHODIMP Run() override
{
((*mObj).*mMethod)(mArg1, mArg2, mArg3);
((*mObj).*mMethod)(ConvertArg<Arg1>(mArg1),
ConvertArg<Arg2>(mArg2),
ConvertArg<Arg3>(mArg3));
return NS_OK;
}
@ -226,7 +252,7 @@ private:
//
template <typename ObjectWrapper, typename Res>
class DaemonNotificationRunnable0 final : public nsRunnable
class DaemonNotificationRunnable0 final : public details::DaemonRunnable
{
public:
typedef typename ObjectWrapper::ObjectType ObjectType;
@ -285,7 +311,7 @@ private:
template <typename ObjectWrapper, typename Res,
typename Tin1, typename Arg1=Tin1>
class DaemonNotificationRunnable1 final : public nsRunnable
class DaemonNotificationRunnable1 final : public details::DaemonRunnable
{
public:
typedef typename ObjectWrapper::ObjectType ObjectType;
@ -322,7 +348,7 @@ public:
if (!obj) {
NS_WARNING("Notification handler not initialized");
} else {
((*obj).*mMethod)(mArg1);
((*obj).*mMethod)(ConvertArg<Arg1>(mArg1));
}
return NS_OK;
}
@ -351,7 +377,7 @@ private:
template <typename ObjectWrapper, typename Res,
typename Tin1, typename Tin2,
typename Arg1=Tin1, typename Arg2=Tin2>
class DaemonNotificationRunnable2 final : public nsRunnable
class DaemonNotificationRunnable2 final : public details::DaemonRunnable
{
public:
typedef typename ObjectWrapper::ObjectType ObjectType;
@ -389,7 +415,8 @@ public:
if (!obj) {
NS_WARNING("Notification handler not initialized");
} else {
((*obj).*mMethod)(mArg1, mArg2);
((*obj).*mMethod)(ConvertArg<Arg1>(mArg1),
ConvertArg<Arg2>(mArg2));
}
return NS_OK;
}
@ -420,7 +447,7 @@ private:
template <typename ObjectWrapper, typename Res,
typename Tin1, typename Tin2, typename Tin3,
typename Arg1=Tin1, typename Arg2=Tin2, typename Arg3=Tin3>
class DaemonNotificationRunnable3 final : public nsRunnable
class DaemonNotificationRunnable3 final : public details::DaemonRunnable
{
public:
typedef typename ObjectWrapper::ObjectType ObjectType;
@ -459,7 +486,9 @@ public:
if (!obj) {
NS_WARNING("Notification handler not initialized");
} else {
((*obj).*mMethod)(mArg1, mArg2, mArg3);
((*obj).*mMethod)(ConvertArg<Arg1>(mArg1),
ConvertArg<Arg2>(mArg2),
ConvertArg<Arg3>(mArg3));
}
return NS_OK;
}
@ -492,7 +521,7 @@ template <typename ObjectWrapper, typename Res,
typename Tin1, typename Tin2, typename Tin3, typename Tin4,
typename Arg1=Tin1, typename Arg2=Tin2,
typename Arg3=Tin3, typename Arg4=Tin4>
class DaemonNotificationRunnable4 final : public nsRunnable
class DaemonNotificationRunnable4 final : public details::DaemonRunnable
{
public:
typedef typename ObjectWrapper::ObjectType ObjectType;
@ -531,7 +560,10 @@ public:
if (!obj) {
NS_WARNING("Notification handler not initialized");
} else {
((*obj).*mMethod)(mArg1, mArg2, mArg3, mArg4);
((*obj).*mMethod)(ConvertArg<Arg1>(mArg1),
ConvertArg<Arg2>(mArg2),
ConvertArg<Arg3>(mArg3),
ConvertArg<Arg4>(mArg4));
}
return NS_OK;
}
@ -566,7 +598,7 @@ template <typename ObjectWrapper, typename Res,
typename Tin4, typename Tin5,
typename Arg1=Tin1, typename Arg2=Tin2, typename Arg3=Tin3,
typename Arg4=Tin4, typename Arg5=Tin5>
class DaemonNotificationRunnable5 final : public nsRunnable
class DaemonNotificationRunnable5 final : public details::DaemonRunnable
{
public:
typedef typename ObjectWrapper::ObjectType ObjectType;
@ -605,7 +637,11 @@ public:
if (!obj) {
NS_WARNING("Notification handler not initialized");
} else {
((*obj).*mMethod)(mArg1, mArg2, mArg3, mArg4, mArg5);
((*obj).*mMethod)(ConvertArg<Arg1>(mArg1),
ConvertArg<Arg2>(mArg2),
ConvertArg<Arg3>(mArg3),
ConvertArg<Arg4>(mArg4),
ConvertArg<Arg5>(mArg5));
}
return NS_OK;
}
@ -641,7 +677,7 @@ template <typename ObjectWrapper, typename Res,
typename Tin4, typename Tin5, typename Tin6,
typename Arg1=Tin1, typename Arg2=Tin2, typename Arg3=Tin3,
typename Arg4=Tin4, typename Arg5=Tin5, typename Arg6=Tin6>
class DaemonNotificationRunnable6 final : public nsRunnable
class DaemonNotificationRunnable6 final : public details::DaemonRunnable
{
public:
typedef typename ObjectWrapper::ObjectType ObjectType;
@ -681,7 +717,12 @@ public:
if (!obj) {
NS_WARNING("Notification handler not initialized");
} else {
((*obj).*mMethod)(mArg1, mArg2, mArg3, mArg4, mArg5, mArg6);
((*obj).*mMethod)(ConvertArg<Arg1>(mArg1),
ConvertArg<Arg2>(mArg2),
ConvertArg<Arg3>(mArg3),
ConvertArg<Arg4>(mArg4),
ConvertArg<Arg5>(mArg5),
ConvertArg<Arg6>(mArg6));
}
return NS_OK;
}
@ -720,7 +761,7 @@ template <typename ObjectWrapper, typename Res,
typename Arg1=Tin1, typename Arg2=Tin2, typename Arg3=Tin3,
typename Arg4=Tin4, typename Arg5=Tin5, typename Arg6=Tin6,
typename Arg7=Tin7, typename Arg8=Tin8>
class DaemonNotificationRunnable8 final : public nsRunnable
class DaemonNotificationRunnable8 final : public details::DaemonRunnable
{
public:
typedef typename ObjectWrapper::ObjectType ObjectType;
@ -763,8 +804,14 @@ public:
if (!obj) {
NS_WARNING("Notification handler not initialized");
} else {
((*obj).*mMethod)(mArg1, mArg2, mArg3, mArg4,
mArg5, mArg6, mArg7, mArg8);
((*obj).*mMethod)(ConvertArg<Arg1>(mArg1),
ConvertArg<Arg2>(mArg2),
ConvertArg<Arg3>(mArg3),
ConvertArg<Arg4>(mArg4),
ConvertArg<Arg5>(mArg5),
ConvertArg<Arg6>(mArg6),
ConvertArg<Arg7>(mArg7),
ConvertArg<Arg8>(mArg8));
}
return NS_OK;
}
@ -808,7 +855,7 @@ template <typename ObjectWrapper, typename Res,
typename Arg1=Tin1, typename Arg2=Tin2, typename Arg3=Tin3,
typename Arg4=Tin4, typename Arg5=Tin5, typename Arg6=Tin6,
typename Arg7=Tin7, typename Arg8=Tin8, typename Arg9=Tin9>
class DaemonNotificationRunnable9 final : public nsRunnable
class DaemonNotificationRunnable9 final : public details::DaemonRunnable
{
public:
typedef typename ObjectWrapper::ObjectType ObjectType;
@ -851,8 +898,15 @@ public:
if (!obj) {
NS_WARNING("Notification handler not initialized");
} else {
((*obj).*mMethod)(mArg1, mArg2, mArg3, mArg4,
mArg5, mArg6, mArg7, mArg8, mArg9);
((*obj).*mMethod)(ConvertArg<Arg1>(mArg1),
ConvertArg<Arg2>(mArg2),
ConvertArg<Arg3>(mArg3),
ConvertArg<Arg4>(mArg4),
ConvertArg<Arg5>(mArg5),
ConvertArg<Arg6>(mArg6),
ConvertArg<Arg7>(mArg7),
ConvertArg<Arg8>(mArg8),
ConvertArg<Arg9>(mArg9));
}
return NS_OK;
}

View File

@ -9,6 +9,7 @@
#include <stdint.h>
#include "mozilla/ipc/DaemonSocketPDU.h"
#include "mozilla/UniquePtr.h"
#include "nsString.h"
namespace mozilla {
@ -786,19 +787,19 @@ struct UnpackArray
, mLength(aLength)
{ }
UnpackArray(nsAutoArrayPtr<T>& aData, size_t aLength)
UnpackArray(UniquePtr<T[]>& aData, size_t aLength)
: mData(nullptr)
, mLength(aLength)
{
aData = new T[mLength];
aData.reset(new T[mLength]);
mData = aData.get();
}
UnpackArray(nsAutoArrayPtr<T>& aData, size_t aSize, size_t aElemSize)
UnpackArray(UniquePtr<T>& aData, size_t aSize, size_t aElemSize)
: mData(nullptr)
, mLength(aSize / aElemSize)
{
aData = new T[mLength];
aData.reset(new T[mLength]);
mData = aData.get();
}