diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2013-12-21 14:55:46 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2013-12-21 14:55:46 -0800 |
commit | d264d7d6a6beb4ebc9affbe1340779ccef381445 (patch) | |
tree | ed49eab0cc0a864cf31a0cbd334dc43a1bee3369 | |
parent | 42f668bb8097a3e5f9153227a07c02e9e3d2ee28 (diff) | |
download | ffi-yajl-d264d7d6a6beb4ebc9affbe1340779ccef381445.tar.gz |
finally all green again
-rw-r--r-- | ext/ffi_yajl/ext/encoder/encoder.c | 77 | ||||
-rw-r--r-- | ext/ffi_yajl/ext/parser/Makefile | 49 |
2 files changed, 85 insertions, 41 deletions
diff --git a/ext/ffi_yajl/ext/encoder/encoder.c b/ext/ffi_yajl/ext/encoder/encoder.c index da4ea17..22d14a6 100644 --- a/ext/ffi_yajl/ext/encoder/encoder.c +++ b/ext/ffi_yajl/ext/encoder/encoder.c @@ -1,10 +1,13 @@ #include <ruby.h> #include <yajl/yajl_gen.h> -static VALUE mFFI_Yajl, mExt, mEncoder, cEncodeError; +static VALUE mFFI_Yajl, mExt, mEncoder, mEncoder2, cEncodeError; /* FIXME: the json gem does a whole bunch of indirection around monkeypatching... not sure if we need to as well... */ +#define CHECK_STATUS(call) \ + if ((status = (call)) != yajl_gen_status_ok) { rb_funcall(mEncoder2, rb_intern("raise_error_for_status"), 1, status); } + typedef struct { VALUE json_opts; int processing_key; @@ -69,49 +72,69 @@ int rb_cHash_ffi_yajl_callback(VALUE key, VALUE val, VALUE extra) { } static VALUE rb_cHash_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) { + yajl_gen_status status; ffs_extra_t extra; extra.yajl_gen = yajl_gen; extra.state = (ffi_state_t *)state; - yajl_gen_map_open((struct yajl_gen_t *) yajl_gen); + CHECK_STATUS( + yajl_gen_map_open((struct yajl_gen_t *) yajl_gen) + ); rb_hash_foreach(self, rb_cHash_ffi_yajl_callback, (VALUE) &extra); - yajl_gen_map_close((struct yajl_gen_t *) yajl_gen); + CHECK_STATUS( + yajl_gen_map_close((struct yajl_gen_t *) yajl_gen) + ); return Qnil; } static VALUE rb_cArray_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) { + yajl_gen_status status; ID sym_ffi_yajl = rb_intern("ffi_yajl"); long i; VALUE val; - yajl_gen_array_open((struct yajl_gen_t *) yajl_gen); + CHECK_STATUS( + yajl_gen_array_open((struct yajl_gen_t *) yajl_gen) + ); for(i=0; i<RARRAY_LEN(self); i++) { val = rb_ary_entry(self, i); rb_funcall(val, sym_ffi_yajl, 2, yajl_gen, state); } - yajl_gen_array_close((struct yajl_gen_t *) yajl_gen); + CHECK_STATUS( + yajl_gen_array_close((struct yajl_gen_t *) yajl_gen) + ); return Qnil; } static VALUE rb_cNilClass_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) { - yajl_gen_null((struct yajl_gen_t *) yajl_gen); + yajl_gen_status status; + CHECK_STATUS( + yajl_gen_null((struct yajl_gen_t *) yajl_gen) + ); return Qnil; } static VALUE rb_cTrueClass_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) { - yajl_gen_bool((struct yajl_gen_t *) yajl_gen, 1); + yajl_gen_status status; + CHECK_STATUS( + yajl_gen_bool((struct yajl_gen_t *) yajl_gen, 1) + ); return Qnil; } static VALUE rb_cFalseClass_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) { - yajl_gen_bool((struct yajl_gen_t *) yajl_gen, 0); + yajl_gen_status status; + CHECK_STATUS( + yajl_gen_bool((struct yajl_gen_t *) yajl_gen, 0) + ); return Qnil; } static VALUE rb_cFixnum_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) { + yajl_gen_status status; ID sym_to_s = rb_intern("to_s"); VALUE str = rb_funcall(self, sym_to_s, 0); char *cptr = RSTRING_PTR(str); @@ -121,14 +144,19 @@ static VALUE rb_cFixnum_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) { rb_raise(cEncodeError, "'%s' is an invalid number", cptr); } if ( ((ffi_state_t *)state)->processing_key ) { - yajl_gen_string((struct yajl_gen_t *) yajl_gen, (unsigned char *)cptr, len); + CHECK_STATUS( + yajl_gen_string((struct yajl_gen_t *) yajl_gen, (unsigned char *)cptr, len) + ); } else { - yajl_gen_integer((struct yajl_gen_t *) yajl_gen, NUM2INT(self)); + CHECK_STATUS( + yajl_gen_integer((struct yajl_gen_t *) yajl_gen, NUM2INT(self)) + ); } return Qnil; } static VALUE rb_cBignum_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) { + yajl_gen_status status; ID sym_to_s = rb_intern("to_s"); VALUE str = rb_funcall(self, sym_to_s, 0); char *cptr = RSTRING_PTR(str); @@ -137,14 +165,19 @@ static VALUE rb_cBignum_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) { rb_raise(cEncodeError, "'%s' is an invalid number", cptr); } if ( ((ffi_state_t *)state)->processing_key ) { - yajl_gen_string((struct yajl_gen_t *) yajl_gen, (unsigned char *)cptr, len); + CHECK_STATUS( + yajl_gen_string((struct yajl_gen_t *) yajl_gen, (unsigned char *)cptr, len) + ); } else { - yajl_gen_number((struct yajl_gen_t *) yajl_gen, cptr, len); + CHECK_STATUS( + yajl_gen_number((struct yajl_gen_t *) yajl_gen, cptr, len) + ); } return Qnil; } static VALUE rb_cFloat_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) { + yajl_gen_status status; ID sym_to_s = rb_intern("to_s"); VALUE str = rb_funcall(self, sym_to_s, 0); char *cptr = RSTRING_PTR(str); @@ -153,29 +186,41 @@ static VALUE rb_cFloat_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) { rb_raise(cEncodeError, "'%s' is an invalid number", cptr); } if ( ((ffi_state_t *)state)->processing_key ) { - yajl_gen_string((struct yajl_gen_t *) yajl_gen, (unsigned char *)cptr, len); + CHECK_STATUS( + yajl_gen_string((struct yajl_gen_t *) yajl_gen, (unsigned char *)cptr, len) + ); } else { - yajl_gen_number((struct yajl_gen_t *) yajl_gen, cptr, len); + CHECK_STATUS( + yajl_gen_number((struct yajl_gen_t *) yajl_gen, cptr, len) + ); } return Qnil; } + static VALUE rb_cString_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) { - yajl_gen_string((struct yajl_gen_t *) yajl_gen, (unsigned char *)RSTRING_PTR(self), RSTRING_LEN(self)); + yajl_gen_status status; + CHECK_STATUS( + yajl_gen_string((struct yajl_gen_t *) yajl_gen, (unsigned char *)RSTRING_PTR(self), RSTRING_LEN(self)) + ); return Qnil; } static VALUE rb_cObject_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) { + yajl_gen_status status; ID sym_to_json = rb_intern("to_json"); VALUE str; str = rb_funcall(self, sym_to_json, 1, ((ffi_state_t *)state)->json_opts); - yajl_gen_number((struct yajl_gen_t *) yajl_gen, (char *)RSTRING_PTR(str), RSTRING_LEN(str)); + CHECK_STATUS( + yajl_gen_number((struct yajl_gen_t *) yajl_gen, (char *)RSTRING_PTR(str), RSTRING_LEN(str)) + ); return Qnil; } void Init_encoder() { mFFI_Yajl = rb_define_module("FFI_Yajl"); + mEncoder2 = rb_define_class_under(mFFI_Yajl, "Encoder", rb_cObject); cEncodeError = rb_define_class_under(mFFI_Yajl, "EncodeError", rb_eStandardError); mExt = rb_define_module_under(mFFI_Yajl, "Ext"); mEncoder = rb_define_module_under(mExt, "Encoder"); diff --git a/ext/ffi_yajl/ext/parser/Makefile b/ext/ffi_yajl/ext/parser/Makefile index 840cc31..de17250 100644 --- a/ext/ffi_yajl/ext/parser/Makefile +++ b/ext/ffi_yajl/ext/parser/Makefile @@ -11,12 +11,12 @@ ECHO = $(ECHO1:0=@echo) #### Start of system configuration section. #### srcdir = . -topdir = /Users/lamont/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0 +topdir = /home/lamont/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0 hdrdir = $(topdir) -arch_hdrdir = /Users/lamont/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0/x86_64-darwin12.4.0 +arch_hdrdir = /home/lamont/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0/x86_64-linux PATH_SEPARATOR = : VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby -prefix = /Users/lamont/.rvm/rubies/ruby-2.0.0-p247 +prefix = /home/lamont/.rvm/rubies/ruby-2.0.0-p247 rubysitearchprefix = $(rubylibprefix)/$(sitearch) rubyarchprefix = $(rubylibprefix)/$(arch) rubylibprefix = $(libdir)/$(RUBY_BASE_NAME) @@ -62,12 +62,12 @@ bindir = $(exec_prefix)/bin archdir = $(rubyarchdir) -CC = /usr/bin/clang -CXX = clang++ +CC = gcc +CXX = g++ LIBRUBY = $(LIBRUBY_SO) LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a -LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME) -LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static +LIBRUBYARG_SHARED = -Wl,-R -Wl,$(libdir) -L$(libdir) -l$(RUBY_SO_NAME) +LIBRUBYARG_STATIC = -Wl,-R -Wl,$(libdir) -L$(libdir) -l$(RUBY_SO_NAME)-static empty = OUTFLAG = -o $(empty) COUTFLAG = -o $(empty) @@ -76,30 +76,30 @@ RUBY_EXTCONF_H = cflags = $(optflags) $(debugflags) $(warnflags) optflags = -O3 -fno-fast-math debugflags = -ggdb3 -warnflags = -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -CCDLFLAGS = -fno-common -CFLAGS = $(CCDLFLAGS) -I/Users/lamont/git/ffi-yajl/include -L/Users/lamont/git/ffi-yajl/lib -O3 -march=nocona -O2 -pipe -fno-common -Wall $(ARCH_FLAG) +warnflags = -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration +CCDLFLAGS = -fPIC +CFLAGS = $(CCDLFLAGS) -I/home/lamont/git/ffi-yajl/include -L/home/lamont/git/ffi-yajl/lib $(cflags) -fPIC -O3 -Wall $(ARCH_FLAG) INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir) DEFS = -CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include $(DEFS) $(cppflags) +CPPFLAGS = $(DEFS) $(cppflags) CXXFLAGS = $(CCDLFLAGS) $(cxxflags) $(ARCH_FLAG) -ldflags = -L/Users/lamont/git/ffi-yajl/lib -I/Users/lamont/git/ffi-yajl/include -L/Users/lamont/git/ffi-yajl/lib -O3 -march=nocona -O2 -pipe -fno-common -lyajl -dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib +ldflags = -L/home/lamont/git/ffi-yajl/lib -I/home/lamont/git/ffi-yajl/include -L/home/lamont/git/ffi-yajl/lib $(cflags) -fPIC -lyajl +dldflags = ARCH_FLAG = DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG) -LDSHARED = $(CC) -dynamic -bundle -LDSHAREDXX = $(CXX) -dynamic -bundle +LDSHARED = $(CC) -shared +LDSHAREDXX = $(CXX) -shared AR = ar EXEEXT = RUBY_INSTALL_NAME = ruby -RUBY_SO_NAME = ruby.2.0.0 +RUBY_SO_NAME = ruby RUBYW_INSTALL_NAME = RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version) RUBYW_BASE_NAME = rubyw RUBY_BASE_NAME = ruby -arch = x86_64-darwin12.4.0 +arch = x86_64-linux sitearch = $(arch) ruby_version = 2.0.0 ruby = $(bindir)/ruby @@ -108,8 +108,8 @@ ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/defines.h $(arch_hdrdir)/ruby/con RM = rm -f RM_RF = $(RUBY) -run -e rm -- -rf -RMDIRS = rmdir -p -MAKEDIRS = mkdir -p +RMDIRS = rmdir --ignore-fail-on-non-empty -p +MAKEDIRS = /bin/mkdir -p INSTALL = /usr/bin/install -c INSTALL_PROG = $(INSTALL) -m 0755 INSTALL_DATA = $(INSTALL) -m 644 @@ -120,8 +120,8 @@ TOUCH = exit > preload = -libpath = . $(libdir) /usr/local/opt/libyaml/lib /usr/local/opt/readline/lib /usr/local/opt/libksba/lib /usr/local/opt/openssl/lib -LIBPATH = -L. -L$(libdir) -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib +libpath = . $(libdir) +LIBPATH = -L. -L$(libdir) -Wl,-R$(libdir) DEFFILE = CLEANFILES = mkmf.log @@ -132,7 +132,7 @@ extout = extout_prefix = target_prefix = /ffi_yajl/ext LOCAL_LIBS = -LIBS = $(LIBRUBYARG_SHARED) -lpthread -ldl -lobjc +LIBS = $(LIBRUBYARG_SHARED) -lpthread -lrt -ldl -lcrypt -lm -lc ORIG_SRCS = parser.c SRCS = $(ORIG_SRCS) OBJS = parser.o @@ -140,7 +140,7 @@ HDRS = TARGET = parser TARGET_NAME = parser TARGET_ENTRY = Init_$(TARGET_NAME) -DLLIB = $(TARGET).bundle +DLLIB = $(TARGET).so EXTSTATIC = STATIC_LIB = @@ -152,7 +152,7 @@ HDRDIR = $(DESTDIR)$(rubyhdrdir)/ruby$(target_prefix) ARCHHDRDIR = $(DESTDIR)$(rubyhdrdir)/$(arch)/ruby$(target_prefix) TARGET_SO = $(DLLIB) -CLEANLIBS = $(TARGET).bundle +CLEANLIBS = $(TARGET).so CLEANOBJS = *.o *.bak all: $(DLLIB) @@ -231,7 +231,6 @@ $(DLLIB): $(OBJS) Makefile $(ECHO) linking shared-object ffi_yajl/ext/$(DLLIB) -$(Q)$(RM) $(@) $(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS) - $(Q) test -z '$(RUBY_CODESIGN)' || codesign -s '$(RUBY_CODESIGN)' -f $@ |