[前][次][番号順一覧][スレッド一覧]

ruby-changes:4320

From: ko1@a...
Date: Thu, 20 Mar 2008 00:21:39 +0900 (JST)
Subject: [ruby-changes:4320] nobu - Ruby:r15810 (trunk): * io.c (argf_initialize_copy): get rid of segfault.

nobu	2008-03-20 00:21:15 +0900 (Thu, 20 Mar 2008)

  New Revision: 15810

  Modified files:
    trunk/ChangeLog
    trunk/io.c

  Log:
    * io.c (argf_initialize_copy): get rid of segfault.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15810&r2=15809&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/io.c?r1=15810&r2=15809&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 15809)
+++ ChangeLog	(revision 15810)
@@ -1,5 +1,7 @@
-Thu Mar 20 00:13:59 2008  Nobuyoshi Nakada  <nobu@r...>
+Thu Mar 20 00:21:12 2008  Nobuyoshi Nakada  <nobu@r...>
 
+	* io.c (argf_initialize_copy): get rid of segfault.
+
 	* io.c (argf_tell, argf_seek_m, argf_set_pos, argf_rewind,
 	  argf_fileno, argf_to_io, argf_eofl, argf_getc, argf_getbyte,
 	  argf_readchar, argf_readbyte, argf_each_line): use receiver.
Index: io.c
===================================================================
--- io.c	(revision 15809)
+++ io.c	(revision 15810)
@@ -138,7 +138,8 @@
     rb_encoding *enc, *enc2;
 };
 
-#define ARGF (*(struct argf *)DATA_PTR(argf))
+#define argf_of(obj) (*(struct argf *)DATA_PTR(obj))
+#define ARGF argf_of(argf)
 
 #ifdef _STDIO_USES_IOSTREAM  /* GNU libc */
 #  ifdef _IO_fpos_t
@@ -4929,16 +4930,22 @@
     free(p->inplace);
 }
 
+static inline void
+argf_init(struct argf *p, VALUE v)
+{
+    p->filename = Qnil;
+    p->current_file = Qnil;
+    p->lineno = Qnil;
+    p->argv = v;
+}
+
 static VALUE
 argf_alloc(VALUE klass)
 {
     struct argf *p;
     VALUE argf = Data_Make_Struct(klass, struct argf, argf_mark, argf_free, p);
 
-    p->filename = Qnil;
-    p->current_file = Qnil;
-    p->lineno = Qnil;
-    p->argv = Qnil;
+    argf_init(p, Qnil);
     return argf;
 }
 
@@ -4957,11 +4964,26 @@
 static VALUE
 argf_initialize(VALUE argf, VALUE argv)
 {
-    rb_argv = argv;
+    memset(&ARGF, 0, sizeof(ARGF));
+    argf_init(&ARGF, argv);
+
     return argf;
 }
 
 static VALUE
+argf_initialize_copy(VALUE argf, VALUE orig)
+{
+    ARGF = argf_of(orig);
+    rb_argv = rb_obj_dup(rb_argv);
+    if (ARGF.inplace) {
+	const char *inplace = ARGF.inplace;
+	ARGF.inplace = 0;
+	ARGF.inplace = ruby_strdup(inplace);
+    }
+    return argf;
+}
+
+static VALUE
 argf_set_lineno(VALUE argf, VALUE val)
 {
     gets_lineno = NUM2INT(val);
@@ -6860,13 +6882,13 @@
     rb_define_global_const("STDOUT", rb_stdout);
     rb_define_global_const("STDERR", rb_stderr);
 
-    argf = argf_alloc(rb_cObject);
-    argf_initialize(argf, rb_ary_new());
-    rb_cARGF = rb_singleton_class(argf);
+    rb_cARGF = rb_class_new(rb_cObject);
+    rb_define_alloc_func(rb_cARGF, argf_alloc);
 
     rb_include_module(rb_cARGF, rb_mEnumerable);
 
-    rb_define_method(rb_cARGF, "initialize", argf_initialize, 1);
+    rb_define_method(rb_cARGF, "initialize", argf_initialize, -2);
+    rb_define_method(rb_cARGF, "initialize_copy", argf_initialize_copy, 1);
     rb_define_method(rb_cARGF, "to_s", argf_to_s, 0);
     rb_define_method(rb_cARGF, "argv", argf_argv, 0);
 
@@ -6913,6 +6935,8 @@
     rb_define_method(rb_cARGF, "internal_encoding", argf_internal_encoding, 0);
     rb_define_method(rb_cARGF, "set_encoding", argf_set_encoding, -1);
 
+    argf = rb_class_new_instance(0, 0, rb_cARGF);
+
     rb_define_readonly_variable("$<", &argf);
     rb_define_global_const("ARGF", argf);
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]