hoodwink.d enhanced


Undocumented Macro DATA_PTR #

by why in bits

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.

said on 09 Feb 2005 at 13:25

A small nit to pick, but the DATA_PTR macro has been around since before Ruby 1.7. It was definitely there in 1.6, when I started developing my favorite Ruby extension.

said on 09 Feb 2005 at 13:43

Gotcha. I misread the Matz citation linked earlier. He was just assuring continued support of DATA_PTR.

Oh that Lovable Lyle. A bashful crocodile is brought to memory…

said on 10 Feb 2005 at 09:45

When you’re a little kid and you’re the only Lyle in your school (verily, in the school system) it helps to know that there’s a crocodile out there who shares your name. I still have those books. ;)

Comments are closed for this entry.