From: nobu.nokada@... Date: 2003-03-18T09:35:14+09:00 Subject: Re: ruby-dev summary 19773-19824 Hi, At Tue, 18 Mar 2003 01:15:53 +0900, Paul Brannan wrote: > > [ruby-dev:19801] RSTRING(str)->ptr > > > > Nobu Nakada confirm that RSTRING(str)->ptr should be a NUL > > terminated string. However, it may be NULL in ruby-1.8.x. > > We must use StringValuePtr() to obtain non-NULL value. > > Will rb_str2cstr be modified to use StringValuePtr(), or will extensions > have to change to get non-NULL C-strings from STR2CSTR in 1.8.0? If it > is not modified, how should extension writers write code to work on both > 1.6.x and 1.8.0? Signatures of rb_str2cstr() and StringValuePtr() are different. StringValuePtr() requires lvalue in order to get rid of possibility of dangling pointer, so extensions should change to use latter. > I'm guessing rb_str2cstr will have to change, since > strlen(RSTRING(str)->ptr) will break if RSTRING(str)->ptr is NULL. If RSTRING(str)->ptr is NULL, RSTRING(str)->len is always 0. > In what conditions will RSTRING(str)->ptr be NULL? An example: ' '.dup.rstrip.gsub(/a/, '') -- Nobu Nakada