25
25
VALUE cNokogiriXmlNamespace ;
26
26
27
27
static void
28
- dealloc_namespace ( xmlNsPtr ns )
28
+ _xml_namespace_dealloc ( void * ptr )
29
29
{
30
30
/*
31
31
* this deallocator is only used for namespace nodes that are part of an xpath
32
32
* node set. see noko_xml_namespace_wrap().
33
33
*/
34
+ xmlNsPtr ns = ptr ;
34
35
NOKOGIRI_DEBUG_START (ns ) ;
36
+
35
37
if (ns -> href ) {
36
38
xmlFree (DISCARD_CONST_QUAL_XMLCHAR (ns -> href ));
37
39
}
@@ -42,6 +44,36 @@ dealloc_namespace(xmlNsPtr ns)
42
44
NOKOGIRI_DEBUG_END (ns ) ;
43
45
}
44
46
47
+ #ifdef HAVE_RB_GC_LOCATION
48
+ static void
49
+ _xml_namespace_update_references (void * ptr )
50
+ {
51
+ xmlNsPtr ns = ptr ;
52
+ if (ns -> _private ) {
53
+ ns -> _private = (void * )rb_gc_location ((VALUE )ns -> _private );
54
+ }
55
+ }
56
+ #else
57
+ # define _xml_namespace_update_references 0
58
+ #endif
59
+
60
+ static const rb_data_type_t nokogiri_xml_namespace_type_with_dealloc = {
61
+ "Nokogiri/XMLNamespace/WithDealloc" ,
62
+ {0 , _xml_namespace_dealloc , 0 , _xml_namespace_update_references },
63
+ 0 , 0 ,
64
+ #ifdef RUBY_TYPED_FREE_IMMEDIATELY
65
+ RUBY_TYPED_FREE_IMMEDIATELY ,
66
+ #endif
67
+ };
68
+
69
+ static const rb_data_type_t nokogiri_xml_namespace_type_without_dealloc = {
70
+ "Nokogiri/XMLNamespace/WithoutDealloc" ,
71
+ {0 , 0 , 0 , _xml_namespace_update_references },
72
+ 0 , 0 ,
73
+ #ifdef RUBY_TYPED_FREE_IMMEDIATELY
74
+ RUBY_TYPED_FREE_IMMEDIATELY ,
75
+ #endif
76
+ };
45
77
46
78
/*
47
79
* call-seq:
@@ -54,7 +86,7 @@ prefix(VALUE self)
54
86
{
55
87
xmlNsPtr ns ;
56
88
57
- Data_Get_Struct (self , xmlNs , ns );
89
+ Noko_Namespace_Get_Struct (self , xmlNs , ns );
58
90
if (!ns -> prefix ) { return Qnil ; }
59
91
60
92
return NOKOGIRI_STR_NEW2 (ns -> prefix );
@@ -71,7 +103,7 @@ href(VALUE self)
71
103
{
72
104
xmlNsPtr ns ;
73
105
74
- Data_Get_Struct (self , xmlNs , ns );
106
+ Noko_Namespace_Get_Struct (self , xmlNs , ns );
75
107
if (!ns -> href ) { return Qnil ; }
76
108
77
109
return NOKOGIRI_STR_NEW2 (ns -> href );
@@ -87,14 +119,18 @@ noko_xml_namespace_wrap(xmlNsPtr c_namespace, xmlDocPtr c_document)
87
119
}
88
120
89
121
if (c_document ) {
90
- rb_namespace = Data_Wrap_Struct (cNokogiriXmlNamespace , 0 , 0 , c_namespace );
122
+ rb_namespace = TypedData_Wrap_Struct (cNokogiriXmlNamespace ,
123
+ & nokogiri_xml_namespace_type_without_dealloc ,
124
+ c_namespace );
91
125
92
126
if (DOC_RUBY_OBJECT_TEST (c_document )) {
93
127
rb_iv_set (rb_namespace , "@document" , DOC_RUBY_OBJECT (c_document ));
94
128
rb_ary_push (DOC_NODE_CACHE (c_document ), rb_namespace );
95
129
}
96
130
} else {
97
- rb_namespace = Data_Wrap_Struct (cNokogiriXmlNamespace , 0 , dealloc_namespace , c_namespace );
131
+ rb_namespace = TypedData_Wrap_Struct (cNokogiriXmlNamespace ,
132
+ & nokogiri_xml_namespace_type_with_dealloc ,
133
+ c_namespace );
98
134
}
99
135
100
136
c_namespace -> _private = (void * )rb_namespace ;
0 commit comments