diff options
| author | Paul Eggert | 2014-05-22 09:40:35 -0700 |
|---|---|---|
| committer | Paul Eggert | 2014-05-22 09:40:35 -0700 |
| commit | 74fde0f44f68a14d920db4d24626984e2964368d (patch) | |
| tree | ce487b5a0080a9a9abbef810f93bb19069defe95 /src | |
| parent | bbd03f131a88ab1ff993bb6bba1bea93e7ee17ea (diff) | |
| download | emacs-74fde0f44f68a14d920db4d24626984e2964368d.tar.gz emacs-74fde0f44f68a14d920db4d24626984e2964368d.zip | |
Supply malloc and alloc_size attributes for extern allocators.
This documents the C API, and helps GCC generate a bit better code.
* conf_post.h (ATTRIBUTE_MALLOC, ATTRIBUTE_ALLOC_SIZE)
(ATTRIBUTE_MALLOC_SIZE): New macros.
* gmalloc.c (malloc, realloc, calloc):
* gtkutil.h (malloc_widget_value):
* lisp.h (ralloc, r_re_alloc, xmalloc, xzalloc, xrealloc, xnmalloc)
(xnrealloc, xstrdup, xlispstrdup, record_xmalloc):
Use them.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 12 | ||||
| -rw-r--r-- | src/conf_post.h | 14 | ||||
| -rw-r--r-- | src/gmalloc.c | 6 | ||||
| -rw-r--r-- | src/gtkutil.h | 2 | ||||
| -rw-r--r-- | src/lisp.h | 21 |
5 files changed, 41 insertions, 14 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 29039395374..5c3486d131a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,15 @@ | |||
| 1 | 2014-05-22 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | Supply malloc and alloc_size attributes for extern allocators. | ||
| 4 | This documents the C API, and helps GCC generate a bit better code. | ||
| 5 | * conf_post.h (ATTRIBUTE_MALLOC, ATTRIBUTE_ALLOC_SIZE) | ||
| 6 | (ATTRIBUTE_MALLOC_SIZE): New macros. | ||
| 7 | * gmalloc.c (malloc, realloc, calloc): | ||
| 8 | * gtkutil.h (malloc_widget_value): | ||
| 9 | * lisp.h (ralloc, r_re_alloc, xmalloc, xzalloc, xrealloc, xnmalloc) | ||
| 10 | (xnrealloc, xstrdup, xlispstrdup, record_xmalloc): | ||
| 11 | Use them. | ||
| 12 | |||
| 1 | 2014-05-21 Paul Eggert <eggert@cs.ucla.edu> | 13 | 2014-05-21 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 14 | ||
| 3 | Don't assume that ImageMagick uses a 16-bit quantum (Bug#17519). | 15 | Don't assume that ImageMagick uses a 16-bit quantum (Bug#17519). |
diff --git a/src/conf_post.h b/src/conf_post.h index 123f4803da5..6f6af3d3e02 100644 --- a/src/conf_post.h +++ b/src/conf_post.h | |||
| @@ -225,6 +225,20 @@ extern void _DebPrint (const char *fmt, ...); | |||
| 225 | 225 | ||
| 226 | #define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST | 226 | #define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST |
| 227 | 227 | ||
| 228 | #if 3 <= __GNUC__ | ||
| 229 | # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) | ||
| 230 | #else | ||
| 231 | # define ATTRIBUTE_MALLOC | ||
| 232 | #endif | ||
| 233 | |||
| 234 | #if 4 < __GNUC__ + (3 <= __GNUC_MINOR__) | ||
| 235 | # define ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args)) | ||
| 236 | #else | ||
| 237 | # define ATTRIBUTE_ALLOC_SIZE(args) | ||
| 238 | #endif | ||
| 239 | |||
| 240 | #define ATTRIBUTE_MALLOC_SIZE(args) ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE (args) | ||
| 241 | |||
| 228 | /* Work around GCC bug 59600: when a function is inlined, the inlined | 242 | /* Work around GCC bug 59600: when a function is inlined, the inlined |
| 229 | code may have its addresses sanitized even if the function has the | 243 | code may have its addresses sanitized even if the function has the |
| 230 | no_sanitize_address attribute. This bug is fixed in GCC 4.9.0 and | 244 | no_sanitize_address attribute. This bug is fixed in GCC 4.9.0 and |
diff --git a/src/gmalloc.c b/src/gmalloc.c index 977abbdbbbd..ab1dfd07db2 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c | |||
| @@ -51,12 +51,12 @@ extern "C" | |||
| 51 | 51 | ||
| 52 | 52 | ||
| 53 | /* Allocate SIZE bytes of memory. */ | 53 | /* Allocate SIZE bytes of memory. */ |
| 54 | extern void *malloc (size_t size); | 54 | extern void *malloc (size_t size) ATTRIBUTE_MALLOC_SIZE ((1)); |
| 55 | /* Re-allocate the previously allocated block | 55 | /* Re-allocate the previously allocated block |
| 56 | in ptr, making the new block SIZE bytes long. */ | 56 | in ptr, making the new block SIZE bytes long. */ |
| 57 | extern void *realloc (void *ptr, size_t size); | 57 | extern void *realloc (void *ptr, size_t size) ATTRIBUTE_ALLOC_SIZE ((2)); |
| 58 | /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */ | 58 | /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */ |
| 59 | extern void *calloc (size_t nmemb, size_t size); | 59 | extern void *calloc (size_t nmemb, size_t size) ATTRIBUTE_MALLOC_SIZE ((1,2)); |
| 60 | /* Free a block allocated by `malloc', `realloc' or `calloc'. */ | 60 | /* Free a block allocated by `malloc', `realloc' or `calloc'. */ |
| 61 | extern void free (void *ptr); | 61 | extern void free (void *ptr); |
| 62 | 62 | ||
diff --git a/src/gtkutil.h b/src/gtkutil.h index 12bf461fd69..b576fc6d9fe 100644 --- a/src/gtkutil.h +++ b/src/gtkutil.h | |||
| @@ -74,7 +74,7 @@ typedef struct xg_menu_item_cb_data_ | |||
| 74 | 74 | ||
| 75 | } xg_menu_item_cb_data; | 75 | } xg_menu_item_cb_data; |
| 76 | 76 | ||
| 77 | extern struct _widget_value *malloc_widget_value (void); | 77 | extern struct _widget_value *malloc_widget_value (void) ATTRIBUTE_MALLOC; |
| 78 | extern void free_widget_value (struct _widget_value *); | 78 | extern void free_widget_value (struct _widget_value *); |
| 79 | 79 | ||
| 80 | extern bool xg_uses_old_file_dialog (void) ATTRIBUTE_CONST; | 80 | extern bool xg_uses_old_file_dialog (void) ATTRIBUTE_CONST; |
diff --git a/src/lisp.h b/src/lisp.h index 67b26ef91c7..40dd03c4fc4 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -3755,9 +3755,9 @@ INLINE void (check_cons_list) (void) { lisp_h_check_cons_list (); } | |||
| 3755 | 3755 | ||
| 3756 | #ifdef REL_ALLOC | 3756 | #ifdef REL_ALLOC |
| 3757 | /* Defined in ralloc.c. */ | 3757 | /* Defined in ralloc.c. */ |
| 3758 | extern void *r_alloc (void **, size_t); | 3758 | extern void *r_alloc (void **, size_t) ATTRIBUTE_ALLOC_SIZE ((2)); |
| 3759 | extern void r_alloc_free (void **); | 3759 | extern void r_alloc_free (void **); |
| 3760 | extern void *r_re_alloc (void **, size_t); | 3760 | extern void *r_re_alloc (void **, size_t) ATTRIBUTE_ALLOC_SIZE ((2)); |
| 3761 | extern void r_alloc_reset_variable (void **, void **); | 3761 | extern void r_alloc_reset_variable (void **, void **); |
| 3762 | extern void r_alloc_inhibit_buffer_relocation (int); | 3762 | extern void r_alloc_inhibit_buffer_relocation (int); |
| 3763 | #endif | 3763 | #endif |
| @@ -4391,16 +4391,17 @@ extern bool initialized; | |||
| 4391 | /* True means ^G can quit instantly. */ | 4391 | /* True means ^G can quit instantly. */ |
| 4392 | extern bool immediate_quit; | 4392 | extern bool immediate_quit; |
| 4393 | 4393 | ||
| 4394 | extern void *xmalloc (size_t); | 4394 | extern void *xmalloc (size_t) ATTRIBUTE_MALLOC_SIZE ((1)); |
| 4395 | extern void *xzalloc (size_t); | 4395 | extern void *xzalloc (size_t) ATTRIBUTE_MALLOC_SIZE ((1)); |
| 4396 | extern void *xrealloc (void *, size_t); | 4396 | extern void *xrealloc (void *, size_t) ATTRIBUTE_ALLOC_SIZE ((2)); |
| 4397 | extern void xfree (void *); | 4397 | extern void xfree (void *); |
| 4398 | extern void *xnmalloc (ptrdiff_t, ptrdiff_t); | 4398 | extern void *xnmalloc (ptrdiff_t, ptrdiff_t) ATTRIBUTE_MALLOC_SIZE ((1,2)); |
| 4399 | extern void *xnrealloc (void *, ptrdiff_t, ptrdiff_t); | 4399 | extern void *xnrealloc (void *, ptrdiff_t, ptrdiff_t) |
| 4400 | ATTRIBUTE_ALLOC_SIZE ((2,3)); | ||
| 4400 | extern void *xpalloc (void *, ptrdiff_t *, ptrdiff_t, ptrdiff_t, ptrdiff_t); | 4401 | extern void *xpalloc (void *, ptrdiff_t *, ptrdiff_t, ptrdiff_t, ptrdiff_t); |
| 4401 | 4402 | ||
| 4402 | extern char *xstrdup (const char *); | 4403 | extern char *xstrdup (const char *) ATTRIBUTE_MALLOC; |
| 4403 | extern char *xlispstrdup (Lisp_Object); | 4404 | extern char *xlispstrdup (Lisp_Object) ATTRIBUTE_MALLOC; |
| 4404 | extern void dupstring (char **, char const *); | 4405 | extern void dupstring (char **, char const *); |
| 4405 | extern void xputenv (const char *); | 4406 | extern void xputenv (const char *); |
| 4406 | 4407 | ||
| @@ -4432,7 +4433,7 @@ extern void init_system_name (void); | |||
| 4432 | 4433 | ||
| 4433 | enum MAX_ALLOCA { MAX_ALLOCA = 16 * 1024 }; | 4434 | enum MAX_ALLOCA { MAX_ALLOCA = 16 * 1024 }; |
| 4434 | 4435 | ||
| 4435 | extern void *record_xmalloc (size_t); | 4436 | extern void *record_xmalloc (size_t) ATTRIBUTE_ALLOC_SIZE ((1)); |
| 4436 | 4437 | ||
| 4437 | #define USE_SAFE_ALLOCA \ | 4438 | #define USE_SAFE_ALLOCA \ |
| 4438 | ptrdiff_t sa_count = SPECPDL_INDEX (); bool sa_must_free = false | 4439 | ptrdiff_t sa_count = SPECPDL_INDEX (); bool sa_must_free = false |