diff --git a/ext/commonmarker/commonmarker.c b/ext/commonmarker/commonmarker.c index 71509159..111399ed 100644 --- a/ext/commonmarker/commonmarker.c +++ b/ext/commonmarker/commonmarker.c @@ -4,7 +4,9 @@ #include "comrak_ffi.h" -int iterate_extension_options(VALUE key, VALUE val, comrak_options_t *config) { +int iterate_extension_options(VALUE key, VALUE val, VALUE arg) { + comrak_options_t *config = (comrak_options_t *)arg; + if (key == ID2SYM(rb_intern("strikethrough"))) { if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { comrak_set_extension_option_strikethrough(config, val); @@ -50,7 +52,9 @@ int iterate_extension_options(VALUE key, VALUE val, comrak_options_t *config) { return ST_CONTINUE; } -int iterate_render_options(VALUE key, VALUE val, comrak_options_t *config) { +int iterate_render_options(VALUE key, VALUE val, VALUE arg) { + comrak_options_t *config = (comrak_options_t *)arg; + if (key == ID2SYM(rb_intern("hardbreaks"))) { if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { comrak_set_render_option_hardbreaks(config, val); @@ -77,7 +81,9 @@ int iterate_render_options(VALUE key, VALUE val, comrak_options_t *config) { return ST_CONTINUE; } -int iterate_parse_options(VALUE key, VALUE val, comrak_options_t *config) { +int iterate_parse_options(VALUE key, VALUE val, VALUE arg) { + comrak_options_t *config = (comrak_options_t *)arg; + if (key == ID2SYM(rb_intern("smart"))) { if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { comrak_set_parse_option_smart(config, val); @@ -92,22 +98,24 @@ int iterate_parse_options(VALUE key, VALUE val, comrak_options_t *config) { return ST_CONTINUE; } -int iterate_options_hash(VALUE rb_option_key, VALUE rb_option_val, comrak_options_t *config) { +int iterate_options_hash(VALUE rb_option_key, VALUE rb_option_val, VALUE arg) { + comrak_options_t *config = (comrak_options_t *)arg; + Check_Type(rb_option_key, T_SYMBOL); // which options are we dealing with? if (rb_option_key == ID2SYM(rb_intern("parse"))) { Check_Type(rb_option_val, T_HASH); - rb_hash_foreach(rb_option_val, iterate_parse_options, config); + rb_hash_foreach(rb_option_val, iterate_parse_options, (VALUE)config); } else if (rb_option_key == ID2SYM(rb_intern("render"))) { Check_Type(rb_option_val, T_HASH); - rb_hash_foreach(rb_option_val, iterate_render_options, config); + rb_hash_foreach(rb_option_val, iterate_render_options, (VALUE)config); } else if (rb_option_key == ID2SYM(rb_intern("extension"))) { Check_Type(rb_option_val, T_HASH); if (rb_hash_aref(rb_option_val, ID2SYM(rb_intern("header_ids"))) == Qnil) { comrak_set_extension_option_header_ids(config, NULL, 0); } - rb_hash_foreach(rb_option_val, iterate_extension_options, config); + rb_hash_foreach(rb_option_val, iterate_extension_options, (VALUE)config); } @@ -121,7 +129,7 @@ VALUE commonmark_to_html(VALUE self, VALUE rb_commonmark, VALUE rb_options) { char *commonmark = StringValueCStr(rb_commonmark); comrak_options_t *options = comrak_options_new(); - rb_hash_foreach(rb_options, iterate_options_hash, options); + rb_hash_foreach(rb_options, iterate_options_hash, (VALUE)options); comrak_str_t html = comrak_commonmark_to_html(commonmark, options);