diff options
-rw-r--r-- | eglib/configure.ac | 6 | ||||
-rw-r--r-- | eglib/src/Makefile.am | 12 | ||||
-rw-r--r-- | eglib/src/eglib-config.h.in | 4 | ||||
-rw-r--r-- | eglib/src/glib.h | 12 | ||||
-rw-r--r-- | eglib/src/gmem.c | 10 | ||||
-rw-r--r-- | eglib/src/goutput.c | 2 | ||||
-rw-r--r-- | eglib/src/gstr.c | 39 | ||||
-rw-r--r-- | eglib/src/vasprintf.c | 32 | ||||
-rw-r--r-- | eglib/src/vasprintf.h | 10 | ||||
-rw-r--r-- | mono/utils/mono-publib.h | 13 | ||||
-rw-r--r-- | msvc/mono.def | 2 | ||||
-rw-r--r-- | msvc/monosgen.def | 2 |
12 files changed, 53 insertions, 91 deletions
diff --git a/eglib/configure.ac b/eglib/configure.ac index 79af2d995bf..dbca788afd6 100644 --- a/eglib/configure.ac +++ b/eglib/configure.ac @@ -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 diff --git a/eglib/src/Makefile.am b/eglib/src/Makefile.am index 31771dfd9a1..1527ba26d30 100644 --- a/eglib/src/Makefile.am +++ b/eglib/src/Makefile.am @@ -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 diff --git a/eglib/src/eglib-config.h.in b/eglib/src/eglib-config.h.in index 15d1b022062..ae7b6d45337 100644 --- a/eglib/src/eglib-config.h.in +++ b/eglib/src/eglib-config.h.in @@ -23,10 +23,6 @@ #define G_HAVE_ALLOCA_H #endif -#if @ENABLE_OVERRIDABLE_ALLOCATORS@ == 1 -#define G_OVERRIDABLE_ALLOCATORS -#endif - typedef unsigned @GSIZE@ gsize; typedef signed @GSIZE@ gssize; diff --git a/eglib/src/glib.h b/eglib/src/glib.h index 849c2dcebbf..23781c16852 100644 --- a/eglib/src/glib.h +++ b/eglib/src/glib.h @@ -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); diff --git a/eglib/src/gmem.c b/eglib/src/gmem.c index 93276ed2834..eff478dcbfa 100644 --- a/eglib/src/gmem.c +++ b/eglib/src/gmem.c @@ -25,11 +25,12 @@ * 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 diff --git a/eglib/src/goutput.c b/eglib/src/goutput.c index 689493be845..ef80cff0347 100644 --- a/eglib/src/goutput.c +++ b/eglib/src/goutput.c @@ -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; diff --git a/eglib/src/gstr.c b/eglib/src/gstr.c index 32430550aaa..8b64da572f6 100644 --- a/eglib/src/gstr.c +++ b/eglib/src/gstr.c @@ -32,13 +32,17 @@ #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 index 72820b8e961..00000000000 --- a/eglib/src/vasprintf.c +++ /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 index 74ea6ae790c..00000000000 --- a/eglib/src/vasprintf.h +++ /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 */ diff --git a/mono/utils/mono-publib.h b/mono/utils/mono-publib.h index df810a98e1a..d6249f1ca3f 100644 --- a/mono/utils/mono-publib.h +++ b/mono/utils/mono-publib.h @@ -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 diff --git a/msvc/mono.def b/msvc/mono.def index 2b3f5135483..3fc85bbee15 100644 --- a/msvc/mono.def +++ b/msvc/mono.def @@ -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 diff --git a/msvc/monosgen.def b/msvc/monosgen.def index faf3f0b0d62..6d97250c240 100644 --- a/msvc/monosgen.def +++ b/msvc/monosgen.def @@ -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 |