diff --git a/ext/json/generator/extconf.rb b/ext/json/generator/extconf.rb index 149f22c13..7b5f3bc70 100644 --- a/ext/json/generator/extconf.rb +++ b/ext/json/generator/extconf.rb @@ -17,4 +17,5 @@ have_header("ruby/re.h") have_header("ruby/encoding.h") end +$INCFLAGS << ' -I../../..' create_makefile 'json/ext/generator' diff --git a/ext/json/generator/generator.c b/ext/json/generator/generator.c index aa895e918..744a5925f 100644 --- a/ext/json/generator/generator.c +++ b/ext/json/generator/generator.c @@ -1315,6 +1315,24 @@ static VALUE cState_depth_set(VALUE self, VALUE depth) return state->depth = FIX2LONG(depth); } +#ifdef __MACRUBY__ +#include "macruby_internal.h" +#include "objc.h" +static IMP json_generator_state_finalize_imp_super = NULL; +static void +json_generator_state_finalize_imp(void *self, SEL sel) +{ + JSON_Generator_State *objState; + Data_Get_Struct(self, JSON_Generator_State, objState); + if (objState != NULL) { + State_free(objState); + } + if (json_generator_state_finalize_imp_super != NULL) { + ((void(*)(void *, SEL))json_generator_state_finalize_imp_super)(self, sel); + } +} +#endif + /* * */ @@ -1416,4 +1434,9 @@ void Init_generator() #endif i_SAFE_STATE_PROTOTYPE = rb_intern("SAFE_STATE_PROTOTYPE"); CJSON_SAFE_STATE_PROTOTYPE = Qnil; + +#ifdef __MACRUBY__ + json_generator_state_finalize_imp_super = rb_objc_install_method2((Class)cState, + "finalize", (IMP)json_generator_state_finalize_imp); +#endif } diff --git a/ext/json/generator/generator.h b/ext/json/generator/generator.h index 9c3f78920..28f3b88d7 100644 --- a/ext/json/generator/generator.h +++ b/ext/json/generator/generator.h @@ -7,7 +7,7 @@ #include "ruby.h" -#if WITH_OBJC +#ifdef __MACRUBY__ /* We cannot use the GC memory functions here because the underlying libedit * function will call free() on the memory, resulting in a leak. */