Skip to content

Commit

Permalink
ext: avoid warnings in rb_hash_foreach calls
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed Aug 5, 2022
1 parent a76379a commit aa4afde
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions ext/commonmarker/commonmarker.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);

}

Expand All @@ -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);

Expand Down

0 comments on commit aa4afde

Please sign in to comment.