Skip to content

Commit

Permalink
ext: migrate Nokogiri::EncodingHandler to TypedData API
Browse files Browse the repository at this point in the history
See #2808
  • Loading branch information
flavorjones committed Mar 6, 2023
1 parent b12c85f commit 1501143
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ext/nokogiri/xml_encoding_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@

VALUE cNokogiriEncodingHandler;


static void
_xml_encoding_handler_dealloc(xmlCharEncodingHandlerPtr c_handler)
xml_encoding_handler_dealloc(void *data)
{
/* make sure iconv handlers are cleaned up and freed */
xmlCharEncodingHandlerPtr c_handler = data;
xmlCharEncCloseFunc(c_handler);
}

static const rb_data_type_t xml_encoding_handler_type = {
.wrap_struct_name = "Nokogiri::EncodingHandler",
.function = {
.dfree = xml_encoding_handler_dealloc,
},
.flags = RUBY_TYPED_FREE_IMMEDIATELY
};


/*
* call-seq: Nokogiri::EncodingHandler.[](name)
Expand All @@ -23,7 +31,7 @@ rb_xml_encoding_handler_s_get(VALUE klass, VALUE key)

handler = xmlFindCharEncodingHandler(StringValueCStr(key));
if (handler) {
return Data_Wrap_Struct(klass, NULL, _xml_encoding_handler_dealloc, handler);
return TypedData_Wrap_Struct(klass, &xml_encoding_handler_type, handler);
}

return Qnil;
Expand Down Expand Up @@ -82,7 +90,7 @@ rb_xml_encoding_handler_name(VALUE self)
{
xmlCharEncodingHandlerPtr handler;

Data_Get_Struct(self, xmlCharEncodingHandler, handler);
TypedData_Get_Struct(self, xmlCharEncodingHandler, &xml_encoding_handler_type, handler);

return NOKOGIRI_STR_NEW2(handler->name);
}
Expand Down

0 comments on commit 1501143

Please sign in to comment.