Project

General

Profile

Feature #4893 ยป String_call_initialize.diff

patch against branches/ruby_1_9_2 - lazaridis.com (Lazaridis Ilias), 06/26/2011 11:01 AM

View differences:

"b/C:\\Users\\LAZARI~1\\AppData\\Local\\Temp\\str4A35.c"
385 385
    return (VALUE)str;
386 386
}
387 387

  
388
static int str_call_initialize = FALSE;
389

  
390
VALUE
391
rb_str_call_initialize_get(VALUE self)
392
{
393
    if (str_call_initialize == TRUE) return Qtrue;
394
    return Qfalse;
395
}
396

  
397
VALUE
398
rb_str_call_initialize_set(VALUE self, VALUE val)
399
{
400
    str_call_initialize = FALSE;
401
    if (val == Qtrue) str_call_initialize = TRUE;
402

  
403
    return self;
404
}
405

  
388 406
static VALUE
389 407
str_new(VALUE klass, const char *ptr, long len)
390 408
{
391 409
    VALUE str;
410
    VALUE argv[1];
392 411

  
393 412
    if (len < 0) {
394 413
	rb_raise(rb_eArgError, "negative string size (or size too big)");
......
408 427
    }
409 428
    STR_SET_LEN(str, len);
410 429
    RSTRING_PTR(str)[len] = '\0';
430

  
431
    if (str_call_initialize) {
432
	argv[0] = (VALUE)str;
433
	rb_obj_call_init((VALUE)str, 1, argv);
434
    }
435

  
411 436
    return str;
412 437
}
413 438

  
......
7449 7474
    rb_cString  = rb_define_class("String", rb_cObject);
7450 7475
    rb_include_module(rb_cString, rb_mComparable);
7451 7476
    rb_define_alloc_func(rb_cString, str_alloc);
7477

  
7478
    rb_define_singleton_method(rb_cString, "call_initialize", rb_str_call_initialize_get, 0);
7479
    rb_define_singleton_method(rb_cString, "call_initialize=", rb_str_call_initialize_set, 1);
7480

  
7452 7481
    rb_define_singleton_method(rb_cString, "try_convert", rb_str_s_try_convert, 1);
7453 7482
    rb_define_method(rb_cString, "initialize", rb_str_init, -1);
7454 7483
    rb_define_method(rb_cString, "initialize_copy", rb_str_replace, 1);