On 13 February 2014 13:05, Martin Storsjo martin@martin.st wrote:
static HRESULT arbfp_blit_alloc(struct wined3d_device *device) {
- struct arbfp_blit_priv *priv; device->blit_priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct arbfp_blit_priv)); if(!device->blit_priv) { ERR("Out of memory\n"); return E_OUTOFMEMORY; }
- priv = device->blit_priv;
- if (wine_rb_init(&priv->shaders, &wined3d_arbfp_blit_rb_functions) == -1)
- {
ERR("Failed to initialize rbtree.\n");
HeapFree(GetProcessHeap(), 0, device->blit_priv);
device->blit_priv = NULL;
return E_OUTOFMEMORY;
- }
- return WINED3D_OK;
}
The following is probably slightly nicer:
static HRESULT arbfp_blit_alloc(struct wined3d_device *device) { - device->blit_priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct arbfp_blit_priv)); - if(!device->blit_priv) { - ERR("Out of memory\n"); + struct arbfp_blit_priv *priv; + + if (!(priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*priv)))) return E_OUTOFMEMORY; + + if (wine_rb_init(&priv->shaders, &wined3d_arbfp_blit_rb_functions) == -1) + { + ERR("Failed to initialize rbtree.\n"); + HeapFree(GetProcessHeap(), 0, priv); + return E_FAIL; } + + device->blit_priv = priv; + return WINED3D_OK; }
- if (desc)
HeapFree(GetProcessHeap(), 0, desc);
There's no point in checking for NULL before HeapFree(). Perhaps more importantly, I think it makes more sense to insert the rbtree entries in arbfp_blit_set(), instead of duplicating the code between gen_p8_shader() and gen_yuv_shader().
On Fri, 14 Feb 2014, Henri Verbeet wrote:
On 13 February 2014 13:05, Martin Storsjo martin@martin.st wrote:
static HRESULT arbfp_blit_alloc(struct wined3d_device *device) {
- struct arbfp_blit_priv *priv; device->blit_priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct arbfp_blit_priv)); if(!device->blit_priv) { ERR("Out of memory\n"); return E_OUTOFMEMORY; }
- priv = device->blit_priv;
- if (wine_rb_init(&priv->shaders, &wined3d_arbfp_blit_rb_functions) == -1)
- {
ERR("Failed to initialize rbtree.\n");
HeapFree(GetProcessHeap(), 0, device->blit_priv);
device->blit_priv = NULL;
return E_OUTOFMEMORY;
- }
- return WINED3D_OK;
}
The following is probably slightly nicer:
static HRESULT arbfp_blit_alloc(struct wined3d_device *device) {
- device->blit_priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(struct arbfp_blit_priv));
- if(!device->blit_priv) {
ERR("Out of memory\n");
- struct arbfp_blit_priv *priv;
- if (!(priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*priv)))) return E_OUTOFMEMORY;
- if (wine_rb_init(&priv->shaders, &wined3d_arbfp_blit_rb_functions) == -1)
- {
ERR("Failed to initialize rbtree.\n");
HeapFree(GetProcessHeap(), 0, priv);
}return E_FAIL;
- device->blit_priv = priv;
- return WINED3D_OK;
}
That's nicer indeed, updated the patch accordingly locally.
- if (desc)
HeapFree(GetProcessHeap(), 0, desc);
There's no point in checking for NULL before HeapFree().
MSDN says "If this pointer is NULL, the behavior is undefined" about the lpMem parameter to HeapFree.
Perhaps more importantly, I think it makes more sense to insert the rbtree entries in arbfp_blit_set(), instead of duplicating the code between gen_p8_shader() and gen_yuv_shader().
Good point, I've updated my patch accordingly.
I'll resend all three patches in a little while unless you or Stefan have got more comments at the moment.
// Martin
On Mon, Feb 17, 2014 at 9:21 AM, Martin Storsjö martin@martin.st wrote:
- if (desc)
HeapFree(GetProcessHeap(), 0, desc);
There's no point in checking for NULL before HeapFree().
MSDN says "If this pointer is NULL, the behavior is undefined" about the lpMem parameter to HeapFree.
Actually it does not matter what MSDN says in this case, the wine source code is very clear: http://source.winehq.org/source/dlls/ntdll/heap.c#L1740
// Martin
Bruno
On Mon, 17 Feb 2014, Bruno Jesus wrote:
On Mon, Feb 17, 2014 at 9:21 AM, Martin Storsjö martin@martin.st wrote:
- if (desc)
HeapFree(GetProcessHeap(), 0, desc);
There's no point in checking for NULL before HeapFree().
MSDN says "If this pointer is NULL, the behavior is undefined" about the lpMem parameter to HeapFree.
Actually it does not matter what MSDN says in this case, the wine source code is very clear: http://source.winehq.org/source/dlls/ntdll/heap.c#L1740
Yes, but isn't the wined3d code supposed to be able to run on top of plain windows as well, not only on top of wine?
// Martin
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Am 2014-02-17 13:29, schrieb Martin Storsjö:
Yes, but isn't the wined3d code supposed to be able to run on top of plain windows as well, not only on top of wine?
Yes, but Windows behaves the same way. We should have tests for that somewhere in kernel32/tests, and all our code (tests and otherwise) assumes that HeapFree(, , NULL) is a no-op.
On Mon, 17 Feb 2014, Stefan Dösinger wrote:
Am 2014-02-17 13:29, schrieb Martin Storsjö:
Yes, but isn't the wined3d code supposed to be able to run on top of plain windows as well, not only on top of wine?
Yes, but Windows behaves the same way. We should have tests for that somewhere in kernel32/tests, and all our code (tests and otherwise) assumes that HeapFree(, , NULL) is a no-op.
Ok then, that makes me more comfortable with doing it like that.
I've resent the set with the remaining patch taking all the comments into consideration now.
// Martin