# Problems with rb\_str\_split()

**URL:** <https://rubytalk.org/t/problems-with-rb-str-split/8770>\
**Category:** ruby-talk\
**Created:** [12 November 2003 09:57 UTC](https://rubytalk.org/t/problems-with-rb-str-split/8770 "2003-11-12T09:57:54Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ian\_Macdonald](https://avatars.discourse-cdn.com/v4/letter/i/f19dbf/32.png) [@Ian\_Macdonald](https://rubytalk.org/u/Ian_Macdonald)\
**Post date:** [12 November 2003 09:57 UTC](https://rubytalk.org/t/problems-with-rb-str-split/8770/1 "2003-11-12T09:57:54Z")

</div>

> Ian Macdonald wrote:
> 
> > > This can probably be fixed with this:
> > > 
> > > cap\_list = rb\_str\_split(rb\_reg\_new(txt, strlen(txt), 0), comma\_sp);
> > > 
> > > but this is entirely untested. Do you want to give it a try?
> > 
> > OK, so that doesn’t work. I know what the problem is, but I don’t know  
> > how to fix it.
> 
> You’re way ahead of me… I’m not sure I even understand the problem.  
> ☹

I have a piece of code that look like this:

const char \*comma\_sp = ", ";

cap\_list = rb\_str\_split(rb\_str\_new2(txt), comma\_sp);

This worked fine in Ruby 1.6.x, but in 1.8.x, it generates a warning in  
any code that invokes the method:

/usr/bin/mycal:101: warning: string pattern instead of regexp; metacharacters no longer effective

Now, I understand why this happens and I’m quite capable of fixing the  
same error when it occurs in pure Ruby code, but I can’t seem to figure  
out how to fix it in Ruby C.

The prototype from intern.h looks like this:

VALUE rb\_str\_split \_((VALUE, const char\*));

So, what’s the problem? How do I pass rb\_str\_split a regex as its second  
argument, instead of a string?

I thought the answer might be this:

cap\_list = rb\_str\_split(rb\_str\_new2(txt),  
rb\_reg\_new(comma\_sp,  
strlen(comma\_sp), 0));

but that makes a VALUE out of the second argument, which is not what the  
prototype expects, so a warning is issued during compilation.

Any ideas?

Ian

> **···**
>
> > > On Wed 29 Oct 2003 at 17:06:07 -0500, Ian Macdonald wrote:  
> > > –  
> > > Ian Macdonald | Ashes to ashes, dust to dust, If God won’t  
> > > System Administrator | have you, the devil must.  
> > > [ian@caliban.org](mailto:ian@caliban.org) |  
> > > [http://www.caliban.org](http://www.caliban.org) |

---

<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:** [12 November 2003 11:02 UTC](https://rubytalk.org/t/problems-with-rb-str-split/8770/2 "2003-11-12T11:02:33Z")

</div>

> This worked fine in Ruby 1.6.x, but in 1.8.x, it generates a warning in  
> any code that invokes the method:

Well, I don't have this problem with 1.8.1

nasun% cat aa.c  
#include \<ruby.h\>

void Init\_aa()  
{  
&nbsp;&nbsp;&nbsp;&nbsp;VALUE res;  
&nbsp;&nbsp;&nbsp;&nbsp;const char \*comma\_sp = ", ";  
&nbsp;&nbsp;&nbsp;&nbsp;int i;

&nbsp;&nbsp;&nbsp;&nbsp;res = rb\_str\_split(rb\_str\_new2("abc, def"), ", ");  
&nbsp;&nbsp;&nbsp;&nbsp;for (i = 0; i \< RARRAY(res)-\>len; i++) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rb\_warn("found %s", StringValuePtr(RARRAY(res)-\>ptr[i]));  
&nbsp;&nbsp;&nbsp;&nbsp;}  
}  
nasun%

nasun% ruby -raa -ve 1  
ruby 1.8.1 (2003-10-31) [sparc-solaris2.8]  
./aa.so: warning: found abc  
./aa.so: warning: found def  
-e:1: warning: useless use of a literal in void context  
nasun%

Guy Decoux

---

<div class="post-metadata">

**Author:** ![Ian\_Macdonald](https://avatars.discourse-cdn.com/v4/letter/i/f19dbf/32.png) [@Ian\_Macdonald](https://rubytalk.org/u/Ian_Macdonald)\
**Post date:** [13 November 2003 08:58 UTC](https://rubytalk.org/t/problems-with-rb-str-split/8770/3 "2003-11-13T08:58:08Z")

</div>

Try running it with warnings enabled (-w):

[ianmacd@jiskefet]$ ruby -raa -wve 1  
ruby 1.8.0 (2003-08-04) [i686-linux-gnu]  
./aa.so: warning: string pattern instead of regexp; metacharacters no longer effective  
./aa.so: warning: found abc  
./aa.so: warning: found def  
-e:1: warning: useless use of a literal in void context

So, how do I get rid of the “string pattern instead of regexp” warning?

Ian

> **···**
>
> On Wed 12 Nov 2003 at 20:02:33 +0900, ts wrote:
> 
> > > This worked fine in Ruby 1.6.x, but in 1.8.x, it generates a warning in  
> > > any code that invokes the method:
> > 
> > Well, I don’t have this problem with 1.8.1
> > 
> > nasun% cat aa.c  
> > #include \<ruby.h\>
> > 
> > void Init\_aa()  
> > {  
> > VALUE res;  
> > const char \*comma\_sp = ", ";  
> > int i;
> > 
> > ```
> > res = rb_str_split(rb_str_new2("abc, def"), ", ");
> > for (i = 0; i < RARRAY(res)->len; i++) {
> > rb_warn("found %s", StringValuePtr(RARRAY(res)->ptr[i]));
> > }
> > 
> > ```
> > 
> > }  
> > nasun%
> > 
> > nasun% ruby -raa -ve 1  
> > ruby 1.8.1 (2003-10-31) [sparc-solaris2.8]  
> > ./aa.so: warning: found abc  
> > ./aa.so: warning: found def  
> > -e:1: warning: useless use of a literal in void context  
> > nasun%
> 
> –  
> Ian Macdonald | A is for Apple. – Hester Pryne  
> System Administrator |  
> [ian@caliban.org](mailto:ian@caliban.org) |  
> [http://www.caliban.org](http://www.caliban.org) |  
> \>

---

<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:** [13 November 2003 09:17 UTC](https://rubytalk.org/t/problems-with-rb-str-split/8770/4 "2003-11-13T09:17:27Z")

</div>

> > Well, I don't have this problem with 1.8.1

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> Try running it with warnings enabled (-w):

With -v warning are enabled

> [ianmacd@jiskefet]$ ruby -raa -wve 1  
> ruby 1.8.0 (2003-08-04) [i686-linux-gnu]

nasun% ruby -raa -wve 1  
ruby 1.8.1 (2003-10-31) [sparc-solaris2.8]  
./aa.so: warning: found abc  
./aa.so: warning: found def  
-e:1: warning: useless use of a literal in void context  
nasun%

Guy Decoux

> **···**
>
> > On Wed 12 Nov 2003 at 20:02:33 +0900, ts wrote:

---

<div class="post-metadata">

**Author:** ![Ian\_Macdonald](https://avatars.discourse-cdn.com/v4/letter/i/f19dbf/32.png) [@Ian\_Macdonald](https://rubytalk.org/u/Ian_Macdonald)\
**Post date:** [13 November 2003 10:29 UTC](https://rubytalk.org/t/problems-with-rb-str-split/8770/5 "2003-11-13T10:29:02Z")

</div>

So, it was just a bug in 1.8.0? Unfortunately, that’s still the latest  
official version, so I’m stuck with the issue at work for the time  
being.

Thanks for your reply.

Ian

> **···**
>
> On Thu 13 Nov 2003 at 18:17:27 +0900, ts wrote:
> 
> > > On Wed 12 Nov 2003 at 20:02:33 +0900, ts wrote:
> > 
> > > > Well, I don’t have this problem with 1.8.1  
> > > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
> > > > Try running it with warnings enabled (-w):
> > 
> > With -v warning are enabled
> > 
> > > [ianmacd@jiskefet]$ ruby -raa -wve 1  
> > > ruby 1.8.0 (2003-08-04) [i686-linux-gnu]
> > 
> > nasun% ruby -raa -wve 1  
> > ruby 1.8.1 (2003-10-31) [sparc-solaris2.8]  
> > ./aa.so: warning: found abc  
> > ./aa.so: warning: found def  
> > -e:1: warning: useless use of a literal in void context  
> > nasun%
> 
> –  
> Ian Macdonald | Fifth Law of Procrastination:  
> System Administrator | Procrastination avoids boredom; one never  
> [ian@caliban.org](mailto:ian@caliban.org) | has the feeling that there is nothing  
> [http://www.caliban.org](http://www.caliban.org) | important to do.  
> \>

---

<div class="post-metadata">

**Author:** ![Zach\_Dennis1](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@Zach\_Dennis1](https://rubytalk.org/u/Zach_Dennis1)\
**Post date:** [13 November 2003 10:34 UTC](https://rubytalk.org/t/problems-with-rb-str-split/8770/6 "2003-11-13T10:34:38Z")

</div>

Has anyone compiled ruby with bcc32 under a windows environment( preferably  
win2000 ) successfully?

I’m having troubles.

Zach

> **···**
>
> -----Original Message-----  
> From: Ian Macdonald [[mailto:ian@caliban.org](mailto:ian@caliban.org)]  
> Sent: Thursday, November 13, 2003 5:29 AM  
> To: ruby-talk ML  
> Subject: Re: problems with rb\_str\_split()
> 
> On Thu 13 Nov 2003 at 18:17:27 +0900, ts wrote:
> 
> > > On Wed 12 Nov 2003 at 20:02:33 +0900, ts wrote:
> > 
> > > > Well, I don’t have this problem with 1.8.1  
> > > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
> > > > Try running it with warnings enabled (-w):
> > 
> > With -v warning are enabled
> > 
> > > [ianmacd@jiskefet]$ ruby -raa -wve 1  
> > > ruby 1.8.0 (2003-08-04) [i686-linux-gnu]
> > 
> > nasun% ruby -raa -wve 1  
> > ruby 1.8.1 (2003-10-31) [sparc-solaris2.8]  
> > ./aa.so: warning: found abc  
> > ./aa.so: warning: found def  
> > -e:1: warning: useless use of a literal in void context  
> > nasun%
> 
> So, it was just a bug in 1.8.0? Unfortunately, that’s still the latest  
> official version, so I’m stuck with the issue at work for the time  
> being.
> 
> Thanks for your reply.
> 
> ## Ian
> 
> Ian Macdonald | Fifth Law of Procrastination:  
> System Administrator | Procrastination avoids boredom; one never  
> [ian@caliban.org](mailto:ian@caliban.org) | has the feeling that there is nothing  
> [http://www.caliban.org](http://www.caliban.org) | important to do.  
> \>

---

<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:** [13 November 2003 10:39 UTC](https://rubytalk.org/t/problems-with-rb-str-split/8770/7 "2003-11-13T10:39:20Z")

</div>

> So, it was just a bug in 1.8.0? Unfortunately, that's still the latest  
> official version, so I'm stuck with the issue at work for the time  
> being.

svg% diff -u aa.c~ aa.c  
--- aa.c~ 2003-11-13 11:34:19.000000000 +0100  
+++ aa.c 2003-11-13 11:37:33.000000000 +0100  
@@ -2,11 +2,14 @@

void Init\_aa()  
{  
- VALUE res;  
+ VALUE res, rv;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const char \*comma\_sp = ", ";  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int i;

+ rv = ruby\_verbose;  
+ ruby\_verbose = Qnil;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res = rb\_str\_split(rb\_str\_new2("abc, def"), ", ");  
+ ruby\_verbose = rv;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (i = 0; i \< RARRAY(res)-\>len; i++) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rb\_warn("found %s", StringValuePtr(RARRAY(res)-\>ptr[i]));  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
svg%

svg% ruby -raa -vwe 1  
ruby 1.8.0 (2003-08-04) [i686-linux]  
./aa.so: warning: found abc  
./aa.so: warning: found def  
-e:1: warning: useless use of a literal in void context  
svg%

Guy Decoux

---

<div class="post-metadata">

**Author:** ![Ian\_Macdonald](https://avatars.discourse-cdn.com/v4/letter/i/f19dbf/32.png) [@Ian\_Macdonald](https://rubytalk.org/u/Ian_Macdonald)\
**Post date:** [13 November 2003 10:54 UTC](https://rubytalk.org/t/problems-with-rb-str-split/8770/8 "2003-11-13T10:54:48Z")

</div>

That’s a nice way around the problem.

Thanks!

Ian

> **···**
>
> On Thu 13 Nov 2003 at 19:39:20 +0900, ts wrote:
> 
> > > So, it was just a bug in 1.8.0? Unfortunately, that’s still the latest  
> > > official version, so I’m stuck with the issue at work for the time  
> > > being.
> > 
> > svg% diff -u aa.c~ aa.c  
> > — aa.c~ 2003-11-13 11:34:19.000000000 +0100  
> > +++ aa.c 2003-11-13 11:37:33.000000000 +0100  
> > @@ -2,11 +2,14 @@
> > 
> > void Init\_aa()  
> > {
> > 
> > - VALUE res;
> > 
> > - VALUE res, rv;  
> > const char \*comma\_sp = ", ";  
> > int i;
> > 
> > - rv = ruby\_verbose;
> > 
> > - ruby\_verbose = Qnil;  
> > res = rb\_str\_split(rb\_str\_new2(“abc, def”), ", ");
> > 
> > - ruby\_verbose = rv;  
> > for (i = 0; i \< RARRAY(res)-\>len; i++) {  
> > rb\_warn(“found %s”, StringValuePtr(RARRAY(res)-\>ptr[i]));  
> > }
> 
> –  
> Ian Macdonald | Actually, what I’d like is a little toy  
> System Administrator | spaceship!!  
> [ian@caliban.org](mailto:ian@caliban.org) |  
> [http://www.caliban.org](http://www.caliban.org) |  
> \>

---

<div class="post-metadata">

**Author:** ![Mark\_Smith1](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Mark\_Smith1](https://rubytalk.org/u/Mark_Smith1)\
**Post date:** [17 November 2003 02:06 UTC](https://rubytalk.org/t/problems-with-rb-str-split/8770/9 "2003-11-17T02:06:41Z")

</div>

Zach Dennis wrote:

> Has anyone compiled ruby with bcc32 under a windows environment( preferably  
> win2000 ) successfully?
> 
> I’m having troubles.

Zach,

I compiled it with no trouble by following the steps in readme.bcc32 in  
the bcc32 folder–both under Win2K and WinXP. Start a console. Be sure  
you are in the “Ruby-1.8.1” directory. Then, set your path to include  
both bin & the lib of bcc  
(path=%path%;c:\borland\bcc55\bin;c:\borland\bcc55\bib) and just follow  
the remaining steps.

It worked, and I was able to run basic Ruby programs successfully.  
However, what keeps me using Andy’s Win32 install is all the little  
extras! Even though I can compile with bcc, I have no clue how to  
compile all the great \*.so file (like Oracle) that make Ruby such a  
valuable tool for me.

Also, there’s a unique item with bcc32. When you read a file, you must  
be sure to include the binary flag “b” or you’ll have trouble with  
stripping characters–IIRC, lone CR’s in mac files on my Win box.

(Now, if I only had a 4D plug-in to run Ruby in that environment!)

> **···**
>
> –  
> Regards,
> 
> Mark Smith  
> maslists [at] cox [dot] net

---

<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:** [13 November 2003 11:05 UTC](https://rubytalk.org/t/problems-with-rb-str-split/8770/10 "2003-11-13T11:05:47Z")

</div>

> That's a nice way around the problem.

You can still use

&nbsp;&nbsp;&nbsp;&nbsp;res = rb\_funcall(rb\_str\_new2("abc, def"), rb\_intern("split"),  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1, rb\_reg\_new(", ", 2, 0));

Guy Decoux

---

<div class="post-metadata">

**Author:** ![Zach\_Dennis1](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@Zach\_Dennis1](https://rubytalk.org/u/Zach_Dennis1)\
**Post date:** [17 November 2003 15:16 UTC](https://rubytalk.org/t/problems-with-rb-str-split/8770/11 "2003-11-17T15:16:57Z")

</div>

Mark,

You use 4d to? I didn’t think there were any other Ruby’ers out there who  
used it! Maybe we shall have to write some 4D-extensions for Ruby. =)

Zach

> **···**
>
> -----Original Message-----  
> From: Mark Smith [[mailto:spam@fakeaddress.net](mailto:spam@fakeaddress.net)]  
> Sent: Sunday, November 16, 2003 9:07 PM  
> To: ruby-talk ML  
> Subject: Re: BCC32 under win environment
> 
> Zach Dennis wrote:
> 
> > Has anyone compiled ruby with bcc32 under a windows environment(  
> > preferably  
> > win2000 ) successfully?
> > 
> > I’m having troubles.
> 
> Zach,
> 
> I compiled it with no trouble by following the steps in readme.bcc32 in  
> the bcc32 folder–both under Win2K and WinXP. Start a console. Be sure  
> you are in the “Ruby-1.8.1” directory. Then, set your path to include  
> both bin & the lib of bcc  
> (path=%path%;c:\borland\bcc55\bin;c:\borland\bcc55\bib) and just follow  
> the remaining steps.
> 
> It worked, and I was able to run basic Ruby programs successfully.  
> However, what keeps me using Andy’s Win32 install is all the little  
> extras! Even though I can compile with bcc, I have no clue how to  
> compile all the great \*.so file (like Oracle) that make Ruby such a  
> valuable tool for me.
> 
> Also, there’s a unique item with bcc32. When you read a file, you must  
> be sure to include the binary flag “b” or you’ll have trouble with  
> stripping characters–IIRC, lone CR’s in mac files on my Win box.
> 
> (Now, if I only had a 4D plug-in to run Ruby in that environment!)
> 
> –  
> Regards,
> 
> Mark Smith  
> maslists [at] cox [dot] net
