Mauricio Fern?ndez wrote:

>On Sun, Oct 16, 2005 at 01:34:13PM +0900, Charles Mills wrote:
>  
>
>>On Oct 14, 2005, at 12:43 PM, Charles E. Thornton wrote:
>>    
>>
>>>>>Can someone provide a short fragment that induces this behavior  
>>>>>(Shared!).
>>>>>          
>>>>>
>>substring:
>>a = "ab"[1,1]
>>    
>>
>
>Not all substring #[] operations cause the underlying string to be shared (the
>above doesn't).
>Take a look at rb_str_substr.
>
>  
>
Actually, it does!

Test File: tst

0001:  #!/usr/bin/ruby
0002:  a = "ab"[1,1]

Produces:
OBJECT ====> Object Address ------>0x00f6fcd024  STRING
RBASIC ====> flags --------------->0x0000002007  SHARED
RBASIC ====> klass --------------->0x00f6fdb7dc  rb_cString
RSTRING ===> len ----------------->2
RSTRING ===> ptr ----------------->0x000875df28 ab
RSTRING ===> aux.shared ---------->0x00f6fcd0b0

OBJECT ====> Object Address ------>0x00f6fcd0b0  STRING
RBASIC ====> flags --------------->0x0000000007
RBASIC ====> klass --------------->0x00f6fdb7dc  rb_cString
RSTRING ===> len ----------------->2
RSTRING ===> ptr ----------------->0x000875df28 ab

I looked at rb_str_substr and I am Confused?  I didn't get your point?
But it brought up another question, what is the Flag STR_ASSOC
used for or mean??

OK, Back to rb_str_substr:  The code:
    if (len > sizeof(struct RString)/2 &&
       beg + len == RSTRING(str)->len && !FL_TEST(str, STR_ASSOC))
seems to create a shared string if the conditional statement above is TRUE!

But what is it really checking?  For example:  "len > sizeof(struct 
RString)/2"
Why do we care if the Length is greater that half the String Structure 
Size??

Sigb -- :-(

-- 
GodFather -- 667 Neighbor of the Beast