diff options
Diffstat (limited to 'generic/regguts.h')
| -rw-r--r-- | generic/regguts.h | 83 | 
1 files changed, 43 insertions, 40 deletions
| diff --git a/generic/regguts.h b/generic/regguts.h index 190d40b..b478e4c 100644 --- a/generic/regguts.h +++ b/generic/regguts.h @@ -39,15 +39,6 @@   * Things that regcustom.h might override.   */ -/* standard header files (NULL is a reasonable indicator for them) */ -#ifndef NULL -#include <stdio.h> -#include <stdlib.h> -#include <ctype.h> -#include <limits.h> -#include <string.h> -#endif -  /* assertions */  #ifndef assert  #ifndef REG_DEBUG @@ -60,24 +51,19 @@  /* voids */  #ifndef VOID -#define	VOID	void			/* for function return values */ +#define	VOID	void		/* for function return values */  #endif  #ifndef DISCARD -#define	DISCARD	void			/* for throwing values away */ +#define	DISCARD	void		/* for throwing values away */  #endif  #ifndef PVOID -#define	PVOID	void *			/* generic pointer */ +#define	PVOID	void *		/* generic pointer */  #endif  #ifndef VS -#define	VS(x)	((void*)(x))		/* cast something to generic ptr */ +#define	VS(x)	((void*)(x))	/* cast something to generic ptr */  #endif  #ifndef NOPARMS -#define	NOPARMS	void			/* for empty parm lists */ -#endif - -/* const */ -#ifndef CONST -#define	CONST	const			/* for old compilers, might be empty */ +#define	NOPARMS	void		/* for empty parm lists */  #endif  /* function-pointer declarator */ @@ -101,11 +87,8 @@  #endif  /* want size of a char in bits, and max value in bounded quantifiers */ -#ifndef CHAR_BIT -#include <limits.h> -#endif  #ifndef _POSIX2_RE_DUP_MAX -#define	_POSIX2_RE_DUP_MAX	255	/* normally from <limits.h> */ +#define	_POSIX2_RE_DUP_MAX 255	/* normally from <limits.h> */  #endif  /* @@ -162,6 +145,7 @@  typedef short color;		/* colors of characters */  typedef int pcolor;		/* what color promotes to */ +#define MAX_COLOR	SHRT_MAX /* max color value */  #define	COLORLESS	(-1)	/* impossible color */  #define	WHITE		0	/* default color, parent of all others */ @@ -189,7 +173,7 @@ union tree {  #define	tcolor	colors.ccolor  #define	tptr	ptrs.pptr -/* internal per-color structure for the color machinery */ +/* Internal per-color descriptor structure for the color machinery */  struct colordesc {      uchr nchrs;			/* number of chars of this color */      color sub;			/* open subcolor (if any); free chain ptr */ @@ -235,9 +219,9 @@ struct colormap {  /*   * Interface definitions for locale-interface functions in locale.c. - * Multi-character collating elements (MCCEs) cause most of the trouble.   */ +/* Representation of a set of characters. */  struct cvec {      int nchrs;			/* number of chrs */      int chrspace;		/* number of chrs possible */ @@ -245,18 +229,11 @@ struct cvec {      int nranges;		/* number of ranges (chr pairs) */      int rangespace;		/* number of chrs possible */      chr *ranges;		/* pointer to vector of chr pairs */ -    int nmcces;			/* number of MCCEs */ -    int mccespace;		/* number of MCCEs possible */ -    int nmccechrs;		/* number of chrs used for MCCEs */ -    chr *mcces[1];		/* pointers to 0-terminated MCCEs */ -				/* and both batches of chrs are on the end */  }; -/* caution:  this value cannot be changed easily */ -#define	MAXMCCE	2		/* length of longest MCCE */ -  /* - * definitions for NFA internal representation + * definitions for non-deterministic finite autmaton (NFA) internal + * representation   *   * Having a "from" pointer within each arc may seem redundant, but it saves a   * lot of hassle. @@ -274,6 +251,7 @@ struct arc {  #define	freechain	outchain      struct arc *inchain;	/* *to's ins chain */      struct arc *colorchain;	/* color's arc chain */ +    struct arc *colorchainRev;	/* back-link in color's arc chain */  };  struct arcbatch {		/* for bulk allocation of arcs */ @@ -284,7 +262,7 @@ struct arcbatch {		/* for bulk allocation of arcs */  struct state {      int no; -#		define	FREESTATE	(-1) +#define	FREESTATE	(-1)      char flag;			/* marks special states */      int nins;			/* number of inarcs */      struct arc *ins;		/* chain of inarcs */ @@ -310,6 +288,9 @@ struct nfa {      struct colormap *cm;	/* the color map */      color bos[2];		/* colors, if any, assigned to BOS and BOL */      color eos[2];		/* colors, if any, assigned to EOS and EOL */ +    size_t size;		/* Current NFA size; differs from nstates as +				 * it also counts the number of states created +				 * by children of this state. */      struct vars *v;		/* simplifies compile error reporting */      struct nfa *parent;		/* parent NFA, if any */  }; @@ -339,6 +320,14 @@ struct cnfa {  #define	NULLCNFA(cnfa)	((cnfa).nstates == 0)  /* + * Used to limit the maximum NFA size to something sane. [Bug 1810264] + */ + +#ifndef REG_MAX_STATES +#   define REG_MAX_STATES	100000 +#endif + +/*   * subexpression tree   */ @@ -352,12 +341,12 @@ struct subre {  #define	CAP	010		/* capturing parens below */  #define	BACKR	020		/* back reference below */  #define	INUSE	0100		/* in use in final tree */ -#define	LOCAL	03		/* bits which may not propagate up */ +#define	NOPROP	03		/* bits which may not propagate up */  #define	LMIX(f)	((f)<<2)	/* LONGER -> MIXED */  #define	SMIX(f)	((f)<<1)	/* SHORTER -> MIXED */ -#define	UP(f)	(((f)&~LOCAL) | (LMIX(f) & SMIX(f) & MIXED)) +#define	UP(f)	(((f)&~NOPROP) | (LMIX(f) & SMIX(f) & MIXED))  #define	MESSY(f)	((f)&(MIXED|CAP|BACKR)) -#define	PREF(f)	((f)&LOCAL) +#define	PREF(f)	((f)&NOPROP)  #define	PREF2(f1, f2)	((PREF(f1) != 0) ? PREF(f1) : PREF(f2))  #define	COMBINE(f1, f2)	(UP((f1)|(f2)) | PREF2(f1, f2))      short retry;		/* index into retry memory */ @@ -378,7 +367,7 @@ struct subre {   */  struct fns { -    VOID FUNCPTR(free, (regex_t *)); +    void FUNCPTR(free, (regex_t *));  };  /* @@ -395,10 +384,24 @@ struct guts {      struct cnfa search;		/* for fast preliminary search */      int ntree;      struct colormap cmap; -    int FUNCPTR(compare, (CONST chr *, CONST chr *, size_t)); +    int FUNCPTR(compare, (const chr *, const chr *, size_t));      struct subre *lacons;	/* lookahead-constraint vector */      int nlacons;		/* size of lacons */  }; + +/* + * Magic for allocating a variable workspace. This default version is + * stack-hungry. + */ + +#ifndef AllocVars +#define AllocVars(vPtr) \ +    struct vars var; \ +    register struct vars *vPtr = &var +#endif +#ifndef FreeVars +#define FreeVars(vPtr) ((void) 0) +#endif  /*   * Local Variables: | 
