* regex.c (EXTEND_BUFFER): Adjust pointers within buffer by

computing their offset from the start of the old buffer and adding
	to the new buffer, rather than by assuming we can add the
	difference between the old buffer and the new buffer (it might not
	fit in an int).  Merge in cosmetic differences from emacs regex.c
	version of this macro.
This commit is contained in:
Jim Kingdon 1994-03-18 18:34:36 +00:00
parent 60e9faebc1
commit ee6d646a4b
2 changed files with 43 additions and 17 deletions

View File

@ -1,3 +1,12 @@
Fri Mar 18 10:25:55 1994 Jim Kingdon (kingdon@lioth.cygnus.com)
* regex.c (EXTEND_BUFFER): Adjust pointers within buffer by
computing their offset from the start of the old buffer and adding
to the new buffer, rather than by assuming we can add the
difference between the old buffer and the new buffer (it might not
fit in an int). Merge in cosmetic differences from emacs regex.c
version of this macro.
Wed Mar 16 15:28:54 1994 Ian Lance Taylor (ian@tweedledumb.cygnus.com) Wed Mar 16 15:28:54 1994 Ian Lance Taylor (ian@tweedledumb.cygnus.com)
* Makefile.in (install-only): Fix use of program_transform_name. * Makefile.in (install-only): Fix use of program_transform_name.

View File

@ -146,23 +146,40 @@ re_set_syntax (syntax)
#define PATUNFETCH p-- #define PATUNFETCH p--
#define EXTEND_BUFFER \ /* This is not an arbitrary limit: the arguments which represent offsets
{ char *old_buffer = bufp->buffer; \ into the pattern are two bytes long. So if 2^16 bytes turns out to
if (bufp->allocated == (1<<16)) goto too_big; \ be too small, many things would have to change. */
bufp->allocated *= 2; \ #define MAX_BUF_SIZE (1 << 16)
if (bufp->allocated > (1<<16)) bufp->allocated = (1<<16); \
if (!(bufp->buffer = (char *) realloc (bufp->buffer, bufp->allocated))) \
goto memory_exhausted; \ /* Extend the buffer by twice its current size via realloc and
c = bufp->buffer - old_buffer; \ reset the pointers that pointed into the old block to point to the
b += c; \ correct places in the new one. If extending the buffer results in it
if (fixup_jump) \ being larger than MAX_BUF_SIZE, then flag memory exhausted. */
fixup_jump += c; \ #define EXTEND_BUFFER \
if (laststart) \ do { \
laststart += c; \ char *old_buffer = bufp->buffer; \
begalt += c; \ if (bufp->allocated == MAX_BUF_SIZE) \
if (pending_exact) \ goto too_big; \
pending_exact += c; \ bufp->allocated <<= 1; \
} if (bufp->allocated > MAX_BUF_SIZE) \
bufp->allocated = MAX_BUF_SIZE; \
bufp->buffer = (char *) realloc (bufp->buffer, bufp->allocated);\
if (bufp->buffer == NULL) \
goto memory_exhausted; \
/* If the buffer moved, move all the pointers into it. */ \
if (old_buffer != bufp->buffer) \
{ \
b = (b - old_buffer) + bufp->buffer; \
begalt = (begalt - old_buffer) + bufp->buffer; \
if (fixup_jump) \
fixup_jump = (fixup_jump - old_buffer) + bufp->buffer;\
if (laststart) \
laststart = (laststart - old_buffer) + bufp->buffer; \
if (pending_exact) \
pending_exact = (pending_exact - old_buffer) + bufp->buffer; \
} \
} while (0)
static void store_jump (), insert_jump (); static void store_jump (), insert_jump ();