Signed-off-by: Michael Stefaniuc mstefani@winehq.org --- version 3: - Removed 'extern "C"' as it isn't needed even for ReactOS - Fixed the missing space in the Copyright (thx Matteo) - Style fix in HeapReAlloc as that is my prefered style too (thx Henri)
version 2: Just use the non-controversial parts. Basically the stuff we already have with following changes:
heap_realloc - Passing NULL as memory pointer will allocate new memory.
no heap_realloc_zero() - few uses - some defined but not used
heap_free() returns void: - No existing use of the heap_free() return value. - There are a few "return HeapFree()" statements but more than half of those are just in heap_free() wrappers.
include/Makefile.in | 1 + include/wine/heap.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 include/wine/heap.h
diff --git a/include/Makefile.in b/include/Makefile.in index b975dd585e..748b64165f 100644 --- a/include/Makefile.in +++ b/include/Makefile.in @@ -680,6 +680,7 @@ HEADER_SRCS = \ windowsx.h \ wine/debug.h \ wine/exception.h \ + wine/heap.h \ wine/library.h \ wine/unicode.h \ winerror.h \ diff --git a/include/wine/heap.h b/include/wine/heap.h new file mode 100644 index 0000000000..014ef6129d --- /dev/null +++ b/include/wine/heap.h @@ -0,0 +1,49 @@ +/* + * Wine heap memory allocation wrappers + * + * Copyright 2006 Jacek Caban for CodeWeavers + * Copyright 2013, 2018 Michael Stefaniuc + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __WINE_WINE_HEAP_H +#define __WINE_WINE_HEAP_H + +#include <windef.h> + +static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(SIZE_T len) +{ + return HeapAlloc(GetProcessHeap(), 0, len); +} + +static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(SIZE_T len) +{ + return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len); +} + +static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, SIZE_T len) +{ + if (!mem) + return HeapAlloc(GetProcessHeap(), 0, len); + return HeapReAlloc(GetProcessHeap(), 0, mem, len); +} + +static inline void heap_free(void *mem) +{ + HeapFree(GetProcessHeap(), 0, mem); +} + +#endif /* __WINE_WINE_HEAP_H */