1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

marshal/reg_clone

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@277 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 1998-07-24 04:32:31 +00:00
parent 3af58a0a57
commit 0d30af8fd2
5 changed files with 57 additions and 29 deletions

View file

@ -1,3 +1,13 @@
Fri Jul 24 02:10:22 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
* marshal.c (r_bytes2): allocated buffer size was too short.
* marshal.c (w_object): saves all options, not only casefold flag.
* re.c (reg_clone): now copies options properly.
* re.c (reg_get_kcode): code number was wrong.
Wed Jul 22 11:59:59 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
* st.c (rehash): still had a GC problem. fixed.

View file

@ -221,6 +221,7 @@ VALUE reg_match_last _((VALUE));
VALUE reg_new _((char*, int, int));
VALUE reg_match _((VALUE, VALUE));
VALUE reg_match2 _((VALUE));
int reg_options _((VALUE));
char*rb_get_kcode _((void));
void rb_set_kcode _((char*));
/* ruby.c */

View file

@ -299,7 +299,7 @@ w_object(obj, arg, limit)
w_uclass(obj, cRegexp, arg);
w_byte(TYPE_REGEXP, arg);
w_bytes(RREGEXP(obj)->str, RREGEXP(obj)->len, arg);
w_byte(FL_TEST(obj, FL_USER1), arg);
w_byte(reg_options(obj), arg);
return;
case T_ARRAY:
@ -511,13 +511,20 @@ r_long(arg)
return x;
}
static long blen; /* hidden length register */
#define r_bytes(s, arg) \
(blen = r_long(arg), r_bytes0(&s,ALLOCA_N(char,blen),blen,arg))
#define r_bytes2(s, len, arg) do { \
(len) = r_long(arg); \
(s) = ALLOCA_N(char,(len)+1); \
r_bytes0((s),(len),(arg)); \
} while (0)
static int
r_bytes0(sp, s, len, arg)
char **sp, *s;
#define r_bytes(s, arg) do { \
int r_bytes_len; \
r_bytes2((s), r_bytes_len, (arg)); \
} while (0)
static void
r_bytes0(s, len, arg)
char *s;
int len;
struct load_arg *arg;
{
@ -531,11 +538,7 @@ r_bytes0(sp, s, len, arg)
memcpy(s, arg->ptr, len);
arg->ptr += len;
}
(s)[len] = '\0';
*sp = s;
return len;
s[len] = '\0';
}
static ID
@ -572,8 +575,9 @@ r_string(arg)
struct load_arg *arg;
{
char *buf;
int len = r_bytes(buf, arg);
int len;
r_bytes2(buf, len, arg);
return str_taint(str_new(buf, len));
}
@ -672,9 +676,12 @@ r_object(arg)
case TYPE_REGEXP:
{
char *buf;
int len = r_bytes(buf, arg);
int ci = r_byte(arg);
return r_regist(reg_new(buf, len, ci), arg);
int len;
int options;
r_bytes2(buf, len, arg);
options = r_byte(arg);
return r_regist(reg_new(buf, len, options), arg);
}
case TYPE_ARRAY:

34
re.c
View file

@ -664,11 +664,11 @@ reg_new_1(klass, s, len, options)
}
VALUE
reg_new(s, len, flag)
reg_new(s, len, options)
char *s;
int len, flag;
int len, options;
{
return reg_new_1(cRegexp, s, len, flag);
return reg_new_1(cRegexp, s, len, options);
}
static int ign_cache;
@ -838,11 +838,11 @@ reg_get_kcode(re)
switch (RBASIC(re)->flags & KCODE_MASK) {
case KCODE_NONE:
kcode |= 2; break;
case KCODE_EUC:
kcode |= 4; break;
case KCODE_EUC:
kcode |= 8; break;
case KCODE_SJIS:
kcode |= 6; break;
kcode |= 12; break;
default:
break;
}
@ -850,16 +850,26 @@ reg_get_kcode(re)
return kcode;
}
int
reg_options(re)
VALUE re;
{
int options = 0;
if (FL_TEST(re, REG_IGNORECASE))
options |= RE_OPTION_IGNORECASE;
if (FL_TEST(re, KCODE_FIXED)) {
options |= reg_get_kcode(re);
}
return options;
}
static VALUE
reg_clone(re)
VALUE re;
{
int flag = FL_TEST(re, REG_IGNORECASE)?1:0;
if (FL_TEST(re, KCODE_FIXED)) {
flag |= reg_get_kcode(re);
}
return reg_new_1(CLASS_OF(re), RREGEXP(re)->str, RREGEXP(re)->len, flag);
return reg_new_1(CLASS_OF(re), RREGEXP(re)->str, RREGEXP(re)->len,
reg_options(re));
}
VALUE

View file

@ -337,7 +337,7 @@ f_sprintf(argc, argv)
case 'b':
case 'u':
default:
if (flags & FPLUS) sign = 1;
if (flags&(FPLUS|FSPACE)) sign = 1;
break;
}
if (flags & FSHARP) {