Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/eglib
diff options
context:
space:
mode:
authorDolphin Hawkins <dolphin@exitzer0.com>2016-07-05 23:49:05 +0300
committerRodrigo Kumpera <kumpera@gmail.com>2016-07-11 20:23:20 +0300
commit856447c71eada81dd547a172ac5c02185215b431 (patch)
treeeb9a98108278ff8767315931dab0fe82f5e2aa7d /eglib
parent3e0eb1a54c69075faf5da563333b1b40550e82a2 (diff)
Fixed up configure overridable allocators option. Moved g_vasprintf implementation to gstr which forwards to the system vasprintf when appropriate
Diffstat (limited to 'eglib')
-rw-r--r--eglib/configure.ac6
-rw-r--r--eglib/src/Makefile.am12
-rw-r--r--eglib/src/eglib-config.h.in4
-rw-r--r--eglib/src/glib.h12
-rw-r--r--eglib/src/gmem.c10
-rw-r--r--eglib/src/goutput.c2
-rw-r--r--eglib/src/gstr.c39
-rw-r--r--eglib/src/vasprintf.c32
-rw-r--r--eglib/src/vasprintf.h10
9 files changed, 51 insertions, 76 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 */