Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/tests/analyzer.c | 11 ++++------- dlls/dwrite/tests/font.c | 35 +++++++++++++++++++---------------- dlls/dwrite/tests/layout.c | 14 ++++++-------- 3 files changed, 29 insertions(+), 31 deletions(-)
diff --git a/dlls/dwrite/tests/analyzer.c b/dlls/dwrite/tests/analyzer.c index 875503ed5a3..d1d44c94012 100644 --- a/dlls/dwrite/tests/analyzer.c +++ b/dlls/dwrite/tests/analyzer.c @@ -134,16 +134,13 @@ static void add_call(struct call_sequence **seq, int sequence_index, const struc if (!call_seq->sequence) { call_seq->size = 10; - call_seq->sequence = HeapAlloc(GetProcessHeap(), 0, - call_seq->size * sizeof (struct call_entry)); + call_seq->sequence = malloc(call_seq->size * sizeof(*call_seq->sequence)); }
if (call_seq->count == call_seq->size) { call_seq->size *= 2; - call_seq->sequence = HeapReAlloc(GetProcessHeap(), 0, - call_seq->sequence, - call_seq->size * sizeof (struct call_entry)); + call_seq->sequence = realloc(call_seq->sequence, call_seq->size * sizeof(*call_seq->sequence)); }
assert(call_seq->sequence); @@ -155,7 +152,7 @@ static inline void flush_sequence(struct call_sequence **seg, int sequence_index { struct call_sequence *call_seq = seg[sequence_index];
- HeapFree(GetProcessHeap(), 0, call_seq->sequence); + free(call_seq->sequence); call_seq->sequence = NULL; call_seq->count = call_seq->size = 0; } @@ -165,7 +162,7 @@ static void init_call_sequences(struct call_sequence **seq, int n) int i;
for (i = 0; i < n; i++) - seq[i] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct call_sequence)); + seq[i] = calloc(1, sizeof(*seq[i])); }
static void test_uint(UINT32 actual, UINT32 expected, const char *name, const struct testcontext *ctxt) diff --git a/dlls/dwrite/tests/font.c b/dlls/dwrite/tests/font.c index 26f94a1e3b1..10722fee444 100644 --- a/dlls/dwrite/tests/font.c +++ b/dlls/dwrite/tests/font.c @@ -783,11 +783,13 @@ static ULONG WINAPI fontdatastream_AddRef(IDWriteFontFileStream *iface)
static ULONG WINAPI fontdatastream_Release(IDWriteFontFileStream *iface) { - struct test_fontdatastream *This = impl_from_IDWriteFontFileStream(iface); - ULONG ref = InterlockedDecrement(&This->ref); - if (ref == 0) - HeapFree(GetProcessHeap(), 0, This); - return ref; + struct test_fontdatastream *stream = impl_from_IDWriteFontFileStream(iface); + ULONG refcount = InterlockedDecrement(&stream->ref); + + if (!refcount) + free(stream); + + return refcount; }
static HRESULT WINAPI fontdatastream_ReadFileFragment(IDWriteFontFileStream *iface, void const **fragment_start, UINT64 offset, UINT64 fragment_size, void **fragment_context) @@ -836,16 +838,17 @@ static const IDWriteFontFileStreamVtbl fontdatastreamvtbl =
static HRESULT create_fontdatastream(LPVOID data, UINT size, IDWriteFontFileStream** iface) { - struct test_fontdatastream *This = HeapAlloc(GetProcessHeap(), 0, sizeof(struct test_fontdatastream)); - if (!This) + struct test_fontdatastream *object = calloc(1, sizeof(*object)); + if (!object) return E_OUTOFMEMORY;
- This->data = data; - This->size = size; - This->ref = 1; - This->IDWriteFontFileStream_iface.lpVtbl = &fontdatastreamvtbl; + object->IDWriteFontFileStream_iface.lpVtbl = &fontdatastreamvtbl; + object->ref = 1; + object->data = data; + object->size = size; + + *iface = &object->IDWriteFontFileStream_iface;
- *iface = &This->IDWriteFontFileStream_iface; return S_OK; }
@@ -6014,7 +6017,7 @@ static void test_CreateGlyphRunAnalysis(void) ok(!IsRectEmpty(&rect), "Unexpected empty bbox.\n");
size = (rect.right - rect.left) * (rect.bottom - rect.top); - bits = HeapAlloc(GetProcessHeap(), 0, size); + bits = malloc(size);
hr = IDWriteGlyphRunAnalysis_CreateAlphaTexture(analysis, DWRITE_TEXTURE_ALIASED_1x1, &rect, bits, size); ok(hr == S_OK, "Failed to get alpha texture, hr %#x.\n", hr); @@ -6029,7 +6032,7 @@ static void test_CreateGlyphRunAnalysis(void) todo_wine ok(hr == DWRITE_E_UNSUPPORTEDOPERATION, "Unexpected hr %#x.\n", hr);
- HeapFree(GetProcessHeap(), 0, bits); + free(bits);
hr = IDWriteFactory_CreateCustomRenderingParams(factory, 0.1f, 0.0f, 1.0f, DWRITE_PIXEL_GEOMETRY_FLAT, DWRITE_RENDERING_MODE_NATURAL, ¶ms); @@ -6095,7 +6098,7 @@ static void test_CreateGlyphRunAnalysis(void) ok(!IsRectEmpty(&rect), "Unexpected empty bbox.\n");
size = (rect.right - rect.left) * (rect.bottom - rect.top); - bits = HeapAlloc(GetProcessHeap(), 0, size); + bits = malloc(size);
hr = IDWriteGlyphRunAnalysis_CreateAlphaTexture(analysis, DWRITE_TEXTURE_ALIASED_1x1, &rect, bits, size); ok(hr == S_OK, "Failed to get alpha texture, hr %#x.\n", hr); @@ -6110,7 +6113,7 @@ static void test_CreateGlyphRunAnalysis(void) todo_wine ok(hr == DWRITE_E_UNSUPPORTEDOPERATION, "Unexpected hr %#x.\n", hr);
- HeapFree(GetProcessHeap(), 0, bits); + free(bits);
IDWriteGlyphRunAnalysis_Release(analysis);
diff --git a/dlls/dwrite/tests/layout.c b/dlls/dwrite/tests/layout.c index 3a6add954d9..95166376ac7 100644 --- a/dlls/dwrite/tests/layout.c +++ b/dlls/dwrite/tests/layout.c @@ -343,14 +343,12 @@ static void add_call(struct drawcall_sequence **seq, int sequence_index, const s
if (!call_seq->sequence) { call_seq->size = 10; - call_seq->sequence = HeapAlloc(GetProcessHeap(), 0, call_seq->size * sizeof (struct drawcall_entry)); + call_seq->sequence = malloc(call_seq->size * sizeof(*call_seq->sequence)); }
if (call_seq->count == call_seq->size) { call_seq->size *= 2; - call_seq->sequence = HeapReAlloc(GetProcessHeap(), 0, - call_seq->sequence, - call_seq->size * sizeof (struct drawcall_entry)); + call_seq->sequence = realloc(call_seq->sequence, call_seq->size * sizeof(*call_seq->sequence)); }
assert(call_seq->sequence); @@ -361,7 +359,7 @@ static inline void flush_sequence(struct drawcall_sequence **seg, int sequence_i { struct drawcall_sequence *call_seq = seg[sequence_index];
- HeapFree(GetProcessHeap(), 0, call_seq->sequence); + free(call_seq->sequence); call_seq->sequence = NULL; call_seq->count = call_seq->size = 0; } @@ -371,7 +369,7 @@ static void init_call_sequences(struct drawcall_sequence **seq, int n) int i;
for (i = 0; i < n; i++) - seq[i] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct drawcall_sequence)); + seq[i] = calloc(1, sizeof(*seq[i])); }
static void ok_sequence_(struct drawcall_sequence **seq, int sequence_index, @@ -879,7 +877,7 @@ static ULONG WINAPI testeffect_Release(IUnknown *iface) LONG ref = InterlockedDecrement(&effect->ref);
if (!ref) - HeapFree(GetProcessHeap(), 0, effect); + free(effect);
return ref; } @@ -894,7 +892,7 @@ static IUnknown *create_test_effect(void) { struct test_effect *effect;
- effect = HeapAlloc(GetProcessHeap(), 0, sizeof(*effect)); + effect = calloc(1, sizeof(*effect)); effect->IUnknown_iface.lpVtbl = &testeffectvtbl; effect->ref = 1;
Hello folks,
* On 2022-01-28 10:29, Nikolay Sivov wrote:
--- a/dlls/dwrite/tests/analyzer.c +++ b/dlls/dwrite/tests/analyzer.c
...
@@ -155,7 +152,7 @@ static inline void flush_sequence(struct call_sequence **seg, int sequence_index { struct call_sequence *call_seq = seg[sequence_index];
- HeapFree(GetProcessHeap(), 0, call_seq->sequence);
- free(call_seq->sequence); call_seq->sequence = NULL; call_seq->count = call_seq->size = 0;
}
may I ask: what's about all the HeapAlloc() => malloc() huss inside the test (or any tests) ? 15y ago the idea was to use as much of WinAPI as possible (at least in DLLs implementation). I say the project is splitting modules into PE-part and the *nix-part these days. Looks nice.
But why to reverse the HeapAlloc() usage in tests?
S.
Saulius Krasuckas saulius2@ar-fi.lt writes:
Hello folks,
- On 2022-01-28 10:29, Nikolay Sivov wrote:
--- a/dlls/dwrite/tests/analyzer.c +++ b/dlls/dwrite/tests/analyzer.c
...
@@ -155,7 +152,7 @@ static inline void flush_sequence(struct call_sequence **seg, int sequence_index { struct call_sequence *call_seq = seg[sequence_index];
- HeapFree(GetProcessHeap(), 0, call_seq->sequence);
- free(call_seq->sequence); call_seq->sequence = NULL; call_seq->count = call_seq->size = 0;
}
may I ask: what's about all the HeapAlloc() => malloc() huss inside the test (or any tests) ? 15y ago the idea was to use as much of WinAPI as possible (at least in DLLs implementation). I say the project is splitting modules into PE-part and the *nix-part these days. Looks nice.
But why to reverse the HeapAlloc() usage in tests?
For all modules that have been converted to PE, malloc() is now also going through the Windows API, so there's no longer a reason to avoid it. And it's more standard and more readable than HeapAlloc().