diff options
| author | Dmitry Antipov | 2012-07-05 10:32:41 +0400 |
|---|---|---|
| committer | Dmitry Antipov | 2012-07-05 10:32:41 +0400 |
| commit | 23f86fce48e1cc8118f0ea5cce49d1acfd4364c4 (patch) | |
| tree | 837ae05f1ad4ad92936f804d580d95751779befe /src/alloc.c | |
| parent | 0497dc44b44f148425ff76c4cb7ef0d2ead9750b (diff) | |
| download | emacs-23f86fce48e1cc8118f0ea5cce49d1acfd4364c4.tar.gz emacs-23f86fce48e1cc8118f0ea5cce49d1acfd4364c4.zip | |
Cleanup xmalloc.
* admin/coccinelle/xzalloc.cocci: Semantic patch to convert
calls to xmalloc with following memset to xzalloc.
* src/lisp.h (xzalloc): New prototype. Omit needless casts.
* src/alloc.c (xzalloc): New function. Omit needless casts.
* src/charset.c: Omit needless casts. Convert all calls to
malloc with following memset to xzalloc.
* src/dispnew.c: Likewise.
* src/fringe.c: Likewise.
* src/image.c: Likewise.
* src/sound.c: Likewise.
* src/term.c: Likewise.
* src/w32fns.c: Likewise.
* src/w32font.c: Likewise.
* src/w32term.c: Likewise.
* src/xfaces.c: Likewise.
* src/xfns.c: Likewise.
* src/xterm.c: Likewise.
* src/atimer.c: Omit needless casts.
* src/buffer.c: Likewise.
* src/callproc.c: Likewise.
* src/ccl.c: Likewise.
* src/coding.c: Likewise.
* src/composite.c: Likewise.
* src/doc.c: Likewise.
* src/doprnt.c: Likewise.
* src/editfns.c: Likewise.
* src/emacs.c: Likewise.
* src/eval.c: Likewise.
* src/filelock.c: Likewise.
* src/fns.c: Likewise.
* src/gtkutil.c: Likewise.
* src/keyboard.c: Likewise.
* src/lisp.h: Likewise.
* src/lread.c: Likewise.
* src/minibuf.c: Likewise.
* src/msdos.c: Likewise.
* src/print.c: Likewise.
* src/process.c: Likewise.
* src/region-cache.c: Likewise.
* src/search.c: Likewise.
* src/sysdep.c: Likewise.
* src/termcap.c: Likewise.
* src/terminal.c: Likewise.
* src/tparam.c: Likewise.
* src/w16select.c: Likewise.
* src/w32.c: Likewise.
* src/w32reg.c: Likewise.
* src/w32select.c: Likewise.
* src/w32uniscribe.c: Likewise.
* src/widget.c: Likewise.
* src/xdisp.c: Likewise.
* src/xmenu.c: Likewise.
* src/xrdb.c: Likewise.
* src/xselect.c: Likewise.
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/alloc.c b/src/alloc.c index ed5d6b5099f..6ef0782ca1b 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -735,6 +735,22 @@ xmalloc (size_t size) | |||
| 735 | return val; | 735 | return val; |
| 736 | } | 736 | } |
| 737 | 737 | ||
| 738 | /* Like the above, but zeroes out the memory just allocated. */ | ||
| 739 | |||
| 740 | void * | ||
| 741 | xzalloc (size_t size) | ||
| 742 | { | ||
| 743 | void *val; | ||
| 744 | |||
| 745 | MALLOC_BLOCK_INPUT; | ||
| 746 | val = malloc (size); | ||
| 747 | MALLOC_UNBLOCK_INPUT; | ||
| 748 | |||
| 749 | if (!val && size) | ||
| 750 | memory_full (size); | ||
| 751 | memset (val, 0, size); | ||
| 752 | return val; | ||
| 753 | } | ||
| 738 | 754 | ||
| 739 | /* Like realloc but check for no memory and block interrupt input.. */ | 755 | /* Like realloc but check for no memory and block interrupt input.. */ |
| 740 | 756 | ||
| @@ -867,7 +883,7 @@ char * | |||
| 867 | xstrdup (const char *s) | 883 | xstrdup (const char *s) |
| 868 | { | 884 | { |
| 869 | size_t len = strlen (s) + 1; | 885 | size_t len = strlen (s) + 1; |
| 870 | char *p = (char *) xmalloc (len); | 886 | char *p = xmalloc (len); |
| 871 | memcpy (p, s, len); | 887 | memcpy (p, s, len); |
| 872 | return p; | 888 | return p; |
| 873 | } | 889 | } |
| @@ -3881,7 +3897,7 @@ mem_insert (void *start, void *end, enum mem_type type) | |||
| 3881 | if (x == NULL) | 3897 | if (x == NULL) |
| 3882 | abort (); | 3898 | abort (); |
| 3883 | #else | 3899 | #else |
| 3884 | x = (struct mem_node *) xmalloc (sizeof *x); | 3900 | x = xmalloc (sizeof *x); |
| 3885 | #endif | 3901 | #endif |
| 3886 | x->start = start; | 3902 | x->start = start; |
| 3887 | x->end = end; | 3903 | x->end = end; |
| @@ -5047,7 +5063,7 @@ pure_alloc (size_t size, int type) | |||
| 5047 | /* Don't allocate a large amount here, | 5063 | /* Don't allocate a large amount here, |
| 5048 | because it might get mmap'd and then its address | 5064 | because it might get mmap'd and then its address |
| 5049 | might not be usable. */ | 5065 | might not be usable. */ |
| 5050 | purebeg = (char *) xmalloc (10000); | 5066 | purebeg = xmalloc (10000); |
| 5051 | pure_size = 10000; | 5067 | pure_size = 10000; |
| 5052 | pure_bytes_used_before_overflow += pure_bytes_used - size; | 5068 | pure_bytes_used_before_overflow += pure_bytes_used - size; |
| 5053 | pure_bytes_used = 0; | 5069 | pure_bytes_used = 0; |