From: "Iñaki Baz Castillo" Date: 2012-05-10T20:08:58+09:00 Subject: Re: How to use Data_Wrap_Struct to assign the DATA VALUE to an exsiting Ruby object? 2012/5/9 Eric Wong : > Ruby itself uses this idiom in some places: > >        DATA_PTR(self) = ptr; Thanks Eric. I've taken a look to file.c in Ruby sources which uses this stuf in functions rb_stat_init() and rb_stat_init_copy(). Unfortunatelly I get a segmentfault after using DATA_PTR(self)=ptr, let me show what I do: Ruby land: --------------- sock = klass.allocate sock.init_udp_socket bind_ip, bind_port C land: ---------- VALUE MyModule_init_udp_socket(VALUE self, VALUE rb_bind_ip, VALUE rb_bind_port) { [...] struct my_udp_cdata* cdata = ALLOC(struct my_udp_cdata); cdata->xxxx = xxxx; cdata->xxxx = xxxx; DATA_PTR(self) = cdata; [...] return self; } This still does NOT crash, but if after the C function I call to any attribute reader of _sock_ or use sock.instance_variable_set(), then it crashes. Am I doing something wrong? Thanks a lot. -- Iñaki Baz Castillo