[Update] Port match to new dup, clone framework

From: Michal Rokos <m.rokos@...>
Date: 2002-08-28 14:42:53 UTC
List: ruby-core #382
Hi,

	I spotted that match (in re.c) is not updated to new clone, dup
	framework.

	This should fix it. :-) (I said should, but I know that nobu
	will find at least 1 bug in it... :-))

		Michal


Index: re.c
===================================================================
RCS file: /src/ruby/re.c,v
retrieving revision 1.77
diff -u -p -r1.77 re.c
--- re.c	2002/08/28 08:05:23	1.77
+++ re.c	2002/08/28 13:51:27
@@ -514,10 +514,11 @@ make_regexp(s, len, flags)
 static VALUE rb_cMatch;
 
 static VALUE
-match_alloc()
+match_alloc(klass)
+    VALUE klass;
 {
     NEWOBJ(match, struct RMatch);
-    OBJSETUP(match, rb_cMatch, T_MATCH);
+    OBJSETUP(match, klass, T_MATCH);
 
     match->str = 0;
     match->regs = 0;
@@ -528,40 +529,17 @@ match_alloc()
 }
 
 static VALUE
-match_clone(match)
-    VALUE match;
+match_become(obj, orig)
+    VALUE obj, orig;
 {
-    NEWOBJ(clone, struct RMatch);
-    CLONESETUP(clone, match);
-
-    clone->str = RMATCH(match)->str;
-    clone->regs = 0;
-
-    clone->regs = ALLOC(struct re_registers);
-    clone->regs->allocated = 0;
-    re_copy_registers(clone->regs, RMATCH(match)->regs);
+    RMATCH(obj)->str = RMATCH(orig)->str;
+    RMATCH(obj)->regs->allocated = 0;
+    re_copy_registers(RMATCH(obj)->regs, RMATCH(orig)->regs);
 
-    return (VALUE)clone;
+    return obj;
 }
 
 static VALUE
-match_dup(match)
-    VALUE match;
-{
-    NEWOBJ(dup, struct RMatch);
-    DUPSETUP(dup, match);
-
-    dup->str = RMATCH(match)->str;
-    dup->regs = 0;
-
-    dup->regs = ALLOC(struct re_registers);
-    dup->regs->allocated = 0;
-    re_copy_registers(dup->regs, RMATCH(match)->regs);
-
-    return (VALUE)dup;
-}
-
-static VALUE
 match_size(match)
     VALUE match;
 {
@@ -741,7 +719,7 @@ rb_reg_search(re, str, pos, reverse)
 
     match = rb_backref_get();
     if (NIL_P(match) || FL_TEST(match, MATCH_BUSY)) {
-	match = match_alloc();
+	match = match_alloc(rb_obj_class(re));
     }
     else {
 	if (rb_safe_level() >= 3) 
@@ -1601,13 +1579,10 @@ Init_Regexp()
 
     rb_cMatch  = rb_define_class("MatchData", rb_cObject);
     rb_define_global_const("MatchingData", rb_cMatch);
-    rb_undef_method(CLASS_OF(rb_cMatch), "allocate");
+    rb_define_singleton_method(rb_cMatch, "allocate", match_alloc, 0);
     rb_undef_method(CLASS_OF(rb_cMatch), "new");
-
-    /* to be replaced by allocation framework */
-    rb_define_method(rb_cMatch, "clone", match_clone, 0);
-    rb_define_method(rb_cMatch, "dup", match_dup, 0);
 
+    rb_define_method(rb_cMatch, "become", match_become, 1);
     rb_define_method(rb_cMatch, "size", match_size, 0);
     rb_define_method(rb_cMatch, "length", match_size, 0);
     rb_define_method(rb_cMatch, "offset", match_offset, 1);

-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Michal Rokos                         Czech Technical University, Prague
E-mail:m.rokos@sh.cvut.cz      ICQ:36118339      Jabber:majkl@jabber.cz
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

In This Thread

Prev Next