Forum: Ruby (Ruby 1.9.1) error: ‘struct RString’ has no memb er named ‘ptr’

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0f1f17ba297242e9d3c86d4cc0a6ea85?d=identicon&s=25 Iñaki Baz Castillo (Guest)
on 2009-04-03 17:36
(Received via mailing list)
Hi, trying to compile a C extension I get this error in Ruby 1.9.1:

  error: ‘struct RString’ has no member named ‘ptr’

The code is:

---------------------------------------
#include <ruby.h>
#include <stdio.h>

static VALUE my_method(VALUE self, VALUE arg) {

  char* name = RSTRING(arg)->ptr;
---------------------------------------


I find in ruby.h:

-------------------------------------------
struct RString {
    struct RBasic basic;
    union {
        struct {
            long len;
            char *ptr;
            union {
                long capa;
                VALUE shared;
            } aux;
        } heap;
        char ary[RSTRING_EMBED_LEN_MAX + 1];
    } as;
};
------------------------------------------


Perhaps a change from 1.8?  How should I access the "ptr" element?
Thanks.
0f1f17ba297242e9d3c86d4cc0a6ea85?d=identicon&s=25 Iñaki Baz Castillo (Guest)
on 2009-04-03 17:38
(Received via mailing list)
2009/4/3 Iñaki Baz Castillo <ibc@aliax.net>:
> static VALUE my_method(VALUE self, VALUE arg) {
>
>        char* name = RSTRING(arg)->ptr;
> ---------------------------------------

It seems that I mut use:

  char* name = RSTRING_PTR(arg);

Am I right?
0f1f17ba297242e9d3c86d4cc0a6ea85?d=identicon&s=25 Iñaki Baz Castillo (Guest)
on 2009-04-03 17:44
(Received via mailing list)
2009/4/3 Iñaki Baz Castillo <ibc@aliax.net>:

>
>        char* name = RSTRING_PTR(arg);
>
> Am I right?

Autoreply: yes :)
This topic is locked and can not be replied to.