summaryrefslogtreecommitdiff
path: root/regex.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-09-25 17:51:29 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-09-25 17:51:29 +0000
commit9448424dbaf7c999a9c5cfe134a35f118f3a2fea (patch)
treeb1ae1b19dcbccfc780d71b22f146cc6079ab95cd /regex.c
parentba2b829a0f154624b1b315b98de01274343b4336 (diff)
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@973 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'regex.c')
-rw-r--r--regex.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/regex.c b/regex.c
index 61bc7253a9..2b2b842b89 100644
--- a/regex.c
+++ b/regex.c
@@ -62,6 +62,8 @@
#endif
#ifdef RUBY_PLATFORM
+#include "defines.h"
+
# define RUBY
extern int rb_prohibit_interrupt;
extern int rb_trap_pending;
@@ -128,11 +130,25 @@ char *alloca();
#define FREE_VARIABLES()
-#define FREE_AND_RETURN_VOID(stackb) do { xfree(stackb); return; } while(0)
-#define FREE_AND_RETURN(stackb,val) do { xfree(stackb); return(val); } while(0)
+#define FREE_AND_RETURN_VOID(stackb) do { \
+ if (stackb != stacka) xfree(stackb); \
+ return; \
+} while(0)
+
+#define FREE_AND_RETURN(stackb,val) do { \
+ if (stackb != stacka) xfree(stackb); \
+ return(val); \
+} while(0)
+
#define DOUBLE_STACK(stackx,stackb,len,type) do { \
- stackx = (type*)xrealloc(stackb, 2 * len * sizeof(type)); \
+ if (stackb == stacka) { \
+ stackx = (type*)xmalloc(2*len*sizeof(type)); \
+ } \
+ else { \
+ stackx = (type*)xrealloc(stackb, 2 * len * sizeof(type)); \
+ } \
} while (0)
+
#endif /* NO_ALLOCA */
#define RE_TALLOC(n,t) ((t*)RE_ALLOCATE((n)*sizeof(t)))
@@ -1245,7 +1261,8 @@ re_compile_pattern(pattern, size, bufp)
Fourth, the value of regnum.
Fifth, the type of the paren. */
- int *stackb = RE_TALLOC(40, int);
+ int stacka[40];
+ int *stackb = stacka;
int *stackp = stackb;
int *stacke = stackb + 40;
int *stackt;
@@ -2752,7 +2769,9 @@ re_compile_fastmap(bufp)
register int j, k;
unsigned is_a_succeed_n;
- unsigned char **stackb = RE_TALLOC(NFAILURES, unsigned char*);
+
+ unsigned char *stacka[NFAILURES];
+ unsigned char **stackb = stacka;
unsigned char **stackp = stackb;
unsigned char **stacke = stackb + NFAILURES;
int options = bufp->options;
@@ -3545,11 +3564,11 @@ re_match(bufp, string_arg, size, pos, regs)
``dummy''; if a failure happens and the failure point is a dummy, it
gets discarded and the next next one is tried. */
+ unsigned char *stacka[MAX_NUM_FAILURE_ITEMS * NFAILURES];
unsigned char **stackb;
unsigned char **stackp;
unsigned char **stacke;
-
/* Information on the contents of registers. These are pointers into
the input strings; they record just what was matched (on this
attempt) by a subexpression part of the pattern, that is, the
@@ -3594,7 +3613,7 @@ re_match(bufp, string_arg, size, pos, regs)
}
/* Initialize the stack. */
- stackb = RE_TALLOC(MAX_NUM_FAILURE_ITEMS * NFAILURES, unsigned char*);
+ stackb = stacka;
stackp = stackb;
stacke = &stackb[MAX_NUM_FAILURE_ITEMS * NFAILURES];