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.
Signed-off-by: Michael Stefaniuc mstefani@winehq.org --- include/Makefile.in | 1 + include/wine/heap.h | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 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..2ae5aff578 --- /dev/null +++ b/include/wine/heap.h @@ -0,0 +1,58 @@ +/* + * 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> + +#ifdef __cplusplus +extern "C" { +#endif + +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 HeapReAlloc(GetProcessHeap(), 0, mem, len); + else + return HeapAlloc(GetProcessHeap(), 0, len); +} + +static inline void heap_free(void *mem) +{ + HeapFree(GetProcessHeap(), 0, mem); +} + +#ifdef __cplusplus +} +#endif + +#endif /* __WINE_WINE_HEAP_H */
On 25 January 2018 at 23:25, Michael Stefaniuc mstefani@winehq.org wrote:
+#ifdef __cplusplus +extern "C" { +#endif
Strictly speaking that's superfluous for internal headers (and more so for ones that only contain static inline functions), I think.
+static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, SIZE_T len) +{
- if (mem)
return HeapReAlloc(GetProcessHeap(), 0, mem, len);
- else
return HeapAlloc(GetProcessHeap(), 0, len);
+}
I'm partial to
if (!mem) return HeapAlloc(...); return HeapReAlloc(...);
but that's purely stylistic, and perhaps a preference that's not universally shared.
On 2018-01-26 00:30, Henri Verbeet wrote:
On 25 January 2018 at 23:25, Michael Stefaniuc mstefani@winehq.org wrote:
+#ifdef __cplusplus +extern "C" { +#endif
Strictly speaking that's superfluous for internal headers (and more so for ones that only contain static inline functions), I think.
Not sure how relevant this is to people -- but third-party projects that import Wine headers and use C++ (*cough* ReactOS ;]) certainly appreciate this sort of thing, even for internal headers. (That said, I agree it's probably not relevant for inline functions only, though it also doesn't hurt)