Fixed up configure overridable allocators option. Moved g_vasprintf implementation...
authorDolphin Hawkins <dolphin@exitzer0.com>
Tue, 5 Jul 2016 20:49:05 +0000 (13:49 -0700)
committerRodrigo Kumpera <kumpera@gmail.com>
Mon, 11 Jul 2016 17:23:20 +0000 (13:23 -0400)
12 files changed:
eglib/configure.ac
eglib/src/Makefile.am
eglib/src/eglib-config.h.in
eglib/src/glib.h
eglib/src/gmem.c
eglib/src/goutput.c
eglib/src/gstr.c
eglib/src/vasprintf.c [deleted file]
eglib/src/vasprintf.h [deleted file]
mono/utils/mono-publib.h
msvc/mono.def
msvc/monosgen.def

index 79af2d995bfa3344fc11a24c6c29cae9aae0d5fa..dbca788afd663e33dc4df87132a14061c4c8d4b2 100644 (file)
@@ -138,16 +138,14 @@ AC_CHECK_FUNCS(strlcpy stpcpy strtok_r rewinddir vasprintf)
 AC_CHECK_FUNCS(getrlimit)
 AC_CHECK_FUNCS(fork execv execve)
 
-AC_ARG_WITH([overidable-allocators], [  --with-overridable-allocators  allow g_*alloc/g_free to call custom allocators set via g_mem_set_vtable])
+AC_ARG_WITH([overridable-allocators], [  --with-overridable-allocators allow g_*alloc/g_free to call custom allocators set via g_mem_set_vtable])
 
 if test x$with_overridable_allocators == xyes; then
-       ENABLE_OVERRIDABLE_ALLOCATORS="1"
+       AC_DEFINE(ENABLE_OVERRIDABLE_ALLOCATORS,1,[Overridable allocator support enabled])
   AC_MSG_NOTICE([Overridable allocator support enabled])
 else
-       ENABLE_OVERRIDABLE_ALLOCATORS="0"
   AC_MSG_NOTICE([Overridable allocator support disabled])
 fi
-AC_SUBST(ENABLE_OVERRIDABLE_ALLOCATORS)
 
 #
 # Mono currently supports 10.6, but strndup is not available prior to 10.7; avoiding
index 31771dfd9a19dab5f0af901207d869f5160264b2..1527ba26d30452bb70aa7403d6cbc1281ad5ec78 100644 (file)
@@ -11,14 +11,6 @@ unix_files = \
        gdate-unix.c  gdir-unix.c  gfile-unix.c  gmisc-unix.c   \
        gmodule-unix.c gtimer-unix.c
 
-# some unices and windows do not have an implementation of vasprintf
-# used by eglib, use provided implementation instead
-if NEED_VASPRINTF
-vasprintf_files = vasprintf.c
-else
-vaprinttf_files = foo.c
-endif
-
 if HOST_WIN32
 os_files = $(win_files)
 else
@@ -32,7 +24,6 @@ libeglib_la_SOURCES = \
        garray.c        \
        gbytearray.c    \
        gerror.c        \
-       vasprintf.h     \
        ghashtable.c    \
        giconv.c        \
        gmem.c          \
@@ -55,8 +46,7 @@ libeglib_la_SOURCES = \
        gutf8.c         \
        gunicode.c      \
        unicode-data.h  \
-       $(os_files)     \
-       $(vasprintf_files)
+       $(os_files)
 
 libeglib_la_CFLAGS = -g -Wall -D_FORTIFY_SOURCE=2
 
index 15d1b022062089b0d97017d5c7461615a71d7c6c..ae7b6d45337183fb48d52b2593f26b7d0c0de28f 100644 (file)
 #define G_HAVE_ALLOCA_H
 #endif
 
-#if @ENABLE_OVERRIDABLE_ALLOCATORS@ == 1
-#define G_OVERRIDABLE_ALLOCATORS
-#endif
-
 typedef unsigned @GSIZE@ gsize;
 typedef signed   @GSIZE@ gssize;
 
index 849c2dcebbf481d66126845e3bd15b3661ad740d..23781c168526edd95498a3260697cbd76af23ff6 100644 (file)
@@ -139,7 +139,7 @@ gpointer g_try_realloc (gpointer obj, gsize size);
 #define g_alloca(size)         alloca (size)
 
 gpointer g_memdup (gconstpointer mem, guint byte_size);
-static inline gchar   *g_strdup (const gchar *str) { if (str) { return (gchar*) g_memdup(str, (guint)strlen (str) + 1); } return NULL; }
+static inline gchar   *g_strdup (const gchar *str) { if (str) { return (gchar*) g_memdup (str, (guint)strlen (str) + 1); } return NULL; }
 gchar **g_strdupv (gchar **str_array);
 
 typedef struct {
@@ -149,11 +149,7 @@ typedef struct {
        gpointer (*calloc)      (gsize    n_blocks, gsize n_block_bytes);
 } GMemVTable;
 
-#if defined (G_OVERRIDABLE_ALLOCATORS)
 void g_mem_set_vtable (GMemVTable* vtable);
-#else
-#define g_mem_set_vtable(x)
-#endif
 
 struct _GMemChunk {
        guint alloc_size;
@@ -226,15 +222,11 @@ gint         g_printf          (gchar const *format, ...);
 gint         g_fprintf         (FILE *file, gchar const *format, ...);
 gint         g_sprintf         (gchar *string, gchar const *format, ...);
 gint         g_snprintf        (gchar *string, gulong n, gchar const *format, ...);
+gint         g_vasprintf       (gchar **ret, const gchar *fmt, va_list ap);
 #define g_vprintf vprintf
 #define g_vfprintf vfprintf
 #define g_vsprintf vsprintf
 #define g_vsnprintf vsnprintf
-#if defined (G_OVERRIDABLE_ALLOCATORS) || !defined (HAVE_VASPRINTF)
-gint         g_vasprintf       (gchar **ret, const gchar *fmt, va_list ap);
-#else
-#define g_vasprintf vasprintf
-#endif
 
 gsize   g_strlcpy            (gchar *dest, const gchar *src, gsize dest_size);
 gchar  *g_stpcpy             (gchar *dest, const char *src);
index 93276ed28345caf0c43a5b370c2ed7837538c7c7..eff478dcbfad01f9ee41cc709a90342a6b3d2550 100644 (file)
  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
+#include <config.h>
 #include <stdio.h>
 #include <string.h>
 #include <glib.h>
 
-#if defined (G_OVERRIDABLE_ALLOCATORS)
+#if defined (ENABLE_OVERRIDABLE_ALLOCATORS)
 
 static GMemVTable sGMemVTable = { malloc, realloc, free, calloc };
 
@@ -41,11 +42,18 @@ g_mem_set_vtable (GMemVTable* vtable)
        sGMemVTable.malloc = vtable->malloc ? vtable->malloc : malloc;
        sGMemVTable.free = vtable->free ? vtable->free : free;
 }
+
 #define G_FREE_INTERNAL sGMemVTable.free
 #define G_REALLOC_INTERNAL sGMemVTable.realloc
 #define G_CALLOC_INTERNAL sGMemVTable.calloc
 #define G_MALLOC_INTERNAL sGMemVTable.malloc
 #else
+
+void
+g_mem_set_vtable (GMemVTable* vtable)
+{
+}
+
 #define G_FREE_INTERNAL free
 #define G_REALLOC_INTERNAL realloc
 #define G_CALLOC_INTERNAL calloc
index 689493be845202536b599be5f4d646a602ca8db5..ef80cff034748e559dea3055bc3bfb175dc3eb76 100644 (file)
@@ -31,8 +31,6 @@
 #include <stdlib.h>
 #include <glib.h>
 
-#include "vasprintf.h"
-
 /* The current fatal levels, error is always fatal */
 static GLogLevelFlags fatal = G_LOG_LEVEL_ERROR;
 static GLogFunc default_log_func;
index 32430550aaa5a964e4b8c62738fdc8c83d5cf369..8b64da572f69967e7c17f459cafcf2beb2b8e55c 100644 (file)
 #include <ctype.h>
 #include <glib.h>
 
-#include "vasprintf.h"
+/* 
+ * g_strndup and g_vasprintf need to allocate memory with g_malloc if 
+ * ENABLE_OVERRIDABLE_ALLOCATORS is defined so that it can be safely freed with g_free 
+ * rather than free.
+ */
 
 /* This is not a macro, because I dont want to put _GNU_SOURCE in the glib.h header */
 gchar *
 g_strndup (const gchar *str, gsize n)
 {
-#if defined (HAVE_STRNDUP) && !defined (G_OVERRIDABLE_ALLOCATORS)
+#if defined (HAVE_STRNDUP) && !defined (ENABLE_OVERRIDABLE_ALLOCATORS)
        return strndup (str, n);
 #else
        if (str) {
@@ -52,6 +56,37 @@ g_strndup (const gchar *str, gsize n)
 #endif
 }
 
+gint g_vasprintf (gchar **ret, const gchar *fmt, va_list ap)
+{
+#if defined (HAVE_VASPRINTF) && !defined (ENABLE_OVERRIDABLE_ALLOCATORS)
+  return vasprintf (ret, fmt, ap);
+#else
+       char *buf;
+       int len;
+       size_t buflen;
+       va_list ap2;
+       
+#if defined(_MSC_VER) || defined(__MINGW64_VERSION_MAJOR)
+       ap2 = ap;
+       len = _vscprintf(fmt, ap2); // NOTE MS specific extension ( :-( )
+#else
+       va_copy(ap2, ap);
+       len = vsnprintf(NULL, 0, fmt, ap2);
+#endif
+
+       if (len >= 0 && (buf = g_malloc ((buflen = (size_t) (len + 1)))) != NULL) {
+               len = vsnprintf(buf, buflen, fmt, ap);
+               *ret = buf;
+       } else {
+               *ret = NULL;
+               len = -1;
+       }
+
+       va_end(ap2);
+       return len;
+#endif
+}
+
 void
 g_strfreev (gchar **str_array)
 {
diff --git a/eglib/src/vasprintf.c b/eglib/src/vasprintf.c
deleted file mode 100644 (file)
index 72820b8..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <glib.h>
-
-gint g_vasprintf (gchar **ret, const gchar *fmt, va_list ap)
-{
-       char *buf;
-       int len;
-       size_t buflen;
-       va_list ap2;
-       
-#if defined(_MSC_VER) || defined(__MINGW64_VERSION_MAJOR)
-       ap2 = ap;
-       len = _vscprintf(fmt, ap2); // NOTE MS specific extension ( :-( )
-#else
-       va_copy(ap2, ap);
-       len = vsnprintf(NULL, 0, fmt, ap2);
-#endif
-       
-       if (len >= 0 && (buf = g_malloc ((buflen = (size_t) (len + 1)))) != NULL) {
-               len = vsnprintf(buf, buflen, fmt, ap);
-               *ret = buf;
-       } else {
-               *ret = NULL;
-               len = -1;
-       }
-       
-       va_end(ap2);
-       return len;
-}
-
diff --git a/eglib/src/vasprintf.h b/eglib/src/vasprintf.h
deleted file mode 100644 (file)
index 74ea6ae..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef __VASPRINTF_H
-#define __VASPRINTF_H
-
-#include <stdarg.h>
-
-#if !defined (HAVE_VASPRINTF) || defined (G_OVERRIDABLE_ALLOCATORS)
-int g_vasprintf(char **ret, const char *fmt, va_list ap);
-#endif
-
-#endif /* __VASPRINTF_H */
index df810a98e1ae1c8fccf1e93d7168713b2fc04f5c..d6249f1ca3facf372aa4ba7187a414dbc75ae0fc 100644 (file)
@@ -71,19 +71,6 @@ typedef uint32_t     mono_unichar4;
 typedef void   (*MonoFunc)     (void* data, void* user_data);
 typedef void   (*MonoHFunc)    (void* key, void* value, void* user_data);
 
-typedef struct {
-       void* (*malloc)  (size_t n_bytes);
-       void* (*realloc) (void* mem, size_t n_bytes);
-       void  (*free)    (void* mem);
-       void* (*calloc)  (size_t n_blocks, size_t n_block_bytes);
-} MonoAllocatorVTable;
-
-/* 
- * eglib must be built with overridable allocator support (G_OVERRIDABLE_ALLOCATORS=1) 
- * for mono_set_allocator_vtable to do anything.
- */
-MONO_API void mono_set_allocator_vtable (MonoAllocatorVTable* vtable);
-
 MONO_API void mono_free (void *);
 
 #define MONO_CONST_RETURN const
index 2b3f513548304530124e4e8a8aa0bbfe10199769..3fc85bbee1567c902fb568c51c1e13c80c07effb 100644 (file)
@@ -1,8 +1,8 @@
 ; file generated by create-windef.pl
 EXPORTS
+g_mem_set_vtable
 MonoFixupCorEE
 mono_add_internal_call
-mono_set_allocator_vtable
 mono_aot_get_method
 mono_aot_register_module
 mono_array_addr_with_size
index faf3f0b0d625e0cd149717401d0bcbeee2f4323b..6d97250c2409658adc10db6cc660cff2ae7e5d9c 100644 (file)
@@ -1,8 +1,8 @@
 ; file generated by create-windef.pl
 EXPORTS
+g_mem_set_vtable
 MonoFixupCorEE
 mono_add_internal_call
-mono_set_allocator_vtable
 mono_aot_get_method
 mono_aot_register_module
 mono_array_addr_with_size