Skip to content

Commit 0d30af8

Browse files
author
matz
committed
marshal/reg_clone
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@277 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 3af58a0 commit 0d30af8

File tree

5 files changed

+56
-28
lines changed

5 files changed

+56
-28
lines changed

ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
Fri Jul 24 02:10:22 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
2+
3+
* marshal.c (r_bytes2): allocated buffer size was too short.
4+
5+
* marshal.c (w_object): saves all options, not only casefold flag.
6+
7+
* re.c (reg_clone): now copies options properly.
8+
9+
* re.c (reg_get_kcode): code number was wrong.
10+
111
Wed Jul 22 11:59:59 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
212

313
* st.c (rehash): still had a GC problem. fixed.

intern.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ VALUE reg_match_last _((VALUE));
221221
VALUE reg_new _((char*, int, int));
222222
VALUE reg_match _((VALUE, VALUE));
223223
VALUE reg_match2 _((VALUE));
224+
int reg_options _((VALUE));
224225
char*rb_get_kcode _((void));
225226
void rb_set_kcode _((char*));
226227
/* ruby.c */

marshal.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ w_object(obj, arg, limit)
299299
w_uclass(obj, cRegexp, arg);
300300
w_byte(TYPE_REGEXP, arg);
301301
w_bytes(RREGEXP(obj)->str, RREGEXP(obj)->len, arg);
302-
w_byte(FL_TEST(obj, FL_USER1), arg);
302+
w_byte(reg_options(obj), arg);
303303
return;
304304

305305
case T_ARRAY:
@@ -511,13 +511,20 @@ r_long(arg)
511511
return x;
512512
}
513513

514-
static long blen; /* hidden length register */
515-
#define r_bytes(s, arg) \
516-
(blen = r_long(arg), r_bytes0(&s,ALLOCA_N(char,blen),blen,arg))
514+
#define r_bytes2(s, len, arg) do { \
515+
(len) = r_long(arg); \
516+
(s) = ALLOCA_N(char,(len)+1); \
517+
r_bytes0((s),(len),(arg)); \
518+
} while (0)
517519

518-
static int
519-
r_bytes0(sp, s, len, arg)
520-
char **sp, *s;
520+
#define r_bytes(s, arg) do { \
521+
int r_bytes_len; \
522+
r_bytes2((s), r_bytes_len, (arg)); \
523+
} while (0)
524+
525+
static void
526+
r_bytes0(s, len, arg)
527+
char *s;
521528
int len;
522529
struct load_arg *arg;
523530
{
@@ -531,11 +538,7 @@ r_bytes0(sp, s, len, arg)
531538
memcpy(s, arg->ptr, len);
532539
arg->ptr += len;
533540
}
534-
535-
(s)[len] = '\0';
536-
*sp = s;
537-
538-
return len;
541+
s[len] = '\0';
539542
}
540543

541544
static ID
@@ -572,8 +575,9 @@ r_string(arg)
572575
struct load_arg *arg;
573576
{
574577
char *buf;
575-
int len = r_bytes(buf, arg);
578+
int len;
576579

580+
r_bytes2(buf, len, arg);
577581
return str_taint(str_new(buf, len));
578582
}
579583

@@ -672,9 +676,12 @@ r_object(arg)
672676
case TYPE_REGEXP:
673677
{
674678
char *buf;
675-
int len = r_bytes(buf, arg);
676-
int ci = r_byte(arg);
677-
return r_regist(reg_new(buf, len, ci), arg);
679+
int len;
680+
int options;
681+
682+
r_bytes2(buf, len, arg);
683+
options = r_byte(arg);
684+
return r_regist(reg_new(buf, len, options), arg);
678685
}
679686

680687
case TYPE_ARRAY:

re.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -664,11 +664,11 @@ reg_new_1(klass, s, len, options)
664664
}
665665

666666
VALUE
667-
reg_new(s, len, flag)
667+
reg_new(s, len, options)
668668
char *s;
669-
int len, flag;
669+
int len, options;
670670
{
671-
return reg_new_1(cRegexp, s, len, flag);
671+
return reg_new_1(cRegexp, s, len, options);
672672
}
673673

674674
static int ign_cache;
@@ -838,28 +838,38 @@ reg_get_kcode(re)
838838

839839
switch (RBASIC(re)->flags & KCODE_MASK) {
840840
case KCODE_NONE:
841-
kcode |= 2; break;
842-
case KCODE_EUC:
843841
kcode |= 4; break;
842+
case KCODE_EUC:
843+
kcode |= 8; break;
844844
case KCODE_SJIS:
845-
kcode |= 6; break;
845+
kcode |= 12; break;
846846
default:
847847
break;
848848
}
849849

850850
return kcode;
851851
}
852852

853-
static VALUE
854-
reg_clone(re)
853+
int
854+
reg_options(re)
855855
VALUE re;
856856
{
857-
int flag = FL_TEST(re, REG_IGNORECASE)?1:0;
857+
int options = 0;
858858

859+
if (FL_TEST(re, REG_IGNORECASE))
860+
options |= RE_OPTION_IGNORECASE;
859861
if (FL_TEST(re, KCODE_FIXED)) {
860-
flag |= reg_get_kcode(re);
862+
options |= reg_get_kcode(re);
861863
}
862-
return reg_new_1(CLASS_OF(re), RREGEXP(re)->str, RREGEXP(re)->len, flag);
864+
return options;
865+
}
866+
867+
static VALUE
868+
reg_clone(re)
869+
VALUE re;
870+
{
871+
return reg_new_1(CLASS_OF(re), RREGEXP(re)->str, RREGEXP(re)->len,
872+
reg_options(re));
863873
}
864874

865875
VALUE

sprintf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ f_sprintf(argc, argv)
337337
case 'b':
338338
case 'u':
339339
default:
340-
if (flags & FPLUS) sign = 1;
340+
if (flags&(FPLUS|FSPACE)) sign = 1;
341341
break;
342342
}
343343
if (flags & FSHARP) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy