Dmitry Timoshkov : taskschd: Add some useful inline helpers for memory management.
Alexandre Julliard
julliard at winehq.org
Tue Jan 28 13:33:24 CST 2014
Module: wine
Branch: master
Commit: 89548cd0ad2b5fbca1297fa48e2005aacb28add6
URL: http://source.winehq.org/git/wine.git/?a=commit;h=89548cd0ad2b5fbca1297fa48e2005aacb28add6
Author: Dmitry Timoshkov <dmitry at baikal.ru>
Date: Tue Jan 28 11:54:36 2014 +0900
taskschd: Add some useful inline helpers for memory management.
---
dlls/taskschd/folder.c | 12 ++++++------
dlls/taskschd/folder_collection.c | 4 ++--
dlls/taskschd/task.c | 4 ++--
dlls/taskschd/taskschd_private.h | 29 +++++++++++++++++++++++++++++
4 files changed, 39 insertions(+), 10 deletions(-)
diff --git a/dlls/taskschd/folder.c b/dlls/taskschd/folder.c
index ce0176a..1793a62 100644
--- a/dlls/taskschd/folder.c
+++ b/dlls/taskschd/folder.c
@@ -60,8 +60,8 @@ static ULONG WINAPI TaskFolder_Release(ITaskFolder *iface)
if (!ref)
{
TRACE("destroying %p\n", iface);
- HeapFree(GetProcessHeap(), 0, folder->path);
- HeapFree(GetProcessHeap(), 0, folder);
+ heap_free(folder->path);
+ heap_free(folder);
}
return ref;
@@ -374,7 +374,7 @@ HRESULT TaskFolder_create(const WCHAR *parent, const WCHAR *path, ITaskFolder **
if (parent) len += strlenW(parent);
/* +1 if parent is not '\' terminated */
- folder_path = HeapAlloc(GetProcessHeap(), 0, (len + 2) * sizeof(WCHAR));
+ folder_path = heap_alloc((len + 2) * sizeof(WCHAR));
if (!folder_path) return E_OUTOFMEMORY;
folder_path[0] = 0;
@@ -399,16 +399,16 @@ HRESULT TaskFolder_create(const WCHAR *parent, const WCHAR *path, ITaskFolder **
hr = create ? reg_create_folder(folder_path, &hfolder) : reg_open_folder(folder_path, &hfolder);
if (hr)
{
- HeapFree(GetProcessHeap(), 0, folder_path);
+ heap_free(folder_path);
return hr;
}
reg_close_folder(hfolder);
- folder = HeapAlloc(GetProcessHeap(), 0, sizeof(*folder));
+ folder = heap_alloc(sizeof(*folder));
if (!folder)
{
- HeapFree(GetProcessHeap(), 0, folder_path);
+ heap_free(folder_path);
return E_OUTOFMEMORY;
}
diff --git a/dlls/taskschd/folder_collection.c b/dlls/taskschd/folder_collection.c
index 3327511..4448667 100644
--- a/dlls/taskschd/folder_collection.c
+++ b/dlls/taskschd/folder_collection.c
@@ -56,7 +56,7 @@ static ULONG WINAPI folders_Release(ITaskFolderCollection *iface)
if (!ref)
{
TRACE("destroying %p\n", iface);
- HeapFree(GetProcessHeap(), 0, folders);
+ heap_free(folders);
}
return ref;
@@ -144,7 +144,7 @@ HRESULT TaskFolderCollection_create(const WCHAR *path, ITaskFolderCollection **o
{
TaskFolderCollection *folders;
- folders = HeapAlloc(GetProcessHeap(), 0, sizeof(*folders));
+ folders = heap_alloc(sizeof(*folders));
if (!folders) return E_OUTOFMEMORY;
folders->ITaskFolderCollection_iface.lpVtbl = &TaskFolderCollection_vtbl;
diff --git a/dlls/taskschd/task.c b/dlls/taskschd/task.c
index a13a968..c424700 100644
--- a/dlls/taskschd/task.c
+++ b/dlls/taskschd/task.c
@@ -59,7 +59,7 @@ static ULONG WINAPI TaskService_Release(ITaskService *iface)
if (!ref)
{
TRACE("destroying %p\n", iface);
- HeapFree(GetProcessHeap(), 0, task_svc);
+ heap_free(task_svc);
}
return ref;
@@ -254,7 +254,7 @@ HRESULT TaskService_create(void **obj)
{
TaskService *task_svc;
- task_svc = HeapAlloc(GetProcessHeap(), 0, sizeof(*task_svc));
+ task_svc = heap_alloc(sizeof(*task_svc));
if (!task_svc) return E_OUTOFMEMORY;
task_svc->ITaskService_iface.lpVtbl = &TaskService_vtbl;
diff --git a/dlls/taskschd/taskschd_private.h b/dlls/taskschd/taskschd_private.h
index 0d801a9..9837cd3 100644
--- a/dlls/taskschd/taskschd_private.h
+++ b/dlls/taskschd/taskschd_private.h
@@ -16,8 +16,37 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
+#include "wine/unicode.h"
+
HRESULT TaskService_create(void **obj) DECLSPEC_HIDDEN;
HRESULT TaskFolder_create(const WCHAR *parent, const WCHAR *path, ITaskFolder **obj, BOOL create) DECLSPEC_HIDDEN;
HRESULT TaskFolderCollection_create(const WCHAR *path, ITaskFolderCollection **obj) DECLSPEC_HIDDEN;
const char *debugstr_variant(const VARIANT *v) DECLSPEC_HIDDEN;
+
+static void *heap_alloc(SIZE_T size) __WINE_ALLOC_SIZE(1);
+static inline void *heap_alloc(SIZE_T size)
+{
+ return HeapAlloc(GetProcessHeap(), 0, size);
+}
+
+static void *heap_realloc(void *ptr, SIZE_T size) __WINE_ALLOC_SIZE(2);
+static inline void *heap_realloc(void *ptr, SIZE_T size)
+{
+ return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
+}
+
+static inline BOOL heap_free(void *ptr)
+{
+ return HeapFree(GetProcessHeap(), 0, ptr);
+}
+
+static inline WCHAR *heap_strdupW(const WCHAR *src)
+{
+ WCHAR *dst;
+ unsigned len;
+ if (!src) return NULL;
+ len = (strlenW(src) + 1) * sizeof(WCHAR);
+ if ((dst = heap_alloc(len))) memcpy(dst, src, len);
+ return dst;
+}
More information about the wine-cvs
mailing list