diff options
| author | Paul Eggert | 2012-07-05 11:35:48 -0700 |
|---|---|---|
| committer | Paul Eggert | 2012-07-05 11:35:48 -0700 |
| commit | 38182d901d030c7d65f4aa7a49b583afb30eb9b7 (patch) | |
| tree | a69e1a571495d6ca1c034359d7c995639774ab9b /src/buffer.c | |
| parent | 6dd5a677dbf794eedaa8325c46d57ac041373361 (diff) | |
| download | emacs-38182d901d030c7d65f4aa7a49b583afb30eb9b7.tar.gz emacs-38182d901d030c7d65f4aa7a49b583afb30eb9b7.zip | |
More xmalloc and related cleanup.
* alloc.c, bidi.c, buffer.c, buffer.h, bytecode.c, callint.c:
* callproc.c, charset.c, coding.c, composite.c, data.c, dispnew.c:
* doc.c, editfns.c, emacs.c, eval.c, fileio.c, filelock.c, fns.c:
* font.c, fontset.c, frame.c, fringe.c, ftfont.c, ftxfont.c, gmalloc.c:
* gtkutil.c, image.c, keyboard.c, keymap.c, lread.c, macros.c, menu.c:
* nsfns.m, nsfont.m, nsmenu.m, nsterm.m, print.c, process.c, ralloc.c:
* regex.c, region-cache.c, scroll.c, search.c, sound.c, syntax.c:
* sysdep.c, term.c, termcap.c, unexmacosx.c, window.c, xdisp.c:
* xfaces.c, xfns.c, xftfont.c, xgselect.c, xmenu.c, xrdb.c, xselect.c:
* xterm.c:
Omit needless casts involving void * pointers and allocation.
Prefer "P = xmalloc (sizeof *P)" to "P = xmalloc (sizeof (TYPE_OF_P))",
as the former is more robust if P's type is changed.
Prefer xzalloc to xmalloc + memset 0.
Simplify malloc-or-realloc to realloc.
Don't worry about xmalloc returning a null pointer.
Prefer xstrdup to xmalloc + strcpy.
* editfns.c (Fmessage_box): Grow message_text by at least 80 when
growing it.
* keyboard.c (apply_modifiers_uncached): Prefer local array to
alloca of a constant.
Diffstat (limited to 'src/buffer.c')
| -rw-r--r-- | src/buffer.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/buffer.c b/src/buffer.c index e1c33f4c711..838932db4df 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -2793,11 +2793,11 @@ mouse_face_overlay_overlaps (Lisp_Object overlay) | |||
| 2793 | Lisp_Object *v, tem; | 2793 | Lisp_Object *v, tem; |
| 2794 | 2794 | ||
| 2795 | size = 10; | 2795 | size = 10; |
| 2796 | v = (Lisp_Object *) alloca (size * sizeof *v); | 2796 | v = alloca (size * sizeof *v); |
| 2797 | n = overlays_in (start, end, 0, &v, &size, NULL, NULL); | 2797 | n = overlays_in (start, end, 0, &v, &size, NULL, NULL); |
| 2798 | if (n > size) | 2798 | if (n > size) |
| 2799 | { | 2799 | { |
| 2800 | v = (Lisp_Object *) alloca (n * sizeof *v); | 2800 | v = alloca (n * sizeof *v); |
| 2801 | overlays_in (start, end, 0, &v, &n, NULL, NULL); | 2801 | overlays_in (start, end, 0, &v, &n, NULL, NULL); |
| 2802 | } | 2802 | } |
| 2803 | 2803 | ||
| @@ -2885,8 +2885,7 @@ ptrdiff_t | |||
| 2885 | sort_overlays (Lisp_Object *overlay_vec, ptrdiff_t noverlays, struct window *w) | 2885 | sort_overlays (Lisp_Object *overlay_vec, ptrdiff_t noverlays, struct window *w) |
| 2886 | { | 2886 | { |
| 2887 | ptrdiff_t i, j; | 2887 | ptrdiff_t i, j; |
| 2888 | struct sortvec *sortvec; | 2888 | struct sortvec *sortvec = alloca (noverlays * sizeof *sortvec); |
| 2889 | sortvec = (struct sortvec *) alloca (noverlays * sizeof (struct sortvec)); | ||
| 2890 | 2889 | ||
| 2891 | /* Put the valid and relevant overlays into sortvec. */ | 2890 | /* Put the valid and relevant overlays into sortvec. */ |
| 2892 | 2891 | ||
| @@ -3893,7 +3892,7 @@ DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0, | |||
| 3893 | 3892 | ||
| 3894 | len = 10; | 3893 | len = 10; |
| 3895 | /* We can't use alloca here because overlays_at can call xrealloc. */ | 3894 | /* We can't use alloca here because overlays_at can call xrealloc. */ |
| 3896 | overlay_vec = xmalloc (len * sizeof (Lisp_Object)); | 3895 | overlay_vec = xmalloc (len * sizeof *overlay_vec); |
| 3897 | 3896 | ||
| 3898 | /* Put all the overlays we want in a vector in overlay_vec. | 3897 | /* Put all the overlays we want in a vector in overlay_vec. |
| 3899 | Store the length in len. */ | 3898 | Store the length in len. */ |
| @@ -3924,7 +3923,7 @@ end of the buffer. */) | |||
| 3924 | CHECK_NUMBER_COERCE_MARKER (end); | 3923 | CHECK_NUMBER_COERCE_MARKER (end); |
| 3925 | 3924 | ||
| 3926 | len = 10; | 3925 | len = 10; |
| 3927 | overlay_vec = xmalloc (len * sizeof (Lisp_Object)); | 3926 | overlay_vec = xmalloc (len * sizeof *overlay_vec); |
| 3928 | 3927 | ||
| 3929 | /* Put all the overlays we want in a vector in overlay_vec. | 3928 | /* Put all the overlays we want in a vector in overlay_vec. |
| 3930 | Store the length in len. */ | 3929 | Store the length in len. */ |
| @@ -3952,7 +3951,7 @@ the value is (point-max). */) | |||
| 3952 | CHECK_NUMBER_COERCE_MARKER (pos); | 3951 | CHECK_NUMBER_COERCE_MARKER (pos); |
| 3953 | 3952 | ||
| 3954 | len = 10; | 3953 | len = 10; |
| 3955 | overlay_vec = xmalloc (len * sizeof (Lisp_Object)); | 3954 | overlay_vec = xmalloc (len * sizeof *overlay_vec); |
| 3956 | 3955 | ||
| 3957 | /* Put all the overlays we want in a vector in overlay_vec. | 3956 | /* Put all the overlays we want in a vector in overlay_vec. |
| 3958 | Store the length in len. | 3957 | Store the length in len. |
| @@ -3996,7 +3995,7 @@ the value is (point-min). */) | |||
| 3996 | return pos; | 3995 | return pos; |
| 3997 | 3996 | ||
| 3998 | len = 10; | 3997 | len = 10; |
| 3999 | overlay_vec = xmalloc (len * sizeof (Lisp_Object)); | 3998 | overlay_vec = xmalloc (len * sizeof *overlay_vec); |
| 4000 | 3999 | ||
| 4001 | /* Put all the overlays we want in a vector in overlay_vec. | 4000 | /* Put all the overlays we want in a vector in overlay_vec. |
| 4002 | Store the length in len. | 4001 | Store the length in len. |
| @@ -4251,7 +4250,7 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after, | |||
| 4251 | First copy the vector contents, in case some of these hooks | 4250 | First copy the vector contents, in case some of these hooks |
| 4252 | do subsequent modification of the buffer. */ | 4251 | do subsequent modification of the buffer. */ |
| 4253 | ptrdiff_t size = last_overlay_modification_hooks_used; | 4252 | ptrdiff_t size = last_overlay_modification_hooks_used; |
| 4254 | Lisp_Object *copy = (Lisp_Object *) alloca (size * sizeof (Lisp_Object)); | 4253 | Lisp_Object *copy = alloca (size * sizeof *copy); |
| 4255 | ptrdiff_t i; | 4254 | ptrdiff_t i; |
| 4256 | 4255 | ||
| 4257 | memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents, | 4256 | memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents, |
| @@ -4873,7 +4872,7 @@ init_buffer_once (void) | |||
| 4873 | /* If you add, remove, or reorder Lisp_Objects in a struct buffer, make | 4872 | /* If you add, remove, or reorder Lisp_Objects in a struct buffer, make |
| 4874 | sure that this is still correct. Otherwise, mark_vectorlike may not | 4873 | sure that this is still correct. Otherwise, mark_vectorlike may not |
| 4875 | trace all Lisp_Objects in buffer_defaults and buffer_local_symbols. */ | 4874 | trace all Lisp_Objects in buffer_defaults and buffer_local_symbols. */ |
| 4876 | const int pvecsize | 4875 | const int pvecsize |
| 4877 | = (offsetof (struct buffer, own_text) - sizeof (struct vectorlike_header)) | 4876 | = (offsetof (struct buffer, own_text) - sizeof (struct vectorlike_header)) |
| 4878 | / sizeof (Lisp_Object); | 4877 | / sizeof (Lisp_Object); |
| 4879 | 4878 | ||
| @@ -5089,7 +5088,7 @@ init_buffer (void) | |||
| 5089 | if (!(IS_DIRECTORY_SEP (pwd[len - 1]))) | 5088 | if (!(IS_DIRECTORY_SEP (pwd[len - 1]))) |
| 5090 | { | 5089 | { |
| 5091 | /* Grow buffer to add directory separator and '\0'. */ | 5090 | /* Grow buffer to add directory separator and '\0'. */ |
| 5092 | pwd = (char *) realloc (pwd, len + 2); | 5091 | pwd = realloc (pwd, len + 2); |
| 5093 | if (!pwd) | 5092 | if (!pwd) |
| 5094 | fatal ("`get_current_dir_name' failed: %s\n", strerror (errno)); | 5093 | fatal ("`get_current_dir_name' failed: %s\n", strerror (errno)); |
| 5095 | pwd[len] = DIRECTORY_SEP; | 5094 | pwd[len] = DIRECTORY_SEP; |