summaryrefslogtreecommitdiff
path: root/malloc.c
diff options
context:
space:
mode:
authorhboehm <hboehm>2006-03-10 06:24:07 +0100
committerIvan Maidanski <ivmai@mail.ru>2011-07-26 19:06:36 +0200
commit65c2804e5bea35c0e3158c063644994d9239a8ab (patch)
tree894ec2e3323aa9ac0113b72ea0c13d6f886f1dad /malloc.c
parent541151996c2ec4b2168538796f3516a31279b806 (diff)
2006-03-09 Hans Boehm <Hans.Boehm@hp.com>
Merge various gc6.7 changes (see doc/README.changes for contributors): * configure.ac, pthread_stop_world.c, pthread_support.c, threadlibs.c, include/gc_config_macros.h, include/gc_pthread_redirects.h, include/leak_detector.h, include/private/gcconfig.h, include/private/thread_local_alloc.h: Add NetBSD threads support. * dbg_mlc.c, malloc.c, include/gc.h: add GC_debug_str_dup, GC_str_dup. * os_dep.c (GC_init_win32), dyn_load.c (win32 GC_register_dynamic_libraries): accept MEM_PRIVATE for Windows 98 etc. * doc/gcinterface.html: Add warnings about thread locals and in-flight exceptions. * tests/tests.am: Add EXE extensions. * Makefile.in, configure: rebuild
Diffstat (limited to 'malloc.c')
-rw-r--r--malloc.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/malloc.c b/malloc.c
index 1513735..47319f8 100644
--- a/malloc.c
+++ b/malloc.c
@@ -14,6 +14,8 @@
*/
#include <stdio.h>
+#include <string.h>
+#include <errno.h>
#include "private/gc_priv.h"
extern void * GC_clear_stack(void *); /* in misc.c, behaves like identity */
@@ -229,6 +231,26 @@ void * GC_generic_malloc(size_t lb, int k)
}
}
+/* provide a version of strdup() that uses the collector to allocate the
+ copy of the string */
+# ifdef __STDC__
+ char *GC_strdup(const char *s)
+# else
+ char *GC_strdup(s)
+ char *s;
+#endif
+{
+ char *copy;
+
+ if (s == NULL) return NULL;
+ if ((copy = GC_malloc_atomic(strlen(s) + 1)) == NULL) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ strcpy(copy, s);
+ return copy;
+}
+
/* Allocate lb bytes of composite (pointerful) data */
#ifdef THREAD_LOCAL_ALLOC
void * GC_core_malloc(size_t lb)
@@ -308,6 +330,10 @@ void * calloc(size_t n, size_t lb)
{
size_t len = strlen(s) + 1;
char * result = ((char *)REDIRECT_MALLOC(len+1));
+ if (result == 0) {
+ errno = ENOMEM;
+ return 0;
+ }
BCOPY(s, result, len+1);
return result;
}