problems with rb_str_split()

Ask a Question related to Ruby, Design and Development.

  1. #1

    Default problems with rb_str_split()

    > Ian Macdonald wrote:
    > > On Wed 29 Oct 2003 at 17:06:07 -0500, 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
    --
    Ian Macdonald | Ashes to ashes, dust to dust, If God won't
    System Administrator | have you, the devil must.
    [email]ian@caliban.org[/email] |
    [url]http://www.caliban.org[/url] |
    |

    Ian Macdonald Guest

  2. Similar Questions and Discussions

    1. Problems with %
      Anyone ever had a problem with passing the % sign in their code, and having the server go crazy and start producing too many threads?
    2. problems with preLoadNetThing and fileName (was problems with preLoadNetThing and importFileInto)
      You don't want to leave the QT member in your cast when you publish your movie - it's not really there, it's linked. When you run the movie it will...
    3. I having problems with IIS
      I just tried to view a page that I had earlier on my own personal web site and was not able to view it. I then tried just plain old localhost and...
    4. AVI Problems
      I would highly recommend using QuickTime instead. I had the same problems that you seem to be having. Once I made .mov's instead, the production time...
    5. XP & ME--- ICS problems
      I have had my 2 computers networked for almost 2 years with no problems until now. Recently my client Computer(ME) lost thr residential gateway...
  3. #2

    Default Re: problems with rb_str_split()

    >>>>> "I" == Ian Macdonald <ian@caliban.org> writes:

    I> This worked fine in Ruby 1.6.x, but in 1.8.x, it generates a warning in
    I> 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%


    Guy Decoux

    ts Guest

  4. #3

    Default Re: problems with rb_str_split()

    On Wed 12 Nov 2003 at 20:02:33 +0900, ts wrote:
    > >>>>> "I" == Ian Macdonald <ian@caliban.org> writes:
    >
    > I> This worked fine in Ruby 1.6.x, but in 1.8.x, it generates a warning in
    > I> 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%
    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
    --
    Ian Macdonald | A is for Apple. -- Hester Pryne
    System Administrator |
    [email]ian@caliban.org[/email] |
    [url]http://www.caliban.org[/url] |
    |

    Ian Macdonald Guest

  5. #4

    Default Re: problems with rb_str_split()

    >>>>> "I" == Ian Macdonald <ian@caliban.org> writes:

    I> On Wed 12 Nov 2003 at 20:02:33 +0900, ts wrote:
    >> Well, I don't have this problem with 1.8.1
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    I> Try running it with warnings enabled (-w):

    With -v warning are enabled

    I> [ianmacd@jiskefet]$ ruby -raa -wve 1
    I> 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

    ts Guest

  6. #5

    Default Re: problems with rb_str_split()

    On Thu 13 Nov 2003 at 18:17:27 +0900, ts wrote:
    > >>>>> "I" == Ian Macdonald <ian@caliban.org> writes:
    >
    > I> On Wed 12 Nov 2003 at 20:02:33 +0900, ts wrote:
    >
    > >> Well, I don't have this problem with 1.8.1
    > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    > I> Try running it with warnings enabled (-w):
    >
    > With -v warning are enabled
    >
    > I> [ianmacd@jiskefet]$ ruby -raa -wve 1
    > I> 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
    [email]ian@caliban.org[/email] | has the feeling that there is nothing
    [url]http://www.caliban.org[/url] | important to do.
    |

    Ian Macdonald Guest

  7. #6

    Default Re: problems with rb_str_split()

    >>>>> "I" == Ian Macdonald <ian@caliban.org> writes:

    I> So, it was just a bug in 1.8.0? Unfortunately, that's still the latest
    I> official version, so I'm stuck with the issue at work for the time
    I> 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]));
    }
    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

    ts Guest

  8. #7

    Default Re: problems with rb_str_split()

    On Thu 13 Nov 2003 at 19:39:20 +0900, ts wrote:
    > >>>>> "I" == Ian Macdonald <ian@caliban.org> writes:
    >
    > I> So, it was just a bug in 1.8.0? Unfortunately, that's still the latest
    > I> official version, so I'm stuck with the issue at work for the time
    > I> 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]));
    > }
    That's a nice way around the problem.

    Thanks!

    Ian
    --
    Ian Macdonald | Actually, what I'd like is a little toy
    System Administrator | spaceship!!
    [email]ian@caliban.org[/email] |
    [url]http://www.caliban.org[/url] |
    |

    Ian Macdonald Guest

  9. #8

    Default Re: problems with rb_str_split()

    >>>>> "I" == Ian Macdonald <ian@caliban.org> writes:

    I> That's a nice way around the problem.

    You can still use

    res = rb_funcall(rb_str_new2("abc, def"), rb_intern("split"),
    1, rb_reg_new(", ", 2, 0));


    Guy Decoux


    ts Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139