From dfd6996a4503eec3d2037d071ecf4f3319de8466 Mon Sep 17 00:00:00 2001 From: NAKAMURA Usaku Date: Tue, 23 Apr 2013 22:09:09 +0900 Subject: [PATCH 1/2] Get rid of gcc-ism. --- ext/yajl/extconf.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/yajl/extconf.rb b/ext/yajl/extconf.rb index 439c0eb5..f0c7a00a 100644 --- a/ext/yajl/extconf.rb +++ b/ext/yajl/extconf.rb @@ -1,7 +1,7 @@ require 'mkmf' require 'rbconfig' -$CFLAGS << ' -Wall -funroll-loops' -$CFLAGS << ' -Wextra -O0 -ggdb3' if ENV['DEBUG'] +$CFLAGS << ' -Wall -funroll-loops' unless $mswin +$CFLAGS << ' -Wextra -O0 -ggdb3' if ENV['DEBUG'] && !$mswin create_makefile('yajl/yajl') From ed8dff5c3d9beb9851ff5c97dc630adbd4eb1ac2 Mon Sep 17 00:00:00 2001 From: NAKAMURA Usaku Date: Tue, 23 Apr 2013 22:09:19 +0900 Subject: [PATCH 2/2] VC++ support. * ext/yajl/yajl_ext.c (yajl_found_number, yajl_found_hash_key): get rid of C99ism. * ext/yajl/yajl_ext.c (rb_yajl_parser_new, rb_yajl_encoder_new): get rid of gcc-ism. * ext/yajl/yajl_enc.c: include ruby.h for the definitions of isinf() and isnan() of VC++. --- ext/yajl/yajl_ext.c | 16 +++++++++++----- ext/yajl/yajl_gen.c | 2 ++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ext/yajl/yajl_ext.c b/ext/yajl/yajl_ext.c index be9e5707..45646fd0 100644 --- a/ext/yajl/yajl_ext.c +++ b/ext/yajl/yajl_ext.c @@ -245,7 +245,7 @@ static int yajl_found_boolean(void * ctx, int boolean) { } static int yajl_found_number(void * ctx, const char * numberVal, unsigned int numberLen) { - char buf[numberLen+1]; + char *buf = ruby_xmalloc(numberLen+1); buf[numberLen] = 0; memcpy(buf, numberVal, numberLen); @@ -256,6 +256,7 @@ static int yajl_found_number(void * ctx, const char * numberVal, unsigned int nu } else { yajl_set_static_value(ctx, rb_cstr2inum(buf, 10)); } + ruby_xfree(buf); return 1; } @@ -285,15 +286,17 @@ static int yajl_found_hash_key(void * ctx, const unsigned char * stringVal, unsi #endif if (wrapper->symbolizeKeys) { - char buf[stringLen+1]; + VALUE stringEncoded; + char *buf = ruby_xmalloc(stringLen+1); memcpy(buf, stringVal, stringLen); buf[stringLen] = 0; - VALUE stringEncoded = rb_str_new2(buf); + stringEncoded = rb_str_new2(buf); #ifdef HAVE_RUBY_ENCODING_H rb_enc_associate(stringEncoded, rb_utf8_encoding()); #endif yajl_set_static_value(ctx, ID2SYM(rb_to_id(stringEncoded))); + ruby_xfree(buf); } else { keyStr = rb_str_new((const char *)stringVal, stringLen); #ifdef HAVE_RUBY_ENCODING_H @@ -388,7 +391,8 @@ static VALUE rb_yajl_parser_new(int argc, VALUE * argv, VALUE klass) { symbolizeKeys = 1; } } - cfg = (yajl_parser_config){allowComments, checkUTF8}; + cfg.allowComments = allowComments; + cfg.checkUTF8 = checkUTF8; obj = Data_Make_Struct(klass, yajl_parser_wrapper, yajl_parser_wrapper_mark, yajl_parser_wrapper_free, wrapper); wrapper->parser = yajl_alloc(&callbacks, &cfg, NULL, (void *)obj); @@ -587,7 +591,9 @@ static VALUE rb_yajl_encoder_new(int argc, VALUE * argv, VALUE klass) { if (!indentString) { indentString = defaultIndentString; } - cfg = (yajl_gen_config){beautify, (const char *)indentString, htmlSafe}; + cfg.beautify = beautify; + cfg.indentString = (const char *)indentString; + cfg.htmlSafe = htmlSafe; obj = Data_Make_Struct(klass, yajl_encoder_wrapper, yajl_encoder_wrapper_mark, yajl_encoder_wrapper_free, wrapper); wrapper->indentString = actualIndent; diff --git a/ext/yajl/yajl_gen.c b/ext/yajl/yajl_gen.c index f5b5baea..bd59bbf9 100644 --- a/ext/yajl/yajl_gen.c +++ b/ext/yajl/yajl_gen.c @@ -30,6 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include "ruby.h" + #include "api/yajl_gen.h" #include "yajl_buf.h" #include "yajl_encode.h"