take two, with nice explanation. brave souls may try using it, the
result is endless hours of fun. it will help untold amounts towards
cleaning wm, but so far it seems to be a fairly large task.
>From e2a39e4ef10710e30a75c4a03a92eeee623376f3 Mon Sep 17 00:00:00 2001
From: Tamas TEVESZ <[email protected]>
Date: Wed, 22 Sep 2010 23:34:37 +0200
Subject: [PATCH] Repair TEST_WITH_GC
The comment in WINGs/memory.c:wfree() pretty much explains the current
situation. There's an incredible amount of mixing the wmalloc/wfree
wrappers with native mallocs/frees on the other side, and a good several
cases of misusing external libraries' APIs. Until this is thoroughly
cleaned, WM with --enable-boehm-gc will hardly even start.
Signed-off-by: Tamas TEVESZ <[email protected]>
---
WINGs/memory.c | 41 ++++++++++++++++++++++++++++-------------
configure.ac | 14 ++++++++++++++
2 files changed, 42 insertions(+), 13 deletions(-)
diff --git a/WINGs/memory.c b/WINGs/memory.c
index 9d770b0..0e350bf 100644
--- a/WINGs/memory.c
+++ b/WINGs/memory.c
@@ -29,9 +29,12 @@
#include <assert.h>
#include <signal.h>
-#ifdef TEST_WITH_GC
+#ifdef USE_BOEHM_GC
+#ifndef GC_DEBUG
+#define GC_DEBUG
+#endif /* !GC_DEBUG */
#include <gc/gc.h>
-#endif
+#endif /* USE_BOEHM_GC */
#ifndef False
# define False 0
@@ -71,16 +74,16 @@ void *wmalloc(size_t size)
assert(size > 0);
-#ifdef TEST_WITH_GC
- tmp = GC_malloc(size);
+#ifdef USE_BOEHM_GC
+ tmp = GC_MALLOC(size);
#else
tmp = malloc(size);
#endif
if (tmp == NULL) {
wwarning("malloc() failed. Retrying after 2s.");
sleep(2);
-#ifdef TEST_WITH_GC
- tmp = GC_malloc(size);
+#ifdef USE_BOEHM_GC
+ tmp = GC_MALLOC(size);
#else
tmp = malloc(size);
#endif
@@ -108,16 +111,16 @@ void *wrealloc(void *ptr, size_t newsize)
wfree(ptr);
nptr = NULL;
} else {
-#ifdef TEST_WITH_GC
- nptr = GC_realloc(ptr, newsize);
+#ifdef USE_BOEHM_GC
+ nptr = GC_REALLOC(ptr, newsize);
#else
nptr = realloc(ptr, newsize);
#endif
if (nptr == NULL) {
wwarning("realloc() failed. Retrying after 2s.");
sleep(2);
-#ifdef TEST_WITH_GC
- nptr = GC_realloc(ptr, newsize);
+#ifdef USE_BOEHM_GC
+ nptr = GC_REALLOC(ptr, newsize);
#else
nptr = realloc(ptr, newsize);
#endif
@@ -164,11 +167,23 @@ void *wretain(void *ptr)
void wfree(void *ptr)
{
-#ifdef TEST_WITH_GC
- GC_free(ptr);
+ if (ptr)
+#ifdef USE_BOEHM_GC
+ /* This should eventually be removed, once the criss-cross
+ * of wmalloc()d memory being free()d, malloc()d memory being
+ * wfree()d, various misuses of calling wfree() on objects
+ * allocated by libc malloc() and calling libc free() on
+ * objects allocated by Boehm GC (think external libraries)
+ * is cleaned up.
+ */
+ if (GC_base(ptr) != 0)
+ GC_FREE(ptr);
+ else
+ free(ptr);
#else
- free(ptr);
+ free(ptr);
#endif
+ ptr = NULL;
}
void wrelease(void *ptr)
diff --git a/configure.ac b/configure.ac
index de5b5a5..da0f24d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -132,6 +132,20 @@ lib_search_path="-L$_libdir"
inc_search_path=`eval echo $includedir`
inc_search_path="-I`eval echo $inc_search_path`"
+dnl Boehm GC
+dnl ========
+with_boehm_gc=no
+AC_ARG_ENABLE([boehm-gc],
+ [AS_HELP_STRING([--enable-boehm-gc], [use Boehm GC instead of the default
libc malloc() [default=no]])],
+ [with_boehm_gc=$enableval])
+
+AS_IF([test "x$with_boehm_gc" = "xyes"],
+ AC_SEARCH_LIBS([GC_malloc], [gc],
+ [AC_DEFINE(USE_BOEHM_GC, 1, [Define if Boehm GC is to be used])],
+ [AC_MSG_FAILURE([--enable-boehm-gc specified but test for libgc
failed])]
+ )
+)
+
dnl ===============================================
dnl Specify paths to look for libraries and headers
dnl ===============================================
--
1.7.0.4
--
[-]
mkdir /nonexistentFrom e2a39e4ef10710e30a75c4a03a92eeee623376f3 Mon Sep 17 00:00:00 2001
From: Tamas TEVESZ <[email protected]>
Date: Wed, 22 Sep 2010 23:34:37 +0200
Subject: [PATCH] Repair TEST_WITH_GC
The comment in WINGs/memory.c:wfree() pretty much explains the current
situation. There's an incredible amount of mixing the wmalloc/wfree
wrappers with native mallocs/frees on the other side, and a good several
cases of misusing external libraries' APIs. Until this is thoroughly
cleaned, WM with --enable-boehm-gc will hardly even start.
Signed-off-by: Tamas TEVESZ <[email protected]>
---
WINGs/memory.c | 41 ++++++++++++++++++++++++++++-------------
configure.ac | 14 ++++++++++++++
2 files changed, 42 insertions(+), 13 deletions(-)
diff --git a/WINGs/memory.c b/WINGs/memory.c
index 9d770b0..0e350bf 100644
--- a/WINGs/memory.c
+++ b/WINGs/memory.c
@@ -29,9 +29,12 @@
#include <assert.h>
#include <signal.h>
-#ifdef TEST_WITH_GC
+#ifdef USE_BOEHM_GC
+#ifndef GC_DEBUG
+#define GC_DEBUG
+#endif /* !GC_DEBUG */
#include <gc/gc.h>
-#endif
+#endif /* USE_BOEHM_GC */
#ifndef False
# define False 0
@@ -71,16 +74,16 @@ void *wmalloc(size_t size)
assert(size > 0);
-#ifdef TEST_WITH_GC
- tmp = GC_malloc(size);
+#ifdef USE_BOEHM_GC
+ tmp = GC_MALLOC(size);
#else
tmp = malloc(size);
#endif
if (tmp == NULL) {
wwarning("malloc() failed. Retrying after 2s.");
sleep(2);
-#ifdef TEST_WITH_GC
- tmp = GC_malloc(size);
+#ifdef USE_BOEHM_GC
+ tmp = GC_MALLOC(size);
#else
tmp = malloc(size);
#endif
@@ -108,16 +111,16 @@ void *wrealloc(void *ptr, size_t newsize)
wfree(ptr);
nptr = NULL;
} else {
-#ifdef TEST_WITH_GC
- nptr = GC_realloc(ptr, newsize);
+#ifdef USE_BOEHM_GC
+ nptr = GC_REALLOC(ptr, newsize);
#else
nptr = realloc(ptr, newsize);
#endif
if (nptr == NULL) {
wwarning("realloc() failed. Retrying after 2s.");
sleep(2);
-#ifdef TEST_WITH_GC
- nptr = GC_realloc(ptr, newsize);
+#ifdef USE_BOEHM_GC
+ nptr = GC_REALLOC(ptr, newsize);
#else
nptr = realloc(ptr, newsize);
#endif
@@ -164,11 +167,23 @@ void *wretain(void *ptr)
void wfree(void *ptr)
{
-#ifdef TEST_WITH_GC
- GC_free(ptr);
+ if (ptr)
+#ifdef USE_BOEHM_GC
+ /* This should eventually be removed, once the criss-cross
+ * of wmalloc()d memory being free()d, malloc()d memory being
+ * wfree()d, various misuses of calling wfree() on objects
+ * allocated by libc malloc() and calling libc free() on
+ * objects allocated by Boehm GC (think external libraries)
+ * is cleaned up.
+ */
+ if (GC_base(ptr) != 0)
+ GC_FREE(ptr);
+ else
+ free(ptr);
#else
- free(ptr);
+ free(ptr);
#endif
+ ptr = NULL;
}
void wrelease(void *ptr)
diff --git a/configure.ac b/configure.ac
index de5b5a5..da0f24d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -132,6 +132,20 @@ lib_search_path="-L$_libdir"
inc_search_path=`eval echo $includedir`
inc_search_path="-I`eval echo $inc_search_path`"
+dnl Boehm GC
+dnl ========
+with_boehm_gc=no
+AC_ARG_ENABLE([boehm-gc],
+ [AS_HELP_STRING([--enable-boehm-gc], [use Boehm GC instead of the default libc malloc() [default=no]])],
+ [with_boehm_gc=$enableval])
+
+AS_IF([test "x$with_boehm_gc" = "xyes"],
+ AC_SEARCH_LIBS([GC_malloc], [gc],
+ [AC_DEFINE(USE_BOEHM_GC, 1, [Define if Boehm GC is to be used])],
+ [AC_MSG_FAILURE([--enable-boehm-gc specified but test for libgc failed])]
+ )
+)
+
dnl ===============================================
dnl Specify paths to look for libraries and headers
dnl ===============================================
--
1.7.0.4