From af1d7677299425547ec39d20810890333a9970a7 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 14 Jul 2011 09:20:47 -0700 Subject: [PATCH] * src/bidi.c: Hold off on these changes for now. See . --- src/ChangeLog | 13 ------------- src/bidi.c | 31 ++++++++++++++----------------- 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index e0de5edda9c..0977b12ab38 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -31,8 +31,6 @@ * image.c (png_load): Don't assume height * row_bytes fits in 'int'. - * bidi.c (bidi_dump_cached_states): Use pD to print ptrdiff_t. - * xfaces.c (Fbitmap_spec_p): Fix integer overflow bug. Without this fix, (bitmap-spec-p '(34359738368 1 "x")) would wrongly return t on a 64-bit host. @@ -116,17 +114,6 @@ Use ptrdiff_t rather than size_t when either will do, as we prefer signed integers. - * bidi.c: Integer signedness and overflow fixes. - (bidi_cache_idx, bidi_cache_last_idx, bidi_cache_fetch_state) - (bidi_cache_search, bidi_cache_find_level_change) - (bidi_cache_iterator_state, bidi_cache_find) - (bidi_find_other_level_edge, bidi_dump_cached_states): - Don't arbitrarily limit cache indexes to int; use ptrdiff_t instead. - (bidi_cache_size): Use ptrdiff_t rather than size_t, as we prefer - signed integers. - (elsz): Make it a (signed) constant. - (bidi_cache_iterator_state): Check for size-calculation overflow. - * alloc.c: Integer signedness and overflow fixes. Do not impose an arbitrary 32-bit limit on malloc sizes when debugging. (__malloc_size_t): Default to size_t, not to int. diff --git a/src/bidi.c b/src/bidi.c index 2662ee3d845..469afdb3819 100644 --- a/src/bidi.c +++ b/src/bidi.c @@ -263,10 +263,10 @@ bidi_copy_it (struct bidi_it *to, struct bidi_it *from) #define BIDI_CACHE_CHUNK 200 static struct bidi_it *bidi_cache; -static ptrdiff_t bidi_cache_size = 0; -enum { elsz = sizeof (struct bidi_it) }; -static ptrdiff_t bidi_cache_idx; /* next unused cache slot */ -static ptrdiff_t bidi_cache_last_idx; /* slot of last cache hit */ +static size_t bidi_cache_size = 0; +static size_t elsz = sizeof (struct bidi_it); +static int bidi_cache_idx; /* next unused cache slot */ +static int bidi_cache_last_idx; /* slot of last cache hit */ static inline void bidi_cache_reset (void) @@ -288,7 +288,7 @@ bidi_cache_shrink (void) } static inline void -bidi_cache_fetch_state (ptrdiff_t idx, struct bidi_it *bidi_it) +bidi_cache_fetch_state (int idx, struct bidi_it *bidi_it) { int current_scan_dir = bidi_it->scan_dir; @@ -304,10 +304,10 @@ bidi_cache_fetch_state (ptrdiff_t idx, struct bidi_it *bidi_it) level less or equal to LEVEL. if LEVEL is -1, disregard the resolved levels in cached states. DIR, if non-zero, means search in that direction from the last cache hit. */ -static inline ptrdiff_t +static inline int bidi_cache_search (EMACS_INT charpos, int level, int dir) { - ptrdiff_t i, i_start; + int i, i_start; if (bidi_cache_idx) { @@ -366,12 +366,12 @@ bidi_cache_search (EMACS_INT charpos, int level, int dir) C, searching backwards (DIR = -1) for LEVEL = 2 will return the index of slot B or A, depending whether BEFORE is, respectively, non-zero or zero. */ -static ptrdiff_t +static int bidi_cache_find_level_change (int level, int dir, int before) { if (bidi_cache_idx) { - ptrdiff_t i = dir ? bidi_cache_last_idx : bidi_cache_idx - 1; + int i = dir ? bidi_cache_last_idx : bidi_cache_idx - 1; int incr = before ? 1 : 0; if (!dir) @@ -407,7 +407,7 @@ bidi_cache_find_level_change (int level, int dir, int before) static inline void bidi_cache_iterator_state (struct bidi_it *bidi_it, int resolved) { - ptrdiff_t idx; + int idx; /* We should never cache on backward scans. */ if (bidi_it->scan_dir == -1) @@ -420,9 +420,6 @@ bidi_cache_iterator_state (struct bidi_it *bidi_it, int resolved) /* Enlarge the cache as needed. */ if (idx >= bidi_cache_size) { - if (min (PTRDIFF_MAX, SIZE_MAX) / elsz - BIDI_CACHE_CHUNK - < bidi_cache_size) - memory_full (SIZE_MAX); bidi_cache_size += BIDI_CACHE_CHUNK; bidi_cache = (struct bidi_it *) xrealloc (bidi_cache, bidi_cache_size * elsz); @@ -471,7 +468,7 @@ bidi_cache_iterator_state (struct bidi_it *bidi_it, int resolved) static inline bidi_type_t bidi_cache_find (EMACS_INT charpos, int level, struct bidi_it *bidi_it) { - ptrdiff_t i = bidi_cache_search (charpos, level, bidi_it->scan_dir); + int i = bidi_cache_search (charpos, level, bidi_it->scan_dir); if (i >= 0) { @@ -1759,7 +1756,7 @@ static void bidi_find_other_level_edge (struct bidi_it *bidi_it, int level, int end_flag) { int dir = end_flag ? -bidi_it->scan_dir : bidi_it->scan_dir; - ptrdiff_t idx; + int idx; /* Try the cache first. */ if ((idx = bidi_cache_find_level_change (level, dir, end_flag)) >= 0) @@ -1915,7 +1912,7 @@ void bidi_dump_cached_states (void) EXTERNALLY_VISIBLE; void bidi_dump_cached_states (void) { - ptrdiff_t i; + int i; int ndigits = 1; if (bidi_cache_idx == 0) @@ -1923,7 +1920,7 @@ bidi_dump_cached_states (void) fprintf (stderr, "The cache is empty.\n"); return; } - fprintf (stderr, "Total of %"pD"d state%s in cache:\n", + fprintf (stderr, "Total of %d state%s in cache:\n", bidi_cache_idx, bidi_cache_idx == 1 ? "" : "s"); for (i = bidi_cache[bidi_cache_idx - 1].charpos; i > 0; i /= 10) -- 2.39.2