GC_API void GC_CALL GC_set_stop_func(GC_stop_func stop_func)
{
DCL_LOCK_STATE;
- GC_ASSERT(stop_func != 0);
+ GC_ASSERT(NONNULL_ARG_NOT_NULL(stop_func));
LOCK();
GC_default_stop_func = stop_func;
UNLOCK();
/* Externally callable routines to invoke full, stop-the-world collection. */
GC_API int GC_CALL GC_try_to_collect(GC_stop_func stop_func)
{
- GC_ASSERT(stop_func != 0);
+ GC_ASSERT(NONNULL_ARG_NOT_NULL(stop_func));
return (int)GC_try_to_collect_general(stop_func, FALSE);
}
GC_API int GC_CALL GC_general_register_disappearing_link(void * * link,
const void * obj)
{
- if (((word)link & (ALIGNMENT-1)) != 0 || NULL == link)
+ if (((word)link & (ALIGNMENT-1)) != 0 || !NONNULL_ARG_NOT_NULL(link))
ABORT("Bad arg to GC_general_register_disappearing_link");
return GC_register_disappearing_link_inner(&GC_dl_hashtbl, link, obj,
"dl");
#ifndef GC_LONG_REFS_NOT_NEEDED
GC_API int GC_CALL GC_register_long_link(void * * link, const void * obj)
{
- if (((word)link & (ALIGNMENT-1)) != 0 || NULL == link)
+ if (((word)link & (ALIGNMENT-1)) != 0 || !NONNULL_ARG_NOT_NULL(link))
ABORT("Bad arg to GC_register_long_link");
return GC_register_disappearing_link_inner(&GC_ll_hashtbl, link, obj,
"long dl");
int result;
DCL_LOCK_STATE;
- if (((word)new_link & (ALIGNMENT-1)) != 0 || new_link == NULL)
+ if (((word)new_link & (ALIGNMENT-1)) != 0
+ || !NONNULL_ARG_NOT_NULL(new_link))
ABORT("Bad new_link arg to GC_move_disappearing_link");
if (((word)link & (ALIGNMENT-1)) != 0)
return GC_NOT_FOUND; /* Nothing to do. */
int result;
DCL_LOCK_STATE;
- if (((word)new_link & (ALIGNMENT-1)) != 0 || new_link == NULL)
+ if (((word)new_link & (ALIGNMENT-1)) != 0
+ || !NONNULL_ARG_NOT_NULL(new_link))
ABORT("Bad new_link arg to GC_move_disappearing_link");
if (((word)link & (ALIGNMENT-1)) != 0)
return GC_NOT_FOUND; /* Nothing to do. */
# define GC_STATIC_ASSERT(expr) (void)sizeof(char[(expr)? 1 : -1])
#endif
+/* Runtime check for an argument declared as non-null is actually not null. */
+#if defined(__GNUC__) && __GNUC__ >= 4
+ /* Workaround tautological-pointer-compare Clang warning. */
+# define NONNULL_ARG_NOT_NULL(arg) (*(volatile void **)&(arg) != NULL)
+#else
+# define NONNULL_ARG_NOT_NULL(arg) (NULL != (arg))
+#endif
+
#define COND_DUMP_CHECKS \
do { \
GC_ASSERT(GC_compute_large_free_bytes() == GC_large_free_bytes); \
GC_API void GC_CALL GC_set_warn_proc(GC_warn_proc p)
{
DCL_LOCK_STATE;
- GC_ASSERT(p != 0);
+ GC_ASSERT(NONNULL_ARG_NOT_NULL(p));
# ifdef GC_WIN32_THREADS
# ifdef CYGWIN32
/* Need explicit GC_INIT call */
GC_API void GC_CALL GC_set_abort_func(GC_abort_func fn)
{
DCL_LOCK_STATE;
- GC_ASSERT(fn != 0);
+ GC_ASSERT(NONNULL_ARG_NOT_NULL(fn));
LOCK();
GC_on_abort = fn;
UNLOCK();
GC_API void GC_CALL GC_set_oom_fn(GC_oom_func fn)
{
- GC_ASSERT(fn != 0);
+ GC_ASSERT(NONNULL_ARG_NOT_NULL(fn));
DCL_LOCK_STATE;
LOCK();
GC_oom_fn = fn;