static HRESULT create_writer(IUnknown *stream, IMalloc *imalloc, xml_encoding encoding, IXmlWriterOutput **output) { xmlwriteroutput *writeroutput; HRESULT hr; *output = NULL; if (imalloc) writeroutput = IMalloc_Alloc(imalloc, sizeof(*writeroutput)); else writeroutput = heap_alloc(sizeof(*writeroutput)); if(!writeroutput) return E_OUTOFMEMORY; writeroutput->IXmlWriterOutput_iface.lpVtbl = &xmlwriteroutputvtbl; writeroutput->ref = 1; writeroutput->imalloc = imalloc; if (imalloc) IMalloc_AddRef(imalloc); writeroutput->encoding = encoding; writeroutput->stream = NULL; hr = init_output_buffer(writeroutput); if (FAILED(hr)) { IUnknown_Release(&writeroutput->IXmlWriterOutput_iface); return hr; } IUnknown_QueryInterface(stream, &IID_IUnknown, (void**)&writeroutput->output); *output = &writeroutput->IXmlWriterOutput_iface; TRACE("returning iface %p\n", *output); return S_OK; }
static void test_IMalloc(void) { LPVOID lpMem; ULONG ulRef; int iRet; HRESULT hRet; LPMALLOC lpMalloc; LPVOID lpVoid; pMAPIGetDefaultMalloc = (void*)GetProcAddress(hMapi32, "MAPIGetDefaultMalloc@0"); if (!pMAPIGetDefaultMalloc) { win_skip("MAPIGetDefaultMalloc is not available\n"); return; } lpMalloc = pMAPIGetDefaultMalloc(); ok(lpMalloc != NULL, "Expected MAPIGetDefaultMalloc to return non-NULL\n"); if (!lpMalloc) { skip("MAPIGetDefaultMalloc failed\n"); return; } lpVoid = NULL; hRet = IMalloc_QueryInterface(lpMalloc, &IID_IUnknown, &lpVoid); ok (hRet == S_OK && lpVoid != NULL, "IID_IUnknown: expected S_OK, non-null, got 0x%08x, %p\n", hRet, lpVoid); lpVoid = NULL; hRet = IMalloc_QueryInterface(lpMalloc, &IID_IMalloc, &lpVoid); ok (hRet == S_OK && lpVoid != NULL, "IID_IIMalloc: expected S_OK, non-null, got 0x%08x, %p\n", hRet, lpVoid); /* Prove that native mapi uses LocalAlloc/LocalFree */ lpMem = IMalloc_Alloc(lpMalloc, 61); ok (lpMem && IMalloc_GetSize(lpMalloc, lpMem) == LocalSize(lpMem), "Expected non-null, same size, got %p, %s size\n", lpMem, lpMem ? "different" : "same"); iRet = IMalloc_DidAlloc(lpMalloc, lpMem); ok (iRet == -1, "DidAlloc, expected -1. got %d\n", iRet); IMalloc_HeapMinimize(lpMalloc); LocalFree(lpMem); ulRef = IMalloc_AddRef(lpMalloc); ok (ulRef == 1u, "AddRef expected 1, returned %d\n", ulRef); ulRef = IMalloc_Release(lpMalloc); ok (ulRef == 1u, "AddRef expected 1, returned %d\n", ulRef); IMalloc_Release(lpMalloc); }
void *CoTaskMemAlloc( uint32 cBytes ) { /* * Note that we don't go through the riff-raff specified above. * We know that the allocator object is /always/ present in the * process, since we never unload it (regardless of its reference * count). Therefore, there's no point in wasting CPU cycles on it. */ if( initCount != 0 ) return IMalloc_Alloc( pTaskMalloc, cBytes ); else return NULL; }
HRESULT WINAPI CreateXmlWriterOutputWithEncodingName(IUnknown *stream, IMalloc *imalloc, LPCWSTR encoding, IXmlWriterOutput **output) { static const WCHAR utf8W[] = {'U','T','F','-','8',0}; xmlwriteroutput *writeroutput; HRESULT hr; TRACE("%p %p %s %p\n", stream, imalloc, debugstr_w(encoding), output); if (!stream || !output) return E_INVALIDARG; *output = NULL; if (imalloc) writeroutput = IMalloc_Alloc(imalloc, sizeof(*writeroutput)); else writeroutput = heap_alloc(sizeof(*writeroutput)); if(!writeroutput) return E_OUTOFMEMORY; writeroutput->IXmlWriterOutput_iface.lpVtbl = &xmlwriteroutputvtbl; writeroutput->ref = 1; writeroutput->imalloc = imalloc; if (imalloc) IMalloc_AddRef(imalloc); writeroutput->encoding = parse_encoding_name(encoding ? encoding : utf8W, -1); writeroutput->stream = NULL; hr = init_output_buffer(writeroutput); if (FAILED(hr)) { IUnknown_Release(&writeroutput->IXmlWriterOutput_iface); return hr; } IUnknown_QueryInterface(stream, &IID_IUnknown, (void**)&writeroutput->output); *output = &writeroutput->IXmlWriterOutput_iface; TRACE("returning iface %p\n", *output); return S_OK; }
HRESULT WINAPI CreateXmlWriter(REFIID riid, void **obj, IMalloc *imalloc) { xmlwriter *writer; TRACE("(%s, %p, %p)\n", wine_dbgstr_guid(riid), obj, imalloc); if (!IsEqualGUID(riid, &IID_IXmlWriter)) { ERR("Unexpected IID requested -> (%s)\n", wine_dbgstr_guid(riid)); return E_FAIL; } if (imalloc) writer = IMalloc_Alloc(imalloc, sizeof(*writer)); else writer = heap_alloc(sizeof(*writer)); if(!writer) return E_OUTOFMEMORY; writer->IXmlWriter_iface.lpVtbl = &xmlwriter_vtbl; writer->ref = 1; writer->imalloc = imalloc; if (imalloc) IMalloc_AddRef(imalloc); writer->output = NULL; writer->indent_level = 0; writer->indent = FALSE; writer->bom = TRUE; writer->omitxmldecl = FALSE; writer->conformance = XmlConformanceLevel_Document; writer->state = XmlWriterState_Initial; writer->bomwritten = FALSE; writer->starttagopen = FALSE; list_init(&writer->elements); *obj = &writer->IXmlWriter_iface; TRACE("returning iface %p\n", *obj); return S_OK; }
/*********************************************************************** * CoTaskMemAlloc [OLE32.@] * * Allocates memory using the current process memory allocator. * * PARAMS * size [I] Size of the memory block to allocate. * * RETURNS * Success: Pointer to newly allocated memory block. * Failure: NULL. */ LPVOID WINAPI CoTaskMemAlloc(ULONG size) { return IMalloc_Alloc((LPMALLOC)&Malloc32,size); }
/*********************************************************************** * CoTaskMemAlloc [OLE32.@] * * Allocates memory using the current process memory allocator. * * PARAMS * size [I] Size of the memory block to allocate. * * RETURNS * Success: Pointer to newly allocated memory block. * Failure: NULL. */ LPVOID WINAPI CoTaskMemAlloc(ULONG size) { return IMalloc_Alloc(&Malloc32.IMalloc_iface,size); }