summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-04 05:11:52 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-04 05:11:52 +0000
commiteeaf7dd3c8a85a6806109de393099fbe7d56b549 (patch)
treee3d1bf835c84e55e22967d01340f105c3e89d7a7
parent8f667853a34ca67826eb6b7d76ec1e89a47327ac (diff)
merge revision(s) 18212:
* regex.c (xmalloc, xrealloc, xfree): not to use ruby managed memory. * regex.c (DOUBLE_STACK, re_compile_fastmap0, re_adjust_startpos), (re_search, re_match_exec): check if failed to allocate memory. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_6@18343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--regex.c46
-rw-r--r--version.h2
3 files changed, 44 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index b5dc9e208d..564b3ec399 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Mon Aug 4 14:10:01 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * regex.c (xmalloc, xrealloc, xfree): not to use ruby managed memory.
+
+ * regex.c (DOUBLE_STACK, re_compile_fastmap0, re_adjust_startpos),
+ (re_search, re_match_exec): check if failed to allocate memory.
+
Mon Aug 4 13:49:36 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* bignum.c (rb_big2str0, bigsqr): made interruptible. [ruby-Bugs-20622]
diff --git a/regex.c b/regex.c
index 45f7e20738..54f6b4c9a1 100644
--- a/regex.c
+++ b/regex.c
@@ -50,6 +50,9 @@
/* We need this for `regex.h', and perhaps for the Emacs include files. */
# include <sys/types.h>
#endif
+#ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
#if !defined(__STDC__) && !defined(_MSC_VER)
# define volatile
@@ -63,6 +66,10 @@
#ifdef RUBY_PLATFORM
#include "defines.h"
+#undef xmalloc
+#undef xrealloc
+#undef xcalloc
+#undef xfree
# define RUBY
extern int rb_prohibit_interrupt;
@@ -104,6 +111,11 @@ void *alloca ();
# include <strings.h>
#endif
+#define xmalloc malloc
+#define xrealloc realloc
+#define xcalloc calloc
+#define xfree free
+
#ifdef C_ALLOCA
#define FREE_VARIABLES() alloca(0)
#else
@@ -127,10 +139,12 @@ void *alloca ();
unsigned int xlen = stacke - stackb; \
if (stackb == stacka) { \
stackx = (type*)xmalloc(2 * xlen * sizeof(type)); \
+ if (!stackx) goto memory_exhausted; \
memcpy(stackx, stackb, xlen * sizeof (type)); \
} \
else { \
stackx = (type*)xrealloc(stackb, 2 * xlen * sizeof(type)); \
+ if (!stackx) goto memory_exhausted; \
} \
/* Rearrange the pointers. */ \
stackp = stackx + (stackp - stackb); \
@@ -2769,8 +2783,8 @@ bm_search(little, llen, big, blen, skip, translate)
The caller must supply the address of a (1 << BYTEWIDTH)-byte data
area as bufp->fastmap.
The other components of bufp describe the pattern to be used. */
-void
-re_compile_fastmap(bufp)
+static int
+re_compile_fastmap0(bufp)
struct re_pattern_buffer *bufp;
{
unsigned char *pattern = (unsigned char*)bufp->buffer;
@@ -2938,7 +2952,7 @@ re_compile_fastmap(bufp)
fastmap[j] = 1;
}
if (bufp->can_be_null) {
- FREE_AND_RETURN_VOID(stackb);
+ FREE_AND_RETURN(stackb, 0);
}
/* Don't return; check the alternative paths
so we can set can_be_null if appropriate. */
@@ -3104,7 +3118,16 @@ re_compile_fastmap(bufp)
else
break;
}
- FREE_AND_RETURN_VOID(stackb);
+ FREE_AND_RETURN(stackb, 0);
+ memory_exhausted:
+ FREE_AND_RETURN(stackb, -2);
+}
+
+void
+re_compile_fastmap(bufp)
+ struct re_pattern_buffer *bufp;
+{
+ (void)re_compile_fastmap0(bufp);
}
/* adjust startpos value to the position between characters. */
@@ -3138,7 +3161,8 @@ re_adjust_startpos(bufp, string, size, startpos, range)
{
/* Update the fastmap now if not correct already. */
if (!bufp->fastmap_accurate) {
- re_compile_fastmap(bufp);
+ int ret = re_compile_fastmap0(bufp);
+ if (ret) return ret;
}
/* Adjust startpos for mbc string */
@@ -3184,7 +3208,8 @@ re_search(bufp, string, size, startpos, range, regs)
/* Update the fastmap now if not correct already. */
if (fastmap && !bufp->fastmap_accurate) {
- re_compile_fastmap(bufp);
+ int ret = re_compile_fastmap0(bufp);
+ if (ret) return ret;
}
@@ -3574,7 +3599,7 @@ re_match_exec(bufp, string_arg, size, pos, beg, 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;
+ unsigned char **const stacka = 0;
unsigned char **stackb;
unsigned char **stackp;
unsigned char **stacke;
@@ -3623,8 +3648,7 @@ re_match_exec(bufp, string_arg, size, pos, beg, regs)
}
/* Initialize the stack. */
- stacka = RE_TALLOC(MAX_NUM_FAILURE_ITEMS * NFAILURES, unsigned char*);
- stackb = stacka;
+ stackb = TMALLOC(MAX_NUM_FAILURE_ITEMS * NFAILURES, unsigned char*);
stackp = stackb;
stacke = &stackb[MAX_NUM_FAILURE_ITEMS * NFAILURES];
@@ -4394,6 +4418,8 @@ re_match_exec(bufp, string_arg, size, pos, beg, regs)
goto restore_best_regs;
FREE_AND_RETURN(stackb,(-1)); /* Failure to match. */
+ memory_exhausted:
+ FREE_AND_RETURN(stackb,(-2));
}
@@ -4657,5 +4683,5 @@ utf8_startpos(string, pos)
mode : C
c-file-style : "gnu"
tab-width : 8
- End :
+ End
*/
diff --git a/version.h b/version.h
index b5c3c1cafe..1322029d7d 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@
#define RUBY_RELEASE_DATE "2008-08-04"
#define RUBY_VERSION_CODE 186
#define RUBY_RELEASE_CODE 20080804
-#define RUBY_PATCHLEVEL 283
+#define RUBY_PATCHLEVEL 284
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8