3232
3333VALUE cXMLAttr ;
3434
35- void rxml_attr_mark (xmlAttrPtr xattr )
35+ static void rxml_attr_mark (void * data )
3636{
37+ xmlAttrPtr xattr = (xmlAttrPtr ) data ;
3738 /* This can happen if Ruby does a GC run after creating the
3839 new attribute but before initializing it. */
3940 if (xattr != NULL )
4041 rxml_node_mark ((xmlNodePtr ) xattr );
4142}
4243
44+ const rb_data_type_t rxml_attr_type = {
45+ "LibXML::XML::Attr" ,
46+ {rxml_attr_mark , NULL , 0 },
47+ & rxml_node_data_type , 0 , RUBY_TYPED_FREE_IMMEDIATELY
48+ };
49+
4350VALUE rxml_attr_wrap (xmlAttrPtr xattr )
4451{
45- return Data_Wrap_Struct (cXMLAttr , rxml_attr_mark , NULL , xattr );
52+ return TypedData_Wrap_Struct (cXMLAttr , & rxml_attr_type , xattr );
4653}
4754
4855static VALUE rxml_attr_alloc (VALUE klass )
4956{
50- return Data_Wrap_Struct (klass , rxml_attr_mark , NULL , NULL );
57+ return TypedData_Wrap_Struct (klass , & rxml_attr_type , NULL );
5158}
5259
5360/*
@@ -78,7 +85,7 @@ static VALUE rxml_attr_initialize(int argc, VALUE *argv, VALUE self)
7885 Check_Type (name , T_STRING );
7986 Check_Type (value , T_STRING );
8087
81- Data_Get_Struct (node , xmlNode , xnode );
88+ TypedData_Get_Struct (node , xmlNode , & rxml_node_data_type , xnode );
8289
8390 if (xnode -> type != XML_ELEMENT_NODE )
8491 rb_raise (rb_eArgError , "Attributes can only be created on element nodes." );
@@ -90,14 +97,14 @@ static VALUE rxml_attr_initialize(int argc, VALUE *argv, VALUE self)
9097 else
9198 {
9299 xmlNsPtr xns ;
93- Data_Get_Struct (ns , xmlNs , xns );
100+ TypedData_Get_Struct (ns , xmlNs , & rxml_namespace_type , xns );
94101 xattr = xmlNewNsProp (xnode , xns , (xmlChar * )StringValuePtr (name ), (xmlChar * )StringValuePtr (value ));
95102 }
96103
97104 if (!xattr )
98105 rb_raise (rb_eRuntimeError , "Could not create attribute." );
99106
100- DATA_PTR ( self ) = xattr ;
107+ RTYPEDDATA_DATA ( self ) = xattr ;
101108 return self ;
102109}
103110
@@ -110,7 +117,7 @@ static VALUE rxml_attr_initialize(int argc, VALUE *argv, VALUE self)
110117static VALUE rxml_attr_child_get (VALUE self )
111118{
112119 xmlAttrPtr xattr ;
113- Data_Get_Struct (self , xmlAttr , xattr );
120+ TypedData_Get_Struct (self , xmlAttr , & rxml_attr_type , xattr );
114121 if (xattr -> children == NULL )
115122 return Qnil ;
116123 else
@@ -129,7 +136,7 @@ static VALUE rxml_attr_child_get(VALUE self)
129136static VALUE rxml_attr_doc_get (VALUE self )
130137{
131138 xmlAttrPtr xattr ;
132- Data_Get_Struct (self , xmlAttr , xattr );
139+ TypedData_Get_Struct (self , xmlAttr , & rxml_attr_type , xattr );
133140 if (xattr -> doc == NULL )
134141 return Qnil ;
135142 else
@@ -145,7 +152,7 @@ static VALUE rxml_attr_doc_get(VALUE self)
145152static VALUE rxml_attr_last_get (VALUE self )
146153{
147154 xmlAttrPtr xattr ;
148- Data_Get_Struct (self , xmlAttr , xattr );
155+ TypedData_Get_Struct (self , xmlAttr , & rxml_attr_type , xattr );
149156 if (xattr -> last == NULL )
150157 return Qnil ;
151158 else
@@ -161,7 +168,7 @@ static VALUE rxml_attr_last_get(VALUE self)
161168static VALUE rxml_attr_name_get (VALUE self )
162169{
163170 xmlAttrPtr xattr ;
164- Data_Get_Struct (self , xmlAttr , xattr );
171+ TypedData_Get_Struct (self , xmlAttr , & rxml_attr_type , xattr );
165172
166173 if (xattr -> name == NULL )
167174 return Qnil ;
@@ -178,7 +185,7 @@ static VALUE rxml_attr_name_get(VALUE self)
178185static VALUE rxml_attr_next_get (VALUE self )
179186{
180187 xmlAttrPtr xattr ;
181- Data_Get_Struct (self , xmlAttr , xattr );
188+ TypedData_Get_Struct (self , xmlAttr , & rxml_attr_type , xattr );
182189 if (xattr -> next == NULL )
183190 return Qnil ;
184191 else
@@ -194,7 +201,7 @@ static VALUE rxml_attr_next_get(VALUE self)
194201static VALUE rxml_attr_node_type (VALUE self )
195202{
196203 xmlAttrPtr xattr ;
197- Data_Get_Struct (self , xmlAttr , xattr );
204+ TypedData_Get_Struct (self , xmlAttr , & rxml_attr_type , xattr );
198205 return INT2NUM (xattr -> type );
199206}
200207
@@ -207,7 +214,7 @@ static VALUE rxml_attr_node_type(VALUE self)
207214static VALUE rxml_attr_ns_get (VALUE self )
208215{
209216 xmlAttrPtr xattr ;
210- Data_Get_Struct (self , xmlAttr , xattr );
217+ TypedData_Get_Struct (self , xmlAttr , & rxml_attr_type , xattr );
211218 if (xattr -> ns == NULL )
212219 return Qnil ;
213220 else
@@ -223,7 +230,7 @@ static VALUE rxml_attr_ns_get(VALUE self)
223230static VALUE rxml_attr_parent_get (VALUE self )
224231{
225232 xmlAttrPtr xattr ;
226- Data_Get_Struct (self , xmlAttr , xattr );
233+ TypedData_Get_Struct (self , xmlAttr , & rxml_attr_type , xattr );
227234 if (xattr -> parent == NULL )
228235 return Qnil ;
229236 else
@@ -239,7 +246,7 @@ static VALUE rxml_attr_parent_get(VALUE self)
239246static VALUE rxml_attr_prev_get (VALUE self )
240247{
241248 xmlAttrPtr xattr ;
242- Data_Get_Struct (self , xmlAttr , xattr );
249+ TypedData_Get_Struct (self , xmlAttr , & rxml_attr_type , xattr );
243250 if (xattr -> prev == NULL )
244251 return Qnil ;
245252 else
@@ -258,12 +265,10 @@ static VALUE rxml_attr_prev_get(VALUE self)
258265static VALUE rxml_attr_remove_ex (VALUE self )
259266{
260267 xmlAttrPtr xattr ;
261- Data_Get_Struct (self , xmlAttr , xattr );
268+ TypedData_Get_Struct (self , xmlAttr , & rxml_attr_type , xattr );
262269 xmlRemoveProp (xattr );
263270
264- RDATA (self )-> data = NULL ;
265- RDATA (self )-> dfree = NULL ;
266- RDATA (self )-> dmark = NULL ;
271+ RTYPEDDATA_DATA (self ) = NULL ;
267272
268273 return Qnil ;
269274}
@@ -280,7 +285,7 @@ VALUE rxml_attr_value_get(VALUE self)
280285 xmlChar * value ;
281286 VALUE result = Qnil ;
282287
283- Data_Get_Struct (self , xmlAttr , xattr );
288+ TypedData_Get_Struct (self , xmlAttr , & rxml_attr_type , xattr );
284289 value = xmlNodeGetContent ((xmlNodePtr )xattr );
285290
286291 if (value != NULL )
@@ -302,7 +307,7 @@ VALUE rxml_attr_value_set(VALUE self, VALUE val)
302307 xmlAttrPtr xattr ;
303308
304309 Check_Type (val , T_STRING );
305- Data_Get_Struct (self , xmlAttr , xattr );
310+ TypedData_Get_Struct (self , xmlAttr , & rxml_attr_type , xattr );
306311
307312 if (xattr -> ns )
308313 xmlSetNsProp (xattr -> parent , xattr -> ns , xattr -> name ,
0 commit comments