diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-07-24 04:32:31 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-07-24 04:32:31 +0000 |
commit | 0d30af8fd2bcfea8cf5dbf87b623c57960ce81bc (patch) | |
tree | 1082583fa79fddd15b1a3ed79d2d2c206d662f45 | |
parent | 3af58a0a57aaea69a6cd622ef14c76e57a06fe84 (diff) |
marshal/reg_clone
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@277 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | intern.h | 1 | ||||
-rw-r--r-- | marshal.c | 39 | ||||
-rw-r--r-- | re.c | 32 | ||||
-rw-r--r-- | sprintf.c | 2 |
5 files changed, 56 insertions, 28 deletions
@@ -1,3 +1,13 @@ +Fri Jul 24 02:10:22 1998 Yukihiro Matsumoto <[email protected]> + + * 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 <[email protected]> * st.c (rehash): still had a GC problem. fixed. @@ -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 */ @@ -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: @@ -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; } -static VALUE -reg_clone(re) +int +reg_options(re) VALUE re; { - int flag = FL_TEST(re, REG_IGNORECASE)?1:0; + int options = 0; + if (FL_TEST(re, REG_IGNORECASE)) + options |= RE_OPTION_IGNORECASE; if (FL_TEST(re, KCODE_FIXED)) { - flag |= reg_get_kcode(re); + options |= reg_get_kcode(re); } - return reg_new_1(CLASS_OF(re), RREGEXP(re)->str, RREGEXP(re)->len, flag); + return options; +} + +static VALUE +reg_clone(re) + VALUE re; +{ + return reg_new_1(CLASS_OF(re), RREGEXP(re)->str, RREGEXP(re)->len, + reg_options(re)); } VALUE @@ -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) { |