Project

General

Profile

Feature #4893 ยป String_call_initialize_v2.diff

lazaridis.com (Lazaridis Ilias), 06/26/2011 08:06 PM

View differences:

"b/P:\\sand\\rubyi2\\sandbox\\rb192\\string.c"
411 411
    return str;
412 412
}
413 413

  
414
static int str_call_initialize = FALSE;
415

  
416
VALUE
417
rb_str_call_initialize_get(VALUE self)
418
{
419
    if (str_call_initialize == TRUE) return Qtrue;
420
    return Qfalse;
421
}
422

  
423
VALUE
424
rb_str_call_initialize_set(VALUE self, VALUE val)
425
{
426
    str_call_initialize = FALSE;
427
    if (val == Qtrue) str_call_initialize = TRUE;
428

  
429
    return self;
430
}
431

  
414 432
VALUE
415 433
rb_str_new(const char *ptr, long len)
416 434
{
417
    return str_new(rb_cString, ptr, len);
435
    VALUE str;
436
	VALUE argv[1];
437
	
438
	str = str_new(rb_cString, ptr, len);
439
	
440
    if (str_call_initialize) {
441
	argv[0] = (VALUE)str;
442
	rb_obj_call_init((VALUE)str, 1, argv);
443
    }
444

  
445
    return str;
418 446
}
419 447

  
420 448
VALUE
......
7449 7477
    rb_cString  = rb_define_class("String", rb_cObject);
7450 7478
    rb_include_module(rb_cString, rb_mComparable);
7451 7479
    rb_define_alloc_func(rb_cString, str_alloc);
7480

  
7481
    rb_define_singleton_method(rb_cString, "call_initialize", rb_str_call_initialize_get, 0);
7482
    rb_define_singleton_method(rb_cString, "call_initialize=", rb_str_call_initialize_set, 1);
7483

  
7452 7484
    rb_define_singleton_method(rb_cString, "try_convert", rb_str_s_try_convert, 1);
7453 7485
    rb_define_method(rb_cString, "initialize", rb_str_init, -1);
7454 7486
    rb_define_method(rb_cString, "initialize_copy", rb_str_replace, 1);