This post originated from an RSS feed registered with Ruby Buzz
by Red Handed.
Original Post: Undocumented Macro DATA_PTR
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
I’ve really got to remember this one. Tim Hunter on ruby-talk brought up this macro for replacing the pointer associated with a Ruby VALUE. Available since 1.7.
VALUE my_obj;
MyStruct my_struct;
my_struct = ALLOC(MyStruct);
DATA_PTR(my_obj) = my_struct;
Use this after initially assigning a pointer with Data_Wrap_Struct or Data_Make_Struct. Which means the same free and mark function pointers will still apply.
Note: While the DATA_PTR macro isn’t touched in the PickAxe II, I’ve found its coverage of the Ruby API to be indispensable. Nuances such as proper use of StringValue and the difference between 1.6 and 1.8 object allocation are essential.