[FUSION] Sync with Wine Staging 3.3. CORE-14434
[reactos.git] / dll / win32 / fusion / asmcache.c
index c8f389a..668aa87 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#include <stdarg.h>
+#include <stdio.h>
+
+#define COBJMACROS
+
+#include "windef.h"
+#include "winbase.h"
+#include "winuser.h"
+#include "winver.h"
+#include "wincrypt.h"
+#include "winreg.h"
+#include "shlwapi.h"
+#include "dbghelp.h"
+#include "ole2.h"
+#include "fusion.h"
+#include "corerror.h"
+
 #include "fusionpriv.h"
+#include "wine/debug.h"
+#include "wine/unicode.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(fusion);
 
 typedef struct {
     IAssemblyCache IAssemblyCache_iface;
@@ -42,9 +63,7 @@ static BOOL create_full_path(LPCWSTR path)
     BOOL ret = TRUE;
     int len;
 
-    new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) * sizeof(WCHAR));
-    if (!new_path)
-        return FALSE;
+    if (!(new_path = heap_alloc((strlenW(path) + 1) * sizeof(WCHAR)))) return FALSE;
 
     strcpyW(new_path, path);
 
@@ -82,7 +101,7 @@ static BOOL create_full_path(LPCWSTR path)
         new_path[len] = '\\';
     }
 
-    HeapFree(GetProcessHeap(), 0, new_path);
+    heap_free(new_path);
     return ret;
 }
 
@@ -179,7 +198,7 @@ static ULONG WINAPI IAssemblyCacheImpl_Release(IAssemblyCache *iface)
     if (!refCount)
     {
         CloseHandle( cache->lock );
-        HeapFree( GetProcessHeap(), 0, cache );
+        heap_free( cache );
     }
     return refCount;
 }
@@ -237,7 +256,7 @@ static HRESULT WINAPI IAssemblyCacheImpl_UninstallAssembly(IAssemblyCache *iface
     if (hr != HRESULT_FROM_WIN32( ERROR_INSUFFICIENT_BUFFER ))
         goto done;
 
-    if (!(path = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
+    if (!(path = heap_alloc( len * sizeof(WCHAR) )))
     {
         hr = E_OUTOFMEMORY;
         goto done;
@@ -272,7 +291,7 @@ done:
     IAssemblyName_Release( asmname );
     if (next) IAssemblyName_Release( next );
     if (asmenum) IAssemblyEnum_Release( asmenum );
-    HeapFree( GetProcessHeap(), 0, path );
+    heap_free( path );
     cache_unlock( cache );
     return hr;
 }
@@ -354,9 +373,7 @@ static HRESULT WINAPI IAssemblyCacheImpl_CreateAssemblyCacheItem(IAssemblyCache
 
     *ppAsmItem = NULL;
 
-    item = HeapAlloc(GetProcessHeap(), 0, sizeof(IAssemblyCacheItemImpl));
-    if (!item)
-        return E_OUTOFMEMORY;
+    if (!(item = heap_alloc(sizeof(*item)))) return E_OUTOFMEMORY;
 
     item->IAssemblyCacheItem_iface.lpVtbl = &AssemblyCacheItemVtbl;
     item->ref = 1;
@@ -379,22 +396,22 @@ static HRESULT copy_file( const WCHAR *src_dir, DWORD src_len, const WCHAR *dst_
     DWORD len = strlenW( filename );
     HRESULT hr = S_OK;
 
-    if (!(src_file = HeapAlloc( GetProcessHeap(), 0, (src_len + len + 1) * sizeof(WCHAR) )))
+    if (!(src_file = heap_alloc( (src_len + len + 1) * sizeof(WCHAR) )))
         return E_OUTOFMEMORY;
     memcpy( src_file, src_dir, src_len * sizeof(WCHAR) );
     strcpyW( src_file + src_len, filename );
 
-    if (!(dst_file = HeapAlloc( GetProcessHeap(), 0, (dst_len + len + 1) * sizeof(WCHAR) )))
+    if (!(dst_file = heap_alloc( (dst_len + len + 1) * sizeof(WCHAR) )))
     {
-        HeapFree( GetProcessHeap(), 0, src_file );
+        heap_free( src_file );
         return E_OUTOFMEMORY;
     }
     memcpy( dst_file, dst_dir, dst_len * sizeof(WCHAR) );
     strcpyW( dst_file + dst_len, filename );
 
     if (!CopyFileW( src_file, dst_file, FALSE )) hr = HRESULT_FROM_WIN32( GetLastError() );
-    HeapFree( GetProcessHeap(), 0, src_file );
-    HeapFree( GetProcessHeap(), 0, dst_file );
+    heap_free( src_file );
+    heap_free( dst_file );
     return hr;
 }
 
@@ -467,7 +484,7 @@ static HRESULT WINAPI IAssemblyCacheImpl_InstallAssembly(IAssemblyCache *iface,
     get_assembly_directory(asmdir, MAX_PATH, clr_version, architecture);
 
     dst_len += strlenW(asmdir) + strlenW(name) + strlenW(version) + strlenW(token);
-    if (!(dst_dir = HeapAlloc(GetProcessHeap(), 0, dst_len * sizeof(WCHAR))))
+    if (!(dst_dir = heap_alloc(dst_len * sizeof(WCHAR))))
     {
         hr = E_OUTOFMEMORY;
         goto done;
@@ -507,13 +524,13 @@ static HRESULT WINAPI IAssemblyCacheImpl_InstallAssembly(IAssemblyCache *iface,
     }
 
 done:
-    HeapFree(GetProcessHeap(), 0, name);
-    HeapFree(GetProcessHeap(), 0, token);
-    HeapFree(GetProcessHeap(), 0, version);
-    HeapFree(GetProcessHeap(), 0, asmpath);
-    HeapFree(GetProcessHeap(), 0, dst_dir);
-    for (i = 0; i < count; i++) HeapFree(GetProcessHeap(), 0, external_files[i]);
-    HeapFree(GetProcessHeap(), 0, external_files);
+    heap_free(name);
+    heap_free(token);
+    heap_free(version);
+    heap_free(asmpath);
+    heap_free(dst_dir);
+    for (i = 0; i < count; i++) heap_free(external_files[i]);
+    heap_free(external_files);
     assembly_release(assembly);
     cache_unlock( cache );
     return hr;
@@ -544,16 +561,14 @@ HRESULT WINAPI CreateAssemblyCache(IAssemblyCache **ppAsmCache, DWORD dwReserved
 
     *ppAsmCache = NULL;
 
-    cache = HeapAlloc(GetProcessHeap(), 0, sizeof(IAssemblyCacheImpl));
-    if (!cache)
-        return E_OUTOFMEMORY;
+    if (!(cache = heap_alloc(sizeof(*cache)))) return E_OUTOFMEMORY;
 
     cache->IAssemblyCache_iface.lpVtbl = &AssemblyCacheVtbl;
     cache->ref = 1;
     cache->lock = CreateMutexW( NULL, FALSE, cache_mutex_nameW );
     if (!cache->lock)
     {
-        HeapFree( GetProcessHeap(), 0, cache );
+        heap_free( cache );
         return HRESULT_FROM_WIN32( GetLastError() );
     }
     *ppAsmCache = &cache->IAssemblyCache_iface;
@@ -606,7 +621,7 @@ static ULONG WINAPI IAssemblyCacheItemImpl_Release(IAssemblyCacheItem *iface)
     TRACE("(%p)->(ref before = %u)\n", This, refCount + 1);
 
     if (!refCount)
-        HeapFree(GetProcessHeap(), 0, This);
+        heap_free(This);
 
     return refCount;
 }