# Ruby-dev summary 19773-19824

**URL:** <https://rubytalk.org/t/ruby-dev-summary-19773-19824/5184>\
**Category:** ruby-talk\
**Created:** [16 March 2003 15:48 UTC](https://rubytalk.org/t/ruby-dev-summary-19773-19824/5184 "2003-03-16T15:48:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Takaaki\_Tateishi1](https://avatars.discourse-cdn.com/v4/letter/t/eb9ed0/32.png) [@Takaaki\_Tateishi1](https://rubytalk.org/u/Takaaki_Tateishi1)\
**Post date:** [16 March 2003 15:48 UTC](https://rubytalk.org/t/ruby-dev-summary-19773-19824/5184/1 "2003-03-16T15:48:46Z")

</div>

Hello,

Here is a ruby-dev summary of last week.

ruby-dev:19773-19824

[ruby-dev:19774] [1.8.0-preview2] make install

Minero Aoki suggested that ‘instruby.rb’ should make umask to  
be 0022, and this suggestion was accepted.

[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.

[ruby-dev:19808] [Oniguruma] Version 1.8.4

Oniguruma 1.8.4 is available at  
ftp://ftp.ruby-lang.org/pub/ruby/contrib/onigd20030312.tar.gz

> **···**
>
> –  
> Takaaki Tateishi [ttate@ttsky.net](mailto:ttate@ttsky.net)

---

<div class="post-metadata">

**Author:** ![Paul\_Brannan](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@Paul\_Brannan](https://rubytalk.org/u/Paul_Brannan)\
**Post date:** [17 March 2003 16:15 UTC](https://rubytalk.org/t/ruby-dev-summary-19773-19824/5184/2 "2003-03-17T16:15:53Z")

</div>

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?

I’m guessing rb\_str2cstr will have to change, since  
strlen(RSTRING(str)-\>ptr) will break if RSTRING(str)-\>ptr is NULL.

In what conditions will RSTRING(str)-\>ptr be NULL?

Paul

> **···**
>
> On Mon, Mar 17, 2003 at 12:48:46AM +0900, Takaaki Tateishi 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.

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [18 March 2003 00:35 UTC](https://rubytalk.org/t/ruby-dev-summary-19773-19824/5184/3 "2003-03-18T00:35:14Z")

</div>

Hi,

> > [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/, ‘’)

> **···**
>
> At Tue, 18 Mar 2003 01:15:53 +0900, Paul Brannan wrote:
> 
> –  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![Paul\_Brannan](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@Paul\_Brannan](https://rubytalk.org/u/Paul_Brannan)\
**Post date:** [18 March 2003 15:59 UTC](https://rubytalk.org/t/ruby-dev-summary-19773-19824/5184/4 "2003-03-18T15:59:26Z")

</div>

> Paul Brannan wrote:
> 
> > 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 don’t understand. Can you elaborate?

> > In what conditions will RSTRING(str)-\>ptr be NULL?
> 
> An example:
> 
> ’ '.dup.rstrip.gsub(/a/, ‘’)

Why will this leave ptr NULL? It doesn’t seem very obvious from the  
source (in str\_gsub, ptr is set equal to buf, which is allocated with  
malloc(), which should never return 0 except on error).

Paul

> **···**
>
> On Tue, Mar 18, 2003 at 09:35:14AM +0900, [nobu.nokada@softhome.net](mailto:nobu.nokada@softhome.net) wrote:

---

<div class="post-metadata">

**Author:** ![ts1](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@ts1](https://rubytalk.org/u/ts1)\
**Post date:** [18 March 2003 16:18 UTC](https://rubytalk.org/t/ruby-dev-summary-19773-19824/5184/5 "2003-03-18T16:18:47Z")

</div>

> > ' '.dup.rstrip.gsub(/a/, '')

> Why will this leave ptr NULL? It doesn't seem very obvious from the  
> source (in str\_gsub, ptr is set equal to buf, which is allocated with  
> malloc(), which should never return 0 except on error).

#gsub don't match, it return rb\_str\_dup("") which give a NULL pointer.

Guy Decoux

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [18 March 2003 19:23 UTC](https://rubytalk.org/t/ruby-dev-summary-19773-19824/5184/6 "2003-03-18T19:23:11Z")

</div>

Hi,

> > > 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 don’t understand. Can you elaborate?

rb\_str2cstr() calls #to\_str method on non-String object and  
returns its ptr but doesn’t the result String itself. So the  
object would be lost at next GC. To solve this problem,  
StringValue() and StringValuePtr() macros were introduced.

As you can see in ruby.h, these macros pass the address of the  
argument to helper functions, therefore you can compile:

char \*s = STR2CSTR(rb\_inspect(Qnil));

(and cause SEGV), but cannot:

char \*s = StringValuePtr(rb\_inspect(Qnil));

> **···**
>
> At Wed, 19 Mar 2003 00:59:26 +0900, Paul Brannan wrote:
> 
> –  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![Paul\_Brannan](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@Paul\_Brannan](https://rubytalk.org/u/Paul_Brannan)\
**Post date:** [19 March 2003 15:00 UTC](https://rubytalk.org/t/ruby-dev-summary-19773-19824/5184/7 "2003-03-19T15:00:54Z")

</div>

Ah, that makes sense. Thanks!

Paul

> **···**
>
> On Wed, Mar 19, 2003 at 04:23:11AM +0900, [nobu.nokada@softhome.net](mailto:nobu.nokada@softhome.net) wrote:
> 
> > rb\_str2cstr() calls #to\_str method on non-String object and  
> > returns its ptr but doesn’t the result String itself. So the  
> > object would be lost at next GC. To solve this problem,  
> > StringValue() and StringValuePtr() macros were introduced.
