@@ -64,7 +64,7 @@ void rxml_document_free(void* data)
6464{
6565 xmlDocPtr xdoc = (xmlDocPtr )data ;
6666 if (!xdoc ) return ;
67- xdoc -> _private = NULL ;
67+ rxml_registry_unregister ( xdoc ) ;
6868 xmlFreeDoc (xdoc );
6969}
7070
@@ -78,15 +78,12 @@ VALUE rxml_document_wrap(xmlDocPtr xdoc)
7878{
7979 VALUE result = Qnil ;
8080
81- // Is this node is already wrapped?
82- if (xdoc -> _private != NULL )
83- {
84- result = (VALUE )xdoc -> _private ;
85- }
86- else
81+ // Is this document already wrapped?
82+ result = rxml_registry_lookup (xdoc );
83+ if (NIL_P (result ))
8784 {
8885 result = TypedData_Wrap_Struct (cXMLDocument , & rxml_document_data_type , xdoc );
89- xdoc -> _private = ( void * ) result ;
86+ rxml_registry_register ( xdoc , result ) ;
9087 }
9188
9289 return result ;
@@ -133,7 +130,7 @@ static VALUE rxml_document_initialize(int argc, VALUE *argv, VALUE self)
133130
134131 // Link the ruby object to the document and the document to the ruby object
135132 RTYPEDDATA_DATA (self ) = xdoc ;
136- xdoc -> _private = ( void * ) self ;
133+ rxml_registry_register ( xdoc , self ) ;
137134
138135 return self ;
139136}
@@ -221,18 +218,18 @@ rxml_document_canonicalize(int argc, VALUE *argv, VALUE self)
221218 // Do stuff if ruby hash passed as argument
222219 if (!NIL_P (option_hash ))
223220 {
224- VALUE o_comments = Qnil ;
225- VALUE o_mode = Qnil ;
226- VALUE o_i_ns_prefixes = Qnil ;
227-
221+ VALUE o_comments = Qnil ;
222+ VALUE o_mode = Qnil ;
223+ VALUE o_i_ns_prefixes = Qnil ;
224+
228225 Check_Type (option_hash , T_HASH );
229226
230227 o_comments = rb_hash_aref (option_hash , ID2SYM (rb_intern ("comments" )));
231228 comments = (RTEST (o_comments ) ? 1 : 0 );
232229
233230 o_mode = rb_hash_aref (option_hash , ID2SYM (rb_intern ("mode" )));
234231 if (!NIL_P (o_mode ))
235- {
232+ {
236233 Check_Type (o_mode , T_FIXNUM );
237234 c14n_mode = NUM2INT (o_mode );
238235 //TODO: clean this up
@@ -242,25 +239,25 @@ rxml_document_canonicalize(int argc, VALUE *argv, VALUE self)
242239
243240 o_i_ns_prefixes = rb_hash_aref (option_hash , ID2SYM (rb_intern ("inclusive_ns_prefixes" )));
244241 if (!NIL_P (o_i_ns_prefixes ))
245- {
242+ {
246243 int i ;
247244 int p = 0 ; //pointer array index
248245 VALUE * list_in = NULL ;
249246 long list_size = 0 ;
250247
251- Check_Type (o_i_ns_prefixes , T_ARRAY );
248+ Check_Type (o_i_ns_prefixes , T_ARRAY );
252249 list_in = RARRAY_PTR (o_i_ns_prefixes );
253250 list_size = RARRAY_LEN (o_i_ns_prefixes );
254251
255252 if (list_size > 0 )
256- {
253+ {
257254 for (i = 0 ; i < list_size ; ++ i ) {
258255 if (p >= C14N_NS_LIMIT ) { break ; }
259256
260257 if (RTEST (list_in [i ]))
261- {
258+ {
262259 if (TYPE (list_in [i ]) == T_STRING )
263- {
260+ {
264261 inc_ns_prefixes_ptr [p ] = (xmlChar * )StringValueCStr (list_in [i ]);
265262 p ++ ;
266263 }
@@ -279,29 +276,29 @@ rxml_document_canonicalize(int argc, VALUE *argv, VALUE self)
279276
280277 o_nodes = rb_hash_aref (option_hash , ID2SYM (rb_intern ("nodes" )));
281278 if (!NIL_P (o_nodes ))
282- {
279+ {
283280 int i ;
284281 int p = 0 ; // index of pointer array
285282 VALUE * list_in = NULL ;
286283 long node_list_size = 0 ;
287284
288- if (CLASS_OF (o_nodes ) == cXMLXPathObject )
289- {
290- o_nodes = rb_funcall (o_nodes , rb_intern ("to_a" ), 0 );
291- }
292- else
293- {
294- Check_Type (o_nodes , T_ARRAY );
295- }
285+ if (CLASS_OF (o_nodes ) == cXMLXPathObject )
286+ {
287+ o_nodes = rb_funcall (o_nodes , rb_intern ("to_a" ), 0 );
288+ }
289+ else
290+ {
291+ Check_Type (o_nodes , T_ARRAY );
292+ }
296293 list_in = RARRAY_PTR (o_nodes );
297294 node_list_size = RARRAY_LEN (o_nodes );
298295
299296 for (i = 0 ; i < node_list_size ; ++ i )
300- {
297+ {
301298 if (p >= C14N_NODESET_LIMIT ) { break ; }
302299
303300 if (RTEST (list_in [i ]))
304- {
301+ {
305302 xmlNodePtr node_ptr ;
306303 TypedData_Get_Struct (list_in [i ], xmlNode , & rxml_node_data_type , node_ptr );
307304 node_ptr_array [p ] = node_ptr ;
@@ -936,9 +933,9 @@ static VALUE rxml_document_version_get(VALUE self)
936933static VALUE rxml_document_xhtml_q (VALUE self )
937934{
938935 xmlDocPtr xdoc ;
939- xmlDtdPtr xdtd ;
936+ xmlDtdPtr xdtd ;
940937 TypedData_Get_Struct (self , xmlDoc , & rxml_document_data_type , xdoc );
941- xdtd = xmlGetIntSubset (xdoc );
938+ xdtd = xmlGetIntSubset (xdoc );
942939 if (xdtd != NULL && xmlIsXHTML (xdtd -> SystemID , xdtd -> ExternalID ) > 0 )
943940 return (Qtrue );
944941 else
0 commit comments