summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2010-05-28 15:29:12 +0200
committerLudovic Courtès <ludo@gnu.org>2010-05-28 17:02:13 +0200
commite3401c659eeb43e72f408a2cf9bdbe7ec9d14f12 (patch)
tree52c5ffdc007083798cb793697297e8edfcfe80c8
parent18dcd80e37d52d8406f02c8b2369b67692057cfd (diff)
downloadguile-e3401c659eeb43e72f408a2cf9bdbe7ec9d14f12.tar.gz
Use GCC's `malloc' attribute for malloc-like routines.
* libguile/__scm.h (SCM_MALLOC): New macro. * libguile/gc.h (scm_malloc, scm_calloc, scm_strdup, scm_strndup, scm_gc_malloc_pointerless, scm_gc_calloc, scm_gc_malloc, scm_gc_strdup, scm_gc_strndup): Mark as `SCM_MALLOC'.
-rw-r--r--libguile/__scm.h11
-rw-r--r--libguile/gc.h23
2 files changed, 24 insertions, 10 deletions
diff --git a/libguile/__scm.h b/libguile/__scm.h
index 93f666244..f0373e84e 100644
--- a/libguile/__scm.h
+++ b/libguile/__scm.h
@@ -3,7 +3,7 @@
#ifndef SCM___SCM_H
#define SCM___SCM_H
-/* Copyright (C) 1995,1996,1998,1999,2000,2001,2002,2003, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1998,1999,2000,2001,2002,2003, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@@ -126,6 +126,15 @@
# undef SCM_ALIGNED
#endif
+/* The SCM_MALLOC macro can be used in function declarations to tell the
+ * compiler that a function may be treated as if any non-NULL pointer it returns
+ * cannot alias any other pointer valid when the function returns. */
+#if defined (__GNUC__) && (__GNUC__ >= 3)
+# define SCM_MALLOC __attribute__ ((__malloc__))
+#else
+# define SCM_MALLOC
+#endif
+
/* {Supported Options}
*
diff --git a/libguile/gc.h b/libguile/gc.h
index 8f05aabcc..3c10b8ab4 100644
--- a/libguile/gc.h
+++ b/libguile/gc.h
@@ -182,23 +182,28 @@ SCM_API void scm_i_gc (const char *what);
SCM_API void scm_gc_mark (SCM p);
SCM_API void scm_gc_sweep (void);
-SCM_API void *scm_malloc (size_t size);
-SCM_API void *scm_calloc (size_t size);
+SCM_API void *scm_malloc (size_t size) SCM_MALLOC;
+SCM_API void *scm_calloc (size_t size) SCM_MALLOC;
SCM_API void *scm_realloc (void *mem, size_t size);
-SCM_API char *scm_strdup (const char *str);
-SCM_API char *scm_strndup (const char *str, size_t n);
+SCM_API char *scm_strdup (const char *str) SCM_MALLOC;
+SCM_API char *scm_strndup (const char *str, size_t n) SCM_MALLOC;
SCM_API void scm_gc_register_collectable_memory (void *mem, size_t size,
const char *what);
SCM_API void scm_gc_unregister_collectable_memory (void *mem, size_t size,
const char *what);
-SCM_API void *scm_gc_malloc_pointerless (size_t size, const char *what);
-SCM_API void *scm_gc_calloc (size_t size, const char *what);
-SCM_API void *scm_gc_malloc (size_t size, const char *what);
+SCM_API void *scm_gc_malloc_pointerless (size_t size, const char *what)
+ SCM_MALLOC;
+SCM_API void *scm_gc_calloc (size_t size, const char *what)
+ SCM_MALLOC;
+SCM_API void *scm_gc_malloc (size_t size, const char *what)
+ SCM_MALLOC;
SCM_API void *scm_gc_realloc (void *mem, size_t old_size,
size_t new_size, const char *what);
SCM_API void scm_gc_free (void *mem, size_t size, const char *what);
-SCM_API char *scm_gc_strdup (const char *str, const char *what);
-SCM_API char *scm_gc_strndup (const char *str, size_t n, const char *what);
+SCM_API char *scm_gc_strdup (const char *str, const char *what)
+ SCM_MALLOC;
+SCM_API char *scm_gc_strndup (const char *str, size_t n, const char *what)
+ SCM_MALLOC;
SCM_API void scm_remember_upto_here_1 (SCM obj);
SCM_API void scm_remember_upto_here_2 (SCM obj1, SCM obj2);