webservices: Implement WsResetHeap.

Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hans Leidekker 2016-04-22 09:42:39 +02:00 committed by Alexandre Julliard
parent 19fecc4f21
commit 767056dc3e
4 changed files with 109 additions and 7 deletions

View File

@ -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;

View File

@ -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();
}

View File

@ -135,7 +135,7 @@
@ stub WsRequestSecurityToken
@ stub WsResetChannel
@ stub WsResetError
@ stub WsResetHeap
@ stdcall WsResetHeap(ptr ptr)
@ stub WsResetListener
@ stub WsResetMessage
@ stub WsResetMetadata

View File

@ -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*,