diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 280 | ||||
| -rw-r--r-- | src/alloc.c | 153 | ||||
| -rw-r--r-- | src/bidi.c | 51 | ||||
| -rw-r--r-- | src/buffer.c | 10 | ||||
| -rw-r--r-- | src/callint.c | 2 | ||||
| -rw-r--r-- | src/callproc.c | 2 | ||||
| -rw-r--r-- | src/data.c | 3 | ||||
| -rw-r--r-- | src/dispnew.c | 67 | ||||
| -rw-r--r-- | src/doprnt.c | 23 | ||||
| -rw-r--r-- | src/editfns.c | 40 | ||||
| -rw-r--r-- | src/emacs.c | 8 | ||||
| -rw-r--r-- | src/eval.c | 10 | ||||
| -rw-r--r-- | src/fileio.c | 6 | ||||
| -rw-r--r-- | src/filelock.c | 15 | ||||
| -rw-r--r-- | src/floatfns.c | 3 | ||||
| -rw-r--r-- | src/fns.c | 26 | ||||
| -rw-r--r-- | src/gmalloc.c | 158 | ||||
| -rw-r--r-- | src/gnutls.c | 3 | ||||
| -rw-r--r-- | src/gtkutil.c | 6 | ||||
| -rw-r--r-- | src/image.c | 226 | ||||
| -rw-r--r-- | src/keyboard.c | 4 | ||||
| -rw-r--r-- | src/keyboard.h | 4 | ||||
| -rw-r--r-- | src/lisp.h | 37 | ||||
| -rw-r--r-- | src/lread.c | 22 | ||||
| -rw-r--r-- | src/nsfns.m | 13 | ||||
| -rw-r--r-- | src/nsfont.m | 57 | ||||
| -rw-r--r-- | src/nsmenu.m | 23 | ||||
| -rw-r--r-- | src/nsterm.h | 8 | ||||
| -rw-r--r-- | src/nsterm.m | 214 | ||||
| -rw-r--r-- | src/print.c | 15 | ||||
| -rw-r--r-- | src/regex.c | 103 | ||||
| -rw-r--r-- | src/s/aix4-2.h | 5 | ||||
| -rw-r--r-- | src/s/ms-w32.h | 5 | ||||
| -rw-r--r-- | src/sysdep.c | 55 | ||||
| -rw-r--r-- | src/xdisp.c | 11 | ||||
| -rw-r--r-- | src/xfaces.c | 10 | ||||
| -rw-r--r-- | src/xselect.c | 7 | ||||
| -rw-r--r-- | src/xterm.h | 4 |
38 files changed, 954 insertions, 735 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index dd25d155c66..6039a54c559 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,283 @@ | |||
| 1 | 2011-07-29 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | * image.c (check_image_size): Use 1024x1024 if unknown frame (Bug#9189). | ||
| 4 | This is needed if max-image-size is a floating-point number. | ||
| 5 | |||
| 6 | 2011-07-28 Andreas Schwab <schwab@linux-m68k.org> | ||
| 7 | |||
| 8 | * print.c (print_object): Print empty symbol as ##. | ||
| 9 | |||
| 10 | * lread.c (read1): Read ## as empty symbol. | ||
| 11 | |||
| 12 | 2011-07-28 Alp Aker <alp.tekin.aker@gmail.com> | ||
| 13 | |||
| 14 | * nsfns.m (x_set_foreground_color): Set f->foreground_pixel when | ||
| 15 | setting frame foreground color (Bug#9175). | ||
| 16 | (x_set_background_color): Likewise. | ||
| 17 | |||
| 18 | * nsmenu.m (-setText): Size tooltip dimensions precisely to | ||
| 19 | contents (Bug#9176). | ||
| 20 | (EmacsTooltip -init): Remove bezels and add shadows to | ||
| 21 | tooltip windows. | ||
| 22 | |||
| 23 | * nsterm.m (ns_dumpglyphs_stretch): Avoid overwriting left fringe | ||
| 24 | or scroll bar (Bug#8470). | ||
| 25 | |||
| 26 | * nsfont.m (nsfont_open): Remove assignment to voffset and | ||
| 27 | unnecessary vars hshink, expand, hd, full_height, min_height. | ||
| 28 | (nsfont_draw): Use s->ybase as baseline for glyph drawing (Bug#8913). | ||
| 29 | |||
| 30 | * nsterm.h (nsfont_info): Remove voffset field. | ||
| 31 | |||
| 32 | 2011-07-28 Alp Aker <alp.tekin.aker@gmail.com> | ||
| 33 | |||
| 34 | Implement strike-through and overline on NextStep (Bug#8863). | ||
| 35 | |||
| 36 | * nsfont.m (nsfont_open): Use underline position provided by font, | ||
| 37 | instead of hard-coded value of 2. | ||
| 38 | (nsfont_draw): Call ns_draw_text_decoration instead. | ||
| 39 | |||
| 40 | * nsterm.h: Add declaration for ns_draw_text_decoration. | ||
| 41 | |||
| 42 | * nsterm.m (ns_draw_text_decoration): New function for drawing | ||
| 43 | underline, overline, and strike-through. | ||
| 44 | (ns_dumpglyphs_image, ns_dumpglyphs_stretch): Add call to | ||
| 45 | ns_draw_text_decoration. Change treatment of cursor drawing to | ||
| 46 | accomodate underlining, etc. | ||
| 47 | |||
| 48 | 2011-07-28 Eli Zaretskii <eliz@gnu.org> | ||
| 49 | |||
| 50 | * buffer.c (init_buffer_once): Set bidi-display-reordering to t by | ||
| 51 | default. | ||
| 52 | |||
| 53 | 2011-07-28 Paul Eggert <eggert@cs.ucla.edu> | ||
| 54 | |||
| 55 | * alloc.c (memory_full) [!SYNC_INPUT]: Fix signal-related race. | ||
| 56 | Without this fix, if a signal arrives just after memory fills up, | ||
| 57 | 'malloc' might be invoked reentrantly. | ||
| 58 | |||
| 59 | * image.c (x_check_image_size) [!HAVE_X_WINDOWS]: Return 1. | ||
| 60 | In other words, assume that every image size is allowed, on non-X | ||
| 61 | hosts. This assumption is probably wrong, but it lets Emacs compile. | ||
| 62 | |||
| 63 | 2011-07-28 Andreas Schwab <schwab@linux-m68k.org> | ||
| 64 | |||
| 65 | * regex.c (re_iswctype): Convert return values to boolean. | ||
| 66 | |||
| 67 | 2011-07-28 Eli Zaretskii <eliz@fencepost.gnu.org> | ||
| 68 | |||
| 69 | * xdisp.c (compute_display_string_pos): Don't use cached display | ||
| 70 | string position if the buffer had its restriction changed. | ||
| 71 | (Bug#9184) | ||
| 72 | |||
| 73 | 2011-07-28 Paul Eggert <eggert@cs.ucla.edu> | ||
| 74 | |||
| 75 | * callproc.c (Fcall_process): Use 'volatile' to avoid vfork clobbering. | ||
| 76 | |||
| 77 | 2011-07-28 Paul Eggert <eggert@cs.ucla.edu> | ||
| 78 | |||
| 79 | Integer signedness and overflow and related fixes. (Bug#9079) | ||
| 80 | |||
| 81 | * bidi.c: Integer size and overflow fixes. | ||
| 82 | (bidi_cache_size, bidi_cache_idx, bidi_cache_last_idx) | ||
| 83 | (bidi_cache_start, bidi_cache_fetch_state, bidi_cache_search) | ||
| 84 | (bidi_cache_find_level_change, bidi_cache_ensure_space) | ||
| 85 | (bidi_cache_iterator_state, bidi_cache_find, bidi_cache_start_stack) | ||
| 86 | (bidi_find_other_level_edge): | ||
| 87 | Use ptrdiff_t instead of EMACS_INT where either will do. | ||
| 88 | This works better on 32-bit hosts configured --with-wide-int. | ||
| 89 | (bidi_cache_ensure_space): Check for size-calculation overflow. | ||
| 90 | Use % rather than repeated addition, for better worst-case speed. | ||
| 91 | Don't set bidi_cache_size until after xrealloc returns, because it | ||
| 92 | might not return. | ||
| 93 | (bidi_dump_cached_states): Use ptrdiff_t, not int, to avoid overflow. | ||
| 94 | (bidi_cache_ensure_space): Also check that the bidi cache size | ||
| 95 | does not exceed that of the largest Lisp string or buffer. See Eli | ||
| 96 | Zaretskii in <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9079#29>. | ||
| 97 | |||
| 98 | * alloc.c (__malloc_size_t): Remove. | ||
| 99 | All uses replaced by size_t. See Andreas Schwab's note | ||
| 100 | <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9079#8>. | ||
| 101 | |||
| 102 | * image.c: Improve checking for integer overflow. | ||
| 103 | (check_image_size): Assume that f is nonnull, since | ||
| 104 | it is always nonnull in practice. This is one less thing to | ||
| 105 | worry about when checking for integer overflow later. | ||
| 106 | (x_check_image_size): New function, which checks for integer | ||
| 107 | overflow issues inside X. | ||
| 108 | (x_create_x_image_and_pixmap, xbm_read_bitmap_data): Use it. | ||
| 109 | This removes the need for a memory_full check. | ||
| 110 | (xbm_image_p): Rewrite to avoid integer multiplication overflow. | ||
| 111 | (Create_Pixmap_From_Bitmap_Data, xbm_load): Use x_check_image_size. | ||
| 112 | (xbm_read_bitmap_data): Change locals back to 'int', since | ||
| 113 | their values must fit in 'int'. | ||
| 114 | (xpm_load_image, png_load, tiff_load): | ||
| 115 | Invoke x_create_x_image_and_pixmap earlier, | ||
| 116 | to avoid much needless work if the image is too large. | ||
| 117 | (tiff_load): Treat overly large images as if | ||
| 118 | x_create_x_image_and_pixmap failed, not as malloc failures. | ||
| 119 | (gs_load): Use x_check_image_size. | ||
| 120 | |||
| 121 | * gtkutil.c: Omit integer casts. | ||
| 122 | (xg_get_pixbuf_from_pixmap): Remove unnecessary cast. | ||
| 123 | (xg_set_toolkit_scroll_bar_thumb): Rewrite to avoid need for cast. | ||
| 124 | |||
| 125 | * image.c (png_load): Don't assume height * row_bytes fits in 'int'. | ||
| 126 | |||
| 127 | * xfaces.c (Fbitmap_spec_p): Fix integer overflow bug. | ||
| 128 | Without this fix, (bitmap-spec-p '(34359738368 1 "x")) | ||
| 129 | would wrongly return t on a 64-bit host. | ||
| 130 | |||
| 131 | * dispnew.c (init_display): Use *_RANGE_OVERFLOW macros. | ||
| 132 | The plain *_OVERFLOW macros run afoul of GCC bug 49705 | ||
| 133 | <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49705> | ||
| 134 | and therefore cause GCC to emit a bogus diagnostic in some cases. | ||
| 135 | |||
| 136 | * image.c: Integer signedness and overflow and related fixes. | ||
| 137 | This is not an exhaustive set of fixes, but it's time to | ||
| 138 | record what I've got. | ||
| 139 | (lookup_pixel_color, check_image_size): Remove redundant decls. | ||
| 140 | (check_image_size): Don't assume that arbitrary EMACS_INT values | ||
| 141 | fit in 'int', or that arbitrary 'double' values fit in 'int'. | ||
| 142 | (x_alloc_image_color, x_create_x_image_and_pixmap, png_load) | ||
| 143 | (tiff_load, imagemagick_load_image): | ||
| 144 | Check for overflow in size calculations. | ||
| 145 | (x_create_x_image_and_pixmap): Remove unnecessary test for | ||
| 146 | xmalloc returning NULL; that can't happen. | ||
| 147 | (xbm_read_bitmap_data): Don't assume sizes fit into 'int'. | ||
| 148 | (xpm_color_bucket): Use better integer hashing function. | ||
| 149 | (xpm_cache_color): Don't possibly over-allocate memory. | ||
| 150 | (struct png_memory_storage, tiff_memory_source, tiff_seek_in_memory) | ||
| 151 | (gif_memory_source): | ||
| 152 | Use ptrdiff_t, not int or size_t, to record sizes. | ||
| 153 | (png_load): Don't assume values greater than 2**31 fit in 'int'. | ||
| 154 | (our_stdio_fill_input_buffer): Prefer ptrdiff_t to size_t when | ||
| 155 | either works, as we prefer signed integers. | ||
| 156 | (tiff_read_from_memory, tiff_write_from_memory): | ||
| 157 | Return tsize_t, not size_t, since that's what the TIFF API wants. | ||
| 158 | (tiff_read_from_memory): Don't fail simply because the read would | ||
| 159 | go past EOF; instead, return a short read. | ||
| 160 | (tiff_load): Omit no-longer-needed casts. | ||
| 161 | (Fimagemagick_types): Don't assume size fits into 'int'. | ||
| 162 | |||
| 163 | Improve hashing quality when configured --with-wide-int. | ||
| 164 | * fns.c (hash_string): New function, taken from sxhash_string. | ||
| 165 | Do not discard information about ASCII character case; this | ||
| 166 | discarding is no longer needed. | ||
| 167 | (sxhash-string): Use it. Change sig to match it. Caller changed. | ||
| 168 | * lisp.h: Declare it. | ||
| 169 | * lread.c (hash_string): Remove, since we now use fns.c's version. | ||
| 170 | The fns.c version returns a wider integer if --with-wide-int is | ||
| 171 | specified, so this should help the quality of the hashing a bit. | ||
| 172 | |||
| 173 | * emacs.c: Integer overflow minor fix. | ||
| 174 | (heap_bss_diff): Now uprintmax_t, not unsigned long. All used changed. | ||
| 175 | Define only if GNU_LINUX. | ||
| 176 | (main, Fdump_emacs): Set and use heap_bss_diff only if GNU_LINUX. | ||
| 177 | |||
| 178 | * dispnew.c: Integer signedness and overflow fixes. | ||
| 179 | Remove unnecessary forward decls, that were a maintenance hassle. | ||
| 180 | (history_tick): Now uprintmax_t, so it's more likely to avoid overflow. | ||
| 181 | All uses changed. | ||
| 182 | (adjust_glyph_matrix, realloc_glyph_pool, adjust_frame_message_buffer) | ||
| 183 | (scrolling_window): Use ptrdiff_t, not int, for byte count. | ||
| 184 | (prepare_desired_row, line_draw_cost): | ||
| 185 | Use int, not unsigned, where either works. | ||
| 186 | (save_current_matrix, restore_current_matrix): | ||
| 187 | Use ptrdiff_t, not size_t, where either works. | ||
| 188 | (init_display): Check for overflow more accurately, and without | ||
| 189 | relying on undefined behavior. | ||
| 190 | |||
| 191 | * editfns.c (pWIDE, pWIDElen, signed_wide, unsigned_wide): | ||
| 192 | Remove, replacing with the new symbols in lisp.h. All uses changed. | ||
| 193 | * fileio.c (make_temp_name): | ||
| 194 | * filelock.c (lock_file_1, lock_file): | ||
| 195 | * xdisp.c (message_dolog): | ||
| 196 | Don't assume PRIdMAX etc. works; this isn't portable to pre-C99 hosts. | ||
| 197 | Use pMd etc. instead. | ||
| 198 | * lisp.h (printmax_t, uprintmax_t, pMd, pMu): New types and macros, | ||
| 199 | replacing the pWIDE etc. symbols removed from editfns.c. | ||
| 200 | |||
| 201 | * keyboard.h (num_input_events): Now uintmax_t. | ||
| 202 | This is (very slightly) less likely to mess up due to wraparound. | ||
| 203 | All uses changed. | ||
| 204 | |||
| 205 | * buffer.c: Integer signedness fixes. | ||
| 206 | (alloc_buffer_text, enlarge_buffer_text): | ||
| 207 | Use ptrdiff_t rather than size_t when either will do, as we prefer | ||
| 208 | signed integers. | ||
| 209 | |||
| 210 | * alloc.c: Integer signedness and overflow fixes. | ||
| 211 | Do not impose an arbitrary 32-bit limit on malloc sizes when debugging. | ||
| 212 | (__malloc_size_t): Default to size_t, not to int. | ||
| 213 | (pure_size, pure_bytes_used_before_overflow, stack_copy_size) | ||
| 214 | (Fgarbage_collect, mark_object_loop_halt, mark_object): | ||
| 215 | Prefer ptrdiff_t to size_t when either would do, as we prefer | ||
| 216 | signed integers. | ||
| 217 | (XMALLOC_OVERRUN_CHECK_OVERHEAD): New macro. | ||
| 218 | (xmalloc_overrun_check_header, xmalloc_overrun_check_trailer): | ||
| 219 | Now const. Initialize with values that are in range even if char | ||
| 220 | is signed. | ||
| 221 | (XMALLOC_PUT_SIZE, XMALLOC_GET_SIZE): Remove, replacing with ... | ||
| 222 | (xmalloc_put_size, xmalloc_get_size): New functions. All uses changed. | ||
| 223 | These functions do the right thing with sizes > 2**32. | ||
| 224 | (check_depth): Now ptrdiff_t, not int. | ||
| 225 | (overrun_check_malloc, overrun_check_realloc, overrun_check_free): | ||
| 226 | Adjust to new way of storing sizes. Check for size overflow bugs | ||
| 227 | in rest of code. | ||
| 228 | (STRING_BYTES_MAX): Adjust to new overheads. The old code was | ||
| 229 | slightly wrong anyway, as it missed one instance of | ||
| 230 | XMALLOC_OVERRUN_CHECK_OVERHEAD. | ||
| 231 | (refill_memory_reserve): Omit needless cast to size_t. | ||
| 232 | (mark_object_loop_halt): Mark as externally visible. | ||
| 233 | |||
| 234 | * xselect.c: Integer signedness and overflow fixes. | ||
| 235 | (Fx_register_dnd_atom, x_handle_dnd_message): | ||
| 236 | Use ptrdiff_t, not size_t, since we prefer signed. | ||
| 237 | (Fx_register_dnd_atom): Check for ptrdiff_t (and size_t) overflow. | ||
| 238 | * xterm.h (struct x_display_info): Use ptrdiff_t, not size_t, for | ||
| 239 | x_dnd_atoms_size and x_dnd_atoms_length. | ||
| 240 | |||
| 241 | * doprnt.c: Prefer signed to unsigned when either works. | ||
| 242 | * eval.c (verror): | ||
| 243 | * doprnt.c (doprnt): | ||
| 244 | * lisp.h (doprnt): | ||
| 245 | * xdisp.c (vmessage): | ||
| 246 | Use ptrdiff_t, not size_t, when using or implementing doprnt, | ||
| 247 | since the sizes cannot exceed ptrdiff_t bounds anyway, and we | ||
| 248 | prefer signed arithmetic to avoid comparison confusion. | ||
| 249 | * doprnt.c (doprnt): Avoid a "+ 1" that can't overflow, | ||
| 250 | but is a bit tricky. | ||
| 251 | |||
| 252 | Assume freestanding C89 headers, string.h, stdlib.h. | ||
| 253 | * data.c, doprnt.c, floatfns.c, print.c: | ||
| 254 | Include float.h unconditionally. | ||
| 255 | * gmalloc.c: Assume C89-at-least behavior for preprocessor, | ||
| 256 | limits.h, stddef.h, string.h. Use memset instead of 'flood'. | ||
| 257 | * regex.c: Likewise for stddef.h, string.h. | ||
| 258 | (ISASCII): Remove; can assume it returns 1 now. All uses removed. | ||
| 259 | * s/aix4-2.h (HAVE_STRING_H): Remove obsolete undef. | ||
| 260 | * s/ms-w32.h (HAVE_LIMITS_H, HAVE_STRING_H, HAVE_STDLIB_H) | ||
| 261 | (STDC_HEADERS): Remove obsolete defines. | ||
| 262 | * sysdep.c: Include limits.h unconditionally. | ||
| 263 | |||
| 264 | Assume support for memcmp, memcpy, memmove, memset. | ||
| 265 | * lisp.h, sysdep.c (memcmp, memcpy, memmove, memset): | ||
| 266 | * regex.c (memcmp, memcpy): | ||
| 267 | Remove; we assume C89 now. | ||
| 268 | |||
| 269 | * gmalloc.c (memcpy, memset, memmove): Remove; we assume C89 now. | ||
| 270 | (__malloc_safe_bcopy): Remove; no longer needed. | ||
| 271 | |||
| 272 | * lisp.h (struct vectorlike_header, struct Lisp_Subr): Signed sizes. | ||
| 273 | Use EMACS_INT, not EMACS_UINT, for sizes. The code works equally | ||
| 274 | well either way, and we prefer signed to unsigned. | ||
| 275 | |||
| 276 | 2011-07-27 Lars Magne Ingebrigtsen <larsi@gnus.org> | ||
| 277 | |||
| 278 | * gnutls.c (emacs_gnutls_read): Don't message anything if the peer | ||
| 279 | closes the connection while we're reading (bug#9182). | ||
| 280 | |||
| 1 | 2011-07-25 Jan Djärv <jan.h.d@swipnet.se> | 281 | 2011-07-25 Jan Djärv <jan.h.d@swipnet.se> |
| 2 | 282 | ||
| 3 | * nsmenu.m (ns_popup_dialog): Add an "ok" button if no buttons | 283 | * nsmenu.m (ns_popup_dialog): Add an "ok" button if no buttons |
diff --git a/src/alloc.c b/src/alloc.c index d48d1f34dbd..b96fc1f0642 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -68,10 +68,6 @@ extern POINTER_TYPE *sbrk (); | |||
| 68 | #ifdef DOUG_LEA_MALLOC | 68 | #ifdef DOUG_LEA_MALLOC |
| 69 | 69 | ||
| 70 | #include <malloc.h> | 70 | #include <malloc.h> |
| 71 | /* malloc.h #defines this as size_t, at least in glibc2. */ | ||
| 72 | #ifndef __malloc_size_t | ||
| 73 | #define __malloc_size_t int | ||
| 74 | #endif | ||
| 75 | 71 | ||
| 76 | /* Specify maximum number of areas to mmap. It would be nice to use a | 72 | /* Specify maximum number of areas to mmap. It would be nice to use a |
| 77 | value that explicitly means "no limit". */ | 73 | value that explicitly means "no limit". */ |
| @@ -82,9 +78,8 @@ extern POINTER_TYPE *sbrk (); | |||
| 82 | 78 | ||
| 83 | /* The following come from gmalloc.c. */ | 79 | /* The following come from gmalloc.c. */ |
| 84 | 80 | ||
| 85 | #define __malloc_size_t size_t | 81 | extern size_t _bytes_used; |
| 86 | extern __malloc_size_t _bytes_used; | 82 | extern size_t __malloc_extra_blocks; |
| 87 | extern __malloc_size_t __malloc_extra_blocks; | ||
| 88 | 83 | ||
| 89 | #endif /* not DOUG_LEA_MALLOC */ | 84 | #endif /* not DOUG_LEA_MALLOC */ |
| 90 | 85 | ||
| @@ -214,12 +209,12 @@ EMACS_INT pure[(PURESIZE + sizeof (EMACS_INT) - 1) / sizeof (EMACS_INT)] = {1,}; | |||
| 214 | /* Pointer to the pure area, and its size. */ | 209 | /* Pointer to the pure area, and its size. */ |
| 215 | 210 | ||
| 216 | static char *purebeg; | 211 | static char *purebeg; |
| 217 | static size_t pure_size; | 212 | static ptrdiff_t pure_size; |
| 218 | 213 | ||
| 219 | /* Number of bytes of pure storage used before pure storage overflowed. | 214 | /* Number of bytes of pure storage used before pure storage overflowed. |
| 220 | If this is non-zero, this implies that an overflow occurred. */ | 215 | If this is non-zero, this implies that an overflow occurred. */ |
| 221 | 216 | ||
| 222 | static size_t pure_bytes_used_before_overflow; | 217 | static ptrdiff_t pure_bytes_used_before_overflow; |
| 223 | 218 | ||
| 224 | /* Value is non-zero if P points into pure space. */ | 219 | /* Value is non-zero if P points into pure space. */ |
| 225 | 220 | ||
| @@ -252,7 +247,7 @@ const char *pending_malloc_warning; | |||
| 252 | 247 | ||
| 253 | #if MAX_SAVE_STACK > 0 | 248 | #if MAX_SAVE_STACK > 0 |
| 254 | static char *stack_copy; | 249 | static char *stack_copy; |
| 255 | static size_t stack_copy_size; | 250 | static ptrdiff_t stack_copy_size; |
| 256 | #endif | 251 | #endif |
| 257 | 252 | ||
| 258 | /* Non-zero means ignore malloc warnings. Set during initialization. | 253 | /* Non-zero means ignore malloc warnings. Set during initialization. |
| @@ -486,14 +481,15 @@ buffer_memory_full (EMACS_INT nbytes) | |||
| 486 | 481 | ||
| 487 | 482 | ||
| 488 | #ifndef XMALLOC_OVERRUN_CHECK | 483 | #ifndef XMALLOC_OVERRUN_CHECK |
| 489 | #define XMALLOC_OVERRUN_CHECK_SIZE 0 | 484 | #define XMALLOC_OVERRUN_CHECK_OVERHEAD 0 |
| 490 | #else | 485 | #else |
| 491 | 486 | ||
| 492 | /* Check for overrun in malloc'ed buffers by wrapping a 16 byte header | 487 | /* Check for overrun in malloc'ed buffers by wrapping a header and trailer |
| 493 | and a 16 byte trailer around each block. | 488 | around each block. |
| 494 | 489 | ||
| 495 | The header consists of 12 fixed bytes + a 4 byte integer contaning the | 490 | The header consists of 16 fixed bytes followed by sizeof (size_t) bytes |
| 496 | original block size, while the trailer consists of 16 fixed bytes. | 491 | containing the original block size in little-endian order, |
| 492 | while the trailer consists of 16 fixed bytes. | ||
| 497 | 493 | ||
| 498 | The header is used to detect whether this block has been allocated | 494 | The header is used to detect whether this block has been allocated |
| 499 | through these functions -- as it seems that some low-level libc | 495 | through these functions -- as it seems that some low-level libc |
| @@ -502,31 +498,47 @@ buffer_memory_full (EMACS_INT nbytes) | |||
| 502 | 498 | ||
| 503 | 499 | ||
| 504 | #define XMALLOC_OVERRUN_CHECK_SIZE 16 | 500 | #define XMALLOC_OVERRUN_CHECK_SIZE 16 |
| 501 | #define XMALLOC_OVERRUN_CHECK_OVERHEAD \ | ||
| 502 | (2 * XMALLOC_OVERRUN_CHECK_SIZE + sizeof (size_t)) | ||
| 505 | 503 | ||
| 506 | static char xmalloc_overrun_check_header[XMALLOC_OVERRUN_CHECK_SIZE-4] = | 504 | static char const xmalloc_overrun_check_header[XMALLOC_OVERRUN_CHECK_SIZE] = |
| 507 | { 0x9a, 0x9b, 0xae, 0xaf, | 505 | { '\x9a', '\x9b', '\xae', '\xaf', |
| 508 | 0xbf, 0xbe, 0xce, 0xcf, | 506 | '\xbf', '\xbe', '\xce', '\xcf', |
| 509 | 0xea, 0xeb, 0xec, 0xed }; | 507 | '\xea', '\xeb', '\xec', '\xed', |
| 508 | '\xdf', '\xde', '\x9c', '\x9d' }; | ||
| 510 | 509 | ||
| 511 | static char xmalloc_overrun_check_trailer[XMALLOC_OVERRUN_CHECK_SIZE] = | 510 | static char const xmalloc_overrun_check_trailer[XMALLOC_OVERRUN_CHECK_SIZE] = |
| 512 | { 0xaa, 0xab, 0xac, 0xad, | 511 | { '\xaa', '\xab', '\xac', '\xad', |
| 513 | 0xba, 0xbb, 0xbc, 0xbd, | 512 | '\xba', '\xbb', '\xbc', '\xbd', |
| 514 | 0xca, 0xcb, 0xcc, 0xcd, | 513 | '\xca', '\xcb', '\xcc', '\xcd', |
| 515 | 0xda, 0xdb, 0xdc, 0xdd }; | 514 | '\xda', '\xdb', '\xdc', '\xdd' }; |
| 516 | 515 | ||
| 517 | /* Macros to insert and extract the block size in the header. */ | 516 | /* Insert and extract the block size in the header. */ |
| 518 | 517 | ||
| 519 | #define XMALLOC_PUT_SIZE(ptr, size) \ | 518 | static void |
| 520 | (ptr[-1] = (size & 0xff), \ | 519 | xmalloc_put_size (unsigned char *ptr, size_t size) |
| 521 | ptr[-2] = ((size >> 8) & 0xff), \ | 520 | { |
| 522 | ptr[-3] = ((size >> 16) & 0xff), \ | 521 | int i; |
| 523 | ptr[-4] = ((size >> 24) & 0xff)) | 522 | for (i = 0; i < sizeof (size_t); i++) |
| 523 | { | ||
| 524 | *--ptr = size & (1 << CHAR_BIT) - 1; | ||
| 525 | size >>= CHAR_BIT; | ||
| 526 | } | ||
| 527 | } | ||
| 524 | 528 | ||
| 525 | #define XMALLOC_GET_SIZE(ptr) \ | 529 | static size_t |
| 526 | (size_t)((unsigned)(ptr[-1]) | \ | 530 | xmalloc_get_size (unsigned char *ptr) |
| 527 | ((unsigned)(ptr[-2]) << 8) | \ | 531 | { |
| 528 | ((unsigned)(ptr[-3]) << 16) | \ | 532 | size_t size = 0; |
| 529 | ((unsigned)(ptr[-4]) << 24)) | 533 | int i; |
| 534 | ptr -= sizeof (size_t); | ||
| 535 | for (i = 0; i < sizeof (size_t); i++) | ||
| 536 | { | ||
| 537 | size <<= CHAR_BIT; | ||
| 538 | size += *ptr++; | ||
| 539 | } | ||
| 540 | return size; | ||
| 541 | } | ||
| 530 | 542 | ||
| 531 | 543 | ||
| 532 | /* The call depth in overrun_check functions. For example, this might happen: | 544 | /* The call depth in overrun_check functions. For example, this might happen: |
| @@ -545,10 +557,10 @@ static char xmalloc_overrun_check_trailer[XMALLOC_OVERRUN_CHECK_SIZE] = | |||
| 545 | 557 | ||
| 546 | xfree(10032) | 558 | xfree(10032) |
| 547 | overrun_check_free(10032) | 559 | overrun_check_free(10032) |
| 548 | decrease overhed | 560 | decrease overhead |
| 549 | free(10016) <- crash, because 10000 is the original pointer. */ | 561 | free(10016) <- crash, because 10000 is the original pointer. */ |
| 550 | 562 | ||
| 551 | static int check_depth; | 563 | static ptrdiff_t check_depth; |
| 552 | 564 | ||
| 553 | /* Like malloc, but wraps allocated block with header and trailer. */ | 565 | /* Like malloc, but wraps allocated block with header and trailer. */ |
| 554 | 566 | ||
| @@ -556,15 +568,16 @@ static POINTER_TYPE * | |||
| 556 | overrun_check_malloc (size_t size) | 568 | overrun_check_malloc (size_t size) |
| 557 | { | 569 | { |
| 558 | register unsigned char *val; | 570 | register unsigned char *val; |
| 559 | size_t overhead = ++check_depth == 1 ? XMALLOC_OVERRUN_CHECK_SIZE*2 : 0; | 571 | int overhead = ++check_depth == 1 ? XMALLOC_OVERRUN_CHECK_OVERHEAD : 0; |
| 572 | if (SIZE_MAX - overhead < size) | ||
| 573 | abort (); | ||
| 560 | 574 | ||
| 561 | val = (unsigned char *) malloc (size + overhead); | 575 | val = (unsigned char *) malloc (size + overhead); |
| 562 | if (val && check_depth == 1) | 576 | if (val && check_depth == 1) |
| 563 | { | 577 | { |
| 564 | memcpy (val, xmalloc_overrun_check_header, | 578 | memcpy (val, xmalloc_overrun_check_header, XMALLOC_OVERRUN_CHECK_SIZE); |
| 565 | XMALLOC_OVERRUN_CHECK_SIZE - 4); | 579 | val += XMALLOC_OVERRUN_CHECK_SIZE + sizeof (size_t); |
| 566 | val += XMALLOC_OVERRUN_CHECK_SIZE; | 580 | xmalloc_put_size (val, size); |
| 567 | XMALLOC_PUT_SIZE(val, size); | ||
| 568 | memcpy (val + size, xmalloc_overrun_check_trailer, | 581 | memcpy (val + size, xmalloc_overrun_check_trailer, |
| 569 | XMALLOC_OVERRUN_CHECK_SIZE); | 582 | XMALLOC_OVERRUN_CHECK_SIZE); |
| 570 | } | 583 | } |
| @@ -580,31 +593,32 @@ static POINTER_TYPE * | |||
| 580 | overrun_check_realloc (POINTER_TYPE *block, size_t size) | 593 | overrun_check_realloc (POINTER_TYPE *block, size_t size) |
| 581 | { | 594 | { |
| 582 | register unsigned char *val = (unsigned char *) block; | 595 | register unsigned char *val = (unsigned char *) block; |
| 583 | size_t overhead = ++check_depth == 1 ? XMALLOC_OVERRUN_CHECK_SIZE*2 : 0; | 596 | int overhead = ++check_depth == 1 ? XMALLOC_OVERRUN_CHECK_OVERHEAD : 0; |
| 597 | if (SIZE_MAX - overhead < size) | ||
| 598 | abort (); | ||
| 584 | 599 | ||
| 585 | if (val | 600 | if (val |
| 586 | && check_depth == 1 | 601 | && check_depth == 1 |
| 587 | && memcmp (xmalloc_overrun_check_header, | 602 | && memcmp (xmalloc_overrun_check_header, |
| 588 | val - XMALLOC_OVERRUN_CHECK_SIZE, | 603 | val - XMALLOC_OVERRUN_CHECK_SIZE - sizeof (size_t), |
| 589 | XMALLOC_OVERRUN_CHECK_SIZE - 4) == 0) | 604 | XMALLOC_OVERRUN_CHECK_SIZE) == 0) |
| 590 | { | 605 | { |
| 591 | size_t osize = XMALLOC_GET_SIZE (val); | 606 | size_t osize = xmalloc_get_size (val); |
| 592 | if (memcmp (xmalloc_overrun_check_trailer, val + osize, | 607 | if (memcmp (xmalloc_overrun_check_trailer, val + osize, |
| 593 | XMALLOC_OVERRUN_CHECK_SIZE)) | 608 | XMALLOC_OVERRUN_CHECK_SIZE)) |
| 594 | abort (); | 609 | abort (); |
| 595 | memset (val + osize, 0, XMALLOC_OVERRUN_CHECK_SIZE); | 610 | memset (val + osize, 0, XMALLOC_OVERRUN_CHECK_SIZE); |
| 596 | val -= XMALLOC_OVERRUN_CHECK_SIZE; | 611 | val -= XMALLOC_OVERRUN_CHECK_SIZE + sizeof (size_t); |
| 597 | memset (val, 0, XMALLOC_OVERRUN_CHECK_SIZE); | 612 | memset (val, 0, XMALLOC_OVERRUN_CHECK_SIZE + sizeof (size_t)); |
| 598 | } | 613 | } |
| 599 | 614 | ||
| 600 | val = (unsigned char *) realloc ((POINTER_TYPE *)val, size + overhead); | 615 | val = (unsigned char *) realloc ((POINTER_TYPE *)val, size + overhead); |
| 601 | 616 | ||
| 602 | if (val && check_depth == 1) | 617 | if (val && check_depth == 1) |
| 603 | { | 618 | { |
| 604 | memcpy (val, xmalloc_overrun_check_header, | 619 | memcpy (val, xmalloc_overrun_check_header, XMALLOC_OVERRUN_CHECK_SIZE); |
| 605 | XMALLOC_OVERRUN_CHECK_SIZE - 4); | 620 | val += XMALLOC_OVERRUN_CHECK_SIZE + sizeof (size_t); |
| 606 | val += XMALLOC_OVERRUN_CHECK_SIZE; | 621 | xmalloc_put_size (val, size); |
| 607 | XMALLOC_PUT_SIZE(val, size); | ||
| 608 | memcpy (val + size, xmalloc_overrun_check_trailer, | 622 | memcpy (val + size, xmalloc_overrun_check_trailer, |
| 609 | XMALLOC_OVERRUN_CHECK_SIZE); | 623 | XMALLOC_OVERRUN_CHECK_SIZE); |
| 610 | } | 624 | } |
| @@ -623,20 +637,20 @@ overrun_check_free (POINTER_TYPE *block) | |||
| 623 | if (val | 637 | if (val |
| 624 | && check_depth == 1 | 638 | && check_depth == 1 |
| 625 | && memcmp (xmalloc_overrun_check_header, | 639 | && memcmp (xmalloc_overrun_check_header, |
| 626 | val - XMALLOC_OVERRUN_CHECK_SIZE, | 640 | val - XMALLOC_OVERRUN_CHECK_SIZE - sizeof (size_t), |
| 627 | XMALLOC_OVERRUN_CHECK_SIZE - 4) == 0) | 641 | XMALLOC_OVERRUN_CHECK_SIZE) == 0) |
| 628 | { | 642 | { |
| 629 | size_t osize = XMALLOC_GET_SIZE (val); | 643 | size_t osize = xmalloc_get_size (val); |
| 630 | if (memcmp (xmalloc_overrun_check_trailer, val + osize, | 644 | if (memcmp (xmalloc_overrun_check_trailer, val + osize, |
| 631 | XMALLOC_OVERRUN_CHECK_SIZE)) | 645 | XMALLOC_OVERRUN_CHECK_SIZE)) |
| 632 | abort (); | 646 | abort (); |
| 633 | #ifdef XMALLOC_CLEAR_FREE_MEMORY | 647 | #ifdef XMALLOC_CLEAR_FREE_MEMORY |
| 634 | val -= XMALLOC_OVERRUN_CHECK_SIZE; | 648 | val -= XMALLOC_OVERRUN_CHECK_SIZE + sizeof (size_t); |
| 635 | memset (val, 0xff, osize + XMALLOC_OVERRUN_CHECK_SIZE*2); | 649 | memset (val, 0xff, osize + XMALLOC_OVERRUN_CHECK_OVERHEAD); |
| 636 | #else | 650 | #else |
| 637 | memset (val + osize, 0, XMALLOC_OVERRUN_CHECK_SIZE); | 651 | memset (val + osize, 0, XMALLOC_OVERRUN_CHECK_SIZE); |
| 638 | val -= XMALLOC_OVERRUN_CHECK_SIZE; | 652 | val -= XMALLOC_OVERRUN_CHECK_SIZE + sizeof (size_t); |
| 639 | memset (val, 0, XMALLOC_OVERRUN_CHECK_SIZE); | 653 | memset (val, 0, XMALLOC_OVERRUN_CHECK_SIZE + sizeof (size_t)); |
| 640 | #endif | 654 | #endif |
| 641 | } | 655 | } |
| 642 | 656 | ||
| @@ -1092,11 +1106,11 @@ static void (*old_free_hook) (void*, const void*); | |||
| 1092 | # define BYTES_USED _bytes_used | 1106 | # define BYTES_USED _bytes_used |
| 1093 | #endif | 1107 | #endif |
| 1094 | 1108 | ||
| 1095 | static __malloc_size_t bytes_used_when_reconsidered; | 1109 | static size_t bytes_used_when_reconsidered; |
| 1096 | 1110 | ||
| 1097 | /* Value of _bytes_used, when spare_memory was freed. */ | 1111 | /* Value of _bytes_used, when spare_memory was freed. */ |
| 1098 | 1112 | ||
| 1099 | static __malloc_size_t bytes_used_when_full; | 1113 | static size_t bytes_used_when_full; |
| 1100 | 1114 | ||
| 1101 | /* This function is used as the hook for free to call. */ | 1115 | /* This function is used as the hook for free to call. */ |
| 1102 | 1116 | ||
| @@ -1661,7 +1675,8 @@ static char const string_overrun_cookie[GC_STRING_OVERRUN_COOKIE_SIZE] = | |||
| 1661 | calculating a value to be passed to malloc. */ | 1675 | calculating a value to be passed to malloc. */ |
| 1662 | #define STRING_BYTES_MAX \ | 1676 | #define STRING_BYTES_MAX \ |
| 1663 | min (STRING_BYTES_BOUND, \ | 1677 | min (STRING_BYTES_BOUND, \ |
| 1664 | ((SIZE_MAX - XMALLOC_OVERRUN_CHECK_SIZE - GC_STRING_EXTRA \ | 1678 | ((SIZE_MAX - XMALLOC_OVERRUN_CHECK_OVERHEAD \ |
| 1679 | - GC_STRING_EXTRA \ | ||
| 1665 | - offsetof (struct sblock, first_data) \ | 1680 | - offsetof (struct sblock, first_data) \ |
| 1666 | - SDATA_DATA_OFFSET) \ | 1681 | - SDATA_DATA_OFFSET) \ |
| 1667 | & ~(sizeof (EMACS_INT) - 1))) | 1682 | & ~(sizeof (EMACS_INT) - 1))) |
| @@ -3267,12 +3282,16 @@ memory_full (size_t nbytes) | |||
| 3267 | int enough_free_memory = 0; | 3282 | int enough_free_memory = 0; |
| 3268 | if (SPARE_MEMORY < nbytes) | 3283 | if (SPARE_MEMORY < nbytes) |
| 3269 | { | 3284 | { |
| 3270 | void *p = malloc (SPARE_MEMORY); | 3285 | void *p; |
| 3286 | |||
| 3287 | MALLOC_BLOCK_INPUT; | ||
| 3288 | p = malloc (SPARE_MEMORY); | ||
| 3271 | if (p) | 3289 | if (p) |
| 3272 | { | 3290 | { |
| 3273 | free (p); | 3291 | free (p); |
| 3274 | enough_free_memory = 1; | 3292 | enough_free_memory = 1; |
| 3275 | } | 3293 | } |
| 3294 | MALLOC_UNBLOCK_INPUT; | ||
| 3276 | } | 3295 | } |
| 3277 | 3296 | ||
| 3278 | if (! enough_free_memory) | 3297 | if (! enough_free_memory) |
| @@ -3320,7 +3339,7 @@ refill_memory_reserve (void) | |||
| 3320 | { | 3339 | { |
| 3321 | #ifndef SYSTEM_MALLOC | 3340 | #ifndef SYSTEM_MALLOC |
| 3322 | if (spare_memory[0] == 0) | 3341 | if (spare_memory[0] == 0) |
| 3323 | spare_memory[0] = (char *) malloc ((size_t) SPARE_MEMORY); | 3342 | spare_memory[0] = (char *) malloc (SPARE_MEMORY); |
| 3324 | if (spare_memory[1] == 0) | 3343 | if (spare_memory[1] == 0) |
| 3325 | spare_memory[1] = (char *) lisp_align_malloc (sizeof (struct cons_block), | 3344 | spare_memory[1] = (char *) lisp_align_malloc (sizeof (struct cons_block), |
| 3326 | MEM_TYPE_CONS); | 3345 | MEM_TYPE_CONS); |
| @@ -4922,7 +4941,7 @@ returns nil, because real GC can't be done. */) | |||
| 4922 | if (NILP (Vpurify_flag)) | 4941 | if (NILP (Vpurify_flag)) |
| 4923 | { | 4942 | { |
| 4924 | char *stack; | 4943 | char *stack; |
| 4925 | size_t stack_size; | 4944 | ptrdiff_t stack_size; |
| 4926 | if (&stack_top_variable < stack_bottom) | 4945 | if (&stack_top_variable < stack_bottom) |
| 4927 | { | 4946 | { |
| 4928 | stack = &stack_top_variable; | 4947 | stack = &stack_top_variable; |
| @@ -5233,7 +5252,7 @@ static int last_marked_index; | |||
| 5233 | links of a list, in mark_object. In debugging, | 5252 | links of a list, in mark_object. In debugging, |
| 5234 | the call to abort will hit a breakpoint. | 5253 | the call to abort will hit a breakpoint. |
| 5235 | Normally this is zero and the check never goes off. */ | 5254 | Normally this is zero and the check never goes off. */ |
| 5236 | static size_t mark_object_loop_halt; | 5255 | ptrdiff_t mark_object_loop_halt EXTERNALLY_VISIBLE; |
| 5237 | 5256 | ||
| 5238 | static void | 5257 | static void |
| 5239 | mark_vectorlike (struct Lisp_Vector *ptr) | 5258 | mark_vectorlike (struct Lisp_Vector *ptr) |
| @@ -5290,7 +5309,7 @@ mark_object (Lisp_Object arg) | |||
| 5290 | void *po; | 5309 | void *po; |
| 5291 | struct mem_node *m; | 5310 | struct mem_node *m; |
| 5292 | #endif | 5311 | #endif |
| 5293 | size_t cdr_count = 0; | 5312 | ptrdiff_t cdr_count = 0; |
| 5294 | 5313 | ||
| 5295 | loop: | 5314 | loop: |
| 5296 | 5315 | ||
diff --git a/src/bidi.c b/src/bidi.c index 412dc94cb86..697ebb92856 100644 --- a/src/bidi.c +++ b/src/bidi.c | |||
| @@ -299,11 +299,11 @@ bidi_copy_it (struct bidi_it *to, struct bidi_it *from) | |||
| 299 | 299 | ||
| 300 | #define BIDI_CACHE_CHUNK 200 | 300 | #define BIDI_CACHE_CHUNK 200 |
| 301 | static struct bidi_it *bidi_cache; | 301 | static struct bidi_it *bidi_cache; |
| 302 | static EMACS_INT bidi_cache_size = 0; | 302 | static ptrdiff_t bidi_cache_size = 0; |
| 303 | enum { elsz = sizeof (struct bidi_it) }; | 303 | enum { elsz = sizeof (struct bidi_it) }; |
| 304 | static EMACS_INT bidi_cache_idx; /* next unused cache slot */ | 304 | static ptrdiff_t bidi_cache_idx; /* next unused cache slot */ |
| 305 | static EMACS_INT bidi_cache_last_idx; /* slot of last cache hit */ | 305 | static ptrdiff_t bidi_cache_last_idx; /* slot of last cache hit */ |
| 306 | static EMACS_INT bidi_cache_start = 0; /* start of cache for this | 306 | static ptrdiff_t bidi_cache_start = 0; /* start of cache for this |
| 307 | "stack" level */ | 307 | "stack" level */ |
| 308 | 308 | ||
| 309 | /* Reset the cache state to the empty state. We only reset the part | 309 | /* Reset the cache state to the empty state. We only reset the part |
| @@ -336,7 +336,7 @@ bidi_cache_shrink (void) | |||
| 336 | } | 336 | } |
| 337 | 337 | ||
| 338 | static inline void | 338 | static inline void |
| 339 | bidi_cache_fetch_state (EMACS_INT idx, struct bidi_it *bidi_it) | 339 | bidi_cache_fetch_state (ptrdiff_t idx, struct bidi_it *bidi_it) |
| 340 | { | 340 | { |
| 341 | int current_scan_dir = bidi_it->scan_dir; | 341 | int current_scan_dir = bidi_it->scan_dir; |
| 342 | 342 | ||
| @@ -352,10 +352,10 @@ bidi_cache_fetch_state (EMACS_INT idx, struct bidi_it *bidi_it) | |||
| 352 | level less or equal to LEVEL. if LEVEL is -1, disregard the | 352 | level less or equal to LEVEL. if LEVEL is -1, disregard the |
| 353 | resolved levels in cached states. DIR, if non-zero, means search | 353 | resolved levels in cached states. DIR, if non-zero, means search |
| 354 | in that direction from the last cache hit. */ | 354 | in that direction from the last cache hit. */ |
| 355 | static inline EMACS_INT | 355 | static inline ptrdiff_t |
| 356 | bidi_cache_search (EMACS_INT charpos, int level, int dir) | 356 | bidi_cache_search (EMACS_INT charpos, int level, int dir) |
| 357 | { | 357 | { |
| 358 | EMACS_INT i, i_start; | 358 | ptrdiff_t i, i_start; |
| 359 | 359 | ||
| 360 | if (bidi_cache_idx > bidi_cache_start) | 360 | if (bidi_cache_idx > bidi_cache_start) |
| 361 | { | 361 | { |
| @@ -417,12 +417,12 @@ bidi_cache_search (EMACS_INT charpos, int level, int dir) | |||
| 417 | C, searching backwards (DIR = -1) for LEVEL = 2 will return the | 417 | C, searching backwards (DIR = -1) for LEVEL = 2 will return the |
| 418 | index of slot B or A, depending whether BEFORE is, respectively, | 418 | index of slot B or A, depending whether BEFORE is, respectively, |
| 419 | non-zero or zero. */ | 419 | non-zero or zero. */ |
| 420 | static EMACS_INT | 420 | static ptrdiff_t |
| 421 | bidi_cache_find_level_change (int level, int dir, int before) | 421 | bidi_cache_find_level_change (int level, int dir, int before) |
| 422 | { | 422 | { |
| 423 | if (bidi_cache_idx) | 423 | if (bidi_cache_idx) |
| 424 | { | 424 | { |
| 425 | EMACS_INT i = dir ? bidi_cache_last_idx : bidi_cache_idx - 1; | 425 | ptrdiff_t i = dir ? bidi_cache_last_idx : bidi_cache_idx - 1; |
| 426 | int incr = before ? 1 : 0; | 426 | int incr = before ? 1 : 0; |
| 427 | 427 | ||
| 428 | xassert (!dir || bidi_cache_last_idx >= 0); | 428 | xassert (!dir || bidi_cache_last_idx >= 0); |
| @@ -458,22 +458,33 @@ bidi_cache_find_level_change (int level, int dir, int before) | |||
| 458 | } | 458 | } |
| 459 | 459 | ||
| 460 | static inline void | 460 | static inline void |
| 461 | bidi_cache_ensure_space (EMACS_INT idx) | 461 | bidi_cache_ensure_space (ptrdiff_t idx) |
| 462 | { | 462 | { |
| 463 | /* Enlarge the cache as needed. */ | 463 | /* Enlarge the cache as needed. */ |
| 464 | if (idx >= bidi_cache_size) | 464 | if (idx >= bidi_cache_size) |
| 465 | { | 465 | { |
| 466 | while (idx >= bidi_cache_size) | 466 | ptrdiff_t new_size; |
| 467 | bidi_cache_size += BIDI_CACHE_CHUNK; | 467 | |
| 468 | bidi_cache = | 468 | /* The bidi cache cannot be larger than the largest Lisp string |
| 469 | (struct bidi_it *) xrealloc (bidi_cache, bidi_cache_size * elsz); | 469 | or buffer. */ |
| 470 | ptrdiff_t string_or_buffer_bound = | ||
| 471 | max (BUF_BYTES_MAX, STRING_BYTES_BOUND); | ||
| 472 | |||
| 473 | /* Also, it cannot be larger than what C can represent. */ | ||
| 474 | ptrdiff_t c_bound = min (PTRDIFF_MAX, SIZE_MAX) / elsz; | ||
| 475 | |||
| 476 | if (min (string_or_buffer_bound, c_bound) <= idx) | ||
| 477 | memory_full (SIZE_MAX); | ||
| 478 | new_size = idx - idx % BIDI_CACHE_CHUNK + BIDI_CACHE_CHUNK; | ||
| 479 | bidi_cache = (struct bidi_it *) xrealloc (bidi_cache, new_size * elsz); | ||
| 480 | bidi_cache_size = new_size; | ||
| 470 | } | 481 | } |
| 471 | } | 482 | } |
| 472 | 483 | ||
| 473 | static inline void | 484 | static inline void |
| 474 | bidi_cache_iterator_state (struct bidi_it *bidi_it, int resolved) | 485 | bidi_cache_iterator_state (struct bidi_it *bidi_it, int resolved) |
| 475 | { | 486 | { |
| 476 | EMACS_INT idx; | 487 | ptrdiff_t idx; |
| 477 | 488 | ||
| 478 | /* We should never cache on backward scans. */ | 489 | /* We should never cache on backward scans. */ |
| 479 | if (bidi_it->scan_dir == -1) | 490 | if (bidi_it->scan_dir == -1) |
| @@ -528,7 +539,7 @@ bidi_cache_iterator_state (struct bidi_it *bidi_it, int resolved) | |||
| 528 | static inline bidi_type_t | 539 | static inline bidi_type_t |
| 529 | bidi_cache_find (EMACS_INT charpos, int level, struct bidi_it *bidi_it) | 540 | bidi_cache_find (EMACS_INT charpos, int level, struct bidi_it *bidi_it) |
| 530 | { | 541 | { |
| 531 | EMACS_INT i = bidi_cache_search (charpos, level, bidi_it->scan_dir); | 542 | ptrdiff_t i = bidi_cache_search (charpos, level, bidi_it->scan_dir); |
| 532 | 543 | ||
| 533 | if (i >= bidi_cache_start) | 544 | if (i >= bidi_cache_start) |
| 534 | { | 545 | { |
| @@ -560,7 +571,7 @@ bidi_peek_at_next_level (struct bidi_it *bidi_it) | |||
| 560 | /* 5-slot stack for saving the start of the previous level of the | 571 | /* 5-slot stack for saving the start of the previous level of the |
| 561 | cache. xdisp.c maintains a 5-slot stack for its iterator state, | 572 | cache. xdisp.c maintains a 5-slot stack for its iterator state, |
| 562 | and we need the same size of our stack. */ | 573 | and we need the same size of our stack. */ |
| 563 | static EMACS_INT bidi_cache_start_stack[IT_STACK_SIZE]; | 574 | static ptrdiff_t bidi_cache_start_stack[IT_STACK_SIZE]; |
| 564 | static int bidi_cache_sp; | 575 | static int bidi_cache_sp; |
| 565 | 576 | ||
| 566 | /* Push the bidi iterator state in preparation for reordering a | 577 | /* Push the bidi iterator state in preparation for reordering a |
| @@ -2123,7 +2134,7 @@ static void | |||
| 2123 | bidi_find_other_level_edge (struct bidi_it *bidi_it, int level, int end_flag) | 2134 | bidi_find_other_level_edge (struct bidi_it *bidi_it, int level, int end_flag) |
| 2124 | { | 2135 | { |
| 2125 | int dir = end_flag ? -bidi_it->scan_dir : bidi_it->scan_dir; | 2136 | int dir = end_flag ? -bidi_it->scan_dir : bidi_it->scan_dir; |
| 2126 | EMACS_INT idx; | 2137 | ptrdiff_t idx; |
| 2127 | 2138 | ||
| 2128 | /* Try the cache first. */ | 2139 | /* Try the cache first. */ |
| 2129 | if ((idx = bidi_cache_find_level_change (level, dir, end_flag)) | 2140 | if ((idx = bidi_cache_find_level_change (level, dir, end_flag)) |
| @@ -2300,7 +2311,7 @@ void bidi_dump_cached_states (void) EXTERNALLY_VISIBLE; | |||
| 2300 | void | 2311 | void |
| 2301 | bidi_dump_cached_states (void) | 2312 | bidi_dump_cached_states (void) |
| 2302 | { | 2313 | { |
| 2303 | int i; | 2314 | ptrdiff_t i; |
| 2304 | int ndigits = 1; | 2315 | int ndigits = 1; |
| 2305 | 2316 | ||
| 2306 | if (bidi_cache_idx == 0) | 2317 | if (bidi_cache_idx == 0) |
| @@ -2308,7 +2319,7 @@ bidi_dump_cached_states (void) | |||
| 2308 | fprintf (stderr, "The cache is empty.\n"); | 2319 | fprintf (stderr, "The cache is empty.\n"); |
| 2309 | return; | 2320 | return; |
| 2310 | } | 2321 | } |
| 2311 | fprintf (stderr, "Total of %"pI"d state%s in cache:\n", | 2322 | fprintf (stderr, "Total of %"pD"d state%s in cache:\n", |
| 2312 | bidi_cache_idx, bidi_cache_idx == 1 ? "" : "s"); | 2323 | bidi_cache_idx, bidi_cache_idx == 1 ? "" : "s"); |
| 2313 | 2324 | ||
| 2314 | for (i = bidi_cache[bidi_cache_idx - 1].charpos; i > 0; i /= 10) | 2325 | for (i = bidi_cache[bidi_cache_idx - 1].charpos; i > 0; i /= 10) |
diff --git a/src/buffer.c b/src/buffer.c index 81c537b9c6a..45d6fa36d04 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -152,7 +152,7 @@ Lisp_Object Qmodification_hooks; | |||
| 152 | Lisp_Object Qinsert_in_front_hooks; | 152 | Lisp_Object Qinsert_in_front_hooks; |
| 153 | Lisp_Object Qinsert_behind_hooks; | 153 | Lisp_Object Qinsert_behind_hooks; |
| 154 | 154 | ||
| 155 | static void alloc_buffer_text (struct buffer *, size_t); | 155 | static void alloc_buffer_text (struct buffer *, ptrdiff_t); |
| 156 | static void free_buffer_text (struct buffer *b); | 156 | static void free_buffer_text (struct buffer *b); |
| 157 | static struct Lisp_Overlay * copy_overlays (struct buffer *, struct Lisp_Overlay *); | 157 | static struct Lisp_Overlay * copy_overlays (struct buffer *, struct Lisp_Overlay *); |
| 158 | static void modify_overlay (struct buffer *, EMACS_INT, EMACS_INT); | 158 | static void modify_overlay (struct buffer *, EMACS_INT, EMACS_INT); |
| @@ -4796,7 +4796,7 @@ extern void r_alloc_free (POINTER_TYPE **ptr); | |||
| 4796 | /* Allocate NBYTES bytes for buffer B's text buffer. */ | 4796 | /* Allocate NBYTES bytes for buffer B's text buffer. */ |
| 4797 | 4797 | ||
| 4798 | static void | 4798 | static void |
| 4799 | alloc_buffer_text (struct buffer *b, size_t nbytes) | 4799 | alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes) |
| 4800 | { | 4800 | { |
| 4801 | POINTER_TYPE *p; | 4801 | POINTER_TYPE *p; |
| 4802 | 4802 | ||
| @@ -4826,8 +4826,8 @@ void | |||
| 4826 | enlarge_buffer_text (struct buffer *b, EMACS_INT delta) | 4826 | enlarge_buffer_text (struct buffer *b, EMACS_INT delta) |
| 4827 | { | 4827 | { |
| 4828 | POINTER_TYPE *p; | 4828 | POINTER_TYPE *p; |
| 4829 | size_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1 | 4829 | ptrdiff_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1 |
| 4830 | + delta); | 4830 | + delta); |
| 4831 | BLOCK_INPUT; | 4831 | BLOCK_INPUT; |
| 4832 | #if defined USE_MMAP_FOR_BUFFERS | 4832 | #if defined USE_MMAP_FOR_BUFFERS |
| 4833 | p = mmap_realloc ((POINTER_TYPE **) &b->text->beg, nbytes); | 4833 | p = mmap_realloc ((POINTER_TYPE **) &b->text->beg, nbytes); |
| @@ -4926,7 +4926,7 @@ init_buffer_once (void) | |||
| 4926 | BVAR (&buffer_defaults, truncate_lines) = Qnil; | 4926 | BVAR (&buffer_defaults, truncate_lines) = Qnil; |
| 4927 | BVAR (&buffer_defaults, word_wrap) = Qnil; | 4927 | BVAR (&buffer_defaults, word_wrap) = Qnil; |
| 4928 | BVAR (&buffer_defaults, ctl_arrow) = Qt; | 4928 | BVAR (&buffer_defaults, ctl_arrow) = Qt; |
| 4929 | BVAR (&buffer_defaults, bidi_display_reordering) = Qnil; | 4929 | BVAR (&buffer_defaults, bidi_display_reordering) = Qt; |
| 4930 | BVAR (&buffer_defaults, bidi_paragraph_direction) = Qnil; | 4930 | BVAR (&buffer_defaults, bidi_paragraph_direction) = Qnil; |
| 4931 | BVAR (&buffer_defaults, cursor_type) = Qt; | 4931 | BVAR (&buffer_defaults, cursor_type) = Qt; |
| 4932 | BVAR (&buffer_defaults, extra_line_spacing) = Qnil; | 4932 | BVAR (&buffer_defaults, extra_line_spacing) = Qnil; |
diff --git a/src/callint.c b/src/callint.c index 26b161a25b3..5cf99495671 100644 --- a/src/callint.c +++ b/src/callint.c | |||
| @@ -339,7 +339,7 @@ invoke it. If KEYS is omitted or nil, the return value of | |||
| 339 | { | 339 | { |
| 340 | Lisp_Object input; | 340 | Lisp_Object input; |
| 341 | Lisp_Object funval = Findirect_function (function, Qt); | 341 | Lisp_Object funval = Findirect_function (function, Qt); |
| 342 | size_t events = num_input_events; | 342 | uintmax_t events = num_input_events; |
| 343 | input = specs; | 343 | input = specs; |
| 344 | /* Compute the arg values using the user's expression. */ | 344 | /* Compute the arg values using the user's expression. */ |
| 345 | GCPRO2 (input, filter_specs); | 345 | GCPRO2 (input, filter_specs); |
diff --git a/src/callproc.c b/src/callproc.c index ad3eddbdd39..f148f6233d4 100644 --- a/src/callproc.c +++ b/src/callproc.c | |||
| @@ -603,6 +603,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) | |||
| 603 | 603 | ||
| 604 | /* vfork, and prevent local vars from being clobbered by the vfork. */ | 604 | /* vfork, and prevent local vars from being clobbered by the vfork. */ |
| 605 | { | 605 | { |
| 606 | int volatile fd1_volatile = fd1; | ||
| 606 | int volatile fd_error_volatile = fd_error; | 607 | int volatile fd_error_volatile = fd_error; |
| 607 | int volatile fd_output_volatile = fd_output; | 608 | int volatile fd_output_volatile = fd_output; |
| 608 | int volatile output_to_buffer_volatile = output_to_buffer; | 609 | int volatile output_to_buffer_volatile = output_to_buffer; |
| @@ -610,6 +611,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) | |||
| 610 | 611 | ||
| 611 | pid = vfork (); | 612 | pid = vfork (); |
| 612 | 613 | ||
| 614 | fd1 = fd1_volatile; | ||
| 613 | fd_error = fd_error_volatile; | 615 | fd_error = fd_error_volatile; |
| 614 | fd_output = fd_output_volatile; | 616 | fd_output = fd_output_volatile; |
| 615 | output_to_buffer = output_to_buffer_volatile; | 617 | output_to_buffer = output_to_buffer_volatile; |
diff --git a/src/data.c b/src/data.c index 7bc04592c57..76a54547a5d 100644 --- a/src/data.c +++ b/src/data.c | |||
| @@ -35,10 +35,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 35 | #include "termhooks.h" /* For FRAME_KBOARD reference in y-or-n-p. */ | 35 | #include "termhooks.h" /* For FRAME_KBOARD reference in y-or-n-p. */ |
| 36 | #include "font.h" | 36 | #include "font.h" |
| 37 | 37 | ||
| 38 | #ifdef STDC_HEADERS | ||
| 39 | #include <float.h> | 38 | #include <float.h> |
| 40 | #endif | ||
| 41 | |||
| 42 | /* If IEEE_FLOATING_POINT isn't defined, default it from FLT_*. */ | 39 | /* If IEEE_FLOATING_POINT isn't defined, default it from FLT_*. */ |
| 43 | #ifndef IEEE_FLOATING_POINT | 40 | #ifndef IEEE_FLOATING_POINT |
| 44 | #if (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \ | 41 | #if (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \ |
diff --git a/src/dispnew.c b/src/dispnew.c index 804ca14d936..57beb1ae30e 100644 --- a/src/dispnew.c +++ b/src/dispnew.c | |||
| @@ -102,57 +102,24 @@ struct dim | |||
| 102 | 102 | ||
| 103 | /* Function prototypes. */ | 103 | /* Function prototypes. */ |
| 104 | 104 | ||
| 105 | static struct glyph_matrix *save_current_matrix (struct frame *); | ||
| 106 | static void restore_current_matrix (struct frame *, struct glyph_matrix *); | ||
| 107 | static int showing_window_margins_p (struct window *); | ||
| 108 | static void fake_current_matrices (Lisp_Object); | ||
| 109 | static void redraw_overlapping_rows (struct window *, int); | ||
| 110 | static void redraw_overlapped_rows (struct window *, int); | ||
| 111 | static int count_blanks (struct glyph *, int); | ||
| 112 | static int count_match (struct glyph *, struct glyph *, | ||
| 113 | struct glyph *, struct glyph *); | ||
| 114 | static unsigned line_draw_cost (struct glyph_matrix *, int); | ||
| 115 | static void update_frame_line (struct frame *, int); | 105 | static void update_frame_line (struct frame *, int); |
| 116 | static struct dim allocate_matrices_for_frame_redisplay | ||
| 117 | (Lisp_Object, int, int, int, int *); | ||
| 118 | static int required_matrix_height (struct window *); | 106 | static int required_matrix_height (struct window *); |
| 119 | static int required_matrix_width (struct window *); | 107 | static int required_matrix_width (struct window *); |
| 120 | static void allocate_matrices_for_window_redisplay (struct window *); | ||
| 121 | static int realloc_glyph_pool (struct glyph_pool *, struct dim); | ||
| 122 | static void adjust_frame_glyphs (struct frame *); | 108 | static void adjust_frame_glyphs (struct frame *); |
| 123 | static struct glyph_matrix *new_glyph_matrix (struct glyph_pool *); | ||
| 124 | static void free_glyph_matrix (struct glyph_matrix *); | ||
| 125 | static void adjust_glyph_matrix (struct window *, struct glyph_matrix *, | ||
| 126 | int, int, struct dim); | ||
| 127 | static void change_frame_size_1 (struct frame *, int, int, int, int, int); | 109 | static void change_frame_size_1 (struct frame *, int, int, int, int, int); |
| 128 | static void increment_row_positions (struct glyph_row *, EMACS_INT, EMACS_INT); | 110 | static void increment_row_positions (struct glyph_row *, EMACS_INT, EMACS_INT); |
| 129 | static void swap_glyph_pointers (struct glyph_row *, struct glyph_row *); | ||
| 130 | #if GLYPH_DEBUG | ||
| 131 | static int glyph_row_slice_p (struct glyph_row *, struct glyph_row *); | ||
| 132 | #endif | ||
| 133 | static void fill_up_frame_row_with_spaces (struct glyph_row *, int); | 111 | static void fill_up_frame_row_with_spaces (struct glyph_row *, int); |
| 134 | static void build_frame_matrix_from_window_tree (struct glyph_matrix *, | 112 | static void build_frame_matrix_from_window_tree (struct glyph_matrix *, |
| 135 | struct window *); | 113 | struct window *); |
| 136 | static void build_frame_matrix_from_leaf_window (struct glyph_matrix *, | 114 | static void build_frame_matrix_from_leaf_window (struct glyph_matrix *, |
| 137 | struct window *); | 115 | struct window *); |
| 138 | static struct glyph_pool *new_glyph_pool (void); | ||
| 139 | static void free_glyph_pool (struct glyph_pool *); | ||
| 140 | static void adjust_frame_glyphs_initially (void); | ||
| 141 | static void adjust_frame_message_buffer (struct frame *); | 116 | static void adjust_frame_message_buffer (struct frame *); |
| 142 | static void adjust_decode_mode_spec_buffer (struct frame *); | 117 | static void adjust_decode_mode_spec_buffer (struct frame *); |
| 143 | static void fill_up_glyph_row_with_spaces (struct glyph_row *); | 118 | static void fill_up_glyph_row_with_spaces (struct glyph_row *); |
| 144 | static void build_frame_matrix (struct frame *); | ||
| 145 | void clear_current_matrices (struct frame *); | ||
| 146 | void scroll_glyph_matrix_range (struct glyph_matrix *, int, int, | ||
| 147 | int, int); | ||
| 148 | static void clear_window_matrices (struct window *, int); | 119 | static void clear_window_matrices (struct window *, int); |
| 149 | static void fill_up_glyph_row_area_with_spaces (struct glyph_row *, int); | 120 | static void fill_up_glyph_row_area_with_spaces (struct glyph_row *, int); |
| 150 | static int scrolling_window (struct window *, int); | 121 | static int scrolling_window (struct window *, int); |
| 151 | static int update_window_line (struct window *, int, int *); | 122 | static int update_window_line (struct window *, int, int *); |
| 152 | static void update_marginal_area (struct window *, int, int); | ||
| 153 | static int update_text_area (struct window *, int); | ||
| 154 | static void make_current (struct glyph_matrix *, struct glyph_matrix *, | ||
| 155 | int); | ||
| 156 | static void mirror_make_current (struct window *, int); | 123 | static void mirror_make_current (struct window *, int); |
| 157 | #if GLYPH_DEBUG | 124 | #if GLYPH_DEBUG |
| 158 | static void check_matrix_pointers (struct glyph_matrix *, | 125 | static void check_matrix_pointers (struct glyph_matrix *, |
| @@ -285,7 +252,7 @@ static int history_idx; | |||
| 285 | /* A tick that's incremented each time something is added to the | 252 | /* A tick that's incremented each time something is added to the |
| 286 | history. */ | 253 | history. */ |
| 287 | 254 | ||
| 288 | static unsigned history_tick; | 255 | static uprintmax_t history_tick; |
| 289 | 256 | ||
| 290 | static void add_frame_display_history (struct frame *, int); | 257 | static void add_frame_display_history (struct frame *, int); |
| 291 | 258 | ||
| @@ -304,7 +271,7 @@ add_window_display_history (struct window *w, const char *msg, int paused_p) | |||
| 304 | buf = redisplay_history[history_idx].trace; | 271 | buf = redisplay_history[history_idx].trace; |
| 305 | ++history_idx; | 272 | ++history_idx; |
| 306 | 273 | ||
| 307 | sprintf (buf, "%d: window %p (`%s')%s\n", | 274 | sprintf (buf, "%"pMu": window %p (`%s')%s\n", |
| 308 | history_tick++, | 275 | history_tick++, |
| 309 | w, | 276 | w, |
| 310 | ((BUFFERP (w->buffer) | 277 | ((BUFFERP (w->buffer) |
| @@ -330,7 +297,7 @@ add_frame_display_history (struct frame *f, int paused_p) | |||
| 330 | buf = redisplay_history[history_idx].trace; | 297 | buf = redisplay_history[history_idx].trace; |
| 331 | ++history_idx; | 298 | ++history_idx; |
| 332 | 299 | ||
| 333 | sprintf (buf, "%d: update frame %p%s", | 300 | sprintf (buf, "%"pMu": update frame %p%s", |
| 334 | history_tick++, | 301 | history_tick++, |
| 335 | f, paused_p ? " ***paused***" : ""); | 302 | f, paused_p ? " ***paused***" : ""); |
| 336 | } | 303 | } |
| @@ -531,7 +498,7 @@ adjust_glyph_matrix (struct window *w, struct glyph_matrix *matrix, int x, int y | |||
| 531 | /* Enlarge MATRIX->rows if necessary. New rows are cleared. */ | 498 | /* Enlarge MATRIX->rows if necessary. New rows are cleared. */ |
| 532 | if (matrix->rows_allocated < dim.height) | 499 | if (matrix->rows_allocated < dim.height) |
| 533 | { | 500 | { |
| 534 | int size = dim.height * sizeof (struct glyph_row); | 501 | ptrdiff_t size = dim.height * sizeof (struct glyph_row); |
| 535 | new_rows = dim.height - matrix->rows_allocated; | 502 | new_rows = dim.height - matrix->rows_allocated; |
| 536 | matrix->rows = (struct glyph_row *) xrealloc (matrix->rows, size); | 503 | matrix->rows = (struct glyph_row *) xrealloc (matrix->rows, size); |
| 537 | memset (matrix->rows + matrix->rows_allocated, 0, | 504 | memset (matrix->rows + matrix->rows_allocated, 0, |
| @@ -1197,7 +1164,7 @@ prepare_desired_row (struct glyph_row *row) | |||
| 1197 | { | 1164 | { |
| 1198 | if (!row->enabled_p) | 1165 | if (!row->enabled_p) |
| 1199 | { | 1166 | { |
| 1200 | unsigned rp = row->reversed_p; | 1167 | int rp = row->reversed_p; |
| 1201 | 1168 | ||
| 1202 | clear_glyph_row (row); | 1169 | clear_glyph_row (row); |
| 1203 | row->enabled_p = 1; | 1170 | row->enabled_p = 1; |
| @@ -1241,7 +1208,7 @@ line_hash_code (struct glyph_row *row) | |||
| 1241 | the number of characters in the line. If must_write_spaces is | 1208 | the number of characters in the line. If must_write_spaces is |
| 1242 | zero, leading and trailing spaces are ignored. */ | 1209 | zero, leading and trailing spaces are ignored. */ |
| 1243 | 1210 | ||
| 1244 | static unsigned int | 1211 | static int |
| 1245 | line_draw_cost (struct glyph_matrix *matrix, int vpos) | 1212 | line_draw_cost (struct glyph_matrix *matrix, int vpos) |
| 1246 | { | 1213 | { |
| 1247 | struct glyph_row *row = matrix->rows + vpos; | 1214 | struct glyph_row *row = matrix->rows + vpos; |
| @@ -1434,7 +1401,7 @@ realloc_glyph_pool (struct glyph_pool *pool, struct dim matrix_dim) | |||
| 1434 | needed = matrix_dim.width * matrix_dim.height; | 1401 | needed = matrix_dim.width * matrix_dim.height; |
| 1435 | if (needed > pool->nglyphs) | 1402 | if (needed > pool->nglyphs) |
| 1436 | { | 1403 | { |
| 1437 | int size = needed * sizeof (struct glyph); | 1404 | ptrdiff_t size = needed * sizeof (struct glyph); |
| 1438 | 1405 | ||
| 1439 | if (pool->glyphs) | 1406 | if (pool->glyphs) |
| 1440 | { | 1407 | { |
| @@ -2060,7 +2027,7 @@ save_current_matrix (struct frame *f) | |||
| 2060 | { | 2027 | { |
| 2061 | struct glyph_row *from = f->current_matrix->rows + i; | 2028 | struct glyph_row *from = f->current_matrix->rows + i; |
| 2062 | struct glyph_row *to = saved->rows + i; | 2029 | struct glyph_row *to = saved->rows + i; |
| 2063 | size_t nbytes = from->used[TEXT_AREA] * sizeof (struct glyph); | 2030 | ptrdiff_t nbytes = from->used[TEXT_AREA] * sizeof (struct glyph); |
| 2064 | to->glyphs[TEXT_AREA] = (struct glyph *) xmalloc (nbytes); | 2031 | to->glyphs[TEXT_AREA] = (struct glyph *) xmalloc (nbytes); |
| 2065 | memcpy (to->glyphs[TEXT_AREA], from->glyphs[TEXT_AREA], nbytes); | 2032 | memcpy (to->glyphs[TEXT_AREA], from->glyphs[TEXT_AREA], nbytes); |
| 2066 | to->used[TEXT_AREA] = from->used[TEXT_AREA]; | 2033 | to->used[TEXT_AREA] = from->used[TEXT_AREA]; |
| @@ -2082,7 +2049,7 @@ restore_current_matrix (struct frame *f, struct glyph_matrix *saved) | |||
| 2082 | { | 2049 | { |
| 2083 | struct glyph_row *from = saved->rows + i; | 2050 | struct glyph_row *from = saved->rows + i; |
| 2084 | struct glyph_row *to = f->current_matrix->rows + i; | 2051 | struct glyph_row *to = f->current_matrix->rows + i; |
| 2085 | size_t nbytes = from->used[TEXT_AREA] * sizeof (struct glyph); | 2052 | ptrdiff_t nbytes = from->used[TEXT_AREA] * sizeof (struct glyph); |
| 2086 | memcpy (to->glyphs[TEXT_AREA], from->glyphs[TEXT_AREA], nbytes); | 2053 | memcpy (to->glyphs[TEXT_AREA], from->glyphs[TEXT_AREA], nbytes); |
| 2087 | to->used[TEXT_AREA] = from->used[TEXT_AREA]; | 2054 | to->used[TEXT_AREA] = from->used[TEXT_AREA]; |
| 2088 | xfree (from->glyphs[TEXT_AREA]); | 2055 | xfree (from->glyphs[TEXT_AREA]); |
| @@ -2270,7 +2237,7 @@ adjust_frame_glyphs_for_window_redisplay (struct frame *f) | |||
| 2270 | static void | 2237 | static void |
| 2271 | adjust_frame_message_buffer (struct frame *f) | 2238 | adjust_frame_message_buffer (struct frame *f) |
| 2272 | { | 2239 | { |
| 2273 | int size = FRAME_MESSAGE_BUF_SIZE (f) + 1; | 2240 | ptrdiff_t size = FRAME_MESSAGE_BUF_SIZE (f) + 1; |
| 2274 | 2241 | ||
| 2275 | if (FRAME_MESSAGE_BUF (f)) | 2242 | if (FRAME_MESSAGE_BUF (f)) |
| 2276 | { | 2243 | { |
| @@ -4303,7 +4270,8 @@ scrolling_window (struct window *w, int header_line_p) | |||
| 4303 | struct glyph_matrix *current_matrix = w->current_matrix; | 4270 | struct glyph_matrix *current_matrix = w->current_matrix; |
| 4304 | int yb = window_text_bottom_y (w); | 4271 | int yb = window_text_bottom_y (w); |
| 4305 | int i, j, first_old, first_new, last_old, last_new; | 4272 | int i, j, first_old, first_new, last_old, last_new; |
| 4306 | int nruns, nbytes, n, run_idx; | 4273 | int nruns, n, run_idx; |
| 4274 | ptrdiff_t nbytes; | ||
| 4307 | struct row_entry *entry; | 4275 | struct row_entry *entry; |
| 4308 | struct redisplay_interface *rif = FRAME_RIF (XFRAME (WINDOW_FRAME (w))); | 4276 | struct redisplay_interface *rif = FRAME_RIF (XFRAME (WINDOW_FRAME (w))); |
| 4309 | 4277 | ||
| @@ -6331,11 +6299,14 @@ init_display (void) | |||
| 6331 | int width = FRAME_TOTAL_COLS (sf); | 6299 | int width = FRAME_TOTAL_COLS (sf); |
| 6332 | int height = FRAME_LINES (sf); | 6300 | int height = FRAME_LINES (sf); |
| 6333 | 6301 | ||
| 6334 | unsigned int total_glyphs = height * (width + 2) * sizeof (struct glyph); | ||
| 6335 | |||
| 6336 | /* If these sizes are so big they cause overflow, just ignore the | 6302 | /* If these sizes are so big they cause overflow, just ignore the |
| 6337 | change. It's not clear what better we could do. */ | 6303 | change. It's not clear what better we could do. The rest of |
| 6338 | if (total_glyphs / sizeof (struct glyph) / height != width + 2) | 6304 | the code assumes that (width + 2) * height * sizeof (struct glyph) |
| 6305 | does not overflow and does not exceed PTRDIFF_MAX or SIZE_MAX. */ | ||
| 6306 | if (INT_ADD_RANGE_OVERFLOW (width, 2, INT_MIN, INT_MAX) | ||
| 6307 | || INT_MULTIPLY_RANGE_OVERFLOW (width + 2, height, INT_MIN, INT_MAX) | ||
| 6308 | || (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (struct glyph) | ||
| 6309 | < (width + 2) * height)) | ||
| 6339 | fatal ("screen size %dx%d too big", width, height); | 6310 | fatal ("screen size %dx%d too big", width, height); |
| 6340 | } | 6311 | } |
| 6341 | 6312 | ||
diff --git a/src/doprnt.c b/src/doprnt.c index 195598c07ea..79f9f36e461 100644 --- a/src/doprnt.c +++ b/src/doprnt.c | |||
| @@ -102,13 +102,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 102 | #include <stdio.h> | 102 | #include <stdio.h> |
| 103 | #include <ctype.h> | 103 | #include <ctype.h> |
| 104 | #include <setjmp.h> | 104 | #include <setjmp.h> |
| 105 | |||
| 106 | #ifdef STDC_HEADERS | ||
| 107 | #include <float.h> | 105 | #include <float.h> |
| 108 | #endif | ||
| 109 | |||
| 110 | #include <unistd.h> | 106 | #include <unistd.h> |
| 111 | |||
| 112 | #include <limits.h> | 107 | #include <limits.h> |
| 113 | 108 | ||
| 114 | #include "lisp.h" | 109 | #include "lisp.h" |
| @@ -134,8 +129,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 134 | String arguments are passed as C strings. | 129 | String arguments are passed as C strings. |
| 135 | Integers are passed as C integers. */ | 130 | Integers are passed as C integers. */ |
| 136 | 131 | ||
| 137 | size_t | 132 | ptrdiff_t |
| 138 | doprnt (char *buffer, register size_t bufsize, const char *format, | 133 | doprnt (char *buffer, ptrdiff_t bufsize, const char *format, |
| 139 | const char *format_end, va_list ap) | 134 | const char *format_end, va_list ap) |
| 140 | { | 135 | { |
| 141 | const char *fmt = format; /* Pointer into format string */ | 136 | const char *fmt = format; /* Pointer into format string */ |
| @@ -145,7 +140,7 @@ doprnt (char *buffer, register size_t bufsize, const char *format, | |||
| 145 | char tembuf[DBL_MAX_10_EXP + 100]; | 140 | char tembuf[DBL_MAX_10_EXP + 100]; |
| 146 | 141 | ||
| 147 | /* Size of sprintf_buffer. */ | 142 | /* Size of sprintf_buffer. */ |
| 148 | size_t size_allocated = sizeof (tembuf); | 143 | ptrdiff_t size_allocated = sizeof (tembuf); |
| 149 | 144 | ||
| 150 | /* Buffer to use for sprintf. Either tembuf or same as BIG_BUFFER. */ | 145 | /* Buffer to use for sprintf. Either tembuf or same as BIG_BUFFER. */ |
| 151 | char *sprintf_buffer = tembuf; | 146 | char *sprintf_buffer = tembuf; |
| @@ -164,7 +159,7 @@ doprnt (char *buffer, register size_t bufsize, const char *format, | |||
| 164 | if (format_end == 0) | 159 | if (format_end == 0) |
| 165 | format_end = format + strlen (format); | 160 | format_end = format + strlen (format); |
| 166 | 161 | ||
| 167 | if ((format_end - format + 1) < sizeof (fixed_buffer)) | 162 | if (format_end - format < sizeof (fixed_buffer) - 1) |
| 168 | fmtcpy = fixed_buffer; | 163 | fmtcpy = fixed_buffer; |
| 169 | else | 164 | else |
| 170 | SAFE_ALLOCA (fmtcpy, char *, format_end - format + 1); | 165 | SAFE_ALLOCA (fmtcpy, char *, format_end - format + 1); |
| @@ -176,7 +171,7 @@ doprnt (char *buffer, register size_t bufsize, const char *format, | |||
| 176 | { | 171 | { |
| 177 | if (*fmt == '%') /* Check for a '%' character */ | 172 | if (*fmt == '%') /* Check for a '%' character */ |
| 178 | { | 173 | { |
| 179 | size_t size_bound = 0; | 174 | ptrdiff_t size_bound = 0; |
| 180 | EMACS_INT width; /* Columns occupied by STRING on display. */ | 175 | EMACS_INT width; /* Columns occupied by STRING on display. */ |
| 181 | int long_flag = 0; | 176 | int long_flag = 0; |
| 182 | int pIlen = sizeof pI - 1; | 177 | int pIlen = sizeof pI - 1; |
| @@ -194,16 +189,16 @@ doprnt (char *buffer, register size_t bufsize, const char *format, | |||
| 194 | This might be a field width or a precision; e.g. | 189 | This might be a field width or a precision; e.g. |
| 195 | %1.1000f and %1000.1f both might need 1000+ bytes. | 190 | %1.1000f and %1000.1f both might need 1000+ bytes. |
| 196 | Parse the width or precision, checking for overflow. */ | 191 | Parse the width or precision, checking for overflow. */ |
| 197 | size_t n = *fmt - '0'; | 192 | ptrdiff_t n = *fmt - '0'; |
| 198 | while (fmt + 1 < format_end | 193 | while (fmt + 1 < format_end |
| 199 | && '0' <= fmt[1] && fmt[1] <= '9') | 194 | && '0' <= fmt[1] && fmt[1] <= '9') |
| 200 | { | 195 | { |
| 201 | /* Avoid size_t overflow. Avoid int overflow too, as | 196 | /* Avoid ptrdiff_t, size_t, and int overflow, as |
| 202 | many sprintfs mishandle widths greater than INT_MAX. | 197 | many sprintfs mishandle widths greater than INT_MAX. |
| 203 | This test is simple but slightly conservative: e.g., | 198 | This test is simple but slightly conservative: e.g., |
| 204 | (INT_MAX - INT_MAX % 10) is reported as an overflow | 199 | (INT_MAX - INT_MAX % 10) is reported as an overflow |
| 205 | even when it's not. */ | 200 | even when it's not. */ |
| 206 | if (n >= min (INT_MAX, SIZE_MAX) / 10) | 201 | if (n >= min (INT_MAX, min (PTRDIFF_MAX, SIZE_MAX)) / 10) |
| 207 | error ("Format width or precision too large"); | 202 | error ("Format width or precision too large"); |
| 208 | n = n * 10 + fmt[1] - '0'; | 203 | n = n * 10 + fmt[1] - '0'; |
| 209 | *string++ = *++fmt; | 204 | *string++ = *++fmt; |
| @@ -235,7 +230,7 @@ doprnt (char *buffer, register size_t bufsize, const char *format, | |||
| 235 | 230 | ||
| 236 | /* Make the size bound large enough to handle floating point formats | 231 | /* Make the size bound large enough to handle floating point formats |
| 237 | with large numbers. */ | 232 | with large numbers. */ |
| 238 | if (size_bound > SIZE_MAX - DBL_MAX_10_EXP - 50) | 233 | if (size_bound > min (PTRDIFF_MAX, SIZE_MAX) - DBL_MAX_10_EXP - 50) |
| 239 | error ("Format width or precision too large"); | 234 | error ("Format width or precision too large"); |
| 240 | size_bound += DBL_MAX_10_EXP + 50; | 235 | size_bound += DBL_MAX_10_EXP + 50; |
| 241 | 236 | ||
diff --git a/src/editfns.c b/src/editfns.c index 56ad99d199f..577263c5aea 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -3504,22 +3504,6 @@ usage: (propertize STRING &rest PROPERTIES) */) | |||
| 3504 | RETURN_UNGCPRO (string); | 3504 | RETURN_UNGCPRO (string); |
| 3505 | } | 3505 | } |
| 3506 | 3506 | ||
| 3507 | /* pWIDE is a conversion for printing large decimal integers (possibly with a | ||
| 3508 | trailing "d" that is ignored). pWIDElen is its length. signed_wide and | ||
| 3509 | unsigned_wide are signed and unsigned types for printing them. Use widest | ||
| 3510 | integers if available so that more floating point values can be converted. */ | ||
| 3511 | #ifdef PRIdMAX | ||
| 3512 | # define pWIDE PRIdMAX | ||
| 3513 | enum { pWIDElen = sizeof PRIdMAX - 2 }; /* Don't count trailing "d". */ | ||
| 3514 | typedef intmax_t signed_wide; | ||
| 3515 | typedef uintmax_t unsigned_wide; | ||
| 3516 | #else | ||
| 3517 | # define pWIDE pI | ||
| 3518 | enum { pWIDElen = sizeof pI - 1 }; | ||
| 3519 | typedef EMACS_INT signed_wide; | ||
| 3520 | typedef EMACS_UINT unsigned_wide; | ||
| 3521 | #endif | ||
| 3522 | |||
| 3523 | DEFUN ("format", Fformat, Sformat, 1, MANY, 0, | 3507 | DEFUN ("format", Fformat, Sformat, 1, MANY, 0, |
| 3524 | doc: /* Format a string out of a format-string and arguments. | 3508 | doc: /* Format a string out of a format-string and arguments. |
| 3525 | The first argument is a format control string. | 3509 | The first argument is a format control string. |
| @@ -3901,7 +3885,11 @@ usage: (format STRING &rest OBJECTS) */) | |||
| 3901 | precision is no more than DBL_USEFUL_PRECISION_MAX. | 3885 | precision is no more than DBL_USEFUL_PRECISION_MAX. |
| 3902 | On all practical hosts, %f is the worst case. */ | 3886 | On all practical hosts, %f is the worst case. */ |
| 3903 | SPRINTF_BUFSIZE = | 3887 | SPRINTF_BUFSIZE = |
| 3904 | sizeof "-." + (DBL_MAX_10_EXP + 1) + USEFUL_PRECISION_MAX | 3888 | sizeof "-." + (DBL_MAX_10_EXP + 1) + USEFUL_PRECISION_MAX, |
| 3889 | |||
| 3890 | /* Length of pM (that is, of pMd without the | ||
| 3891 | trailing "d"). */ | ||
| 3892 | pMlen = sizeof pMd - 2 | ||
| 3905 | }; | 3893 | }; |
| 3906 | verify (0 < USEFUL_PRECISION_MAX); | 3894 | verify (0 < USEFUL_PRECISION_MAX); |
| 3907 | 3895 | ||
| @@ -3914,7 +3902,7 @@ usage: (format STRING &rest OBJECTS) */) | |||
| 3914 | 3902 | ||
| 3915 | /* Copy of conversion specification, modified somewhat. | 3903 | /* Copy of conversion specification, modified somewhat. |
| 3916 | At most three flags F can be specified at once. */ | 3904 | At most three flags F can be specified at once. */ |
| 3917 | char convspec[sizeof "%FFF.*d" + pWIDElen]; | 3905 | char convspec[sizeof "%FFF.*d" + pMlen]; |
| 3918 | 3906 | ||
| 3919 | /* Avoid undefined behavior in underlying sprintf. */ | 3907 | /* Avoid undefined behavior in underlying sprintf. */ |
| 3920 | if (conversion == 'd' || conversion == 'i') | 3908 | if (conversion == 'd' || conversion == 'i') |
| @@ -3922,7 +3910,7 @@ usage: (format STRING &rest OBJECTS) */) | |||
| 3922 | 3910 | ||
| 3923 | /* Create the copy of the conversion specification, with | 3911 | /* Create the copy of the conversion specification, with |
| 3924 | any width and precision removed, with ".*" inserted, | 3912 | any width and precision removed, with ".*" inserted, |
| 3925 | and with pWIDE inserted for integer formats. */ | 3913 | and with pM inserted for integer formats. */ |
| 3926 | { | 3914 | { |
| 3927 | char *f = convspec; | 3915 | char *f = convspec; |
| 3928 | *f++ = '%'; | 3916 | *f++ = '%'; |
| @@ -3937,8 +3925,8 @@ usage: (format STRING &rest OBJECTS) */) | |||
| 3937 | || conversion == 'o' || conversion == 'x' | 3925 | || conversion == 'o' || conversion == 'x' |
| 3938 | || conversion == 'X') | 3926 | || conversion == 'X') |
| 3939 | { | 3927 | { |
| 3940 | memcpy (f, pWIDE, pWIDElen); | 3928 | memcpy (f, pMd, pMlen); |
| 3941 | f += pWIDElen; | 3929 | f += pMlen; |
| 3942 | zero_flag &= ~ precision_given; | 3930 | zero_flag &= ~ precision_given; |
| 3943 | } | 3931 | } |
| 3944 | *f++ = conversion; | 3932 | *f++ = conversion; |
| @@ -3978,7 +3966,7 @@ usage: (format STRING &rest OBJECTS) */) | |||
| 3978 | /* For float, maybe we should use "%1.0f" | 3966 | /* For float, maybe we should use "%1.0f" |
| 3979 | instead so it also works for values outside | 3967 | instead so it also works for values outside |
| 3980 | the integer range. */ | 3968 | the integer range. */ |
| 3981 | signed_wide x; | 3969 | printmax_t x; |
| 3982 | if (INTEGERP (args[n])) | 3970 | if (INTEGERP (args[n])) |
| 3983 | x = XINT (args[n]); | 3971 | x = XINT (args[n]); |
| 3984 | else | 3972 | else |
| @@ -3986,13 +3974,13 @@ usage: (format STRING &rest OBJECTS) */) | |||
| 3986 | double d = XFLOAT_DATA (args[n]); | 3974 | double d = XFLOAT_DATA (args[n]); |
| 3987 | if (d < 0) | 3975 | if (d < 0) |
| 3988 | { | 3976 | { |
| 3989 | x = TYPE_MINIMUM (signed_wide); | 3977 | x = TYPE_MINIMUM (printmax_t); |
| 3990 | if (x < d) | 3978 | if (x < d) |
| 3991 | x = d; | 3979 | x = d; |
| 3992 | } | 3980 | } |
| 3993 | else | 3981 | else |
| 3994 | { | 3982 | { |
| 3995 | x = TYPE_MAXIMUM (signed_wide); | 3983 | x = TYPE_MAXIMUM (printmax_t); |
| 3996 | if (d < x) | 3984 | if (d < x) |
| 3997 | x = d; | 3985 | x = d; |
| 3998 | } | 3986 | } |
| @@ -4002,7 +3990,7 @@ usage: (format STRING &rest OBJECTS) */) | |||
| 4002 | else | 3990 | else |
| 4003 | { | 3991 | { |
| 4004 | /* Don't sign-extend for octal or hex printing. */ | 3992 | /* Don't sign-extend for octal or hex printing. */ |
| 4005 | unsigned_wide x; | 3993 | uprintmax_t x; |
| 4006 | if (INTEGERP (args[n])) | 3994 | if (INTEGERP (args[n])) |
| 4007 | x = XUINT (args[n]); | 3995 | x = XUINT (args[n]); |
| 4008 | else | 3996 | else |
| @@ -4012,7 +4000,7 @@ usage: (format STRING &rest OBJECTS) */) | |||
| 4012 | x = 0; | 4000 | x = 0; |
| 4013 | else | 4001 | else |
| 4014 | { | 4002 | { |
| 4015 | x = TYPE_MAXIMUM (unsigned_wide); | 4003 | x = TYPE_MAXIMUM (uprintmax_t); |
| 4016 | if (d < x) | 4004 | if (d < x) |
| 4017 | x = d; | 4005 | x = d; |
| 4018 | } | 4006 | } |
diff --git a/src/emacs.c b/src/emacs.c index ecf372d40ad..4c818ff048f 100644 --- a/src/emacs.c +++ b/src/emacs.c | |||
| @@ -171,8 +171,10 @@ char *stack_bottom; | |||
| 171 | /* The address where the heap starts (from the first sbrk (0) call). */ | 171 | /* The address where the heap starts (from the first sbrk (0) call). */ |
| 172 | static void *my_heap_start; | 172 | static void *my_heap_start; |
| 173 | 173 | ||
| 174 | #ifdef GNU_LINUX | ||
| 174 | /* The gap between BSS end and heap start as far as we can tell. */ | 175 | /* The gap between BSS end and heap start as far as we can tell. */ |
| 175 | static unsigned long heap_bss_diff; | 176 | static uprintmax_t heap_bss_diff; |
| 177 | #endif | ||
| 176 | 178 | ||
| 177 | /* Nonzero means running Emacs without interactive terminal. */ | 179 | /* Nonzero means running Emacs without interactive terminal. */ |
| 178 | int noninteractive; | 180 | int noninteractive; |
| @@ -717,6 +719,7 @@ main (int argc, char **argv) | |||
| 717 | setenv ("G_SLICE", "always-malloc", 1); | 719 | setenv ("G_SLICE", "always-malloc", 1); |
| 718 | #endif | 720 | #endif |
| 719 | 721 | ||
| 722 | #ifdef GNU_LINUX | ||
| 720 | if (!initialized) | 723 | if (!initialized) |
| 721 | { | 724 | { |
| 722 | extern char my_endbss[]; | 725 | extern char my_endbss[]; |
| @@ -727,6 +730,7 @@ main (int argc, char **argv) | |||
| 727 | 730 | ||
| 728 | heap_bss_diff = (char *)my_heap_start - max (my_endbss, my_endbss_static); | 731 | heap_bss_diff = (char *)my_heap_start - max (my_endbss, my_endbss_static); |
| 729 | } | 732 | } |
| 733 | #endif | ||
| 730 | 734 | ||
| 731 | #ifdef RUN_TIME_REMAP | 735 | #ifdef RUN_TIME_REMAP |
| 732 | if (initialized) | 736 | if (initialized) |
| @@ -2136,7 +2140,7 @@ You must run Emacs in batch mode in order to dump it. */) | |||
| 2136 | { | 2140 | { |
| 2137 | fprintf (stderr, "**************************************************\n"); | 2141 | fprintf (stderr, "**************************************************\n"); |
| 2138 | fprintf (stderr, "Warning: Your system has a gap between BSS and the\n"); | 2142 | fprintf (stderr, "Warning: Your system has a gap between BSS and the\n"); |
| 2139 | fprintf (stderr, "heap (%lu bytes). This usually means that exec-shield\n", | 2143 | fprintf (stderr, "heap (%"pMu" bytes). This usually means that exec-shield\n", |
| 2140 | heap_bss_diff); | 2144 | heap_bss_diff); |
| 2141 | fprintf (stderr, "or something similar is in effect. The dump may\n"); | 2145 | fprintf (stderr, "or something similar is in effect. The dump may\n"); |
| 2142 | fprintf (stderr, "fail because of this. See the section about\n"); | 2146 | fprintf (stderr, "fail because of this. See the section about\n"); |
diff --git a/src/eval.c b/src/eval.c index 90d0df61858..ef169e80e27 100644 --- a/src/eval.c +++ b/src/eval.c | |||
| @@ -1968,18 +1968,18 @@ void | |||
| 1968 | verror (const char *m, va_list ap) | 1968 | verror (const char *m, va_list ap) |
| 1969 | { | 1969 | { |
| 1970 | char buf[4000]; | 1970 | char buf[4000]; |
| 1971 | size_t size = sizeof buf; | 1971 | ptrdiff_t size = sizeof buf; |
| 1972 | size_t size_max = STRING_BYTES_BOUND + 1; | 1972 | ptrdiff_t size_max = STRING_BYTES_BOUND + 1; |
| 1973 | size_t mlen = strlen (m); | 1973 | char const *m_end = m + strlen (m); |
| 1974 | char *buffer = buf; | 1974 | char *buffer = buf; |
| 1975 | size_t used; | 1975 | ptrdiff_t used; |
| 1976 | Lisp_Object string; | 1976 | Lisp_Object string; |
| 1977 | 1977 | ||
| 1978 | while (1) | 1978 | while (1) |
| 1979 | { | 1979 | { |
| 1980 | va_list ap_copy; | 1980 | va_list ap_copy; |
| 1981 | va_copy (ap_copy, ap); | 1981 | va_copy (ap_copy, ap); |
| 1982 | used = doprnt (buffer, size, m, m + mlen, ap_copy); | 1982 | used = doprnt (buffer, size, m, m_end, ap_copy); |
| 1983 | va_end (ap_copy); | 1983 | va_end (ap_copy); |
| 1984 | 1984 | ||
| 1985 | /* Note: the -1 below is because `doprnt' returns the number of bytes | 1985 | /* Note: the -1 below is because `doprnt' returns the number of bytes |
diff --git a/src/fileio.c b/src/fileio.c index 3e1aa54462f..61713689351 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -587,9 +587,9 @@ make_temp_name (Lisp_Object prefix, int base64_p) | |||
| 587 | { | 587 | { |
| 588 | Lisp_Object val; | 588 | Lisp_Object val; |
| 589 | int len, clen; | 589 | int len, clen; |
| 590 | intmax_t pid; | 590 | printmax_t pid; |
| 591 | char *p, *data; | 591 | char *p, *data; |
| 592 | char pidbuf[INT_BUFSIZE_BOUND (pid_t)]; | 592 | char pidbuf[INT_BUFSIZE_BOUND (printmax_t)]; |
| 593 | int pidlen; | 593 | int pidlen; |
| 594 | 594 | ||
| 595 | CHECK_STRING (prefix); | 595 | CHECK_STRING (prefix); |
| @@ -611,7 +611,7 @@ make_temp_name (Lisp_Object prefix, int base64_p) | |||
| 611 | else | 611 | else |
| 612 | { | 612 | { |
| 613 | #ifdef HAVE_LONG_FILE_NAMES | 613 | #ifdef HAVE_LONG_FILE_NAMES |
| 614 | pidlen = sprintf (pidbuf, "%"PRIdMAX, pid); | 614 | pidlen = sprintf (pidbuf, "%"pMd, pid); |
| 615 | #else | 615 | #else |
| 616 | pidbuf[0] = make_temp_name_tbl[pid & 63], pid >>= 6; | 616 | pidbuf[0] = make_temp_name_tbl[pid & 63], pid >>= 6; |
| 617 | pidbuf[1] = make_temp_name_tbl[pid & 63], pid >>= 6; | 617 | pidbuf[1] = make_temp_name_tbl[pid & 63], pid >>= 6; |
diff --git a/src/filelock.c b/src/filelock.c index 18483b6f3f3..c28ee7837fa 100644 --- a/src/filelock.c +++ b/src/filelock.c | |||
| @@ -337,7 +337,7 @@ static int | |||
| 337 | lock_file_1 (char *lfname, int force) | 337 | lock_file_1 (char *lfname, int force) |
| 338 | { | 338 | { |
| 339 | register int err; | 339 | register int err; |
| 340 | intmax_t boot, pid; | 340 | printmax_t boot, pid; |
| 341 | const char *user_name; | 341 | const char *user_name; |
| 342 | const char *host_name; | 342 | const char *host_name; |
| 343 | char *lock_info_str; | 343 | char *lock_info_str; |
| @@ -354,15 +354,15 @@ lock_file_1 (char *lfname, int force) | |||
| 354 | else | 354 | else |
| 355 | host_name = ""; | 355 | host_name = ""; |
| 356 | lock_info_str = (char *)alloca (strlen (user_name) + strlen (host_name) | 356 | lock_info_str = (char *)alloca (strlen (user_name) + strlen (host_name) |
| 357 | + 2 * INT_STRLEN_BOUND (intmax_t) | 357 | + 2 * INT_STRLEN_BOUND (printmax_t) |
| 358 | + sizeof "@.:"); | 358 | + sizeof "@.:"); |
| 359 | pid = getpid (); | 359 | pid = getpid (); |
| 360 | 360 | ||
| 361 | if (boot) | 361 | if (boot) |
| 362 | sprintf (lock_info_str, "%s@%s.%"PRIdMAX":%"PRIdMAX, | 362 | sprintf (lock_info_str, "%s@%s.%"pMd":%"pMd, |
| 363 | user_name, host_name, pid, boot); | 363 | user_name, host_name, pid, boot); |
| 364 | else | 364 | else |
| 365 | sprintf (lock_info_str, "%s@%s.%"PRIdMAX, | 365 | sprintf (lock_info_str, "%s@%s.%"pMd, |
| 366 | user_name, host_name, pid); | 366 | user_name, host_name, pid); |
| 367 | 367 | ||
| 368 | err = symlink (lock_info_str, lfname); | 368 | err = symlink (lock_info_str, lfname); |
| @@ -542,7 +542,7 @@ lock_file (Lisp_Object fn) | |||
| 542 | register Lisp_Object attack, orig_fn, encoded_fn; | 542 | register Lisp_Object attack, orig_fn, encoded_fn; |
| 543 | register char *lfname, *locker; | 543 | register char *lfname, *locker; |
| 544 | lock_info_type lock_info; | 544 | lock_info_type lock_info; |
| 545 | intmax_t pid; | 545 | printmax_t pid; |
| 546 | struct gcpro gcpro1; | 546 | struct gcpro gcpro1; |
| 547 | 547 | ||
| 548 | /* Don't do locking while dumping Emacs. | 548 | /* Don't do locking while dumping Emacs. |
| @@ -581,9 +581,10 @@ lock_file (Lisp_Object fn) | |||
| 581 | 581 | ||
| 582 | /* Else consider breaking the lock */ | 582 | /* Else consider breaking the lock */ |
| 583 | locker = (char *) alloca (strlen (lock_info.user) + strlen (lock_info.host) | 583 | locker = (char *) alloca (strlen (lock_info.user) + strlen (lock_info.host) |
| 584 | + INT_STRLEN_BOUND (intmax_t) + sizeof "@ (pid )"); | 584 | + INT_STRLEN_BOUND (printmax_t) |
| 585 | + sizeof "@ (pid )"); | ||
| 585 | pid = lock_info.pid; | 586 | pid = lock_info.pid; |
| 586 | sprintf (locker, "%s@%s (pid %"PRIdMAX")", | 587 | sprintf (locker, "%s@%s (pid %"pMd")", |
| 587 | lock_info.user, lock_info.host, pid); | 588 | lock_info.user, lock_info.host, pid); |
| 588 | FREE_LOCK_INFO (lock_info); | 589 | FREE_LOCK_INFO (lock_info); |
| 589 | 590 | ||
diff --git a/src/floatfns.c b/src/floatfns.c index e003f492fe6..89aa052e8b1 100644 --- a/src/floatfns.c +++ b/src/floatfns.c | |||
| @@ -53,10 +53,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 53 | #include "lisp.h" | 53 | #include "lisp.h" |
| 54 | #include "syssignal.h" | 54 | #include "syssignal.h" |
| 55 | 55 | ||
| 56 | #if STDC_HEADERS | ||
| 57 | #include <float.h> | 56 | #include <float.h> |
| 58 | #endif | ||
| 59 | |||
| 60 | /* If IEEE_FLOATING_POINT isn't defined, default it from FLT_*. */ | 57 | /* If IEEE_FLOATING_POINT isn't defined, default it from FLT_*. */ |
| 61 | #ifndef IEEE_FLOATING_POINT | 58 | #ifndef IEEE_FLOATING_POINT |
| 62 | #if (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \ | 59 | #if (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \ |
| @@ -4098,25 +4098,33 @@ sweep_weak_hash_tables (void) | |||
| 4098 | #define SXHASH_REDUCE(X) \ | 4098 | #define SXHASH_REDUCE(X) \ |
| 4099 | ((((X) ^ (X) >> (BITS_PER_EMACS_INT - FIXNUM_BITS))) & INTMASK) | 4099 | ((((X) ^ (X) >> (BITS_PER_EMACS_INT - FIXNUM_BITS))) & INTMASK) |
| 4100 | 4100 | ||
| 4101 | /* Return a hash for string PTR which has length LEN. The hash | 4101 | /* Return a hash for string PTR which has length LEN. The hash value |
| 4102 | code returned is guaranteed to fit in a Lisp integer. */ | 4102 | can be any EMACS_UINT value. */ |
| 4103 | 4103 | ||
| 4104 | static EMACS_UINT | 4104 | EMACS_UINT |
| 4105 | sxhash_string (unsigned char *ptr, EMACS_INT len) | 4105 | hash_string (char const *ptr, ptrdiff_t len) |
| 4106 | { | 4106 | { |
| 4107 | unsigned char *p = ptr; | 4107 | char const *p = ptr; |
| 4108 | unsigned char *end = p + len; | 4108 | char const *end = p + len; |
| 4109 | unsigned char c; | 4109 | unsigned char c; |
| 4110 | EMACS_UINT hash = 0; | 4110 | EMACS_UINT hash = 0; |
| 4111 | 4111 | ||
| 4112 | while (p != end) | 4112 | while (p != end) |
| 4113 | { | 4113 | { |
| 4114 | c = *p++; | 4114 | c = *p++; |
| 4115 | if (c >= 0140) | ||
| 4116 | c -= 40; | ||
| 4117 | hash = SXHASH_COMBINE (hash, c); | 4115 | hash = SXHASH_COMBINE (hash, c); |
| 4118 | } | 4116 | } |
| 4119 | 4117 | ||
| 4118 | return hash; | ||
| 4119 | } | ||
| 4120 | |||
| 4121 | /* Return a hash for string PTR which has length LEN. The hash | ||
| 4122 | code returned is guaranteed to fit in a Lisp integer. */ | ||
| 4123 | |||
| 4124 | static EMACS_UINT | ||
| 4125 | sxhash_string (char const *ptr, ptrdiff_t len) | ||
| 4126 | { | ||
| 4127 | EMACS_UINT hash = hash_string (ptr, len); | ||
| 4120 | return SXHASH_REDUCE (hash); | 4128 | return SXHASH_REDUCE (hash); |
| 4121 | } | 4129 | } |
| 4122 | 4130 | ||
| @@ -4231,7 +4239,7 @@ sxhash (Lisp_Object obj, int depth) | |||
| 4231 | /* Fall through. */ | 4239 | /* Fall through. */ |
| 4232 | 4240 | ||
| 4233 | case Lisp_String: | 4241 | case Lisp_String: |
| 4234 | hash = sxhash_string (SDATA (obj), SCHARS (obj)); | 4242 | hash = sxhash_string (SSDATA (obj), SBYTES (obj)); |
| 4235 | break; | 4243 | break; |
| 4236 | 4244 | ||
| 4237 | /* This can be everything from a vector to an overlay. */ | 4245 | /* This can be everything from a vector to an overlay. */ |
diff --git a/src/gmalloc.c b/src/gmalloc.c index a023d2d78e5..fa4aa1fdf6a 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c | |||
| @@ -41,37 +41,13 @@ Fifth Floor, Boston, MA 02110-1301, USA. | |||
| 41 | #define USE_PTHREAD | 41 | #define USE_PTHREAD |
| 42 | #endif | 42 | #endif |
| 43 | 43 | ||
| 44 | #if ((defined __cplusplus || (defined (__STDC__) && __STDC__) \ | ||
| 45 | || defined STDC_HEADERS || defined PROTOTYPES)) | ||
| 46 | #undef PP | 44 | #undef PP |
| 47 | #define PP(args) args | 45 | #define PP(args) args |
| 48 | #undef __ptr_t | 46 | #undef __ptr_t |
| 49 | #define __ptr_t void * | 47 | #define __ptr_t void * |
| 50 | #else /* Not C++ or ANSI C. */ | ||
| 51 | #undef PP | ||
| 52 | #define PP(args) () | ||
| 53 | #undef __ptr_t | ||
| 54 | #define __ptr_t char * | ||
| 55 | #endif /* C++ or ANSI C. */ | ||
| 56 | 48 | ||
| 57 | #if defined(_LIBC) || defined(STDC_HEADERS) || defined(USG) | ||
| 58 | #include <string.h> | 49 | #include <string.h> |
| 59 | #else | ||
| 60 | #ifndef memset | ||
| 61 | #define memset(s, zero, n) bzero ((s), (n)) | ||
| 62 | #endif | ||
| 63 | #ifndef memcpy | ||
| 64 | #define memcpy(d, s, n) bcopy ((s), (d), (n)) | ||
| 65 | #endif | ||
| 66 | #endif | ||
| 67 | |||
| 68 | #ifdef HAVE_LIMITS_H | ||
| 69 | #include <limits.h> | 50 | #include <limits.h> |
| 70 | #endif | ||
| 71 | #ifndef CHAR_BIT | ||
| 72 | #define CHAR_BIT 8 | ||
| 73 | #endif | ||
| 74 | |||
| 75 | #include <unistd.h> | 51 | #include <unistd.h> |
| 76 | 52 | ||
| 77 | #ifdef USE_PTHREAD | 53 | #ifdef USE_PTHREAD |
| @@ -86,26 +62,9 @@ extern "C" | |||
| 86 | { | 62 | { |
| 87 | #endif | 63 | #endif |
| 88 | 64 | ||
| 89 | #ifdef STDC_HEADERS | ||
| 90 | #include <stddef.h> | 65 | #include <stddef.h> |
| 91 | #define __malloc_size_t size_t | 66 | #define __malloc_size_t size_t |
| 92 | #define __malloc_ptrdiff_t ptrdiff_t | 67 | #define __malloc_ptrdiff_t ptrdiff_t |
| 93 | #else | ||
| 94 | #ifdef __GNUC__ | ||
| 95 | #include <stddef.h> | ||
| 96 | #ifdef __SIZE_TYPE__ | ||
| 97 | #define __malloc_size_t __SIZE_TYPE__ | ||
| 98 | #endif | ||
| 99 | #endif | ||
| 100 | #ifndef __malloc_size_t | ||
| 101 | #define __malloc_size_t unsigned int | ||
| 102 | #endif | ||
| 103 | #define __malloc_ptrdiff_t int | ||
| 104 | #endif | ||
| 105 | |||
| 106 | #ifndef NULL | ||
| 107 | #define NULL 0 | ||
| 108 | #endif | ||
| 109 | 68 | ||
| 110 | 69 | ||
| 111 | /* Allocate SIZE bytes of memory. */ | 70 | /* Allocate SIZE bytes of memory. */ |
| @@ -1069,20 +1028,6 @@ Fifth Floor, Boston, MA 02110-1301, USA. | |||
| 1069 | #endif | 1028 | #endif |
| 1070 | 1029 | ||
| 1071 | 1030 | ||
| 1072 | /* Cope with systems lacking `memmove'. */ | ||
| 1073 | #ifndef memmove | ||
| 1074 | #if (!defined(_LIBC) && !defined(STDC_HEADERS) && !defined(USG)) | ||
| 1075 | #ifdef emacs | ||
| 1076 | #undef __malloc_safe_bcopy | ||
| 1077 | #define __malloc_safe_bcopy safe_bcopy | ||
| 1078 | #endif | ||
| 1079 | /* This function is defined in realloc.c. */ | ||
| 1080 | extern void __malloc_safe_bcopy PP ((__ptr_t, __ptr_t, __malloc_size_t)); | ||
| 1081 | #define memmove(to, from, size) __malloc_safe_bcopy ((from), (to), (size)) | ||
| 1082 | #endif | ||
| 1083 | #endif | ||
| 1084 | |||
| 1085 | |||
| 1086 | /* Debugging hook for free. */ | 1031 | /* Debugging hook for free. */ |
| 1087 | void (*__free_hook) PP ((__ptr_t __ptr)); | 1032 | void (*__free_hook) PP ((__ptr_t __ptr)); |
| 1088 | 1033 | ||
| @@ -1402,85 +1347,6 @@ Fifth Floor, Boston, MA 02110-1301, USA. | |||
| 1402 | #endif | 1347 | #endif |
| 1403 | 1348 | ||
| 1404 | 1349 | ||
| 1405 | |||
| 1406 | /* Cope with systems lacking `memmove'. */ | ||
| 1407 | #if (!defined(_LIBC) && !defined(STDC_HEADERS) && !defined(USG)) | ||
| 1408 | |||
| 1409 | #ifdef emacs | ||
| 1410 | #undef __malloc_safe_bcopy | ||
| 1411 | #define __malloc_safe_bcopy safe_bcopy | ||
| 1412 | #else | ||
| 1413 | |||
| 1414 | /* Snarfed directly from Emacs src/dispnew.c: | ||
| 1415 | XXX Should use system bcopy if it handles overlap. */ | ||
| 1416 | |||
| 1417 | /* Like bcopy except never gets confused by overlap. */ | ||
| 1418 | |||
| 1419 | void | ||
| 1420 | __malloc_safe_bcopy (afrom, ato, size) | ||
| 1421 | __ptr_t afrom; | ||
| 1422 | __ptr_t ato; | ||
| 1423 | __malloc_size_t size; | ||
| 1424 | { | ||
| 1425 | char *from = afrom, *to = ato; | ||
| 1426 | |||
| 1427 | if (size <= 0 || from == to) | ||
| 1428 | return; | ||
| 1429 | |||
| 1430 | /* If the source and destination don't overlap, then bcopy can | ||
| 1431 | handle it. If they do overlap, but the destination is lower in | ||
| 1432 | memory than the source, we'll assume bcopy can handle that. */ | ||
| 1433 | if (to < from || from + size <= to) | ||
| 1434 | bcopy (from, to, size); | ||
| 1435 | |||
| 1436 | /* Otherwise, we'll copy from the end. */ | ||
| 1437 | else | ||
| 1438 | { | ||
| 1439 | register char *endf = from + size; | ||
| 1440 | register char *endt = to + size; | ||
| 1441 | |||
| 1442 | /* If TO - FROM is large, then we should break the copy into | ||
| 1443 | nonoverlapping chunks of TO - FROM bytes each. However, if | ||
| 1444 | TO - FROM is small, then the bcopy function call overhead | ||
| 1445 | makes this not worth it. The crossover point could be about | ||
| 1446 | anywhere. Since I don't think the obvious copy loop is too | ||
| 1447 | bad, I'm trying to err in its favor. */ | ||
| 1448 | if (to - from < 64) | ||
| 1449 | { | ||
| 1450 | do | ||
| 1451 | *--endt = *--endf; | ||
| 1452 | while (endf != from); | ||
| 1453 | } | ||
| 1454 | else | ||
| 1455 | { | ||
| 1456 | for (;;) | ||
| 1457 | { | ||
| 1458 | endt -= (to - from); | ||
| 1459 | endf -= (to - from); | ||
| 1460 | |||
| 1461 | if (endt < to) | ||
| 1462 | break; | ||
| 1463 | |||
| 1464 | bcopy (endf, endt, to - from); | ||
| 1465 | } | ||
| 1466 | |||
| 1467 | /* If SIZE wasn't a multiple of TO - FROM, there will be a | ||
| 1468 | little left over. The amount left over is | ||
| 1469 | (endt + (to - from)) - to, which is endt - from. */ | ||
| 1470 | bcopy (from, to, endt - from); | ||
| 1471 | } | ||
| 1472 | } | ||
| 1473 | } | ||
| 1474 | #endif /* emacs */ | ||
| 1475 | |||
| 1476 | #ifndef memmove | ||
| 1477 | extern void __malloc_safe_bcopy PP ((__ptr_t, __ptr_t, __malloc_size_t)); | ||
| 1478 | #define memmove(to, from, size) __malloc_safe_bcopy ((from), (to), (size)) | ||
| 1479 | #endif | ||
| 1480 | |||
| 1481 | #endif | ||
| 1482 | |||
| 1483 | |||
| 1484 | #define min(A, B) ((A) < (B) ? (A) : (B)) | 1350 | #define min(A, B) ((A) < (B) ? (A) : (B)) |
| 1485 | 1351 | ||
| 1486 | /* Debugging hook for realloc. */ | 1352 | /* Debugging hook for realloc. */ |
| @@ -1983,22 +1849,6 @@ struct hdr | |||
| 1983 | unsigned long int magic; /* Magic number to check header integrity. */ | 1849 | unsigned long int magic; /* Magic number to check header integrity. */ |
| 1984 | }; | 1850 | }; |
| 1985 | 1851 | ||
| 1986 | #if defined(_LIBC) || defined(STDC_HEADERS) || defined(USG) | ||
| 1987 | #define flood memset | ||
| 1988 | #else | ||
| 1989 | static void flood (__ptr_t, int, __malloc_size_t); | ||
| 1990 | static void | ||
| 1991 | flood (ptr, val, size) | ||
| 1992 | __ptr_t ptr; | ||
| 1993 | int val; | ||
| 1994 | __malloc_size_t size; | ||
| 1995 | { | ||
| 1996 | char *cp = ptr; | ||
| 1997 | while (size--) | ||
| 1998 | *cp++ = val; | ||
| 1999 | } | ||
| 2000 | #endif | ||
| 2001 | |||
| 2002 | static enum mcheck_status checkhdr (const struct hdr *); | 1852 | static enum mcheck_status checkhdr (const struct hdr *); |
| 2003 | static enum mcheck_status | 1853 | static enum mcheck_status |
| 2004 | checkhdr (hdr) | 1854 | checkhdr (hdr) |
| @@ -2037,7 +1887,7 @@ freehook (ptr) | |||
| 2037 | hdr = ((struct hdr *) ptr) - 1; | 1887 | hdr = ((struct hdr *) ptr) - 1; |
| 2038 | checkhdr (hdr); | 1888 | checkhdr (hdr); |
| 2039 | hdr->magic = MAGICFREE; | 1889 | hdr->magic = MAGICFREE; |
| 2040 | flood (ptr, FREEFLOOD, hdr->size); | 1890 | memset (ptr, FREEFLOOD, hdr->size); |
| 2041 | } | 1891 | } |
| 2042 | else | 1892 | else |
| 2043 | hdr = NULL; | 1893 | hdr = NULL; |
| @@ -2063,7 +1913,7 @@ mallochook (size) | |||
| 2063 | hdr->size = size; | 1913 | hdr->size = size; |
| 2064 | hdr->magic = MAGICWORD; | 1914 | hdr->magic = MAGICWORD; |
| 2065 | ((char *) &hdr[1])[size] = MAGICBYTE; | 1915 | ((char *) &hdr[1])[size] = MAGICBYTE; |
| 2066 | flood ((__ptr_t) (hdr + 1), MALLOCFLOOD, size); | 1916 | memset ((__ptr_t) (hdr + 1), MALLOCFLOOD, size); |
| 2067 | return (__ptr_t) (hdr + 1); | 1917 | return (__ptr_t) (hdr + 1); |
| 2068 | } | 1918 | } |
| 2069 | 1919 | ||
| @@ -2083,7 +1933,7 @@ reallochook (ptr, size) | |||
| 2083 | 1933 | ||
| 2084 | checkhdr (hdr); | 1934 | checkhdr (hdr); |
| 2085 | if (size < osize) | 1935 | if (size < osize) |
| 2086 | flood ((char *) ptr + size, FREEFLOOD, osize - size); | 1936 | memset ((char *) ptr + size, FREEFLOOD, osize - size); |
| 2087 | } | 1937 | } |
| 2088 | 1938 | ||
| 2089 | __free_hook = old_free_hook; | 1939 | __free_hook = old_free_hook; |
| @@ -2100,7 +1950,7 @@ reallochook (ptr, size) | |||
| 2100 | hdr->magic = MAGICWORD; | 1950 | hdr->magic = MAGICWORD; |
| 2101 | ((char *) &hdr[1])[size] = MAGICBYTE; | 1951 | ((char *) &hdr[1])[size] = MAGICBYTE; |
| 2102 | if (size > osize) | 1952 | if (size > osize) |
| 2103 | flood ((char *) (hdr + 1) + osize, MALLOCFLOOD, size - osize); | 1953 | memset ((char *) (hdr + 1) + osize, MALLOCFLOOD, size - osize); |
| 2104 | return (__ptr_t) (hdr + 1); | 1954 | return (__ptr_t) (hdr + 1); |
| 2105 | } | 1955 | } |
| 2106 | 1956 | ||
diff --git a/src/gnutls.c b/src/gnutls.c index 3175f55041d..fc651d2c7e4 100644 --- a/src/gnutls.c +++ b/src/gnutls.c | |||
| @@ -382,6 +382,9 @@ emacs_gnutls_read (struct Lisp_Process *proc, char *buf, EMACS_INT nbyte) | |||
| 382 | rtnval = fn_gnutls_record_recv (state, buf, nbyte); | 382 | rtnval = fn_gnutls_record_recv (state, buf, nbyte); |
| 383 | if (rtnval >= 0) | 383 | if (rtnval >= 0) |
| 384 | return rtnval; | 384 | return rtnval; |
| 385 | else if (rtnval == GNUTLS_E_UNEXPECTED_PACKET_LENGTH) | ||
| 386 | /* The peer closed the connection. */ | ||
| 387 | return 0; | ||
| 385 | else if (emacs_gnutls_handle_error (state, rtnval) == 0) | 388 | else if (emacs_gnutls_handle_error (state, rtnval) == 0) |
| 386 | /* non-fatal error */ | 389 | /* non-fatal error */ |
| 387 | return -1; | 390 | return -1; |
diff --git a/src/gtkutil.c b/src/gtkutil.c index 35b366222de..8826b08851a 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c | |||
| @@ -269,8 +269,8 @@ xg_get_pixbuf_from_pixmap (FRAME_PTR f, Pixmap pix) | |||
| 269 | GDK_COLORSPACE_RGB, | 269 | GDK_COLORSPACE_RGB, |
| 270 | FALSE, | 270 | FALSE, |
| 271 | xim->bitmap_unit, | 271 | xim->bitmap_unit, |
| 272 | (int) width, | 272 | width, |
| 273 | (int) height, | 273 | height, |
| 274 | xim->bytes_per_line, | 274 | xim->bytes_per_line, |
| 275 | NULL, | 275 | NULL, |
| 276 | NULL); | 276 | NULL); |
| @@ -3646,7 +3646,7 @@ xg_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar, | |||
| 3646 | gtk_adjustment_set_page_size (adj, size); | 3646 | gtk_adjustment_set_page_size (adj, size); |
| 3647 | gtk_adjustment_set_step_increment (adj, new_step); | 3647 | gtk_adjustment_set_step_increment (adj, new_step); |
| 3648 | /* Assume a page increment is about 95% of the page size */ | 3648 | /* Assume a page increment is about 95% of the page size */ |
| 3649 | gtk_adjustment_set_page_increment (adj,(int) (0.95*size)); | 3649 | gtk_adjustment_set_page_increment (adj, size - size / 20); |
| 3650 | changed = 1; | 3650 | changed = 1; |
| 3651 | } | 3651 | } |
| 3652 | } | 3652 | } |
diff --git a/src/image.c b/src/image.c index fa39ff12681..d1091aec6f3 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -136,7 +136,6 @@ static unsigned long lookup_rgb_color (struct frame *f, int r, int g, int b); | |||
| 136 | #ifdef COLOR_TABLE_SUPPORT | 136 | #ifdef COLOR_TABLE_SUPPORT |
| 137 | static void free_color_table (void); | 137 | static void free_color_table (void); |
| 138 | static unsigned long *colors_in_color_table (int *n); | 138 | static unsigned long *colors_in_color_table (int *n); |
| 139 | static unsigned long lookup_pixel_color (struct frame *f, unsigned long p); | ||
| 140 | #endif | 139 | #endif |
| 141 | static Lisp_Object Finit_image_library (Lisp_Object, Lisp_Object); | 140 | static Lisp_Object Finit_image_library (Lisp_Object, Lisp_Object); |
| 142 | 141 | ||
| @@ -987,7 +986,6 @@ or omitted means use the selected frame. */) | |||
| 987 | ***********************************************************************/ | 986 | ***********************************************************************/ |
| 988 | 987 | ||
| 989 | static void free_image (struct frame *f, struct image *img); | 988 | static void free_image (struct frame *f, struct image *img); |
| 990 | static int check_image_size (struct frame *f, int width, int height); | ||
| 991 | 989 | ||
| 992 | #define MAX_IMAGE_SIZE 6.0 | 990 | #define MAX_IMAGE_SIZE 6.0 |
| 993 | /* Allocate and return a new image structure for image specification | 991 | /* Allocate and return a new image structure for image specification |
| @@ -1042,7 +1040,7 @@ free_image (struct frame *f, struct image *img) | |||
| 1042 | /* Return 1 if the given widths and heights are valid for display; | 1040 | /* Return 1 if the given widths and heights are valid for display; |
| 1043 | otherwise, return 0. */ | 1041 | otherwise, return 0. */ |
| 1044 | 1042 | ||
| 1045 | int | 1043 | static int |
| 1046 | check_image_size (struct frame *f, int width, int height) | 1044 | check_image_size (struct frame *f, int width, int height) |
| 1047 | { | 1045 | { |
| 1048 | int w, h; | 1046 | int w, h; |
| @@ -1051,7 +1049,8 @@ check_image_size (struct frame *f, int width, int height) | |||
| 1051 | return 0; | 1049 | return 0; |
| 1052 | 1050 | ||
| 1053 | if (INTEGERP (Vmax_image_size)) | 1051 | if (INTEGERP (Vmax_image_size)) |
| 1054 | w = h = XINT (Vmax_image_size); | 1052 | return (width <= XINT (Vmax_image_size) |
| 1053 | && height <= XINT (Vmax_image_size)); | ||
| 1055 | else if (FLOATP (Vmax_image_size)) | 1054 | else if (FLOATP (Vmax_image_size)) |
| 1056 | { | 1055 | { |
| 1057 | if (f != NULL) | 1056 | if (f != NULL) |
| @@ -1061,13 +1060,11 @@ check_image_size (struct frame *f, int width, int height) | |||
| 1061 | } | 1060 | } |
| 1062 | else | 1061 | else |
| 1063 | w = h = 1024; /* Arbitrary size for unknown frame. */ | 1062 | w = h = 1024; /* Arbitrary size for unknown frame. */ |
| 1064 | w = (int) (XFLOAT_DATA (Vmax_image_size) * w); | 1063 | return (width <= XFLOAT_DATA (Vmax_image_size) * w |
| 1065 | h = (int) (XFLOAT_DATA (Vmax_image_size) * h); | 1064 | && height <= XFLOAT_DATA (Vmax_image_size) * h); |
| 1066 | } | 1065 | } |
| 1067 | else | 1066 | else |
| 1068 | return 1; | 1067 | return 1; |
| 1069 | |||
| 1070 | return (width <= w && height <= h); | ||
| 1071 | } | 1068 | } |
| 1072 | 1069 | ||
| 1073 | /* Prepare image IMG for display on frame F. Must be called before | 1070 | /* Prepare image IMG for display on frame F. Must be called before |
| @@ -1368,7 +1365,9 @@ x_alloc_image_color (struct frame *f, struct image *img, Lisp_Object color_name, | |||
| 1368 | 1365 | ||
| 1369 | xassert (STRINGP (color_name)); | 1366 | xassert (STRINGP (color_name)); |
| 1370 | 1367 | ||
| 1371 | if (x_defined_color (f, SSDATA (color_name), &color, 1)) | 1368 | if (x_defined_color (f, SSDATA (color_name), &color, 1) |
| 1369 | && img->ncolors < min (min (PTRDIFF_MAX, SIZE_MAX) / sizeof *img->colors, | ||
| 1370 | INT_MAX)) | ||
| 1372 | { | 1371 | { |
| 1373 | /* This isn't called frequently so we get away with simply | 1372 | /* This isn't called frequently so we get away with simply |
| 1374 | reallocating the color vector to the needed size, here. */ | 1373 | reallocating the color vector to the needed size, here. */ |
| @@ -1911,6 +1910,44 @@ static int x_create_x_image_and_pixmap (struct frame *, int, int, int, | |||
| 1911 | static void x_destroy_x_image (XImagePtr); | 1910 | static void x_destroy_x_image (XImagePtr); |
| 1912 | static void x_put_x_image (struct frame *, XImagePtr, Pixmap, int, int); | 1911 | static void x_put_x_image (struct frame *, XImagePtr, Pixmap, int, int); |
| 1913 | 1912 | ||
| 1913 | /* Return nonzero if XIMG's size WIDTH x HEIGHT doesn't break the | ||
| 1914 | windowing system. | ||
| 1915 | WIDTH and HEIGHT must both be positive. | ||
| 1916 | If XIMG is null, assume it is a bitmap. */ | ||
| 1917 | static int | ||
| 1918 | x_check_image_size (XImagePtr ximg, int width, int height) | ||
| 1919 | { | ||
| 1920 | #ifdef HAVE_X_WINDOWS | ||
| 1921 | /* Respect Xlib's limits: it cannot deal with images that have more | ||
| 1922 | than INT_MAX (and/or UINT_MAX) bytes. And respect Emacs's limits | ||
| 1923 | of PTRDIFF_MAX (and/or SIZE_MAX) bytes for any object. */ | ||
| 1924 | enum | ||
| 1925 | { | ||
| 1926 | XLIB_BYTES_MAX = min (INT_MAX, UINT_MAX), | ||
| 1927 | X_IMAGE_BYTES_MAX = min (XLIB_BYTES_MAX, min (PTRDIFF_MAX, SIZE_MAX)) | ||
| 1928 | }; | ||
| 1929 | |||
| 1930 | int bitmap_pad, depth, bytes_per_line; | ||
| 1931 | if (ximg) | ||
| 1932 | { | ||
| 1933 | bitmap_pad = ximg->bitmap_pad; | ||
| 1934 | depth = ximg->depth; | ||
| 1935 | bytes_per_line = ximg->bytes_per_line; | ||
| 1936 | } | ||
| 1937 | else | ||
| 1938 | { | ||
| 1939 | bitmap_pad = 8; | ||
| 1940 | depth = 1; | ||
| 1941 | bytes_per_line = (width >> 3) + ((width & 7) != 0); | ||
| 1942 | } | ||
| 1943 | return (width <= (INT_MAX - (bitmap_pad - 1)) / depth | ||
| 1944 | && height <= X_IMAGE_BYTES_MAX / bytes_per_line); | ||
| 1945 | #else | ||
| 1946 | /* FIXME: Implement this check for the HAVE_NS and HAVE_NTGUI cases. | ||
| 1947 | For now, assume that every image size is allowed on these systems. */ | ||
| 1948 | return 1; | ||
| 1949 | #endif | ||
| 1950 | } | ||
| 1914 | 1951 | ||
| 1915 | /* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on | 1952 | /* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on |
| 1916 | frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created. | 1953 | frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created. |
| @@ -1943,6 +1980,15 @@ x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth, | |||
| 1943 | return 0; | 1980 | return 0; |
| 1944 | } | 1981 | } |
| 1945 | 1982 | ||
| 1983 | if (! x_check_image_size (*ximg, width, height)) | ||
| 1984 | { | ||
| 1985 | x_destroy_x_image (*ximg); | ||
| 1986 | *ximg = NULL; | ||
| 1987 | image_error ("Image too large (%dx%d)", | ||
| 1988 | make_number (width), make_number (height)); | ||
| 1989 | return 0; | ||
| 1990 | } | ||
| 1991 | |||
| 1946 | /* Allocate image raster. */ | 1992 | /* Allocate image raster. */ |
| 1947 | (*ximg)->data = (char *) xmalloc ((*ximg)->bytes_per_line * height); | 1993 | (*ximg)->data = (char *) xmalloc ((*ximg)->bytes_per_line * height); |
| 1948 | 1994 | ||
| @@ -1989,11 +2035,6 @@ x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth, | |||
| 1989 | palette_colors = 1 << depth - 1; | 2035 | palette_colors = 1 << depth - 1; |
| 1990 | 2036 | ||
| 1991 | *ximg = xmalloc (sizeof (XImage) + palette_colors * sizeof (RGBQUAD)); | 2037 | *ximg = xmalloc (sizeof (XImage) + palette_colors * sizeof (RGBQUAD)); |
| 1992 | if (*ximg == NULL) | ||
| 1993 | { | ||
| 1994 | image_error ("Unable to allocate memory for XImage", Qnil, Qnil); | ||
| 1995 | return 0; | ||
| 1996 | } | ||
| 1997 | 2038 | ||
| 1998 | header = &(*ximg)->info.bmiHeader; | 2039 | header = &(*ximg)->info.bmiHeader; |
| 1999 | memset (&(*ximg)->info, 0, sizeof (BITMAPINFO)); | 2040 | memset (&(*ximg)->info, 0, sizeof (BITMAPINFO)); |
| @@ -2365,7 +2406,7 @@ xbm_image_p (Lisp_Object object) | |||
| 2365 | } | 2406 | } |
| 2366 | else if (BOOL_VECTOR_P (data)) | 2407 | else if (BOOL_VECTOR_P (data)) |
| 2367 | { | 2408 | { |
| 2368 | if (XBOOL_VECTOR (data)->size < width * height) | 2409 | if (XBOOL_VECTOR (data)->size / height < width) |
| 2369 | return 0; | 2410 | return 0; |
| 2370 | } | 2411 | } |
| 2371 | else | 2412 | else |
| @@ -2561,13 +2602,15 @@ Create_Pixmap_From_Bitmap_Data (struct frame *f, struct image *img, char *data, | |||
| 2561 | img->pixmap = ns_image_from_XBM (data, img->width, img->height); | 2602 | img->pixmap = ns_image_from_XBM (data, img->width, img->height); |
| 2562 | 2603 | ||
| 2563 | #else | 2604 | #else |
| 2564 | img->pixmap | 2605 | img->pixmap = |
| 2565 | = XCreatePixmapFromBitmapData (FRAME_X_DISPLAY (f), | 2606 | (x_check_image_size (0, img->width, img->height) |
| 2607 | ? XCreatePixmapFromBitmapData (FRAME_X_DISPLAY (f), | ||
| 2566 | FRAME_X_WINDOW (f), | 2608 | FRAME_X_WINDOW (f), |
| 2567 | data, | 2609 | data, |
| 2568 | img->width, img->height, | 2610 | img->width, img->height, |
| 2569 | fg, bg, | 2611 | fg, bg, |
| 2570 | DefaultDepthOfScreen (FRAME_X_SCREEN (f))); | 2612 | DefaultDepthOfScreen (FRAME_X_SCREEN (f))) |
| 2613 | : NO_PIXMAP); | ||
| 2571 | #endif /* !HAVE_NTGUI && !HAVE_NS */ | 2614 | #endif /* !HAVE_NTGUI && !HAVE_NS */ |
| 2572 | } | 2615 | } |
| 2573 | 2616 | ||
| @@ -2674,6 +2717,13 @@ xbm_read_bitmap_data (struct frame *f, unsigned char *contents, unsigned char *e | |||
| 2674 | expect ('='); | 2717 | expect ('='); |
| 2675 | expect ('{'); | 2718 | expect ('{'); |
| 2676 | 2719 | ||
| 2720 | if (! x_check_image_size (0, *width, *height)) | ||
| 2721 | { | ||
| 2722 | if (!inhibit_image_error) | ||
| 2723 | image_error ("Image too large (%dx%d)", | ||
| 2724 | make_number (*width), make_number (*height)); | ||
| 2725 | goto failure; | ||
| 2726 | } | ||
| 2677 | bytes_per_line = (*width + 7) / 8 + padding_p; | 2727 | bytes_per_line = (*width + 7) / 8 + padding_p; |
| 2678 | nbytes = bytes_per_line * *height; | 2728 | nbytes = bytes_per_line * *height; |
| 2679 | p = *data = (char *) xmalloc (nbytes); | 2729 | p = *data = (char *) xmalloc (nbytes); |
| @@ -2864,6 +2914,12 @@ xbm_load (struct frame *f, struct image *img) | |||
| 2864 | img->width = XFASTINT (fmt[XBM_WIDTH].value); | 2914 | img->width = XFASTINT (fmt[XBM_WIDTH].value); |
| 2865 | img->height = XFASTINT (fmt[XBM_HEIGHT].value); | 2915 | img->height = XFASTINT (fmt[XBM_HEIGHT].value); |
| 2866 | xassert (img->width > 0 && img->height > 0); | 2916 | xassert (img->width > 0 && img->height > 0); |
| 2917 | if (!check_image_size (f, img->width, img->height)) | ||
| 2918 | { | ||
| 2919 | image_error ("Invalid image size (see `max-image-size')", | ||
| 2920 | Qnil, Qnil); | ||
| 2921 | return 0; | ||
| 2922 | } | ||
| 2867 | } | 2923 | } |
| 2868 | 2924 | ||
| 2869 | /* Get foreground and background colors, maybe allocate colors. */ | 2925 | /* Get foreground and background colors, maybe allocate colors. */ |
| @@ -2925,9 +2981,13 @@ xbm_load (struct frame *f, struct image *img) | |||
| 2925 | #endif | 2981 | #endif |
| 2926 | /* Create the pixmap. */ | 2982 | /* Create the pixmap. */ |
| 2927 | 2983 | ||
| 2928 | Create_Pixmap_From_Bitmap_Data (f, img, bits, | 2984 | if (x_check_image_size (0, img->width, img->height)) |
| 2929 | foreground, background, | 2985 | Create_Pixmap_From_Bitmap_Data (f, img, bits, |
| 2930 | non_default_colors); | 2986 | foreground, background, |
| 2987 | non_default_colors); | ||
| 2988 | else | ||
| 2989 | img->pixmap = NO_PIXMAP; | ||
| 2990 | |||
| 2931 | if (img->pixmap) | 2991 | if (img->pixmap) |
| 2932 | success_p = 1; | 2992 | success_p = 1; |
| 2933 | else | 2993 | else |
| @@ -3125,12 +3185,8 @@ xpm_free_color_cache (void) | |||
| 3125 | static int | 3185 | static int |
| 3126 | xpm_color_bucket (char *color_name) | 3186 | xpm_color_bucket (char *color_name) |
| 3127 | { | 3187 | { |
| 3128 | unsigned h = 0; | 3188 | EMACS_UINT hash = hash_string (color_name, strlen (color_name)); |
| 3129 | char *s; | 3189 | return hash % XPM_COLOR_CACHE_BUCKETS; |
| 3130 | |||
| 3131 | for (s = color_name; *s; ++s) | ||
| 3132 | h = (h << 2) ^ *s; | ||
| 3133 | return h %= XPM_COLOR_CACHE_BUCKETS; | ||
| 3134 | } | 3190 | } |
| 3135 | 3191 | ||
| 3136 | 3192 | ||
| @@ -3147,7 +3203,7 @@ xpm_cache_color (struct frame *f, char *color_name, XColor *color, int bucket) | |||
| 3147 | if (bucket < 0) | 3203 | if (bucket < 0) |
| 3148 | bucket = xpm_color_bucket (color_name); | 3204 | bucket = xpm_color_bucket (color_name); |
| 3149 | 3205 | ||
| 3150 | nbytes = sizeof *p + strlen (color_name); | 3206 | nbytes = offsetof (struct xpm_cached_color, name) + strlen (color_name) + 1; |
| 3151 | p = (struct xpm_cached_color *) xmalloc (nbytes); | 3207 | p = (struct xpm_cached_color *) xmalloc (nbytes); |
| 3152 | strcpy (p->name, color_name); | 3208 | strcpy (p->name, color_name); |
| 3153 | p->color = *color; | 3209 | p->color = *color; |
| @@ -3849,6 +3905,18 @@ xpm_load_image (struct frame *f, | |||
| 3849 | goto failure; | 3905 | goto failure; |
| 3850 | } | 3906 | } |
| 3851 | 3907 | ||
| 3908 | if (!x_create_x_image_and_pixmap (f, width, height, 0, | ||
| 3909 | &ximg, &img->pixmap) | ||
| 3910 | #ifndef HAVE_NS | ||
| 3911 | || !x_create_x_image_and_pixmap (f, width, height, 1, | ||
| 3912 | &mask_img, &img->mask) | ||
| 3913 | #endif | ||
| 3914 | ) | ||
| 3915 | { | ||
| 3916 | image_error ("Image too large", Qnil, Qnil); | ||
| 3917 | goto failure; | ||
| 3918 | } | ||
| 3919 | |||
| 3852 | expect (','); | 3920 | expect (','); |
| 3853 | 3921 | ||
| 3854 | XSETFRAME (frame, f); | 3922 | XSETFRAME (frame, f); |
| @@ -3942,18 +4010,6 @@ xpm_load_image (struct frame *f, | |||
| 3942 | expect (','); | 4010 | expect (','); |
| 3943 | } | 4011 | } |
| 3944 | 4012 | ||
| 3945 | if (!x_create_x_image_and_pixmap (f, width, height, 0, | ||
| 3946 | &ximg, &img->pixmap) | ||
| 3947 | #ifndef HAVE_NS | ||
| 3948 | || !x_create_x_image_and_pixmap (f, width, height, 1, | ||
| 3949 | &mask_img, &img->mask) | ||
| 3950 | #endif | ||
| 3951 | ) | ||
| 3952 | { | ||
| 3953 | image_error ("Out of memory (%s)", img->spec, Qnil); | ||
| 3954 | goto error; | ||
| 3955 | } | ||
| 3956 | |||
| 3957 | for (y = 0; y < height; y++) | 4013 | for (y = 0; y < height; y++) |
| 3958 | { | 4014 | { |
| 3959 | expect (XPM_TK_STRING); | 4015 | expect (XPM_TK_STRING); |
| @@ -5518,8 +5574,8 @@ my_png_warning (png_struct *png_ptr, const char *msg) | |||
| 5518 | struct png_memory_storage | 5574 | struct png_memory_storage |
| 5519 | { | 5575 | { |
| 5520 | unsigned char *bytes; /* The data */ | 5576 | unsigned char *bytes; /* The data */ |
| 5521 | size_t len; /* How big is it? */ | 5577 | ptrdiff_t len; /* How big is it? */ |
| 5522 | int index; /* Where are we? */ | 5578 | ptrdiff_t index; /* Where are we? */ |
| 5523 | }; | 5579 | }; |
| 5524 | 5580 | ||
| 5525 | 5581 | ||
| @@ -5563,7 +5619,8 @@ png_load (struct frame *f, struct image *img) | |||
| 5563 | { | 5619 | { |
| 5564 | Lisp_Object file, specified_file; | 5620 | Lisp_Object file, specified_file; |
| 5565 | Lisp_Object specified_data; | 5621 | Lisp_Object specified_data; |
| 5566 | int x, y, i; | 5622 | int x, y; |
| 5623 | ptrdiff_t i; | ||
| 5567 | XImagePtr ximg, mask_img = NULL; | 5624 | XImagePtr ximg, mask_img = NULL; |
| 5568 | png_struct *png_ptr = NULL; | 5625 | png_struct *png_ptr = NULL; |
| 5569 | png_info *info_ptr = NULL, *end_info = NULL; | 5626 | png_info *info_ptr = NULL, *end_info = NULL; |
| @@ -5683,11 +5740,19 @@ png_load (struct frame *f, struct image *img) | |||
| 5683 | fn_png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, | 5740 | fn_png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, |
| 5684 | &interlace_type, NULL, NULL); | 5741 | &interlace_type, NULL, NULL); |
| 5685 | 5742 | ||
| 5686 | if (!check_image_size (f, width, height)) | 5743 | if (! (width <= INT_MAX && height <= INT_MAX |
| 5744 | && check_image_size (f, width, height))) | ||
| 5687 | { | 5745 | { |
| 5688 | image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil); | 5746 | image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil); |
| 5689 | goto error; | 5747 | goto error; |
| 5690 | } | 5748 | } |
| 5749 | |||
| 5750 | /* Create the X image and pixmap now, so that the work below can be | ||
| 5751 | omitted if the image is too large for X. */ | ||
| 5752 | if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, | ||
| 5753 | &img->pixmap)) | ||
| 5754 | goto error; | ||
| 5755 | |||
| 5691 | /* If image contains simply transparency data, we prefer to | 5756 | /* If image contains simply transparency data, we prefer to |
| 5692 | construct a clipping mask. */ | 5757 | construct a clipping mask. */ |
| 5693 | if (fn_png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS)) | 5758 | if (fn_png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS)) |
| @@ -5776,7 +5841,10 @@ png_load (struct frame *f, struct image *img) | |||
| 5776 | row_bytes = fn_png_get_rowbytes (png_ptr, info_ptr); | 5841 | row_bytes = fn_png_get_rowbytes (png_ptr, info_ptr); |
| 5777 | 5842 | ||
| 5778 | /* Allocate memory for the image. */ | 5843 | /* Allocate memory for the image. */ |
| 5779 | pixels = (png_byte *) xmalloc (row_bytes * height * sizeof *pixels); | 5844 | if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof *rows < height |
| 5845 | || min (PTRDIFF_MAX, SIZE_MAX) / sizeof *pixels / height < row_bytes) | ||
| 5846 | memory_full (SIZE_MAX); | ||
| 5847 | pixels = (png_byte *) xmalloc (sizeof *pixels * row_bytes * height); | ||
| 5780 | rows = (png_byte **) xmalloc (height * sizeof *rows); | 5848 | rows = (png_byte **) xmalloc (height * sizeof *rows); |
| 5781 | for (i = 0; i < height; ++i) | 5849 | for (i = 0; i < height; ++i) |
| 5782 | rows[i] = pixels + i * row_bytes; | 5850 | rows[i] = pixels + i * row_bytes; |
| @@ -5790,11 +5858,6 @@ png_load (struct frame *f, struct image *img) | |||
| 5790 | fp = NULL; | 5858 | fp = NULL; |
| 5791 | } | 5859 | } |
| 5792 | 5860 | ||
| 5793 | /* Create the X image and pixmap. */ | ||
| 5794 | if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, | ||
| 5795 | &img->pixmap)) | ||
| 5796 | goto error; | ||
| 5797 | |||
| 5798 | /* Create an image and pixmap serving as mask if the PNG image | 5861 | /* Create an image and pixmap serving as mask if the PNG image |
| 5799 | contains an alpha channel. */ | 5862 | contains an alpha channel. */ |
| 5800 | if (channels == 4 | 5863 | if (channels == 4 |
| @@ -6192,7 +6255,7 @@ our_stdio_fill_input_buffer (j_decompress_ptr cinfo) | |||
| 6192 | src = (struct jpeg_stdio_mgr *) cinfo->src; | 6255 | src = (struct jpeg_stdio_mgr *) cinfo->src; |
| 6193 | if (!src->finished) | 6256 | if (!src->finished) |
| 6194 | { | 6257 | { |
| 6195 | size_t bytes; | 6258 | ptrdiff_t bytes; |
| 6196 | 6259 | ||
| 6197 | bytes = fread (src->buffer, 1, JPEG_STDIO_BUFFER_SIZE, src->file); | 6260 | bytes = fread (src->buffer, 1, JPEG_STDIO_BUFFER_SIZE, src->file); |
| 6198 | if (bytes > 0) | 6261 | if (bytes > 0) |
| @@ -6602,34 +6665,33 @@ init_tiff_functions (Lisp_Object libraries) | |||
| 6602 | typedef struct | 6665 | typedef struct |
| 6603 | { | 6666 | { |
| 6604 | unsigned char *bytes; | 6667 | unsigned char *bytes; |
| 6605 | size_t len; | 6668 | ptrdiff_t len; |
| 6606 | int index; | 6669 | ptrdiff_t index; |
| 6607 | } | 6670 | } |
| 6608 | tiff_memory_source; | 6671 | tiff_memory_source; |
| 6609 | 6672 | ||
| 6610 | static size_t | 6673 | static tsize_t |
| 6611 | tiff_read_from_memory (thandle_t data, tdata_t buf, tsize_t size) | 6674 | tiff_read_from_memory (thandle_t data, tdata_t buf, tsize_t size) |
| 6612 | { | 6675 | { |
| 6613 | tiff_memory_source *src = (tiff_memory_source *) data; | 6676 | tiff_memory_source *src = (tiff_memory_source *) data; |
| 6614 | 6677 | ||
| 6615 | if (size > src->len - src->index) | 6678 | size = min (size, src->len - src->index); |
| 6616 | return (size_t) -1; | ||
| 6617 | memcpy (buf, src->bytes + src->index, size); | 6679 | memcpy (buf, src->bytes + src->index, size); |
| 6618 | src->index += size; | 6680 | src->index += size; |
| 6619 | return size; | 6681 | return size; |
| 6620 | } | 6682 | } |
| 6621 | 6683 | ||
| 6622 | static size_t | 6684 | static tsize_t |
| 6623 | tiff_write_from_memory (thandle_t data, tdata_t buf, tsize_t size) | 6685 | tiff_write_from_memory (thandle_t data, tdata_t buf, tsize_t size) |
| 6624 | { | 6686 | { |
| 6625 | return (size_t) -1; | 6687 | return -1; |
| 6626 | } | 6688 | } |
| 6627 | 6689 | ||
| 6628 | static toff_t | 6690 | static toff_t |
| 6629 | tiff_seek_in_memory (thandle_t data, toff_t off, int whence) | 6691 | tiff_seek_in_memory (thandle_t data, toff_t off, int whence) |
| 6630 | { | 6692 | { |
| 6631 | tiff_memory_source *src = (tiff_memory_source *) data; | 6693 | tiff_memory_source *src = (tiff_memory_source *) data; |
| 6632 | int idx; | 6694 | ptrdiff_t idx; |
| 6633 | 6695 | ||
| 6634 | switch (whence) | 6696 | switch (whence) |
| 6635 | { | 6697 | { |
| @@ -6765,8 +6827,8 @@ tiff_load (struct frame *f, struct image *img) | |||
| 6765 | memsrc.index = 0; | 6827 | memsrc.index = 0; |
| 6766 | 6828 | ||
| 6767 | tiff = fn_TIFFClientOpen ("memory_source", "r", (thandle_t)&memsrc, | 6829 | tiff = fn_TIFFClientOpen ("memory_source", "r", (thandle_t)&memsrc, |
| 6768 | (TIFFReadWriteProc) tiff_read_from_memory, | 6830 | tiff_read_from_memory, |
| 6769 | (TIFFReadWriteProc) tiff_write_from_memory, | 6831 | tiff_write_from_memory, |
| 6770 | tiff_seek_in_memory, | 6832 | tiff_seek_in_memory, |
| 6771 | tiff_close_memory, | 6833 | tiff_close_memory, |
| 6772 | tiff_size_of_memory, | 6834 | tiff_size_of_memory, |
| @@ -6805,7 +6867,16 @@ tiff_load (struct frame *f, struct image *img) | |||
| 6805 | return 0; | 6867 | return 0; |
| 6806 | } | 6868 | } |
| 6807 | 6869 | ||
| 6808 | buf = (uint32 *) xmalloc (width * height * sizeof *buf); | 6870 | /* Create the X image and pixmap. */ |
| 6871 | if (! (height <= min (PTRDIFF_MAX, SIZE_MAX) / sizeof *buf / width | ||
| 6872 | && x_create_x_image_and_pixmap (f, width, height, 0, | ||
| 6873 | &ximg, &img->pixmap))) | ||
| 6874 | { | ||
| 6875 | fn_TIFFClose (tiff); | ||
| 6876 | return 0; | ||
| 6877 | } | ||
| 6878 | |||
| 6879 | buf = (uint32 *) xmalloc (sizeof *buf * width * height); | ||
| 6809 | 6880 | ||
| 6810 | rc = fn_TIFFReadRGBAImage (tiff, width, height, buf, 0); | 6881 | rc = fn_TIFFReadRGBAImage (tiff, width, height, buf, 0); |
| 6811 | 6882 | ||
| @@ -6826,13 +6897,6 @@ tiff_load (struct frame *f, struct image *img) | |||
| 6826 | return 0; | 6897 | return 0; |
| 6827 | } | 6898 | } |
| 6828 | 6899 | ||
| 6829 | /* Create the X image and pixmap. */ | ||
| 6830 | if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, &img->pixmap)) | ||
| 6831 | { | ||
| 6832 | xfree (buf); | ||
| 6833 | return 0; | ||
| 6834 | } | ||
| 6835 | |||
| 6836 | /* Initialize the color table. */ | 6900 | /* Initialize the color table. */ |
| 6837 | init_color_table (); | 6901 | init_color_table (); |
| 6838 | 6902 | ||
| @@ -7034,8 +7098,8 @@ init_gif_functions (Lisp_Object libraries) | |||
| 7034 | typedef struct | 7098 | typedef struct |
| 7035 | { | 7099 | { |
| 7036 | unsigned char *bytes; | 7100 | unsigned char *bytes; |
| 7037 | size_t len; | 7101 | ptrdiff_t len; |
| 7038 | int index; | 7102 | ptrdiff_t index; |
| 7039 | } | 7103 | } |
| 7040 | gif_memory_source; | 7104 | gif_memory_source; |
| 7041 | 7105 | ||
| @@ -7668,7 +7732,8 @@ imagemagick_load_image (struct frame *f, struct image *img, | |||
| 7668 | height = MagickGetImageHeight (image_wand); | 7732 | height = MagickGetImageHeight (image_wand); |
| 7669 | width = MagickGetImageWidth (image_wand); | 7733 | width = MagickGetImageWidth (image_wand); |
| 7670 | 7734 | ||
| 7671 | if (! check_image_size (f, width, height)) | 7735 | if (! (width <= INT_MAX && height <= INT_MAX |
| 7736 | && check_image_size (f, width, height))) | ||
| 7672 | { | 7737 | { |
| 7673 | image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil); | 7738 | image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil); |
| 7674 | goto imagemagick_error; | 7739 | goto imagemagick_error; |
| @@ -7872,7 +7937,7 @@ recognize as images, such as C. See `imagemagick-types-inhibit'. */) | |||
| 7872 | size_t numf = 0; | 7937 | size_t numf = 0; |
| 7873 | ExceptionInfo ex; | 7938 | ExceptionInfo ex; |
| 7874 | char **imtypes = GetMagickList ("*", &numf, &ex); | 7939 | char **imtypes = GetMagickList ("*", &numf, &ex); |
| 7875 | int i; | 7940 | size_t i; |
| 7876 | Lisp_Object Qimagemagicktype; | 7941 | Lisp_Object Qimagemagicktype; |
| 7877 | for (i = 0; i < numf; i++) | 7942 | for (i = 0; i < numf; i++) |
| 7878 | { | 7943 | { |
| @@ -8426,12 +8491,15 @@ gs_load (struct frame *f, struct image *img) | |||
| 8426 | /* Create the pixmap. */ | 8491 | /* Create the pixmap. */ |
| 8427 | xassert (img->pixmap == NO_PIXMAP); | 8492 | xassert (img->pixmap == NO_PIXMAP); |
| 8428 | 8493 | ||
| 8429 | /* Only W32 version did BLOCK_INPUT here. ++kfs */ | 8494 | if (x_check_image_size (0, img->width, img->height)) |
| 8430 | BLOCK_INPUT; | 8495 | { |
| 8431 | img->pixmap = XCreatePixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | 8496 | /* Only W32 version did BLOCK_INPUT here. ++kfs */ |
| 8432 | img->width, img->height, | 8497 | BLOCK_INPUT; |
| 8433 | DefaultDepthOfScreen (FRAME_X_SCREEN (f))); | 8498 | img->pixmap = XCreatePixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
| 8434 | UNBLOCK_INPUT; | 8499 | img->width, img->height, |
| 8500 | DefaultDepthOfScreen (FRAME_X_SCREEN (f))); | ||
| 8501 | UNBLOCK_INPUT; | ||
| 8502 | } | ||
| 8435 | 8503 | ||
| 8436 | if (!img->pixmap) | 8504 | if (!img->pixmap) |
| 8437 | { | 8505 | { |
diff --git a/src/keyboard.c b/src/keyboard.c index 62de68cbf74..1c5cfcde951 100644 --- a/src/keyboard.c +++ b/src/keyboard.c | |||
| @@ -210,8 +210,8 @@ Lisp_Object unread_switch_frame; | |||
| 210 | /* Last size recorded for a current buffer which is not a minibuffer. */ | 210 | /* Last size recorded for a current buffer which is not a minibuffer. */ |
| 211 | static EMACS_INT last_non_minibuf_size; | 211 | static EMACS_INT last_non_minibuf_size; |
| 212 | 212 | ||
| 213 | /* Total number of times read_char has returned, modulo SIZE_MAX + 1. */ | 213 | /* Total number of times read_char has returned, modulo UINTMAX_MAX + 1. */ |
| 214 | size_t num_input_events; | 214 | uintmax_t num_input_events; |
| 215 | 215 | ||
| 216 | /* Value of num_nonmacro_input_events as of last auto save. */ | 216 | /* Value of num_nonmacro_input_events as of last auto save. */ |
| 217 | 217 | ||
diff --git a/src/keyboard.h b/src/keyboard.h index 91008a3ea24..69c804c873d 100644 --- a/src/keyboard.h +++ b/src/keyboard.h | |||
| @@ -191,8 +191,8 @@ extern KBOARD *current_kboard; | |||
| 191 | /* A list of all kboard objects, linked through next_kboard. */ | 191 | /* A list of all kboard objects, linked through next_kboard. */ |
| 192 | extern KBOARD *all_kboards; | 192 | extern KBOARD *all_kboards; |
| 193 | 193 | ||
| 194 | /* Total number of times read_char has returned, modulo SIZE_MAX + 1. */ | 194 | /* Total number of times read_char has returned, modulo UINTMAX_MAX + 1. */ |
| 195 | extern size_t num_input_events; | 195 | extern uintmax_t num_input_events; |
| 196 | 196 | ||
| 197 | /* Nonzero means polling for input is temporarily suppressed. */ | 197 | /* Nonzero means polling for input is temporarily suppressed. */ |
| 198 | extern int poll_suppress_count; | 198 | extern int poll_suppress_count; |
diff --git a/src/lisp.h b/src/lisp.h index 623dfabec99..f404f8c368d 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -61,6 +61,23 @@ extern void check_cons_list (void); | |||
| 61 | # define EMACS_UINT unsigned EMACS_INT | 61 | # define EMACS_UINT unsigned EMACS_INT |
| 62 | #endif | 62 | #endif |
| 63 | 63 | ||
| 64 | /* printmax_t and uprintmax_t are types for printing large integers. | ||
| 65 | These are the widest integers that are supported for printing. | ||
| 66 | pMd etc. are conversions for printing them. | ||
| 67 | On C99 hosts, there's no problem, as even the widest integers work. | ||
| 68 | Fall back on EMACS_INT on pre-C99 hosts. */ | ||
| 69 | #ifdef PRIdMAX | ||
| 70 | typedef intmax_t printmax_t; | ||
| 71 | typedef uintmax_t uprintmax_t; | ||
| 72 | # define pMd PRIdMAX | ||
| 73 | # define pMu PRIuMAX | ||
| 74 | #else | ||
| 75 | typedef EMACS_INT printmax_t; | ||
| 76 | typedef EMACS_UINT uprintmax_t; | ||
| 77 | # define pMd pI"d" | ||
| 78 | # define pMu pI"u" | ||
| 79 | #endif | ||
| 80 | |||
| 64 | /* Use pD to format ptrdiff_t values, which suffice for indexes into | 81 | /* Use pD to format ptrdiff_t values, which suffice for indexes into |
| 65 | buffers and strings. Emacs never allocates objects larger than | 82 | buffers and strings. Emacs never allocates objects larger than |
| 66 | PTRDIFF_MAX bytes, as they cause problems with pointer subtraction. | 83 | PTRDIFF_MAX bytes, as they cause problems with pointer subtraction. |
| @@ -835,7 +852,7 @@ struct Lisp_String | |||
| 835 | <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8546>. */ | 852 | <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8546>. */ |
| 836 | struct vectorlike_header | 853 | struct vectorlike_header |
| 837 | { | 854 | { |
| 838 | EMACS_UINT size; | 855 | EMACS_INT size; |
| 839 | 856 | ||
| 840 | /* Pointer to the next vector-like object. It is generally a buffer or a | 857 | /* Pointer to the next vector-like object. It is generally a buffer or a |
| 841 | Lisp_Vector alias, so for convenience it is a union instead of a | 858 | Lisp_Vector alias, so for convenience it is a union instead of a |
| @@ -1030,7 +1047,7 @@ struct Lisp_Bool_Vector | |||
| 1030 | 1047 | ||
| 1031 | struct Lisp_Subr | 1048 | struct Lisp_Subr |
| 1032 | { | 1049 | { |
| 1033 | EMACS_UINT size; | 1050 | EMACS_INT size; |
| 1034 | union { | 1051 | union { |
| 1035 | Lisp_Object (*a0) (void); | 1052 | Lisp_Object (*a0) (void); |
| 1036 | Lisp_Object (*a1) (Lisp_Object); | 1053 | Lisp_Object (*a1) (Lisp_Object); |
| @@ -2542,6 +2559,7 @@ extern void sweep_weak_hash_tables (void); | |||
| 2542 | extern Lisp_Object Qcursor_in_echo_area; | 2559 | extern Lisp_Object Qcursor_in_echo_area; |
| 2543 | extern Lisp_Object Qstring_lessp; | 2560 | extern Lisp_Object Qstring_lessp; |
| 2544 | extern Lisp_Object QCsize, QCtest, QCweakness, Qequal, Qeq, Qeql; | 2561 | extern Lisp_Object QCsize, QCtest, QCweakness, Qequal, Qeq, Qeql; |
| 2562 | EMACS_UINT hash_string (char const *, ptrdiff_t); | ||
| 2545 | EMACS_UINT sxhash (Lisp_Object, int); | 2563 | EMACS_UINT sxhash (Lisp_Object, int); |
| 2546 | Lisp_Object make_hash_table (Lisp_Object, Lisp_Object, Lisp_Object, | 2564 | Lisp_Object make_hash_table (Lisp_Object, Lisp_Object, Lisp_Object, |
| 2547 | Lisp_Object, Lisp_Object, Lisp_Object, | 2565 | Lisp_Object, Lisp_Object, Lisp_Object, |
| @@ -2870,7 +2888,8 @@ extern void float_to_string (char *, double); | |||
| 2870 | extern void syms_of_print (void); | 2888 | extern void syms_of_print (void); |
| 2871 | 2889 | ||
| 2872 | /* Defined in doprnt.c */ | 2890 | /* Defined in doprnt.c */ |
| 2873 | extern size_t doprnt (char *, size_t, const char *, const char *, va_list); | 2891 | extern ptrdiff_t doprnt (char *, ptrdiff_t, const char *, const char *, |
| 2892 | va_list); | ||
| 2874 | 2893 | ||
| 2875 | /* Defined in lread.c. */ | 2894 | /* Defined in lread.c. */ |
| 2876 | extern Lisp_Object Qvariable_documentation, Qstandard_input; | 2895 | extern Lisp_Object Qvariable_documentation, Qstandard_input; |
| @@ -3431,18 +3450,6 @@ extern EMACS_INT emacs_read (int, char *, EMACS_INT); | |||
| 3431 | extern EMACS_INT emacs_write (int, const char *, EMACS_INT); | 3450 | extern EMACS_INT emacs_write (int, const char *, EMACS_INT); |
| 3432 | enum { READLINK_BUFSIZE = 1024 }; | 3451 | enum { READLINK_BUFSIZE = 1024 }; |
| 3433 | extern char *emacs_readlink (const char *, char [READLINK_BUFSIZE]); | 3452 | extern char *emacs_readlink (const char *, char [READLINK_BUFSIZE]); |
| 3434 | #ifndef HAVE_MEMSET | ||
| 3435 | extern void *memset (void *, int, size_t); | ||
| 3436 | #endif | ||
| 3437 | #ifndef HAVE_MEMCPY | ||
| 3438 | extern void *memcpy (void *, void *, size_t); | ||
| 3439 | #endif | ||
| 3440 | #ifndef HAVE_MEMMOVE | ||
| 3441 | extern void *memmove (void *, void *, size_t); | ||
| 3442 | #endif | ||
| 3443 | #ifndef HAVE_MEMCMP | ||
| 3444 | extern int memcmp (void *, void *, size_t); | ||
| 3445 | #endif | ||
| 3446 | 3453 | ||
| 3447 | EXFUN (Funlock_buffer, 0); | 3454 | EXFUN (Funlock_buffer, 0); |
| 3448 | extern void unlock_all_files (void); | 3455 | extern void unlock_all_files (void); |
diff --git a/src/lread.c b/src/lread.c index 83b158d97d8..78ff195e990 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -2670,6 +2670,9 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list) | |||
| 2670 | } | 2670 | } |
| 2671 | goto read_symbol; | 2671 | goto read_symbol; |
| 2672 | } | 2672 | } |
| 2673 | /* ## is the empty symbol. */ | ||
| 2674 | if (c == '#') | ||
| 2675 | return Fintern (build_string (""), Qnil); | ||
| 2673 | /* Reader forms that can reuse previously read objects. */ | 2676 | /* Reader forms that can reuse previously read objects. */ |
| 2674 | if (c >= '0' && c <= '9') | 2677 | if (c >= '0' && c <= '9') |
| 2675 | { | 2678 | { |
| @@ -3648,8 +3651,6 @@ static Lisp_Object initial_obarray; | |||
| 3648 | 3651 | ||
| 3649 | static size_t oblookup_last_bucket_number; | 3652 | static size_t oblookup_last_bucket_number; |
| 3650 | 3653 | ||
| 3651 | static size_t hash_string (const char *ptr, size_t len); | ||
| 3652 | |||
| 3653 | /* Get an error if OBARRAY is not an obarray. | 3654 | /* Get an error if OBARRAY is not an obarray. |
| 3654 | If it is one, return it. */ | 3655 | If it is one, return it. */ |
| 3655 | 3656 | ||
| @@ -3892,23 +3893,6 @@ oblookup (Lisp_Object obarray, register const char *ptr, EMACS_INT size, EMACS_I | |||
| 3892 | XSETINT (tem, hash); | 3893 | XSETINT (tem, hash); |
| 3893 | return tem; | 3894 | return tem; |
| 3894 | } | 3895 | } |
| 3895 | |||
| 3896 | static size_t | ||
| 3897 | hash_string (const char *ptr, size_t len) | ||
| 3898 | { | ||
| 3899 | register const char *p = ptr; | ||
| 3900 | register const char *end = p + len; | ||
| 3901 | register unsigned char c; | ||
| 3902 | register size_t hash = 0; | ||
| 3903 | |||
| 3904 | while (p != end) | ||
| 3905 | { | ||
| 3906 | c = *p++; | ||
| 3907 | if (c >= 0140) c -= 40; | ||
| 3908 | hash = (hash << 3) + (hash >> (CHAR_BIT * sizeof hash - 4)) + c; | ||
| 3909 | } | ||
| 3910 | return hash; | ||
| 3911 | } | ||
| 3912 | 3896 | ||
| 3913 | void | 3897 | void |
| 3914 | map_obarray (Lisp_Object obarray, void (*fn) (Lisp_Object, Lisp_Object), Lisp_Object arg) | 3898 | map_obarray (Lisp_Object obarray, void (*fn) (Lisp_Object, Lisp_Object), Lisp_Object arg) |
diff --git a/src/nsfns.m b/src/nsfns.m index 0452086201e..85246a4c25f 100644 --- a/src/nsfns.m +++ b/src/nsfns.m | |||
| @@ -321,6 +321,7 @@ static void | |||
| 321 | x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) | 321 | x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
| 322 | { | 322 | { |
| 323 | NSColor *col; | 323 | NSColor *col; |
| 324 | CGFloat r, g, b, alpha; | ||
| 324 | 325 | ||
| 325 | if (ns_lisp_to_color (arg, &col)) | 326 | if (ns_lisp_to_color (arg, &col)) |
| 326 | { | 327 | { |
| @@ -332,6 +333,10 @@ x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) | |||
| 332 | [f->output_data.ns->foreground_color release]; | 333 | [f->output_data.ns->foreground_color release]; |
| 333 | f->output_data.ns->foreground_color = col; | 334 | f->output_data.ns->foreground_color = col; |
| 334 | 335 | ||
| 336 | [col getRed: &r green: &g blue: &b alpha: &alpha]; | ||
| 337 | FRAME_FOREGROUND_PIXEL (f) = | ||
| 338 | ARGB_TO_ULONG ((int)(alpha*0xff), (int)(r*0xff), (int)(g*0xff), (int)(b*0xff)); | ||
| 339 | |||
| 335 | if (FRAME_NS_VIEW (f)) | 340 | if (FRAME_NS_VIEW (f)) |
| 336 | { | 341 | { |
| 337 | update_face_from_frame_parameter (f, Qforeground_color, arg); | 342 | update_face_from_frame_parameter (f, Qforeground_color, arg); |
| @@ -348,7 +353,7 @@ x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) | |||
| 348 | struct face *face; | 353 | struct face *face; |
| 349 | NSColor *col; | 354 | NSColor *col; |
| 350 | NSView *view = FRAME_NS_VIEW (f); | 355 | NSView *view = FRAME_NS_VIEW (f); |
| 351 | float alpha; | 356 | CGFloat r, g, b, alpha; |
| 352 | 357 | ||
| 353 | if (ns_lisp_to_color (arg, &col)) | 358 | if (ns_lisp_to_color (arg, &col)) |
| 354 | { | 359 | { |
| @@ -364,10 +369,14 @@ x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) | |||
| 364 | [col retain]; | 369 | [col retain]; |
| 365 | [f->output_data.ns->background_color release]; | 370 | [f->output_data.ns->background_color release]; |
| 366 | f->output_data.ns->background_color = col; | 371 | f->output_data.ns->background_color = col; |
| 372 | |||
| 373 | [col getRed: &r green: &g blue: &b alpha: &alpha]; | ||
| 374 | FRAME_BACKGROUND_PIXEL (f) = | ||
| 375 | ARGB_TO_ULONG ((int)(alpha*0xff), (int)(r*0xff), (int)(g*0xff), (int)(b*0xff)); | ||
| 376 | |||
| 367 | if (view != nil) | 377 | if (view != nil) |
| 368 | { | 378 | { |
| 369 | [[view window] setBackgroundColor: col]; | 379 | [[view window] setBackgroundColor: col]; |
| 370 | alpha = [col alphaComponent]; | ||
| 371 | 380 | ||
| 372 | if (alpha != 1.0) | 381 | if (alpha != 1.0) |
| 373 | [[view window] setOpaque: NO]; | 382 | [[view window] setOpaque: NO]; |
diff --git a/src/nsfont.m b/src/nsfont.m index 76c70aadf9f..60f8c5321aa 100644 --- a/src/nsfont.m +++ b/src/nsfont.m | |||
| @@ -804,8 +804,6 @@ nsfont_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size) | |||
| 804 | font->props[FONT_FILE_INDEX] = Qnil; | 804 | font->props[FONT_FILE_INDEX] = Qnil; |
| 805 | 805 | ||
| 806 | { | 806 | { |
| 807 | double expand, hshrink; | ||
| 808 | float full_height, min_height, hd; | ||
| 809 | const char *fontName = [[nsfont fontName] UTF8String]; | 807 | const char *fontName = [[nsfont fontName] UTF8String]; |
| 810 | int len = strlen (fontName); | 808 | int len = strlen (fontName); |
| 811 | 809 | ||
| @@ -837,26 +835,16 @@ nsfont_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size) | |||
| 837 | [sfont maximumAdvancement].width : ns_char_width (sfont, '0'); | 835 | [sfont maximumAdvancement].width : ns_char_width (sfont, '0'); |
| 838 | 836 | ||
| 839 | brect = [sfont boundingRectForFont]; | 837 | brect = [sfont boundingRectForFont]; |
| 840 | full_height = brect.size.height; | ||
| 841 | min_height = [sfont ascender] - adjusted_descender; | ||
| 842 | hd = full_height - min_height; | ||
| 843 | 838 | ||
| 844 | /* standard height, similar to Carbon. Emacs.app: was 0.5 by default. */ | 839 | font_info->underpos = [sfont underlinePosition]; |
| 845 | expand = 0.0; | ||
| 846 | hshrink = 1.0; | ||
| 847 | |||
| 848 | font_info->underpos = 2; /*[sfont underlinePosition] is often clipped out */ | ||
| 849 | font_info->underwidth = [sfont underlineThickness]; | 840 | font_info->underwidth = [sfont underlineThickness]; |
| 850 | font_info->size = font->pixel_size; | 841 | font_info->size = font->pixel_size; |
| 851 | font_info->voffset = lrint (hshrink * [sfont ascender] + expand * hd / 2); | ||
| 852 | 842 | ||
| 853 | /* max bounds */ | 843 | /* max bounds */ |
| 854 | font_info->max_bounds.ascent = | 844 | font_info->max_bounds.ascent = lrint ([sfont ascender]); |
| 855 | lrint (hshrink * [sfont ascender] + expand * hd/2); | ||
| 856 | /* Descender is usually negative. Use floor to avoid | 845 | /* Descender is usually negative. Use floor to avoid |
| 857 | clipping descenders. */ | 846 | clipping descenders. */ |
| 858 | font_info->max_bounds.descent = | 847 | font_info->max_bounds.descent = -lrint (floor(adjusted_descender)); |
| 859 | -lrint (floor(hshrink* adjusted_descender - expand*hd/2)); | ||
| 860 | font_info->height = | 848 | font_info->height = |
| 861 | font_info->max_bounds.ascent + font_info->max_bounds.descent; | 849 | font_info->max_bounds.ascent + font_info->max_bounds.descent; |
| 862 | font_info->max_bounds.width = lrint (font_info->width); | 850 | font_info->max_bounds.width = lrint (font_info->width); |
| @@ -1165,7 +1153,7 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y, | |||
| 1165 | 1153 | ||
| 1166 | 1154 | ||
| 1167 | /* set up for character rendering */ | 1155 | /* set up for character rendering */ |
| 1168 | r.origin.y += font->voffset + (s->height - font->height)/2; | 1156 | r.origin.y = s->ybase; |
| 1169 | 1157 | ||
| 1170 | col = (NS_FACE_FOREGROUND (face) != 0 | 1158 | col = (NS_FACE_FOREGROUND (face) != 0 |
| 1171 | ? ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), s->f) | 1159 | ? ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), s->f) |
| @@ -1196,20 +1184,7 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y, | |||
| 1196 | /*[context GSSetTextDrawingMode: GSTextFill]; /// not implemented yet */ | 1184 | /*[context GSSetTextDrawingMode: GSTextFill]; /// not implemented yet */ |
| 1197 | } | 1185 | } |
| 1198 | 1186 | ||
| 1199 | /* do underline */ | 1187 | [col set]; |
| 1200 | if (face->underline_p) | ||
| 1201 | { | ||
| 1202 | if (face->underline_color != 0) | ||
| 1203 | [ns_lookup_indexed_color (face->underline_color, s->f) set]; | ||
| 1204 | else | ||
| 1205 | [col set]; | ||
| 1206 | DPSmoveto (context, r.origin.x, r.origin.y + font->underpos); | ||
| 1207 | DPSlineto (context, r.origin.x+r.size.width, r.origin.y+font->underpos); | ||
| 1208 | if (face->underline_color != 0) | ||
| 1209 | [col set]; | ||
| 1210 | } | ||
| 1211 | else | ||
| 1212 | [col set]; | ||
| 1213 | 1188 | ||
| 1214 | /* draw with DPSxshow () */ | 1189 | /* draw with DPSxshow () */ |
| 1215 | DPSmoveto (context, r.origin.x, r.origin.y); | 1190 | DPSmoveto (context, r.origin.x, r.origin.y); |
| @@ -1255,23 +1230,7 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y, | |||
| 1255 | CGContextSetTextDrawingMode (gcontext, kCGTextFill); | 1230 | CGContextSetTextDrawingMode (gcontext, kCGTextFill); |
| 1256 | } | 1231 | } |
| 1257 | 1232 | ||
| 1258 | if (face->underline_p) | 1233 | [col set]; |
| 1259 | { | ||
| 1260 | if (face->underline_color != 0) | ||
| 1261 | [ns_lookup_indexed_color (face->underline_color, s->f) set]; | ||
| 1262 | else | ||
| 1263 | [col set]; | ||
| 1264 | CGContextBeginPath (gcontext); | ||
| 1265 | CGContextMoveToPoint (gcontext, | ||
| 1266 | r.origin.x, r.origin.y + font->underpos); | ||
| 1267 | CGContextAddLineToPoint (gcontext, r.origin.x + r.size.width, | ||
| 1268 | r.origin.y + font->underpos); | ||
| 1269 | CGContextStrokePath (gcontext); | ||
| 1270 | if (face->underline_color != 0) | ||
| 1271 | [col set]; | ||
| 1272 | } | ||
| 1273 | else | ||
| 1274 | [col set]; | ||
| 1275 | 1234 | ||
| 1276 | CGContextSetTextPosition (gcontext, r.origin.x, r.origin.y); | 1235 | CGContextSetTextPosition (gcontext, r.origin.x, r.origin.y); |
| 1277 | CGContextShowGlyphsWithAdvances (gcontext, s->char2b + s->cmp_from, | 1236 | CGContextShowGlyphsWithAdvances (gcontext, s->char2b + s->cmp_from, |
| @@ -1287,6 +1246,10 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y, | |||
| 1287 | CGContextRestoreGState (gcontext); | 1246 | CGContextRestoreGState (gcontext); |
| 1288 | } | 1247 | } |
| 1289 | #endif /* NS_IMPL_COCOA */ | 1248 | #endif /* NS_IMPL_COCOA */ |
| 1249 | |||
| 1250 | /* Draw underline, overline, strike-through. */ | ||
| 1251 | ns_draw_text_decoration (s, face, col, r.size.width, r.origin.x); | ||
| 1252 | |||
| 1290 | return to-from; | 1253 | return to-from; |
| 1291 | } | 1254 | } |
| 1292 | 1255 | ||
diff --git a/src/nsmenu.m b/src/nsmenu.m index 6931b7a3c01..6bde229ed4d 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m | |||
| @@ -1228,8 +1228,8 @@ update_frame_tool_bar (FRAME_PTR f) | |||
| 1228 | 1228 | ||
| 1229 | [textField setEditable: NO]; | 1229 | [textField setEditable: NO]; |
| 1230 | [textField setSelectable: NO]; | 1230 | [textField setSelectable: NO]; |
| 1231 | [textField setBordered: YES]; | 1231 | [textField setBordered: NO]; |
| 1232 | [textField setBezeled: YES]; | 1232 | [textField setBezeled: NO]; |
| 1233 | [textField setDrawsBackground: YES]; | 1233 | [textField setDrawsBackground: YES]; |
| 1234 | 1234 | ||
| 1235 | win = [[NSWindow alloc] | 1235 | win = [[NSWindow alloc] |
| @@ -1237,6 +1237,7 @@ update_frame_tool_bar (FRAME_PTR f) | |||
| 1237 | styleMask: 0 | 1237 | styleMask: 0 |
| 1238 | backing: NSBackingStoreBuffered | 1238 | backing: NSBackingStoreBuffered |
| 1239 | defer: YES]; | 1239 | defer: YES]; |
| 1240 | [win setHasShadow: YES]; | ||
| 1240 | [win setReleasedWhenClosed: NO]; | 1241 | [win setReleasedWhenClosed: NO]; |
| 1241 | [win setDelegate: self]; | 1242 | [win setDelegate: self]; |
| 1242 | [[win contentView] addSubview: textField]; | 1243 | [[win contentView] addSubview: textField]; |
| @@ -1257,17 +1258,15 @@ update_frame_tool_bar (FRAME_PTR f) | |||
| 1257 | - (void) setText: (char *)text | 1258 | - (void) setText: (char *)text |
| 1258 | { | 1259 | { |
| 1259 | NSString *str = [NSString stringWithUTF8String: text]; | 1260 | NSString *str = [NSString stringWithUTF8String: text]; |
| 1260 | NSRect r = [textField frame]; | 1261 | NSRect r = [textField frame]; |
| 1261 | NSSize textSize = [str sizeWithAttributes: | 1262 | NSSize tooltipDims; |
| 1262 | [NSDictionary dictionaryWithObject: [[textField font] screenFont] | 1263 | |
| 1263 | forKey: NSFontAttributeName]]; | ||
| 1264 | NSSize padSize = [[[textField font] screenFont] | ||
| 1265 | boundingRectForFont].size; | ||
| 1266 | |||
| 1267 | r.size.width = textSize.width + padSize.width/2; | ||
| 1268 | r.size.height = textSize.height + padSize.height/2; | ||
| 1269 | [textField setFrame: r]; | ||
| 1270 | [textField setStringValue: str]; | 1264 | [textField setStringValue: str]; |
| 1265 | tooltipDims = [[textField cell] cellSize]; | ||
| 1266 | |||
| 1267 | r.size.width = tooltipDims.width; | ||
| 1268 | r.size.height = tooltipDims.height; | ||
| 1269 | [textField setFrame: r]; | ||
| 1271 | } | 1270 | } |
| 1272 | 1271 | ||
| 1273 | - (void) showAtX: (int)x Y: (int)y for: (int)seconds | 1272 | - (void) showAtX: (int)x Y: (int)y for: (int)seconds |
diff --git a/src/nsterm.h b/src/nsterm.h index f419391a11e..6ea9161c922 100644 --- a/src/nsterm.h +++ b/src/nsterm.h | |||
| @@ -467,7 +467,6 @@ struct nsfont_info | |||
| 467 | #endif | 467 | #endif |
| 468 | char bold, ital; /* convenience flags */ | 468 | char bold, ital; /* convenience flags */ |
| 469 | char synthItal; | 469 | char synthItal; |
| 470 | float voffset; /* mean of ascender/descender offsets */ | ||
| 471 | XCharStruct max_bounds; | 470 | XCharStruct max_bounds; |
| 472 | /* we compute glyph codes and metrics on-demand in blocks of 256 indexed | 471 | /* we compute glyph codes and metrics on-demand in blocks of 256 indexed |
| 473 | by hibyte, lobyte */ | 472 | by hibyte, lobyte */ |
| @@ -825,6 +824,13 @@ extern unsigned long ns_get_rgb_color (struct frame *f, | |||
| 825 | float r, float g, float b, float a); | 824 | float r, float g, float b, float a); |
| 826 | extern NSPoint last_mouse_motion_position; | 825 | extern NSPoint last_mouse_motion_position; |
| 827 | 826 | ||
| 827 | /* From nsterm.m, needed in nsfont.m. */ | ||
| 828 | #ifdef __OBJC__ | ||
| 829 | extern void | ||
| 830 | ns_draw_text_decoration (struct glyph_string *s, struct face *face, | ||
| 831 | NSColor *defaultCol, CGFloat width, CGFloat x); | ||
| 832 | #endif | ||
| 833 | |||
| 828 | #ifdef NS_IMPL_GNUSTEP | 834 | #ifdef NS_IMPL_GNUSTEP |
| 829 | extern char gnustep_base_version[]; /* version tracking */ | 835 | extern char gnustep_base_version[]; /* version tracking */ |
| 830 | #endif | 836 | #endif |
diff --git a/src/nsterm.m b/src/nsterm.m index e45dc1a902d..d4b1a3f8473 100644 --- a/src/nsterm.m +++ b/src/nsterm.m | |||
| @@ -263,8 +263,6 @@ static void ns_condemn_scroll_bars (struct frame *f); | |||
| 263 | static void ns_judge_scroll_bars (struct frame *f); | 263 | static void ns_judge_scroll_bars (struct frame *f); |
| 264 | void x_set_frame_alpha (struct frame *f); | 264 | void x_set_frame_alpha (struct frame *f); |
| 265 | 265 | ||
| 266 | /* FIXME: figure out what to do with underline_minimum_offset. */ | ||
| 267 | |||
| 268 | 266 | ||
| 269 | /* ========================================================================== | 267 | /* ========================================================================== |
| 270 | 268 | ||
| @@ -2597,6 +2595,107 @@ ns_get_glyph_string_clip_rect (struct glyph_string *s, NativeRectangle *nr) | |||
| 2597 | return n; | 2595 | return n; |
| 2598 | } | 2596 | } |
| 2599 | 2597 | ||
| 2598 | void | ||
| 2599 | ns_draw_text_decoration (struct glyph_string *s, struct face *face, | ||
| 2600 | NSColor *defaultCol, CGFloat width, CGFloat x) | ||
| 2601 | /* -------------------------------------------------------------------------- | ||
| 2602 | Draw underline, overline, and strike-through on glyph string s. | ||
| 2603 | -------------------------------------------------------------------------- */ | ||
| 2604 | { | ||
| 2605 | if (s->for_overlaps) | ||
| 2606 | return; | ||
| 2607 | |||
| 2608 | /* Do underline. */ | ||
| 2609 | if (face->underline_p) | ||
| 2610 | { | ||
| 2611 | NSRect r; | ||
| 2612 | unsigned long thickness, position; | ||
| 2613 | |||
| 2614 | /* If the prev was underlined, match its appearance. */ | ||
| 2615 | if (s->prev && s->prev->face->underline_p | ||
| 2616 | && s->prev->underline_thickness > 0) | ||
| 2617 | { | ||
| 2618 | thickness = s->prev->underline_thickness; | ||
| 2619 | position = s->prev->underline_position; | ||
| 2620 | } | ||
| 2621 | else | ||
| 2622 | { | ||
| 2623 | struct font *font; | ||
| 2624 | unsigned long descent; | ||
| 2625 | |||
| 2626 | font=s->font; | ||
| 2627 | descent = s->y + s->height - s->ybase; | ||
| 2628 | |||
| 2629 | /* Use underline thickness of font, defaulting to 1. */ | ||
| 2630 | thickness = (font && font->underline_thickness > 0) | ||
| 2631 | ? font->underline_thickness : 1; | ||
| 2632 | |||
| 2633 | /* Determine the offset of underlining from the baseline. */ | ||
| 2634 | if (x_underline_at_descent_line) | ||
| 2635 | position = descent - thickness; | ||
| 2636 | else if (x_use_underline_position_properties | ||
| 2637 | && font && font->underline_position >= 0) | ||
| 2638 | position = font->underline_position; | ||
| 2639 | else if (font) | ||
| 2640 | position = lround (font->descent / 2); | ||
| 2641 | else | ||
| 2642 | position = underline_minimum_offset; | ||
| 2643 | |||
| 2644 | position = max (position, underline_minimum_offset); | ||
| 2645 | |||
| 2646 | /* Ensure underlining is not cropped. */ | ||
| 2647 | if (descent <= position) | ||
| 2648 | { | ||
| 2649 | position = descent - 1; | ||
| 2650 | thickness = 1; | ||
| 2651 | } | ||
| 2652 | else if (descent < position + thickness) | ||
| 2653 | thickness = 1; | ||
| 2654 | } | ||
| 2655 | |||
| 2656 | s->underline_thickness = thickness; | ||
| 2657 | s->underline_position = position; | ||
| 2658 | |||
| 2659 | r = NSMakeRect (x, s->ybase + position, width, thickness); | ||
| 2660 | |||
| 2661 | if (face->underline_defaulted_p) | ||
| 2662 | [defaultCol set]; | ||
| 2663 | else | ||
| 2664 | [ns_lookup_indexed_color (face->underline_color, s->f) set]; | ||
| 2665 | NSRectFill (r); | ||
| 2666 | } | ||
| 2667 | |||
| 2668 | /* Do overline. We follow other terms in using a thickness of 1 | ||
| 2669 | and ignoring overline_margin. */ | ||
| 2670 | if (face->overline_p) | ||
| 2671 | { | ||
| 2672 | NSRect r; | ||
| 2673 | r = NSMakeRect (x, s->y, width, 1); | ||
| 2674 | |||
| 2675 | if (face->overline_color_defaulted_p) | ||
| 2676 | [defaultCol set]; | ||
| 2677 | else | ||
| 2678 | [ns_lookup_indexed_color (face->overline_color, s->f) set]; | ||
| 2679 | NSRectFill (r); | ||
| 2680 | } | ||
| 2681 | |||
| 2682 | /* Do strike-through. We follow other terms for thickness and | ||
| 2683 | vertical position.*/ | ||
| 2684 | if (face->strike_through_p) | ||
| 2685 | { | ||
| 2686 | NSRect r; | ||
| 2687 | unsigned long dy; | ||
| 2688 | |||
| 2689 | dy = lrint ((s->height - 1) / 2); | ||
| 2690 | r = NSMakeRect (x, s->y + dy, width, 1); | ||
| 2691 | |||
| 2692 | if (face->strike_through_color_defaulted_p) | ||
| 2693 | [defaultCol set]; | ||
| 2694 | else | ||
| 2695 | [ns_lookup_indexed_color (face->strike_through_color, s->f) set]; | ||
| 2696 | NSRectFill (r); | ||
| 2697 | } | ||
| 2698 | } | ||
| 2600 | 2699 | ||
| 2601 | static void | 2700 | static void |
| 2602 | ns_draw_box (NSRect r, float thickness, NSColor *col, char left_p, char right_p) | 2701 | ns_draw_box (NSRect r, float thickness, NSColor *col, char left_p, char right_p) |
| @@ -2854,6 +2953,7 @@ ns_dumpglyphs_image (struct glyph_string *s, NSRect r) | |||
| 2854 | char raised_p; | 2953 | char raised_p; |
| 2855 | NSRect br; | 2954 | NSRect br; |
| 2856 | struct face *face; | 2955 | struct face *face; |
| 2956 | NSColor *tdCol; | ||
| 2857 | 2957 | ||
| 2858 | NSTRACE (ns_dumpglyphs_image); | 2958 | NSTRACE (ns_dumpglyphs_image); |
| 2859 | 2959 | ||
| @@ -2882,10 +2982,7 @@ ns_dumpglyphs_image (struct glyph_string *s, NSRect r) | |||
| 2882 | else | 2982 | else |
| 2883 | face = FACE_FROM_ID (s->f, s->first_glyph->face_id); | 2983 | face = FACE_FROM_ID (s->f, s->first_glyph->face_id); |
| 2884 | 2984 | ||
| 2885 | if (s->hl == DRAW_CURSOR) | 2985 | [ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), s->f) set]; |
| 2886 | [FRAME_CURSOR_COLOR (s->f) set]; | ||
| 2887 | else | ||
| 2888 | [ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), s->f) set]; | ||
| 2889 | 2986 | ||
| 2890 | if (bg_height > s->slice.height || s->img->hmargin || s->img->vmargin | 2987 | if (bg_height > s->slice.height || s->img->hmargin || s->img->vmargin |
| 2891 | || s->img->mask || s->img->pixmap == 0 || s->width != s->background_width) | 2988 | || s->img->mask || s->img->pixmap == 0 || s->width != s->background_width) |
| @@ -2923,6 +3020,27 @@ ns_dumpglyphs_image (struct glyph_string *s, NSRect r) | |||
| 2923 | [img compositeToPoint: NSMakePoint (x, y + s->slice.height) | 3020 | [img compositeToPoint: NSMakePoint (x, y + s->slice.height) |
| 2924 | operation: NSCompositeSourceOver]; | 3021 | operation: NSCompositeSourceOver]; |
| 2925 | 3022 | ||
| 3023 | if (s->hl == DRAW_CURSOR) | ||
| 3024 | { | ||
| 3025 | [FRAME_CURSOR_COLOR (s->f) set]; | ||
| 3026 | if (s->w->phys_cursor_type == FILLED_BOX_CURSOR) | ||
| 3027 | tdCol = ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), s->f); | ||
| 3028 | else | ||
| 3029 | /* Currently on NS img->mask is always 0. Since | ||
| 3030 | get_window_cursor_type specifies a hollow box cursor when on | ||
| 3031 | a non-masked image we never reach this clause. But we put it | ||
| 3032 | in in antipication of better support for image masks on | ||
| 3033 | NS. */ | ||
| 3034 | tdCol = ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), s->f); | ||
| 3035 | } | ||
| 3036 | else | ||
| 3037 | { | ||
| 3038 | tdCol = ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), s->f); | ||
| 3039 | } | ||
| 3040 | |||
| 3041 | /* Draw underline, overline, strike-through. */ | ||
| 3042 | ns_draw_text_decoration (s, face, tdCol, br.size.width, br.origin.x); | ||
| 3043 | |||
| 2926 | /* Draw relief, if requested */ | 3044 | /* Draw relief, if requested */ |
| 2927 | if (s->img->relief || s->hl ==DRAW_IMAGE_RAISED || s->hl ==DRAW_IMAGE_SUNKEN) | 3045 | if (s->img->relief || s->hl ==DRAW_IMAGE_RAISED || s->hl ==DRAW_IMAGE_SUNKEN) |
| 2928 | { | 3046 | { |
| @@ -2967,22 +3085,49 @@ ns_dumpglyphs_stretch (struct glyph_string *s) | |||
| 2967 | NSRect r[2]; | 3085 | NSRect r[2]; |
| 2968 | int n, i; | 3086 | int n, i; |
| 2969 | struct face *face; | 3087 | struct face *face; |
| 3088 | NSColor *fgCol, *bgCol; | ||
| 2970 | 3089 | ||
| 2971 | if (!s->background_filled_p) | 3090 | if (!s->background_filled_p) |
| 2972 | { | 3091 | { |
| 2973 | n = ns_get_glyph_string_clip_rect (s, r); | 3092 | n = ns_get_glyph_string_clip_rect (s, r); |
| 2974 | *r = NSMakeRect (s->x, s->y, s->background_width, s->height); | 3093 | *r = NSMakeRect (s->x, s->y, s->background_width, s->height); |
| 2975 | 3094 | ||
| 3095 | ns_focus (s->f, r, n); | ||
| 3096 | |||
| 3097 | if (s->hl == DRAW_MOUSE_FACE) | ||
| 3098 | { | ||
| 3099 | face = FACE_FROM_ID (s->f, MOUSE_HL_INFO (s->f)->mouse_face_face_id); | ||
| 3100 | if (!face) | ||
| 3101 | face = FACE_FROM_ID (s->f, MOUSE_FACE_ID); | ||
| 3102 | } | ||
| 3103 | else | ||
| 3104 | face = FACE_FROM_ID (s->f, s->first_glyph->face_id); | ||
| 3105 | |||
| 3106 | bgCol = ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), s->f); | ||
| 3107 | fgCol = ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), s->f); | ||
| 3108 | |||
| 2976 | for (i=0; i<n; i++) | 3109 | for (i=0; i<n; i++) |
| 2977 | { | 3110 | { |
| 2978 | if (!s->row->full_width_p) | 3111 | if (!s->row->full_width_p) |
| 2979 | { | 3112 | { |
| 3113 | int overrun, leftoverrun; | ||
| 3114 | |||
| 2980 | /* truncate to avoid overwriting fringe and/or scrollbar */ | 3115 | /* truncate to avoid overwriting fringe and/or scrollbar */ |
| 2981 | int overrun = max (0, (s->x + s->background_width) | 3116 | overrun = max (0, (s->x + s->background_width) |
| 2982 | - (WINDOW_BOX_RIGHT_EDGE_X (s->w) | 3117 | - (WINDOW_BOX_RIGHT_EDGE_X (s->w) |
| 2983 | - WINDOW_RIGHT_FRINGE_WIDTH (s->w))); | 3118 | - WINDOW_RIGHT_FRINGE_WIDTH (s->w))); |
| 2984 | r[i].size.width -= overrun; | 3119 | r[i].size.width -= overrun; |
| 2985 | 3120 | ||
| 3121 | /* truncate to avoid overwriting to left of the window box */ | ||
| 3122 | leftoverrun = (WINDOW_BOX_LEFT_EDGE_X (s->w) | ||
| 3123 | + WINDOW_LEFT_FRINGE_WIDTH (s->w)) - s->x; | ||
| 3124 | |||
| 3125 | if (leftoverrun > 0) | ||
| 3126 | { | ||
| 3127 | r[i].origin.x += leftoverrun; | ||
| 3128 | r[i].size.width -= leftoverrun; | ||
| 3129 | } | ||
| 3130 | |||
| 2986 | /* XXX: Try to work between problem where a stretch glyph on | 3131 | /* XXX: Try to work between problem where a stretch glyph on |
| 2987 | a partially-visible bottom row will clear part of the | 3132 | a partially-visible bottom row will clear part of the |
| 2988 | modeline, and another where list-buffers headers and similar | 3133 | modeline, and another where list-buffers headers and similar |
| @@ -2998,30 +3143,37 @@ ns_dumpglyphs_stretch (struct glyph_string *s) | |||
| 2998 | FRAME_PIXEL_WIDTH (s->f)); | 3143 | FRAME_PIXEL_WIDTH (s->f)); |
| 2999 | } | 3144 | } |
| 3000 | 3145 | ||
| 3146 | [bgCol set]; | ||
| 3147 | |||
| 3001 | /* NOTE: under NS this is NOT used to draw cursors, but we must avoid | 3148 | /* NOTE: under NS this is NOT used to draw cursors, but we must avoid |
| 3002 | overwriting cursor (usually when cursor on a tab) */ | 3149 | overwriting cursor (usually when cursor on a tab) */ |
| 3003 | if (s->hl == DRAW_CURSOR) | 3150 | if (s->hl == DRAW_CURSOR) |
| 3004 | { | 3151 | { |
| 3005 | r[i].origin.x += s->width; | 3152 | CGFloat x, width; |
| 3006 | r[i].size.width -= s->width; | ||
| 3007 | } | ||
| 3008 | } | ||
| 3009 | 3153 | ||
| 3010 | ns_focus (s->f, r, n); | 3154 | x = r[i].origin.x; |
| 3155 | width = s->w->phys_cursor_width; | ||
| 3156 | r[i].size.width -= width; | ||
| 3157 | r[i].origin.x += width; | ||
| 3011 | 3158 | ||
| 3012 | if (s->hl == DRAW_MOUSE_FACE) | 3159 | NSRectFill (r[i]); |
| 3013 | { | ||
| 3014 | face = FACE_FROM_ID (s->f, MOUSE_HL_INFO (s->f)->mouse_face_face_id); | ||
| 3015 | if (!face) | ||
| 3016 | face = FACE_FROM_ID (s->f, MOUSE_FACE_ID); | ||
| 3017 | } | ||
| 3018 | else | ||
| 3019 | face = FACE_FROM_ID (s->f, s->first_glyph->face_id); | ||
| 3020 | 3160 | ||
| 3021 | [ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), s->f) set]; | 3161 | /* Draw overlining, etc. on the cursor. */ |
| 3162 | if (s->w->phys_cursor_type == FILLED_BOX_CURSOR) | ||
| 3163 | ns_draw_text_decoration (s, face, bgCol, width, x); | ||
| 3164 | else | ||
| 3165 | ns_draw_text_decoration (s, face, fgCol, width, x); | ||
| 3166 | } | ||
| 3167 | else | ||
| 3168 | { | ||
| 3169 | NSRectFill (r[i]); | ||
| 3170 | } | ||
| 3022 | 3171 | ||
| 3023 | NSRectFill (r[0]); | 3172 | /* Draw overlining, etc. on the stretch glyph (or the part |
| 3024 | NSRectFill (r[1]); | 3173 | of the stretch glyph after the cursor). */ |
| 3174 | ns_draw_text_decoration (s, face, fgCol, r[i].size.width, | ||
| 3175 | r[i].origin.x); | ||
| 3176 | } | ||
| 3025 | ns_unfocus (s->f); | 3177 | ns_unfocus (s->f); |
| 3026 | s->background_filled_p = 1; | 3178 | s->background_filled_p = 1; |
| 3027 | } | 3179 | } |
| @@ -6556,23 +6708,17 @@ Only works on OSX 10.6 or later. */); | |||
| 6556 | Vx_toolkit_scroll_bars = Qnil; | 6708 | Vx_toolkit_scroll_bars = Qnil; |
| 6557 | #endif | 6709 | #endif |
| 6558 | 6710 | ||
| 6559 | /* these are unsupported but we need the declarations to avoid whining | ||
| 6560 | messages from cus-start.el */ | ||
| 6561 | DEFVAR_BOOL ("x-use-underline-position-properties", | 6711 | DEFVAR_BOOL ("x-use-underline-position-properties", |
| 6562 | x_use_underline_position_properties, | 6712 | x_use_underline_position_properties, |
| 6563 | doc: /* NOT SUPPORTED UNDER NS. | 6713 | doc: /*Non-nil means make use of UNDERLINE_POSITION font properties. |
| 6564 | *Non-nil means make use of UNDERLINE_POSITION font properties. | ||
| 6565 | A value of nil means ignore them. If you encounter fonts with bogus | 6714 | A value of nil means ignore them. If you encounter fonts with bogus |
| 6566 | UNDERLINE_POSITION font properties, for example 7x13 on XFree prior | 6715 | UNDERLINE_POSITION font properties, for example 7x13 on XFree prior |
| 6567 | to 4.1, set this to nil. | 6716 | to 4.1, set this to nil. */); |
| 6568 | |||
| 6569 | NOTE: Not supported on Mac yet. */); | ||
| 6570 | x_use_underline_position_properties = 0; | 6717 | x_use_underline_position_properties = 0; |
| 6571 | 6718 | ||
| 6572 | DEFVAR_BOOL ("x-underline-at-descent-line", | 6719 | DEFVAR_BOOL ("x-underline-at-descent-line", |
| 6573 | x_underline_at_descent_line, | 6720 | x_underline_at_descent_line, |
| 6574 | doc: /* NOT SUPPORTED UNDER NS. | 6721 | doc: /* Non-nil means to draw the underline at the same place as the descent line. |
| 6575 | *Non-nil means to draw the underline at the same place as the descent line. | ||
| 6576 | A value of nil means to draw the underline according to the value of the | 6722 | A value of nil means to draw the underline according to the value of the |
| 6577 | variable `x-use-underline-position-properties', which is usually at the | 6723 | variable `x-use-underline-position-properties', which is usually at the |
| 6578 | baseline level. The default value is nil. */); | 6724 | baseline level. The default value is nil. */); |
diff --git a/src/print.c b/src/print.c index 242bcb5b0d1..9e30bc82258 100644 --- a/src/print.c +++ b/src/print.c | |||
| @@ -47,10 +47,7 @@ static Lisp_Object Qtemp_buffer_setup_hook; | |||
| 47 | static Lisp_Object Qfloat_output_format; | 47 | static Lisp_Object Qfloat_output_format; |
| 48 | 48 | ||
| 49 | #include <math.h> | 49 | #include <math.h> |
| 50 | |||
| 51 | #if STDC_HEADERS | ||
| 52 | #include <float.h> | 50 | #include <float.h> |
| 53 | #endif | ||
| 54 | #include <ftoastr.h> | 51 | #include <ftoastr.h> |
| 55 | 52 | ||
| 56 | /* Default to values appropriate for IEEE floating point. */ | 53 | /* Default to values appropriate for IEEE floating point. */ |
| @@ -1540,13 +1537,19 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag | |||
| 1540 | else | 1537 | else |
| 1541 | confusing = 0; | 1538 | confusing = 0; |
| 1542 | 1539 | ||
| 1540 | size_byte = SBYTES (name); | ||
| 1541 | |||
| 1543 | if (! NILP (Vprint_gensym) && !SYMBOL_INTERNED_P (obj)) | 1542 | if (! NILP (Vprint_gensym) && !SYMBOL_INTERNED_P (obj)) |
| 1544 | { | 1543 | { |
| 1545 | PRINTCHAR ('#'); | 1544 | PRINTCHAR ('#'); |
| 1546 | PRINTCHAR (':'); | 1545 | PRINTCHAR (':'); |
| 1547 | } | 1546 | } |
| 1548 | 1547 | else if (size_byte == 0) | |
| 1549 | size_byte = SBYTES (name); | 1548 | { |
| 1549 | PRINTCHAR ('#'); | ||
| 1550 | PRINTCHAR ('#'); | ||
| 1551 | break; | ||
| 1552 | } | ||
| 1550 | 1553 | ||
| 1551 | for (i = 0, i_byte = 0; i_byte < size_byte;) | 1554 | for (i = 0, i_byte = 0; i_byte < size_byte;) |
| 1552 | { | 1555 | { |
| @@ -1559,7 +1562,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag | |||
| 1559 | { | 1562 | { |
| 1560 | if (c == '\"' || c == '\\' || c == '\'' | 1563 | if (c == '\"' || c == '\\' || c == '\'' |
| 1561 | || c == ';' || c == '#' || c == '(' || c == ')' | 1564 | || c == ';' || c == '#' || c == '(' || c == ')' |
| 1562 | || c == ',' || c =='.' || c == '`' | 1565 | || c == ',' || c == '.' || c == '`' |
| 1563 | || c == '[' || c == ']' || c == '?' || c <= 040 | 1566 | || c == '[' || c == ']' || c == '?' || c <= 040 |
| 1564 | || confusing) | 1567 | || confusing) |
| 1565 | PRINTCHAR ('\\'), confusing = 0; | 1568 | PRINTCHAR ('\\'), confusing = 0; |
diff --git a/src/regex.c b/src/regex.c index 625c59ccf0b..862f848976c 100644 --- a/src/regex.c +++ b/src/regex.c | |||
| @@ -37,9 +37,9 @@ | |||
| 37 | # include <config.h> | 37 | # include <config.h> |
| 38 | #endif | 38 | #endif |
| 39 | 39 | ||
| 40 | #if defined STDC_HEADERS && !defined emacs | 40 | #include <stddef.h> |
| 41 | # include <stddef.h> | 41 | |
| 42 | #else | 42 | #ifdef emacs |
| 43 | /* We need this for `regex.h', and perhaps for the Emacs include files. */ | 43 | /* We need this for `regex.h', and perhaps for the Emacs include files. */ |
| 44 | # include <sys/types.h> | 44 | # include <sys/types.h> |
| 45 | #endif | 45 | #endif |
| @@ -238,18 +238,7 @@ xrealloc (void *block, size_t size) | |||
| 238 | # endif | 238 | # endif |
| 239 | # define realloc xrealloc | 239 | # define realloc xrealloc |
| 240 | 240 | ||
| 241 | /* This is the normal way of making sure we have memcpy, memcmp and memset. */ | 241 | # include <string.h> |
| 242 | # if defined HAVE_STRING_H || defined STDC_HEADERS || defined _LIBC | ||
| 243 | # include <string.h> | ||
| 244 | # else | ||
| 245 | # include <strings.h> | ||
| 246 | # ifndef memcmp | ||
| 247 | # define memcmp(s1, s2, n) bcmp (s1, s2, n) | ||
| 248 | # endif | ||
| 249 | # ifndef memcpy | ||
| 250 | # define memcpy(d, s, n) (bcopy (s, d, n), (d)) | ||
| 251 | # endif | ||
| 252 | # endif | ||
| 253 | 242 | ||
| 254 | /* Define the syntax stuff for \<, \>, etc. */ | 243 | /* Define the syntax stuff for \<, \>, etc. */ |
| 255 | 244 | ||
| @@ -357,25 +346,6 @@ enum syntaxcode { Swhitespace = 0, Sword = 1, Ssymbol = 2 }; | |||
| 357 | 346 | ||
| 358 | #else /* not emacs */ | 347 | #else /* not emacs */ |
| 359 | 348 | ||
| 360 | /* Jim Meyering writes: | ||
| 361 | |||
| 362 | "... Some ctype macros are valid only for character codes that | ||
| 363 | isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when | ||
| 364 | using /bin/cc or gcc but without giving an ansi option). So, all | ||
| 365 | ctype uses should be through macros like ISPRINT... If | ||
| 366 | STDC_HEADERS is defined, then autoconf has verified that the ctype | ||
| 367 | macros don't need to be guarded with references to isascii. ... | ||
| 368 | Defining isascii to 1 should let any compiler worth its salt | ||
| 369 | eliminate the && through constant folding." | ||
| 370 | Solaris defines some of these symbols so we must undefine them first. */ | ||
| 371 | |||
| 372 | # undef ISASCII | ||
| 373 | # if defined STDC_HEADERS || (!defined isascii && !defined HAVE_ISASCII) | ||
| 374 | # define ISASCII(c) 1 | ||
| 375 | # else | ||
| 376 | # define ISASCII(c) isascii(c) | ||
| 377 | # endif | ||
| 378 | |||
| 379 | /* 1 if C is an ASCII character. */ | 349 | /* 1 if C is an ASCII character. */ |
| 380 | # define IS_REAL_ASCII(c) ((c) < 0200) | 350 | # define IS_REAL_ASCII(c) ((c) < 0200) |
| 381 | 351 | ||
| @@ -383,27 +353,28 @@ enum syntaxcode { Swhitespace = 0, Sword = 1, Ssymbol = 2 }; | |||
| 383 | # define ISUNIBYTE(c) 1 | 353 | # define ISUNIBYTE(c) 1 |
| 384 | 354 | ||
| 385 | # ifdef isblank | 355 | # ifdef isblank |
| 386 | # define ISBLANK(c) (ISASCII (c) && isblank (c)) | 356 | # define ISBLANK(c) isblank (c) |
| 387 | # else | 357 | # else |
| 388 | # define ISBLANK(c) ((c) == ' ' || (c) == '\t') | 358 | # define ISBLANK(c) ((c) == ' ' || (c) == '\t') |
| 389 | # endif | 359 | # endif |
| 390 | # ifdef isgraph | 360 | # ifdef isgraph |
| 391 | # define ISGRAPH(c) (ISASCII (c) && isgraph (c)) | 361 | # define ISGRAPH(c) isgraph (c) |
| 392 | # else | 362 | # else |
| 393 | # define ISGRAPH(c) (ISASCII (c) && isprint (c) && !isspace (c)) | 363 | # define ISGRAPH(c) (isprint (c) && !isspace (c)) |
| 394 | # endif | 364 | # endif |
| 395 | 365 | ||
| 366 | /* Solaris defines ISPRINT so we must undefine it first. */ | ||
| 396 | # undef ISPRINT | 367 | # undef ISPRINT |
| 397 | # define ISPRINT(c) (ISASCII (c) && isprint (c)) | 368 | # define ISPRINT(c) isprint (c) |
| 398 | # define ISDIGIT(c) (ISASCII (c) && isdigit (c)) | 369 | # define ISDIGIT(c) isdigit (c) |
| 399 | # define ISALNUM(c) (ISASCII (c) && isalnum (c)) | 370 | # define ISALNUM(c) isalnum (c) |
| 400 | # define ISALPHA(c) (ISASCII (c) && isalpha (c)) | 371 | # define ISALPHA(c) isalpha (c) |
| 401 | # define ISCNTRL(c) (ISASCII (c) && iscntrl (c)) | 372 | # define ISCNTRL(c) iscntrl (c) |
| 402 | # define ISLOWER(c) (ISASCII (c) && islower (c)) | 373 | # define ISLOWER(c) islower (c) |
| 403 | # define ISPUNCT(c) (ISASCII (c) && ispunct (c)) | 374 | # define ISPUNCT(c) ispunct (c) |
| 404 | # define ISSPACE(c) (ISASCII (c) && isspace (c)) | 375 | # define ISSPACE(c) isspace (c) |
| 405 | # define ISUPPER(c) (ISASCII (c) && isupper (c)) | 376 | # define ISUPPER(c) isupper (c) |
| 406 | # define ISXDIGIT(c) (ISASCII (c) && isxdigit (c)) | 377 | # define ISXDIGIT(c) isxdigit (c) |
| 407 | 378 | ||
| 408 | # define ISWORD(c) ISALPHA(c) | 379 | # define ISWORD(c) ISALPHA(c) |
| 409 | 380 | ||
| @@ -450,10 +421,6 @@ init_syntax_once (void) | |||
| 450 | 421 | ||
| 451 | #endif /* not emacs */ | 422 | #endif /* not emacs */ |
| 452 | 423 | ||
| 453 | #ifndef NULL | ||
| 454 | # define NULL (void *)0 | ||
| 455 | #endif | ||
| 456 | |||
| 457 | /* We remove any previous definition of `SIGN_EXTEND_CHAR', | 424 | /* We remove any previous definition of `SIGN_EXTEND_CHAR', |
| 458 | since ours (we hope) works properly with all combinations of | 425 | since ours (we hope) works properly with all combinations of |
| 459 | machines, compilers, `char' and `unsigned char' argument types. | 426 | machines, compilers, `char' and `unsigned char' argument types. |
| @@ -2126,23 +2093,23 @@ re_iswctype (int ch, re_wctype_t cc) | |||
| 2126 | { | 2093 | { |
| 2127 | switch (cc) | 2094 | switch (cc) |
| 2128 | { | 2095 | { |
| 2129 | case RECC_ALNUM: return ISALNUM (ch); | 2096 | case RECC_ALNUM: return ISALNUM (ch) != 0; |
| 2130 | case RECC_ALPHA: return ISALPHA (ch); | 2097 | case RECC_ALPHA: return ISALPHA (ch) != 0; |
| 2131 | case RECC_BLANK: return ISBLANK (ch); | 2098 | case RECC_BLANK: return ISBLANK (ch) != 0; |
| 2132 | case RECC_CNTRL: return ISCNTRL (ch); | 2099 | case RECC_CNTRL: return ISCNTRL (ch) != 0; |
| 2133 | case RECC_DIGIT: return ISDIGIT (ch); | 2100 | case RECC_DIGIT: return ISDIGIT (ch) != 0; |
| 2134 | case RECC_GRAPH: return ISGRAPH (ch); | 2101 | case RECC_GRAPH: return ISGRAPH (ch) != 0; |
| 2135 | case RECC_LOWER: return ISLOWER (ch); | 2102 | case RECC_LOWER: return ISLOWER (ch) != 0; |
| 2136 | case RECC_PRINT: return ISPRINT (ch); | 2103 | case RECC_PRINT: return ISPRINT (ch) != 0; |
| 2137 | case RECC_PUNCT: return ISPUNCT (ch); | 2104 | case RECC_PUNCT: return ISPUNCT (ch) != 0; |
| 2138 | case RECC_SPACE: return ISSPACE (ch); | 2105 | case RECC_SPACE: return ISSPACE (ch) != 0; |
| 2139 | case RECC_UPPER: return ISUPPER (ch); | 2106 | case RECC_UPPER: return ISUPPER (ch) != 0; |
| 2140 | case RECC_XDIGIT: return ISXDIGIT (ch); | 2107 | case RECC_XDIGIT: return ISXDIGIT (ch) != 0; |
| 2141 | case RECC_ASCII: return IS_REAL_ASCII (ch); | 2108 | case RECC_ASCII: return IS_REAL_ASCII (ch) != 0; |
| 2142 | case RECC_NONASCII: return !IS_REAL_ASCII (ch); | 2109 | case RECC_NONASCII: return !IS_REAL_ASCII (ch) != 0; |
| 2143 | case RECC_UNIBYTE: return ISUNIBYTE (ch); | 2110 | case RECC_UNIBYTE: return ISUNIBYTE (ch) != 0; |
| 2144 | case RECC_MULTIBYTE: return !ISUNIBYTE (ch); | 2111 | case RECC_MULTIBYTE: return !ISUNIBYTE (ch) != 0; |
| 2145 | case RECC_WORD: return ISWORD (ch); | 2112 | case RECC_WORD: return ISWORD (ch) != 0; |
| 2146 | case RECC_ERROR: return false; | 2113 | case RECC_ERROR: return false; |
| 2147 | default: | 2114 | default: |
| 2148 | abort(); | 2115 | abort(); |
diff --git a/src/s/aix4-2.h b/src/s/aix4-2.h index c2715fffe01..b44bd0308a3 100644 --- a/src/s/aix4-2.h +++ b/src/s/aix4-2.h | |||
| @@ -47,11 +47,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 47 | /* AIX doesn't define this. */ | 47 | /* AIX doesn't define this. */ |
| 48 | #define unix 1 | 48 | #define unix 1 |
| 49 | 49 | ||
| 50 | /* string.h defines rindex as a macro, at least with native cc, so we | ||
| 51 | lose declaring char * rindex without this. | ||
| 52 | It is just a guess which versions of AIX need this definition. */ | ||
| 53 | #undef HAVE_STRING_H | ||
| 54 | |||
| 55 | /* Perry Smith <pedz@ddivt1.austin.ibm.com> says these are correct. */ | 50 | /* Perry Smith <pedz@ddivt1.austin.ibm.com> says these are correct. */ |
| 56 | #define SIGNALS_VIA_CHARACTERS | 51 | #define SIGNALS_VIA_CHARACTERS |
| 57 | #define CLASH_DETECTION | 52 | #define CLASH_DETECTION |
diff --git a/src/s/ms-w32.h b/src/s/ms-w32.h index bf6cc66798c..813c3cef115 100644 --- a/src/s/ms-w32.h +++ b/src/s/ms-w32.h | |||
| @@ -111,11 +111,7 @@ struct sigaction { | |||
| 111 | #undef HAVE_UTIME_H | 111 | #undef HAVE_UTIME_H |
| 112 | #undef HAVE_LINUX_VERSION_H | 112 | #undef HAVE_LINUX_VERSION_H |
| 113 | #undef HAVE_SYS_SYSTEMINFO_H | 113 | #undef HAVE_SYS_SYSTEMINFO_H |
| 114 | #define HAVE_LIMITS_H 1 | ||
| 115 | #define HAVE_STRING_H 1 | ||
| 116 | #define HAVE_STDLIB_H 1 | ||
| 117 | #define HAVE_PWD_H 1 | 114 | #define HAVE_PWD_H 1 |
| 118 | #define STDC_HEADERS 1 | ||
| 119 | #define TIME_WITH_SYS_TIME 1 | 115 | #define TIME_WITH_SYS_TIME 1 |
| 120 | 116 | ||
| 121 | #define HAVE_GETTIMEOFDAY 1 | 117 | #define HAVE_GETTIMEOFDAY 1 |
| @@ -386,4 +382,3 @@ extern void _DebPrint (const char *fmt, ...); | |||
| 386 | 382 | ||
| 387 | 383 | ||
| 388 | /* ============================================================ */ | 384 | /* ============================================================ */ |
| 389 | |||
diff --git a/src/sysdep.c b/src/sysdep.c index fc2f846b0dc..4bd1f54b9e6 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -26,9 +26,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 26 | #include <pwd.h> | 26 | #include <pwd.h> |
| 27 | #include <grp.h> | 27 | #include <grp.h> |
| 28 | #endif /* HAVE_PWD_H */ | 28 | #endif /* HAVE_PWD_H */ |
| 29 | #ifdef HAVE_LIMITS_H | ||
| 30 | #include <limits.h> | 29 | #include <limits.h> |
| 31 | #endif /* HAVE_LIMITS_H */ | ||
| 32 | #include <unistd.h> | 30 | #include <unistd.h> |
| 33 | 31 | ||
| 34 | #include <allocator.h> | 32 | #include <allocator.h> |
| @@ -2215,59 +2213,6 @@ rmdir (char *dpath) | |||
| 2215 | #endif /* !HAVE_RMDIR */ | 2213 | #endif /* !HAVE_RMDIR */ |
| 2216 | 2214 | ||
| 2217 | 2215 | ||
| 2218 | #ifndef HAVE_MEMSET | ||
| 2219 | void * | ||
| 2220 | memset (void *b, int n, size_t length) | ||
| 2221 | { | ||
| 2222 | unsigned char *p = b; | ||
| 2223 | while (length-- > 0) | ||
| 2224 | *p++ = n; | ||
| 2225 | return b; | ||
| 2226 | } | ||
| 2227 | #endif /* !HAVE_MEMSET */ | ||
| 2228 | |||
| 2229 | #ifndef HAVE_MEMCPY | ||
| 2230 | void * | ||
| 2231 | memcpy (void *b1, void *b2, size_t length) | ||
| 2232 | { | ||
| 2233 | unsigned char *p1 = b1, *p2 = b2; | ||
| 2234 | while (length-- > 0) | ||
| 2235 | *p1++ = *p2++; | ||
| 2236 | return b1; | ||
| 2237 | } | ||
| 2238 | #endif /* !HAVE_MEMCPY */ | ||
| 2239 | |||
| 2240 | #ifndef HAVE_MEMMOVE | ||
| 2241 | void * | ||
| 2242 | memmove (void *b1, void *b2, size_t length) | ||
| 2243 | { | ||
| 2244 | unsigned char *p1 = b1, *p2 = b2; | ||
| 2245 | if (p1 < p2 || p1 >= p2 + length) | ||
| 2246 | while (length-- > 0) | ||
| 2247 | *p1++ = *p2++; | ||
| 2248 | else | ||
| 2249 | { | ||
| 2250 | p1 += length; | ||
| 2251 | p2 += length; | ||
| 2252 | while (length-- > 0) | ||
| 2253 | *--p1 = *--p2; | ||
| 2254 | } | ||
| 2255 | return b1; | ||
| 2256 | } | ||
| 2257 | #endif /* !HAVE_MEMCPY */ | ||
| 2258 | |||
| 2259 | #ifndef HAVE_MEMCMP | ||
| 2260 | int | ||
| 2261 | memcmp (void *b1, void *b2, size_t length) | ||
| 2262 | { | ||
| 2263 | unsigned char *p1 = b1, *p2 = b2; | ||
| 2264 | while (length-- > 0) | ||
| 2265 | if (*p1++ != *p2++) | ||
| 2266 | return p1[-1] < p2[-1] ? -1 : 1; | ||
| 2267 | return 0; | ||
| 2268 | } | ||
| 2269 | #endif /* !HAVE_MEMCMP */ | ||
| 2270 | |||
| 2271 | #ifndef HAVE_STRSIGNAL | 2216 | #ifndef HAVE_STRSIGNAL |
| 2272 | char * | 2217 | char * |
| 2273 | strsignal (int code) | 2218 | strsignal (int code) |
diff --git a/src/xdisp.c b/src/xdisp.c index 1aef5c7caa8..597793c70b5 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -3184,7 +3184,8 @@ compute_display_string_pos (struct text_pos *position, | |||
| 3184 | b = XBUFFER (object); | 3184 | b = XBUFFER (object); |
| 3185 | if (b == cached_disp_buffer | 3185 | if (b == cached_disp_buffer |
| 3186 | && BUF_MODIFF (b) == cached_disp_modiff | 3186 | && BUF_MODIFF (b) == cached_disp_modiff |
| 3187 | && BUF_OVERLAY_MODIFF (b) == cached_disp_overlay_modiff) | 3187 | && BUF_OVERLAY_MODIFF (b) == cached_disp_overlay_modiff |
| 3188 | && !b->clip_changed) | ||
| 3188 | { | 3189 | { |
| 3189 | if (cached_prev_pos >= 0 | 3190 | if (cached_prev_pos >= 0 |
| 3190 | && cached_prev_pos < charpos && charpos <= cached_disp_pos) | 3191 | && cached_prev_pos < charpos && charpos <= cached_disp_pos) |
| @@ -8877,7 +8878,7 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte) | |||
| 8877 | if (nlflag) | 8878 | if (nlflag) |
| 8878 | { | 8879 | { |
| 8879 | EMACS_INT this_bol, this_bol_byte, prev_bol, prev_bol_byte; | 8880 | EMACS_INT this_bol, this_bol_byte, prev_bol, prev_bol_byte; |
| 8880 | intmax_t dups; | 8881 | printmax_t dups; |
| 8881 | insert_1 ("\n", 1, 1, 0, 0); | 8882 | insert_1 ("\n", 1, 1, 0, 0); |
| 8882 | 8883 | ||
| 8883 | scan_newline (Z, Z_BYTE, BEG, BEG_BYTE, -2, 0); | 8884 | scan_newline (Z, Z_BYTE, BEG, BEG_BYTE, -2, 0); |
| @@ -8901,12 +8902,12 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte) | |||
| 8901 | if (dups > 1) | 8902 | if (dups > 1) |
| 8902 | { | 8903 | { |
| 8903 | char dupstr[sizeof " [ times]" | 8904 | char dupstr[sizeof " [ times]" |
| 8904 | + INT_STRLEN_BOUND (intmax_t)]; | 8905 | + INT_STRLEN_BOUND (printmax_t)]; |
| 8905 | int duplen; | 8906 | int duplen; |
| 8906 | 8907 | ||
| 8907 | /* If you change this format, don't forget to also | 8908 | /* If you change this format, don't forget to also |
| 8908 | change message_log_check_duplicate. */ | 8909 | change message_log_check_duplicate. */ |
| 8909 | sprintf (dupstr, " [%"PRIdMAX" times]", dups); | 8910 | sprintf (dupstr, " [%"pMd" times]", dups); |
| 8910 | duplen = strlen (dupstr); | 8911 | duplen = strlen (dupstr); |
| 8911 | TEMP_SET_PT_BOTH (Z - 1, Z_BYTE - 1); | 8912 | TEMP_SET_PT_BOTH (Z - 1, Z_BYTE - 1); |
| 8912 | insert_1 (dupstr, duplen, 1, 0, 1); | 8913 | insert_1 (dupstr, duplen, 1, 0, 1); |
| @@ -9299,7 +9300,7 @@ vmessage (const char *m, va_list ap) | |||
| 9299 | { | 9300 | { |
| 9300 | if (m) | 9301 | if (m) |
| 9301 | { | 9302 | { |
| 9302 | size_t len; | 9303 | ptrdiff_t len; |
| 9303 | 9304 | ||
| 9304 | len = doprnt (FRAME_MESSAGE_BUF (f), | 9305 | len = doprnt (FRAME_MESSAGE_BUF (f), |
| 9305 | FRAME_MESSAGE_BUF_SIZE (f), m, (char *)0, ap); | 9306 | FRAME_MESSAGE_BUF_SIZE (f), m, (char *)0, ap); |
diff --git a/src/xfaces.c b/src/xfaces.c index 32729ce6f8d..52b125b42e6 100644 --- a/src/xfaces.c +++ b/src/xfaces.c | |||
| @@ -940,11 +940,13 @@ the pixmap. Bits are stored row by row, each row occupies | |||
| 940 | } | 940 | } |
| 941 | } | 941 | } |
| 942 | 942 | ||
| 943 | if (NATNUMP (width) && NATNUMP (height) && STRINGP (data)) | 943 | if (STRINGP (data) |
| 944 | && INTEGERP (width) && 0 < XINT (width) | ||
| 945 | && INTEGERP (height) && 0 < XINT (height)) | ||
| 944 | { | 946 | { |
| 945 | int bytes_per_row = ((XFASTINT (width) + BITS_PER_CHAR - 1) | 947 | EMACS_INT bytes_per_row = ((XINT (width) + BITS_PER_CHAR - 1) |
| 946 | / BITS_PER_CHAR); | 948 | / BITS_PER_CHAR); |
| 947 | if (SBYTES (data) >= bytes_per_row * XINT (height)) | 949 | if (XINT (height) <= SBYTES (data) / bytes_per_row) |
| 948 | pixmap_p = 1; | 950 | pixmap_p = 1; |
| 949 | } | 951 | } |
| 950 | } | 952 | } |
diff --git a/src/xselect.c b/src/xselect.c index 5e5bdb55eca..f63977a73de 100644 --- a/src/xselect.c +++ b/src/xselect.c | |||
| @@ -2381,7 +2381,7 @@ FRAME is on. If FRAME is nil, the selected frame is used. */) | |||
| 2381 | { | 2381 | { |
| 2382 | Atom x_atom; | 2382 | Atom x_atom; |
| 2383 | struct frame *f = check_x_frame (frame); | 2383 | struct frame *f = check_x_frame (frame); |
| 2384 | size_t i; | 2384 | ptrdiff_t i; |
| 2385 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | 2385 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
| 2386 | 2386 | ||
| 2387 | 2387 | ||
| @@ -2402,6 +2402,9 @@ FRAME is on. If FRAME is nil, the selected frame is used. */) | |||
| 2402 | 2402 | ||
| 2403 | if (dpyinfo->x_dnd_atoms_length == dpyinfo->x_dnd_atoms_size) | 2403 | if (dpyinfo->x_dnd_atoms_length == dpyinfo->x_dnd_atoms_size) |
| 2404 | { | 2404 | { |
| 2405 | if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof *dpyinfo->x_dnd_atoms / 2 | ||
| 2406 | < dpyinfo->x_dnd_atoms_size) | ||
| 2407 | memory_full (SIZE_MAX); | ||
| 2405 | dpyinfo->x_dnd_atoms_size *= 2; | 2408 | dpyinfo->x_dnd_atoms_size *= 2; |
| 2406 | dpyinfo->x_dnd_atoms = xrealloc (dpyinfo->x_dnd_atoms, | 2409 | dpyinfo->x_dnd_atoms = xrealloc (dpyinfo->x_dnd_atoms, |
| 2407 | sizeof (*dpyinfo->x_dnd_atoms) | 2410 | sizeof (*dpyinfo->x_dnd_atoms) |
| @@ -2424,7 +2427,7 @@ x_handle_dnd_message (struct frame *f, XClientMessageEvent *event, struct x_disp | |||
| 2424 | int x, y; | 2427 | int x, y; |
| 2425 | unsigned char *data = (unsigned char *) event->data.b; | 2428 | unsigned char *data = (unsigned char *) event->data.b; |
| 2426 | int idata[5]; | 2429 | int idata[5]; |
| 2427 | size_t i; | 2430 | ptrdiff_t i; |
| 2428 | 2431 | ||
| 2429 | for (i = 0; i < dpyinfo->x_dnd_atoms_length; ++i) | 2432 | for (i = 0; i < dpyinfo->x_dnd_atoms_length; ++i) |
| 2430 | if (dpyinfo->x_dnd_atoms[i] == event->message_type) break; | 2433 | if (dpyinfo->x_dnd_atoms[i] == event->message_type) break; |
diff --git a/src/xterm.h b/src/xterm.h index a4767361bb3..30867656710 100644 --- a/src/xterm.h +++ b/src/xterm.h | |||
| @@ -326,8 +326,8 @@ struct x_display_info | |||
| 326 | 326 | ||
| 327 | /* Atoms that are drag and drop atoms */ | 327 | /* Atoms that are drag and drop atoms */ |
| 328 | Atom *x_dnd_atoms; | 328 | Atom *x_dnd_atoms; |
| 329 | size_t x_dnd_atoms_size; | 329 | ptrdiff_t x_dnd_atoms_size; |
| 330 | size_t x_dnd_atoms_length; | 330 | ptrdiff_t x_dnd_atoms_length; |
| 331 | 331 | ||
| 332 | /* Extended window manager hints, Atoms supported by the window manager and | 332 | /* Extended window manager hints, Atoms supported by the window manager and |
| 333 | atoms for settig the window type. */ | 333 | atoms for settig the window type. */ |