summaryrefslogtreecommitdiff
path: root/malloc.c
diff options
context:
space:
mode:
authorivmai <ivmai>2011-04-09 12:50:54 +0200
committerIvan Maidanski <ivmai@mail.ru>2011-07-26 19:06:57 +0200
commit00ee2f7451eed8bd1cceda8001df1722067c9f17 (patch)
tree59f3abf96c4cd02aee4cfb9475c22407a73f5eaa /malloc.c
parentbe457cfd5dde0cc1a1db497a70c15b7bd38153b8 (diff)
2011-04-09 Ivan Maidanski <ivmai@mail.ru>
* dbg_mlc.c (GC_register_finalizer_no_order): Remove redundant declaration. * dbg_mlc.c (GC_debug_malloc_replacement, GC_debug_realloc_replacement): Rename RA to GC_DBG_RA. * malloc.c (GC_debug_malloc_replacement): Ditto. * mallocx.c (GC_debug_realloc_replacement): Ditto. * dbg_mlc.c (GC_store_debug_info): Move proto from dbg_mlc.h. * malloc.c (GC_strdup, GC_strndup, GC_wcsdup): Move to mallocx.c. * malloc.c: Include errno.h only REDIRECT_MALLOC; remove redundant includes of string.h. * mallocx.c: Include string.h (for GC_strdup). * include/private/dbg_mlc.h (GC_store_debug_info): Move declaration to dbg_mlc.c. * include/private/gc_locks.h (UNCOND_LOCK, UNCOND_UNLOCK): Remove redundant trailing ';'. * include/private/gc_priv.h (START_WORLD, COND_DUMP): Ditto. * include/private/gc_locks.h (LOCK, UNLOCK): Place opening '{' properly. * include/private/gc_priv.h (GC_DBG_RA): Move from dbg_mlc.c, malloc.c, mallocx.c.
Diffstat (limited to 'malloc.c')
-rw-r--r--malloc.c82
1 files changed, 9 insertions, 73 deletions
diff --git a/malloc.c b/malloc.c
index 026e3f9..781d65a 100644
--- a/malloc.c
+++ b/malloc.c
@@ -17,9 +17,6 @@
#include <stdio.h>
#include <string.h>
-#ifndef MSWINCE
-# include <errno.h>
-#endif
GC_INNER void GC_extend_size_map(size_t); /* in misc.c */
@@ -232,65 +229,6 @@ GC_API void * GC_CALL GC_generic_malloc(size_t lb, int k)
}
}
-/* provide a version of strdup() that uses the collector to allocate the
- copy of the string */
-GC_API char * GC_CALL GC_strdup(const char *s)
-{
- char *copy;
- size_t lb;
- if (s == NULL) return NULL;
- lb = strlen(s) + 1;
- if ((copy = GC_malloc_atomic(lb)) == NULL) {
-# ifndef MSWINCE
- errno = ENOMEM;
-# endif
- return NULL;
- }
-# ifndef MSWINCE
- strcpy(copy, s);
-# else
- /* strcpy() is deprecated in WinCE */
- memcpy(copy, s, lb);
-# endif
- return copy;
-}
-
-GC_API char * GC_CALL GC_strndup(const char *str, size_t size)
-{
- char *copy;
- size_t len = strlen(str); /* str is expected to be non-NULL */
- if (len > size)
- len = size;
- copy = GC_malloc_atomic(len + 1);
- if (copy == NULL) {
-# ifndef MSWINCE
- errno = ENOMEM;
-# endif
- return NULL;
- }
- BCOPY(str, copy, len);
- copy[len] = '\0';
- return copy;
-}
-
-#ifdef GC_REQUIRE_WCSDUP
-# include <wchar.h> /* for wcslen() */
-
- GC_API wchar_t * GC_CALL GC_wcsdup(const wchar_t *str)
- {
- size_t lb = (wcslen(str) + 1) * sizeof(wchar_t);
- wchar_t *copy = GC_malloc_atomic(lb);
- if (copy == NULL) {
-# ifndef MSWINCE
- errno = ENOMEM;
-# endif
- return NULL;
- }
- BCOPY(str, copy, lb);
- return copy;
- }
-#endif /* GC_REQUIRE_WCSDUP */
-
/* Allocate lb bytes of composite (pointerful) data */
#ifdef THREAD_LOCAL_ALLOC
GC_INNER void * GC_core_malloc(size_t lb)
@@ -326,19 +264,19 @@ GC_API char * GC_CALL GC_strndup(const char *str, size_t size)
}
}
-# ifdef REDIRECT_MALLOC
+#ifdef REDIRECT_MALLOC
+
+# ifndef MSWINCE
+# include <errno.h>
+# endif
/* Avoid unnecessary nested procedure calls here, by #defining some */
/* malloc replacements. Otherwise we end up saving a */
/* meaningless return address in the object. It also speeds things up, */
/* but it is admittedly quite ugly. */
-# ifdef GC_ADD_CALLER
-# define RA GC_RETURN_ADDR,
-# else
-# define RA
-# endif
+
# define GC_debug_malloc_replacement(lb) \
- GC_debug_malloc(lb, RA "unknown", 0)
+ GC_debug_malloc(lb, GC_DBG_RA "unknown", 0)
void * malloc(size_t lb)
{
@@ -381,7 +319,7 @@ void * malloc(size_t lb)
WARN("Failed to find ld.so text mapping: Expect crash\n", 0);
}
}
-#endif
+#endif /* GC_LINUX_THREADS */
void * calloc(size_t n, size_t lb)
{
@@ -408,7 +346,6 @@ void * calloc(size_t n, size_t lb)
}
#ifndef strdup
-# include <string.h>
char *strdup(const char *s)
{
size_t lb = strlen(s) + 1;
@@ -427,7 +364,6 @@ void * calloc(size_t n, size_t lb)
#ifndef strndup
/* This is similar to strdup(). */
-# include <string.h>
char *strndup(const char *str, size_t size)
{
char *copy;
@@ -447,7 +383,7 @@ void * calloc(size_t n, size_t lb)
#undef GC_debug_malloc_replacement
-# endif /* REDIRECT_MALLOC */
+#endif /* REDIRECT_MALLOC */
/* Explicitly deallocate an object p. */
GC_API void GC_CALL GC_free(void * p)