Project

General

Profile

Feature #4893 ยป String_call_initialize_v3.diff

patch using FL_USER18 as flag - lazaridis.com (Lazaridis Ilias), 07/04/2011 09:02 PM

View differences:

"b/C:\\Users\\LAZARI~1\\AppData\\Local\\Temp\\str186F.c"
406 406
    return str;
407 407
}
408 408

  
409
#define FL_CALL_INIT FL_USER18
410

  
411
VALUE
412
rb_str_call_initialize_get(VALUE self)
413
{
414
    if (FL_TEST(rb_cString, FL_CALL_INIT)) return Qtrue;
415
    return Qfalse;
416
}
417

  
418
VALUE
419
rb_str_call_initialize_set(VALUE self, VALUE val)
420
{
421
	FL_UNSET(rb_cString, FL_CALL_INIT);
422
    if (val == Qtrue) FL_SET(rb_cString, FL_CALL_INIT);
423
	
424
    return self;
425
}
426

  
409 427
VALUE
410 428
rb_str_new(const char *ptr, long len)
411 429
{
412
    return str_new(rb_cString, ptr, len);
430
    VALUE str;
431
    VALUE argv[1];
432

  
433
    str = str_new(rb_cString, ptr, len);
434

  
435
    if (FL_TEST(rb_cString, FL_CALL_INIT)) {
436
	argv[0] = (VALUE)str;
437
	rb_obj_call_init((VALUE)str, 1, argv);
438
    }
439

  
440
    return str;
413 441
}
414 442

  
415 443
VALUE
......
5117 5145
	    CHECK_IF_ASCII(c);
5118 5146
	    t += tlen;
5119 5147
	}
5120
	if (!STR_EMBED_P(str)) {
5121
	    xfree(RSTRING(str)->as.heap.ptr);
5122
	}
5123 5148
	*t = '\0';
5124 5149
	RSTRING(str)->as.heap.ptr = buf;
5125 5150
	RSTRING(str)->as.heap.len = t - buf;
......
7724 7749
    rb_cString  = rb_define_class("String", rb_cObject);
7725 7750
    rb_include_module(rb_cString, rb_mComparable);
7726 7751
    rb_define_alloc_func(rb_cString, str_alloc);
7752

  
7753
    rb_define_singleton_method(rb_cString, "call_initialize", rb_str_call_initialize_get, 0);
7754
    rb_define_singleton_method(rb_cString, "call_initialize=", rb_str_call_initialize_set, 1);
7755

  
7727 7756
    rb_define_singleton_method(rb_cString, "try_convert", rb_str_s_try_convert, 1);
7728 7757
    rb_define_method(rb_cString, "initialize", rb_str_init, -1);
7729 7758
    rb_define_method(rb_cString, "initialize_copy", rb_str_replace, 1);