Signed-off-by: Rémi Bernon <rbernon(a)codeweavers.com>
---
dlls/dinput/joystick_linux.c | 21 +++++++--------------
dlls/dinput/joystick_linuxinput.c | 15 ++++++++-------
dlls/dinput/joystick_osx.c | 21 +++++++--------------
dlls/dinput/keyboard.c | 15 +++++++++------
dlls/dinput/mouse.c | 16 +++++++++-------
5 files changed, 40 insertions(+), 48 deletions(-)
diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c
index a33b16454b0..14074bb176c 100644
--- a/dlls/dinput/joystick_linux.c
+++ b/dlls/dinput/joystick_linux.c
@@ -451,8 +451,7 @@ static HRESULT joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINS
return S_FALSE;
}
-static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
- JoystickImpl **pdev, unsigned short index)
+static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickImpl **out, unsigned short index )
{
DWORD i;
JoystickImpl* newDevice;
@@ -461,14 +460,10 @@ static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
int idx = 0;
DIDEVICEINSTANCEW ddi;
- TRACE("%s %p %p %hu\n", debugstr_guid(rguid), dinput, pdev, index);
+ TRACE( "%s %p %p %hu\n", debugstr_guid( rguid ), dinput, out, index );
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
- if (newDevice == 0) {
- WARN("out of memory\n");
- *pdev = 0;
- return DIERR_OUTOFMEMORY;
- }
+ if (!newDevice) return DIERR_OUTOFMEMORY;
newDevice->joydev = &joystick_devices[index];
newDevice->joyfd = -1;
@@ -564,8 +559,7 @@ static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
_dump_DIDEVCAPS(&newDevice->generic.devcaps);
}
- *pdev = newDevice;
-
+ *out = newDevice;
return DI_OK;
FAILED:
@@ -576,8 +570,6 @@ FAILED1:
release_DataFormat(&newDevice->generic.base.data_format);
HeapFree(GetProcessHeap(),0,newDevice->generic.axis_map);
HeapFree(GetProcessHeap(),0,newDevice);
- *pdev = 0;
-
return hr;
}
@@ -641,8 +633,9 @@ static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REF
return DIERR_NOINTERFACE;
}
- hr = alloc_device(rguid, dinput, &This, index);
- if (!This) return hr;
+ if (FAILED(hr = alloc_device( rguid, dinput, &This, index ))) return hr;
+
+ TRACE( "Created a Joystick device (%p)\n", This );
if (unicode)
*pdev = &This->generic.base.IDirectInputDevice8W_iface;
diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c
index 2e2c8a87261..95b2df81ece 100644
--- a/dlls/dinput/joystick_linuxinput.c
+++ b/dlls/dinput/joystick_linuxinput.c
@@ -444,7 +444,7 @@ static HRESULT joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINS
return S_FALSE;
}
-static JoystickImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput, unsigned short index)
+static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickImpl **out, unsigned short index )
{
JoystickImpl* newDevice;
LPDIDATAFORMAT df = NULL;
@@ -453,7 +453,7 @@ static JoystickImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput, unsig
DIDEVICEINSTANCEW ddi;
newDevice = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(JoystickImpl));
- if (!newDevice) return NULL;
+ if (!newDevice) return DIERR_OUTOFMEMORY;
newDevice->generic.base.IDirectInputDevice8A_iface.lpVtbl = &JoystickAvt;
newDevice->generic.base.IDirectInputDevice8W_iface.lpVtbl = &JoystickWvt;
@@ -584,14 +584,15 @@ static JoystickImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput, unsig
IDirectInput_AddRef(&newDevice->generic.base.dinput->IDirectInput7A_iface);
- return newDevice;
+ *out = newDevice;
+ return DI_OK;
failed:
if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
HeapFree(GetProcessHeap(), 0, df);
HeapFree(GetProcessHeap(), 0, newDevice->generic.axis_map);
HeapFree(GetProcessHeap(), 0, newDevice);
- return NULL;
+ return DIERR_OUTOFMEMORY;
}
/******************************************************************************
@@ -630,6 +631,7 @@ static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REF
have_joydevs && index < have_joydevs)
{
JoystickImpl *This;
+ HRESULT hr;
if (riid == NULL)
;/* nothing */
@@ -653,10 +655,9 @@ static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REF
return DIERR_NOINTERFACE;
}
- This = alloc_device(rguid, dinput, index);
- TRACE("Created a Joystick device (%p)\n", This);
+ if (FAILED(hr = alloc_device( rguid, dinput, &This, index ))) return hr;
- if (!This) return DIERR_OUTOFMEMORY;
+ TRACE( "Created a Joystick device (%p)\n", This );
if (unicode)
*pdev = &This->generic.base.IDirectInputDevice8W_iface;
diff --git a/dlls/dinput/joystick_osx.c b/dlls/dinput/joystick_osx.c
index e2212557180..65d0a4a36eb 100644
--- a/dlls/dinput/joystick_osx.c
+++ b/dlls/dinput/joystick_osx.c
@@ -1105,8 +1105,7 @@ static BOOL osx_axis_has_ff(FFCAPABILITIES *ffcaps, UInt8 axis)
return FALSE;
}
-static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
- JoystickImpl **pdev, unsigned short index)
+static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickImpl **out, unsigned short index )
{
DWORD i;
IOHIDDeviceRef device;
@@ -1119,14 +1118,10 @@ static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
int slider_count = 0;
FFCAPABILITIES ffcaps;
- TRACE("%s %p %p %hu\n", debugstr_guid(rguid), dinput, pdev, index);
+ TRACE( "%s %p %p %hu\n", debugstr_guid( rguid ), dinput, out, index );
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
- if (newDevice == 0) {
- WARN("out of memory\n");
- *pdev = 0;
- return DIERR_OUTOFMEMORY;
- }
+ if (!newDevice) return DIERR_OUTOFMEMORY;
newDevice->id = index;
@@ -1287,8 +1282,7 @@ static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
_dump_DIDEVCAPS(&newDevice->generic.devcaps);
}
- *pdev = newDevice;
-
+ *out = newDevice;
return DI_OK;
FAILED:
@@ -1300,8 +1294,6 @@ FAILED:
release_DataFormat(&newDevice->generic.base.data_format);
HeapFree(GetProcessHeap(),0,newDevice->generic.name);
HeapFree(GetProcessHeap(),0,newDevice);
- *pdev = 0;
-
return hr;
}
@@ -1380,8 +1372,9 @@ static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REF
return DIERR_NOINTERFACE;
}
- hr = alloc_device(rguid, dinput, &This, index);
- if (!This) return hr;
+ if (FAILED(hr = alloc_device( rguid, dinput, &This, index ))) return hr;
+
+ TRACE( "Created a Joystick device (%p)\n", This );
if (unicode)
*pdev = &This->generic.base.IDirectInputDevice8W_iface;
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c
index 9d4ceda3edc..e9fa9eb8cbc 100644
--- a/dlls/dinput/keyboard.c
+++ b/dlls/dinput/keyboard.c
@@ -240,13 +240,15 @@ static HRESULT keyboarddev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVI
return S_FALSE;
}
-static SysKeyboardImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput)
+static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysKeyboardImpl **out )
{
SysKeyboardImpl* newDevice;
LPDIDATAFORMAT df = NULL;
int i, idx = 0;
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysKeyboardImpl));
+ if (!newDevice) return DIERR_OUTOFMEMORY;
+
newDevice->base.IDirectInputDevice8A_iface.lpVtbl = &SysKeyboardAvt;
newDevice->base.IDirectInputDevice8W_iface.lpVtbl = &SysKeyboardWvt;
newDevice->base.ref = 1;
@@ -278,13 +280,14 @@ static SysKeyboardImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput)
newDevice->base.data_format.wine_df = df;
IDirectInput_AddRef(&newDevice->base.dinput->IDirectInput7A_iface);
- return newDevice;
+ *out = newDevice;
+ return DI_OK;
failed:
if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
HeapFree(GetProcessHeap(), 0, df);
HeapFree(GetProcessHeap(), 0, newDevice);
- return NULL;
+ return DIERR_OUTOFMEMORY;
}
@@ -296,6 +299,7 @@ static HRESULT keyboarddev_create_device(IDirectInputImpl *dinput, REFGUID rguid
if (IsEqualGUID(&GUID_SysKeyboard, rguid)) /* Wine Keyboard */
{
SysKeyboardImpl *This;
+ HRESULT hr;
if (riid == NULL)
;/* nothing */
@@ -319,10 +323,9 @@ static HRESULT keyboarddev_create_device(IDirectInputImpl *dinput, REFGUID rguid
return DIERR_NOINTERFACE;
}
- This = alloc_device(rguid, dinput);
- TRACE("Created a Keyboard device (%p)\n", This);
+ if (FAILED(hr = alloc_device( rguid, dinput, &This ))) return hr;
- if (!This) return DIERR_OUTOFMEMORY;
+ TRACE( "Created a Keyboard device (%p)\n", This );
if (unicode)
*pdev = &This->base.IDirectInputDevice8W_iface;
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c
index e5bd697a0ea..e789d260e5a 100644
--- a/dlls/dinput/mouse.c
+++ b/dlls/dinput/mouse.c
@@ -184,7 +184,7 @@ static HRESULT mousedev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEI
return S_FALSE;
}
-static SysMouseImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput)
+static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysMouseImpl **out )
{
SysMouseImpl* newDevice;
LPDIDATAFORMAT df = NULL;
@@ -193,7 +193,8 @@ static SysMouseImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput)
HKEY hkey, appkey;
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysMouseImpl));
- if (!newDevice) return NULL;
+ if (!newDevice) return DIERR_OUTOFMEMORY;
+
newDevice->base.IDirectInputDevice8A_iface.lpVtbl = &SysMouseAvt;
newDevice->base.IDirectInputDevice8W_iface.lpVtbl = &SysMouseWvt;
newDevice->base.ref = 1;
@@ -237,13 +238,14 @@ static SysMouseImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput)
newDevice->base.raw_device.usUsage = 2; /* HID generic mouse */
}
- return newDevice;
+ *out = newDevice;
+ return DI_OK;
failed:
if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
HeapFree(GetProcessHeap(), 0, df);
HeapFree(GetProcessHeap(), 0, newDevice);
- return NULL;
+ return DIERR_OUTOFMEMORY;
}
static HRESULT mousedev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPVOID *pdev, int unicode)
@@ -254,6 +256,7 @@ static HRESULT mousedev_create_device(IDirectInputImpl *dinput, REFGUID rguid, R
if (IsEqualGUID(&GUID_SysMouse, rguid)) /* Wine Mouse */
{
SysMouseImpl *This;
+ HRESULT hr;
if (riid == NULL)
;/* nothing */
@@ -277,10 +280,9 @@ static HRESULT mousedev_create_device(IDirectInputImpl *dinput, REFGUID rguid, R
return DIERR_NOINTERFACE;
}
- This = alloc_device(rguid, dinput);
- TRACE("Created a Mouse device (%p)\n", This);
+ if (FAILED(hr = alloc_device( rguid, dinput, &This ))) return hr;
- if (!This) return DIERR_OUTOFMEMORY;
+ TRACE( "Created a Mouse device (%p)\n", This );
if (unicode)
*pdev = &This->base.IDirectInputDevice8W_iface;
--
2.31.0