+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.
+
2011-04-07 Ivan Maidanski <ivmai@mail.ru>
* alloc.c (GC_check_heap, GC_print_all_smashed): Move the
GC_INNER void GC_default_print_heap_obj_proc(ptr_t p);
-GC_API void GC_CALL GC_register_finalizer_no_order(void * obj,
- GC_finalization_proc fn, void * cd,
- GC_finalization_proc *ofn, void * *ocd);
-
#ifndef SHORT_DBG_HDRS
/* Check whether object with base pointer p has debugging info */
/* p is assumed to point to a legitimate object in our part */
}
return(FALSE);
}
-#endif
+#endif /* !SHORT_DBG_HDRS */
#ifdef KEEP_BACK_PTRS
GC_INNER void GC_start_debugging(void)
{
-# ifndef SHORT_DBG_HDRS
- GC_check_heap = GC_check_heap_proc;
- GC_print_all_smashed = GC_print_all_smashed_proc;
-# else
- GC_check_heap = GC_do_nothing;
- GC_print_all_smashed = GC_do_nothing;
-# endif
- GC_print_heap_obj = GC_debug_print_heap_obj_proc;
- GC_debugging_started = TRUE;
- GC_register_displacement((word)sizeof(oh));
+# ifndef SHORT_DBG_HDRS
+ GC_check_heap = GC_check_heap_proc;
+ GC_print_all_smashed = GC_print_all_smashed_proc;
+# else
+ GC_check_heap = GC_do_nothing;
+ GC_print_all_smashed = GC_do_nothing;
+# endif
+ GC_print_heap_obj = GC_debug_print_heap_obj_proc;
+ GC_debugging_started = TRUE;
+ GC_register_displacement((word)sizeof(oh));
}
size_t GC_debug_header_size = sizeof(oh);
store_old(obj, my_old_fn, (struct closure *)my_old_cd, ofn, ocd);
}
-#ifdef GC_ADD_CALLER
-# define RA GC_RETURN_ADDR,
-#else
-# define RA
-#endif
-
GC_API void * GC_CALL GC_debug_malloc_replacement(size_t lb)
{
- return GC_debug_malloc(lb, RA "unknown", 0);
+ return GC_debug_malloc(lb, GC_DBG_RA "unknown", 0);
}
GC_API void * GC_CALL GC_debug_realloc_replacement(void *p, size_t lb)
{
- return GC_debug_realloc(p, lb, RA "unknown", 0);
+ return GC_debug_realloc(p, lb, GC_DBG_RA "unknown", 0);
}
return((void *) op);
}
-GC_INNER void GC_start_debugging(void);
+GC_INNER void GC_start_debugging(void); /* defined in dbg_mlc.c */
+
+/* Store debugging info into p. Return displaced pointer. */
+/* Assumes we don't hold allocation lock. */
+GC_INNER ptr_t GC_store_debug_info(ptr_t p, word sz, const char *str,
+ word integer);
/* Similar to GC_gcj_malloc, but add debug info. This is allocated */
/* with GC_gcj_debug_kind. */
void * result;
DCL_LOCK_STATE;
- /* We're careful to avoid extra calls, which could */
+ /* We're careful to avoid extra calls, which could */
/* confuse the backtrace. */
LOCK();
maybe_finalize();
# define GC_HAS_DEBUG_INFO(p) GC_has_other_debug_info(p)
#endif
-/* Store debugging info into p. Return displaced pointer. */
-/* Assumes we don't hold allocation lock. */
-GC_INNER ptr_t GC_store_debug_info(ptr_t p, word sz, const char *str,
- word integer);
-
#endif /* _DBG_MLC_H */
{ GC_ASSERT(I_HOLD_LOCK()); UNSET_LOCK_HOLDER(); \
LeaveCriticalSection(&GC_allocate_ml); }
# else
-# define UNCOND_LOCK() EnterCriticalSection(&GC_allocate_ml);
-# define UNCOND_UNLOCK() LeaveCriticalSection(&GC_allocate_ml);
+# define UNCOND_LOCK() EnterCriticalSection(&GC_allocate_ml)
+# define UNCOND_UNLOCK() LeaveCriticalSection(&GC_allocate_ml)
# endif /* !GC_ASSERTIONS */
# define SET_LOCK_HOLDER() GC_lock_holder = GetCurrentThreadId()
# define UNSET_LOCK_HOLDER() GC_lock_holder = NO_THREAD
/* GC_call_with_alloc_lock. */
# ifdef GC_ASSERTIONS
# define UNCOND_LOCK() \
- { if (AO_test_and_set_acquire(&GC_allocate_lock) == AO_TS_SET) \
- GC_lock(); \
- SET_LOCK_HOLDER(); }
+ { if (AO_test_and_set_acquire(&GC_allocate_lock) == AO_TS_SET) \
+ GC_lock(); \
+ SET_LOCK_HOLDER(); }
# define UNCOND_UNLOCK() \
- { GC_ASSERT(I_HOLD_LOCK()); UNSET_LOCK_HOLDER(); \
- AO_CLEAR(&GC_allocate_lock); }
+ { GC_ASSERT(I_HOLD_LOCK()); UNSET_LOCK_HOLDER(); \
+ AO_CLEAR(&GC_allocate_lock); }
# else
# define UNCOND_LOCK() \
- { if (AO_test_and_set_acquire(&GC_allocate_lock) == AO_TS_SET) \
- GC_lock(); }
-# define UNCOND_UNLOCK() \
- AO_CLEAR(&GC_allocate_lock)
+ { if (AO_test_and_set_acquire(&GC_allocate_lock) == AO_TS_SET) \
+ GC_lock(); }
+# define UNCOND_UNLOCK() AO_CLEAR(&GC_allocate_lock)
# endif /* !GC_ASSERTIONS */
# else /* THREAD_LOCAL_ALLOC || USE_PTHREAD_LOCKS */
# ifndef USE_PTHREAD_LOCKS
# include <pthread.h>
GC_EXTERN pthread_mutex_t GC_allocate_ml;
# ifdef GC_ASSERTIONS
-# define UNCOND_LOCK() \
- { GC_lock(); \
- SET_LOCK_HOLDER(); }
+# define UNCOND_LOCK() { GC_lock(); SET_LOCK_HOLDER(); }
# define UNCOND_UNLOCK() \
{ GC_ASSERT(I_HOLD_LOCK()); UNSET_LOCK_HOLDER(); \
pthread_mutex_unlock(&GC_allocate_ml); }
# else /* !GC_ASSERTIONS */
# if defined(NO_PTHREAD_TRYLOCK)
-# define UNCOND_LOCK() GC_lock();
+# define UNCOND_LOCK() GC_lock()
# else /* !defined(NO_PTHREAD_TRYLOCK) */
# define UNCOND_LOCK() \
- { if (0 != pthread_mutex_trylock(&GC_allocate_ml)) GC_lock(); }
+ { if (0 != pthread_mutex_trylock(&GC_allocate_ml)) \
+ GC_lock(); }
# endif
# define UNCOND_UNLOCK() pthread_mutex_unlock(&GC_allocate_ml)
# endif /* !GC_ASSERTIONS */
#if defined(UNCOND_LOCK) && !defined(LOCK)
/* At least two thread running; need to lock. */
-# define LOCK() if (GC_need_to_lock) { UNCOND_LOCK(); }
-# define UNLOCK() if (GC_need_to_lock) { UNCOND_UNLOCK(); }
+# define LOCK() { if (GC_need_to_lock) UNCOND_LOCK(); }
+# define UNLOCK() { if (GC_need_to_lock) UNCOND_UNLOCK(); }
#endif
# ifndef ENTER_GC
# define START_WORLD() \
PCR_ThCtl_SetExclusiveMode(PCR_ThCtl_ExclusiveMode_null, \
PCR_allSigsBlocked, \
- PCR_waitForever);
+ PCR_waitForever)
# else
# if defined(GC_WIN32_THREADS) || defined(GC_PTHREADS)
GC_INNER void GC_stop_world(void);
GC_INNER void * GC_clear_stack(void *);
/* in misc.c, behaves like identity. */
+#ifdef GC_ADD_CALLER
+# define GC_DBG_RA GC_RETURN_ADDR,
+#else
+# define GC_DBG_RA /* empty */
+#endif
+
/* We make the GC_clear_stack() call a tail one, hoping to get more of */
/* the stack. */
#define GENERAL_MALLOC(lb,k) \
#ifndef NO_DEBUGGING
GC_EXTERN GC_bool GC_dump_regularly;
/* Generate regular debugging dumps. */
-# define COND_DUMP if (GC_dump_regularly) GC_dump();
+# define COND_DUMP if (GC_dump_regularly) GC_dump()
#else
-# define COND_DUMP
+# define COND_DUMP /* empty */
#endif
#ifdef KEEP_BACK_PTRS
#include <stdio.h>
#include <string.h>
-#ifndef MSWINCE
-# include <errno.h>
-#endif
GC_INNER void GC_extend_size_map(size_t); /* in misc.c */
}
}
-/* 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)
}
}
-# 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)
{
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)
{
}
#ifndef strdup
-# include <string.h>
char *strdup(const char *s)
{
size_t lb = strlen(s) + 1;
#ifndef strndup
/* This is similar to strdup(). */
-# include <string.h>
char *strndup(const char *str, size_t size)
{
char *copy;
#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)
*/
#include <stdio.h>
+#include <string.h>
#ifdef MSWINCE
# ifndef WIN32_LEAN_AND_MEAN
# ifdef REDIRECT_REALLOC
/* As with malloc, avoid two levels of extra calls here. */
-# ifdef GC_ADD_CALLER
-# define RA GC_RETURN_ADDR,
-# else
-# define RA
-# endif
+
# define GC_debug_realloc_replacement(p, lb) \
- GC_debug_realloc(p, lb, RA "unknown", 0)
+ GC_debug_realloc(p, lb, GC_DBG_RA "unknown", 0)
void * realloc(void * p, size_t lb)
{
}
}
#endif /* ATOMIC_UNCOLLECTABLE */
+
+/* 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 */