mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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@18212 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e2ec68e53a
commit
6e45597cfe
2 changed files with 43 additions and 10 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
Fri Jul 25 19:45:42 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.
|
||||||
|
|
||||||
Fri Jul 25 18:04:17 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Fri Jul 25 18:04:17 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* bignum.c (rb_big2str0, bigsqr): made interruptible. [ruby-Bugs-20622]
|
* bignum.c (rb_big2str0, bigsqr): made interruptible. [ruby-Bugs-20622]
|
||||||
|
|
46
regex.c
46
regex.c
|
@ -50,6 +50,9 @@
|
||||||
/* We need this for `regex.h', and perhaps for the Emacs include files. */
|
/* We need this for `regex.h', and perhaps for the Emacs include files. */
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_STDLIB_H
|
||||||
|
# include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !defined(__STDC__) && !defined(_MSC_VER)
|
#if !defined(__STDC__) && !defined(_MSC_VER)
|
||||||
# define volatile
|
# define volatile
|
||||||
|
@ -63,6 +66,10 @@
|
||||||
|
|
||||||
#ifdef RUBY_PLATFORM
|
#ifdef RUBY_PLATFORM
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
#undef xmalloc
|
||||||
|
#undef xrealloc
|
||||||
|
#undef xcalloc
|
||||||
|
#undef xfree
|
||||||
|
|
||||||
# define RUBY
|
# define RUBY
|
||||||
extern int rb_prohibit_interrupt;
|
extern int rb_prohibit_interrupt;
|
||||||
|
@ -104,6 +111,11 @@ void *alloca ();
|
||||||
# include <strings.h>
|
# include <strings.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define xmalloc malloc
|
||||||
|
#define xrealloc realloc
|
||||||
|
#define xcalloc calloc
|
||||||
|
#define xfree free
|
||||||
|
|
||||||
#ifdef C_ALLOCA
|
#ifdef C_ALLOCA
|
||||||
#define FREE_VARIABLES() alloca(0)
|
#define FREE_VARIABLES() alloca(0)
|
||||||
#else
|
#else
|
||||||
|
@ -127,10 +139,12 @@ void *alloca ();
|
||||||
unsigned int xlen = stacke - stackb; \
|
unsigned int xlen = stacke - stackb; \
|
||||||
if (stackb == stacka) { \
|
if (stackb == stacka) { \
|
||||||
stackx = (type*)xmalloc(2 * xlen * sizeof(type)); \
|
stackx = (type*)xmalloc(2 * xlen * sizeof(type)); \
|
||||||
|
if (!stackx) goto memory_exhausted; \
|
||||||
memcpy(stackx, stackb, xlen * sizeof (type)); \
|
memcpy(stackx, stackb, xlen * sizeof (type)); \
|
||||||
} \
|
} \
|
||||||
else { \
|
else { \
|
||||||
stackx = (type*)xrealloc(stackb, 2 * xlen * sizeof(type)); \
|
stackx = (type*)xrealloc(stackb, 2 * xlen * sizeof(type)); \
|
||||||
|
if (!stackx) goto memory_exhausted; \
|
||||||
} \
|
} \
|
||||||
/* Rearrange the pointers. */ \
|
/* Rearrange the pointers. */ \
|
||||||
stackp = stackx + (stackp - stackb); \
|
stackp = stackx + (stackp - stackb); \
|
||||||
|
@ -2775,8 +2789,8 @@ bm_search(little, llen, big, blen, skip, translate)
|
||||||
The caller must supply the address of a (1 << BYTEWIDTH)-byte data
|
The caller must supply the address of a (1 << BYTEWIDTH)-byte data
|
||||||
area as bufp->fastmap.
|
area as bufp->fastmap.
|
||||||
The other components of bufp describe the pattern to be used. */
|
The other components of bufp describe the pattern to be used. */
|
||||||
void
|
static int
|
||||||
re_compile_fastmap(bufp)
|
re_compile_fastmap0(bufp)
|
||||||
struct re_pattern_buffer *bufp;
|
struct re_pattern_buffer *bufp;
|
||||||
{
|
{
|
||||||
unsigned char *pattern = (unsigned char*)bufp->buffer;
|
unsigned char *pattern = (unsigned char*)bufp->buffer;
|
||||||
|
@ -2944,7 +2958,7 @@ re_compile_fastmap(bufp)
|
||||||
fastmap[j] = 1;
|
fastmap[j] = 1;
|
||||||
}
|
}
|
||||||
if (bufp->can_be_null) {
|
if (bufp->can_be_null) {
|
||||||
FREE_AND_RETURN_VOID(stackb);
|
FREE_AND_RETURN(stackb, 0);
|
||||||
}
|
}
|
||||||
/* Don't return; check the alternative paths
|
/* Don't return; check the alternative paths
|
||||||
so we can set can_be_null if appropriate. */
|
so we can set can_be_null if appropriate. */
|
||||||
|
@ -3110,7 +3124,16 @@ re_compile_fastmap(bufp)
|
||||||
else
|
else
|
||||||
break;
|
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. */
|
/* adjust startpos value to the position between characters. */
|
||||||
|
@ -3144,7 +3167,8 @@ re_adjust_startpos(bufp, string, size, startpos, range)
|
||||||
{
|
{
|
||||||
/* Update the fastmap now if not correct already. */
|
/* Update the fastmap now if not correct already. */
|
||||||
if (!bufp->fastmap_accurate) {
|
if (!bufp->fastmap_accurate) {
|
||||||
re_compile_fastmap(bufp);
|
int ret = re_compile_fastmap0(bufp);
|
||||||
|
if (ret) return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Adjust startpos for mbc string */
|
/* Adjust startpos for mbc string */
|
||||||
|
@ -3190,7 +3214,8 @@ re_search(bufp, string, size, startpos, range, regs)
|
||||||
|
|
||||||
/* Update the fastmap now if not correct already. */
|
/* Update the fastmap now if not correct already. */
|
||||||
if (fastmap && !bufp->fastmap_accurate) {
|
if (fastmap && !bufp->fastmap_accurate) {
|
||||||
re_compile_fastmap(bufp);
|
int ret = re_compile_fastmap0(bufp);
|
||||||
|
if (ret) return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3580,7 +3605,7 @@ re_match_exec(bufp, string_arg, size, pos, beg, regs)
|
||||||
``dummy''; if a failure happens and the failure point is a dummy, it
|
``dummy''; if a failure happens and the failure point is a dummy, it
|
||||||
gets discarded and the next next one is tried. */
|
gets discarded and the next next one is tried. */
|
||||||
|
|
||||||
unsigned char **stacka;
|
unsigned char **const stacka = 0;
|
||||||
unsigned char **stackb;
|
unsigned char **stackb;
|
||||||
unsigned char **stackp;
|
unsigned char **stackp;
|
||||||
unsigned char **stacke;
|
unsigned char **stacke;
|
||||||
|
@ -3629,8 +3654,7 @@ re_match_exec(bufp, string_arg, size, pos, beg, regs)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize the stack. */
|
/* Initialize the stack. */
|
||||||
stacka = RE_TALLOC(MAX_NUM_FAILURE_ITEMS * NFAILURES, unsigned char*);
|
stackb = TMALLOC(MAX_NUM_FAILURE_ITEMS * NFAILURES, unsigned char*);
|
||||||
stackb = stacka;
|
|
||||||
stackp = stackb;
|
stackp = stackb;
|
||||||
stacke = &stackb[MAX_NUM_FAILURE_ITEMS * NFAILURES];
|
stacke = &stackb[MAX_NUM_FAILURE_ITEMS * NFAILURES];
|
||||||
|
|
||||||
|
@ -4400,6 +4424,8 @@ re_match_exec(bufp, string_arg, size, pos, beg, regs)
|
||||||
goto restore_best_regs;
|
goto restore_best_regs;
|
||||||
|
|
||||||
FREE_AND_RETURN(stackb,(-1)); /* Failure to match. */
|
FREE_AND_RETURN(stackb,(-1)); /* Failure to match. */
|
||||||
|
memory_exhausted:
|
||||||
|
FREE_AND_RETURN(stackb,(-2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4663,5 +4689,5 @@ utf8_startpos(string, pos)
|
||||||
mode : C
|
mode : C
|
||||||
c-file-style : "gnu"
|
c-file-style : "gnu"
|
||||||
tab-width : 8
|
tab-width : 8
|
||||||
End :
|
End
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue