[PATCH] winegstreamer: Override glib memory allocations
Maarten Lankhorst
m.b.lankhorst at gmail.com
Wed Dec 8 16:00:38 CST 2010
---
dlls/winegstreamer/Makefile.in | 1 +
dlls/winegstreamer/glibmem.c | 66 ++++++++++++++++++++++++++++++++++++++
dlls/winegstreamer/gst_private.h | 1 +
dlls/winegstreamer/main.c | 1 +
4 files changed, 69 insertions(+), 0 deletions(-)
create mode 100644 dlls/winegstreamer/glibmem.c
diff --git a/dlls/winegstreamer/Makefile.in b/dlls/winegstreamer/Makefile.in
index f6695be..d8c1e2b 100644
--- a/dlls/winegstreamer/Makefile.in
+++ b/dlls/winegstreamer/Makefile.in
@@ -4,6 +4,7 @@ EXTRAINCL = @GSTREAMER_INCL@
EXTRALIBS = @GSTREAMER_LIBS@ @LIBPTHREAD@
C_SRCS = \
+ glibmem.c \
glibthread.c \
gstdemux.c \
gsttffilter.c \
diff --git a/dlls/winegstreamer/glibmem.c b/dlls/winegstreamer/glibmem.c
new file mode 100644
index 0000000..a7a1f73
--- /dev/null
+++ b/dlls/winegstreamer/glibmem.c
@@ -0,0 +1,66 @@
+/* Copyright 2010 Maarten Lankhorst for CodeWeavers
+ *
+ * GLIB - Library of useful routines for C programming
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * 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
+ */
+
+/* Based on glib2.0/glib/gmem.c */
+
+#include <stdarg.h>
+#include "windef.h"
+#include "winbase.h"
+
+#include <glib.h>
+
+static gpointer standard_malloc(gsize n_bytes)
+{
+ return HeapAlloc(GetProcessHeap(), 0, n_bytes ? n_bytes : 1);
+}
+
+static gpointer standard_realloc(gpointer mem, gsize n_bytes)
+{
+ if (!mem)
+ return HeapAlloc(GetProcessHeap(), 0, n_bytes);
+ else
+ return HeapReAlloc(GetProcessHeap(), 0, mem, n_bytes);
+}
+
+static void standard_free(gpointer mem)
+{
+ HeapFree(GetProcessHeap(), 0, mem);
+}
+
+static gpointer standard_calloc(gsize n_blocks, gsize n_bytes)
+{
+ if (!n_blocks || !n_bytes)
+ return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 1);
+ else
+ return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, n_blocks * n_bytes);
+}
+
+static GMemVTable glib_mem_vtable = {
+ standard_malloc,
+ standard_realloc,
+ standard_free,
+ standard_calloc,
+ standard_malloc,
+ standard_realloc,
+};
+
+void g_mem_impl_init (void) {
+ g_mem_set_vtable(&glib_mem_vtable);
+}
diff --git a/dlls/winegstreamer/gst_private.h b/dlls/winegstreamer/gst_private.h
index 741fdf4..9336e9c 100644
--- a/dlls/winegstreamer/gst_private.h
+++ b/dlls/winegstreamer/gst_private.h
@@ -45,6 +45,7 @@ IUnknown * CALLBACK Gstreamer_Mp3_create(IUnknown *pUnkOuter, HRESULT *phr);
IUnknown * CALLBACK Gstreamer_YUV_create(IUnknown *pUnkOuter, HRESULT *phr);
IUnknown * CALLBACK Gstreamer_Splitter_create(IUnknown *pUnkOuter, HRESULT *phr);
+void g_mem_impl_init(void);
void g_thread_impl_init(void);
DWORD Gstreamer_init(void);
#endif /* __GST_PRIVATE_INCLUDED__ */
diff --git a/dlls/winegstreamer/main.c b/dlls/winegstreamer/main.c
index 941f433..869890f 100644
--- a/dlls/winegstreamer/main.c
+++ b/dlls/winegstreamer/main.c
@@ -254,6 +254,7 @@ DWORD Gstreamer_init(void) {
argv[0] = argv0;
argv[1] = argv1;
argv[2] = NULL;
+ g_mem_impl_init();
g_thread_impl_init();
inited = gst_init_check(&argc, &argv, &err);
HeapFree(GetProcessHeap(), 0, argv);
--
1.7.1
More information about the wine-patches
mailing list