[02/10] webservices: Implement WsResetHeap.
Hans Leidekker
hans at codeweavers.com
Fri Apr 22 02:42:39 CDT 2016
Signed-off-by: Hans Leidekker <hans at codeweavers.com>
---
dlls/webservices/reader.c | 38 ++++++++++++++++----
dlls/webservices/tests/reader.c | 75 +++++++++++++++++++++++++++++++++++++++
dlls/webservices/webservices.spec | 2 +-
include/webservices.h | 1 +
4 files changed, 109 insertions(+), 7 deletions(-)
diff --git a/dlls/webservices/reader.c b/dlls/webservices/reader.c
index 555ab71..e30864d 100644
--- a/dlls/webservices/reader.c
+++ b/dlls/webservices/reader.c
@@ -157,33 +157,48 @@ struct heap
struct prop prop[sizeof(heap_props)/sizeof(heap_props[0])];
};
+static BOOL ensure_heap( struct heap *heap )
+{
+ SIZE_T size;
+ if (heap->handle) return TRUE;
+ if (prop_get( heap->prop, heap->prop_count, WS_HEAP_PROPERTY_MAX_SIZE, &size, sizeof(size) ) != S_OK)
+ return FALSE;
+ if (!(heap->handle = HeapCreate( 0, 0, size ))) return FALSE;
+ return TRUE;
+}
+
void *ws_alloc( WS_HEAP *handle, SIZE_T size )
{
struct heap *heap = (struct heap *)handle;
+ if (!ensure_heap( heap )) return NULL;
return HeapAlloc( heap->handle, 0, size );
}
static void *ws_alloc_zero( WS_HEAP *handle, SIZE_T size )
{
struct heap *heap = (struct heap *)handle;
+ if (!ensure_heap( heap )) return NULL;
return HeapAlloc( heap->handle, HEAP_ZERO_MEMORY, size );
}
void *ws_realloc( WS_HEAP *handle, void *ptr, SIZE_T size )
{
struct heap *heap = (struct heap *)handle;
+ if (!ensure_heap( heap )) return NULL;
return HeapReAlloc( heap->handle, 0, ptr, size );
}
static void *ws_realloc_zero( WS_HEAP *handle, void *ptr, SIZE_T size )
{
struct heap *heap = (struct heap *)handle;
+ if (!ensure_heap( heap )) return NULL;
return HeapReAlloc( heap->handle, HEAP_ZERO_MEMORY, ptr, size );
}
void ws_free( WS_HEAP *handle, void *ptr )
{
struct heap *heap = (struct heap *)handle;
+ if (!heap->handle) return;
HeapFree( heap->handle, 0, ptr );
}
@@ -233,12 +248,6 @@ HRESULT WINAPI WsCreateHeap( SIZE_T max_size, SIZE_T trim_size, const WS_HEAP_PR
prop_set( heap->prop, heap->prop_count, WS_HEAP_PROPERTY_MAX_SIZE, &max_size, sizeof(max_size) );
prop_set( heap->prop, heap->prop_count, WS_HEAP_PROPERTY_TRIM_SIZE, &trim_size, sizeof(trim_size) );
- if (!(heap->handle = HeapCreate( 0, 0, max_size )))
- {
- heap_free( heap );
- return E_OUTOFMEMORY;
- }
-
*handle = (WS_HEAP *)heap;
return S_OK;
}
@@ -257,6 +266,23 @@ void WINAPI WsFreeHeap( WS_HEAP *handle )
heap_free( heap );
}
+/**************************************************************************
+ * WsResetHeap [webservices.@]
+ */
+HRESULT WINAPI WsResetHeap( WS_HEAP *handle, WS_ERROR *error )
+{
+ struct heap *heap = (struct heap *)handle;
+
+ TRACE( "%p %p\n", handle, error );
+ if (error) FIXME( "ignoring error parameter\n" );
+
+ if (!heap) return E_INVALIDARG;
+
+ HeapDestroy( heap->handle );
+ heap->handle = NULL;
+ return S_OK;
+}
+
struct node *alloc_node( WS_XML_NODE_TYPE type )
{
struct node *ret;
diff --git a/dlls/webservices/tests/reader.c b/dlls/webservices/tests/reader.c
index 9b5face..5c94fef 100644
--- a/dlls/webservices/tests/reader.c
+++ b/dlls/webservices/tests/reader.c
@@ -2850,6 +2850,80 @@ static void test_repeating_element(void)
WsFreeHeap( heap );
}
+static void test_WsResetHeap(void)
+{
+ HRESULT hr;
+ WS_HEAP *heap;
+ SIZE_T requested, actual;
+ ULONG size;
+ void *ptr;
+
+ hr = WsCreateHeap( 1 << 16, 0, NULL, 0, &heap, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+
+ requested = 0xdeadbeef;
+ size = sizeof(requested);
+ hr = WsGetHeapProperty( heap, WS_HEAP_PROPERTY_REQUESTED_SIZE, &requested, size, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+ ok( !requested, "got %u\n", (ULONG)requested );
+
+ actual = 0xdeadbeef;
+ size = sizeof(actual);
+ hr = WsGetHeapProperty( heap, WS_HEAP_PROPERTY_ACTUAL_SIZE, &actual, size, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+ ok( !actual, "got %u\n", (ULONG)actual );
+
+ hr = WsAlloc( heap, 128, &ptr, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+
+ requested = 0xdeadbeef;
+ size = sizeof(requested);
+ hr = WsGetHeapProperty( heap, WS_HEAP_PROPERTY_REQUESTED_SIZE, &requested, size, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+ todo_wine ok( requested == 128, "got %u\n", (ULONG)requested );
+
+ actual = 0xdeadbeef;
+ size = sizeof(actual);
+ hr = WsGetHeapProperty( heap, WS_HEAP_PROPERTY_ACTUAL_SIZE, &actual, size, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+ todo_wine ok( actual == 128, "got %u\n", (ULONG)actual );
+
+ hr = WsAlloc( heap, 1, &ptr, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+
+ requested = 0xdeadbeef;
+ size = sizeof(requested);
+ hr = WsGetHeapProperty( heap, WS_HEAP_PROPERTY_REQUESTED_SIZE, &requested, size, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+ todo_wine ok( requested == 129, "got %u\n", (ULONG)requested );
+
+ actual = 0xdeadbeef;
+ size = sizeof(actual);
+ hr = WsGetHeapProperty( heap, WS_HEAP_PROPERTY_ACTUAL_SIZE, &actual, size, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+ todo_wine ok( actual == 384, "got %u\n", (ULONG)actual );
+
+ hr = WsResetHeap( NULL, NULL );
+ ok( hr == E_INVALIDARG, "got %08x\n", hr );
+
+ hr = WsResetHeap( heap, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+
+ requested = 0xdeadbeef;
+ size = sizeof(requested);
+ hr = WsGetHeapProperty( heap, WS_HEAP_PROPERTY_REQUESTED_SIZE, &requested, size, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+ ok( !requested, "got %u\n", (ULONG)requested );
+
+ actual = 0xdeadbeef;
+ size = sizeof(actual);
+ hr = WsGetHeapProperty( heap, WS_HEAP_PROPERTY_ACTUAL_SIZE, &actual, size, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+ todo_wine ok( actual == 128, "got %u\n", (ULONG)actual );
+
+ WsFreeHeap( heap );
+}
+
START_TEST(reader)
{
test_WsCreateError();
@@ -2874,4 +2948,5 @@ START_TEST(reader)
test_text_field_mapping();
test_complex_struct_type();
test_repeating_element();
+ test_WsResetHeap();
}
diff --git a/dlls/webservices/webservices.spec b/dlls/webservices/webservices.spec
index 001b3ca..8c3b999 100644
--- a/dlls/webservices/webservices.spec
+++ b/dlls/webservices/webservices.spec
@@ -135,7 +135,7 @@
@ stub WsRequestSecurityToken
@ stub WsResetChannel
@ stub WsResetError
-@ stub WsResetHeap
+@ stdcall WsResetHeap(ptr ptr)
@ stub WsResetListener
@ stub WsResetMessage
@ stub WsResetMetadata
diff --git a/include/webservices.h b/include/webservices.h
index bfc84e2..87035bc 100644
--- a/include/webservices.h
+++ b/include/webservices.h
@@ -955,6 +955,7 @@ HRESULT WINAPI WsReadToStartElement(WS_XML_READER*, const WS_XML_STRING*, const
BOOL*, WS_ERROR*);
HRESULT WINAPI WsReadType(WS_XML_READER*, WS_TYPE_MAPPING, WS_TYPE, const void*, WS_READ_OPTION,
WS_HEAP*, void*, ULONG, WS_ERROR*);
+HRESULT WINAPI WsResetHeap(WS_HEAP*, WS_ERROR*);
HRESULT WINAPI WsSetChannelProperty(WS_CHANNEL*, WS_CHANNEL_PROPERTY_ID, const void*, ULONG, WS_ERROR*);
HRESULT WINAPI WsSetErrorProperty(WS_ERROR*, WS_ERROR_PROPERTY_ID, const void*, ULONG);
HRESULT WINAPI WsSetInput(WS_XML_READER*, const WS_XML_READER_ENCODING*, const WS_XML_READER_INPUT*,
--
2.8.0.rc3
More information about the wine-patches
mailing list