diff options
author | Jaymala Sinha <jsinha@chef.io> | 2019-10-10 15:15:44 -0400 |
---|---|---|
committer | Jaymala Sinha <jsinha@chef.io> | 2019-10-10 15:15:44 -0400 |
commit | a9747fff21cb0f4e9577f773ac5b245ced26ebe2 (patch) | |
tree | 33d31c2eabccb8d09077f30a2d415d64343ee59c /lib | |
parent | 5460919d0313a53c8eb36aa7c98c9c87431f89ba (diff) | |
download | ffi-yajl-a9747fff21cb0f4e9577f773ac5b245ced26ebe2.tar.gz |
Resolve rubocop failures
Signed-off-by: Jaymala Sinha <jsinha@chef.io>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ffi_yajl/ffi.rb | 56 | ||||
-rw-r--r-- | lib/ffi_yajl/ffi/encoder.rb | 2 | ||||
-rw-r--r-- | lib/ffi_yajl/ffi/parser.rb | 13 |
3 files changed, 37 insertions, 34 deletions
diff --git a/lib/ffi_yajl/ffi.rb b/lib/ffi_yajl/ffi.rb index 7211c79..25bb852 100644 --- a/lib/ffi_yajl/ffi.rb +++ b/lib/ffi_yajl/ffi.rb @@ -42,24 +42,24 @@ module FFI_Yajl class YajlCallbacks < ::FFI::Struct layout :yajl_null, :pointer, - :yajl_boolean, :pointer, - :yajl_integer, :pointer, - :yajl_double, :pointer, - :yajl_number, :pointer, - :yajl_string, :pointer, - :yajl_start_map, :pointer, - :yajl_map_key, :pointer, - :yajl_end_map, :pointer, - :yajl_start_array, :pointer, - :yajl_end_array, :pointer + :yajl_boolean, :pointer, + :yajl_integer, :pointer, + :yajl_double, :pointer, + :yajl_number, :pointer, + :yajl_string, :pointer, + :yajl_start_map, :pointer, + :yajl_map_key, :pointer, + :yajl_end_map, :pointer, + :yajl_start_array, :pointer, + :yajl_end_array, :pointer end - enum :yajl_status, [ - :yajl_status_ok, - :yajl_status_client_canceled, - :yajl_status_insufficient_data, - :yajl_status_error, - ] + enum :yajl_status, %i{ + yajl_status_ok + yajl_status_client_canceled + yajl_status_insufficient_data + yajl_status_error + } # FFI::Enums are slow, should remove the rest # enum :yajl_gen_status, [ @@ -97,22 +97,22 @@ module FFI_Yajl # const char *yajl_status_to_string (yajl_status code) attach_function :yajl_status_to_string, [ :yajl_status ], :string # yajl_handle yajl_alloc(const yajl_callbacks * callbacks, yajl_alloc_funcs * afs, void * ctx) - attach_function :yajl_alloc, [:pointer, :pointer, :pointer], :yajl_handle + attach_function :yajl_alloc, %i{pointer pointer pointer}, :yajl_handle # void yajl_free (yajl_handle handle) attach_function :yajl_free, [:yajl_handle], :void # yajl_status yajl_parse (yajl_handle hand, const unsigned char *jsonText, unsigned int jsonTextLength) - attach_function :yajl_parse, [:yajl_handle, :ustring, :uint], :yajl_status + attach_function :yajl_parse, %i{yajl_handle ustring uint}, :yajl_status # yajl_status yajl_parse_complete (yajl_handle hand) attach_function :yajl_complete_parse, [:yajl_handle], :yajl_status # unsigned char *yajl_get_error (yajl_handle hand, int verbose, const unsigned char *jsonText, unsigned int jsonTextLength) - attach_function :yajl_get_error, [:yajl_handle, :int, :ustring, :int], :ustring + attach_function :yajl_get_error, %i{yajl_handle int ustring int}, :ustring # void yajl_free_error (yajl_handle hand, unsigned char *str) - attach_function :yajl_free_error, [:yajl_handle, :ustring], :void + attach_function :yajl_free_error, %i{yajl_handle ustring}, :void # - attach_function :yajl_config, [:yajl_handle, :yajl_option, :varargs], :int + attach_function :yajl_config, %i{yajl_handle yajl_option varargs}, :int - attach_function :yajl_gen_config, [:yajl_gen, :yajl_gen_option, :varargs], :int + attach_function :yajl_gen_config, %i{yajl_gen yajl_gen_option varargs}, :int # yajl_gen yajl_gen_alloc (const yajl_alloc_funcs *allocFuncs) attach_function :yajl_gen_alloc, [:pointer], :yajl_gen @@ -121,18 +121,18 @@ module FFI_Yajl # void yajl_gen_free (yajl_gen handle) attach_function :yajl_gen_free, [:yajl_gen], :void - attach_function :yajl_gen_integer, [:yajl_gen, :long_long], :int - attach_function :yajl_gen_double, [:yajl_gen, :double], :int - attach_function :yajl_gen_number, [:yajl_gen, :ustring, :int], :int - attach_function :yajl_gen_string, [:yajl_gen, :ustring, :int], :int + attach_function :yajl_gen_integer, %i{yajl_gen long_long}, :int + attach_function :yajl_gen_double, %i{yajl_gen double}, :int + attach_function :yajl_gen_number, %i{yajl_gen ustring int}, :int + attach_function :yajl_gen_string, %i{yajl_gen ustring int}, :int attach_function :yajl_gen_null, [:yajl_gen], :int - attach_function :yajl_gen_bool, [:yajl_gen, :int], :int + attach_function :yajl_gen_bool, %i{yajl_gen int}, :int attach_function :yajl_gen_map_open, [:yajl_gen], :int attach_function :yajl_gen_map_close, [:yajl_gen], :int attach_function :yajl_gen_array_open, [:yajl_gen], :int attach_function :yajl_gen_array_close, [:yajl_gen], :int # yajl_gen_status yajl_gen_get_buf (yajl_gen hand, const unsigned char **buf, unsigned int *len) - attach_function :yajl_gen_get_buf, [:yajl_gen, :pointer, :pointer], :int + attach_function :yajl_gen_get_buf, %i{yajl_gen pointer pointer}, :int # void yajl_gen_clear (yajl_gen hand) attach_function :yajl_gen_clear, [:yajl_gen], :void end diff --git a/lib/ffi_yajl/ffi/encoder.rb b/lib/ffi_yajl/ffi/encoder.rb index 62b2c96..e5fbfdb 100644 --- a/lib/ffi_yajl/ffi/encoder.rb +++ b/lib/ffi_yajl/ffi/encoder.rb @@ -161,6 +161,7 @@ class Integer if str == "NaN" || str == "Infinity" || str == "-Infinity" raise ::FFI_Yajl::EncodeError, "'#{str}' is an invalid number" end + if state[:processing_key] if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0 FFI_Yajl::Encoder.raise_error_for_status(status, str) @@ -179,6 +180,7 @@ class Float if str == "NaN" || str == "Infinity" || str == "-Infinity" raise ::FFI_Yajl::EncodeError, "'#{str}' is an invalid number" end + if state[:processing_key] if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0 FFI_Yajl::Encoder.raise_error_for_status(status, str) diff --git a/lib/ffi_yajl/ffi/parser.rb b/lib/ffi_yajl/ffi/parser.rb index fa9d599..d991d67 100644 --- a/lib/ffi_yajl/ffi/parser.rb +++ b/lib/ffi_yajl/ffi/parser.rb @@ -30,6 +30,7 @@ module FFI_Yajl if @opts[:unique_key_checking] && stack.last.key?(key) raise FFI_Yajl::ParseError, "repeated key: #{key}" end + stack.last[key] = val when Array stack.last.push(val) @@ -55,15 +56,15 @@ module FFI_Yajl set_value(nil) 1 end - @boolean_callback = ::FFI::Function.new(:int, [:pointer, :int]) do |ctx, boolval| + @boolean_callback = ::FFI::Function.new(:int, %i{pointer int}) do |ctx, boolval| set_value(boolval == 1 ? true : false) 1 end - @integer_callback = ::FFI::Function.new(:int, [:pointer, :long_long]) do |ctx, intval| + @integer_callback = ::FFI::Function.new(:int, %i{pointer long_long}) do |ctx, intval| set_value(intval) 1 end - @number_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t ]) do |ctx, stringval, stringlen| + @number_callback = ::FFI::Function.new(:int, %i{pointer string size_t}) do |ctx, stringval, stringlen| s = stringval.slice(0, stringlen) s.force_encoding("UTF-8") if defined? Encoding # XXX: I can't think of a better way to do this right now. need to call to_f if and only if its a float. @@ -71,11 +72,11 @@ module FFI_Yajl set_value(v) 1 end - @double_callback = ::FFI::Function.new(:int, [:pointer, :double]) do |ctx, doubleval| + @double_callback = ::FFI::Function.new(:int, %i{pointer double}) do |ctx, doubleval| set_value(doubleval) 1 end - @string_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t]) do |ctx, stringval, stringlen| + @string_callback = ::FFI::Function.new(:int, %i{pointer string size_t}) do |ctx, stringval, stringlen| s = stringval.slice(0, stringlen) s.force_encoding("UTF-8") if defined? Encoding set_value(s) @@ -86,7 +87,7 @@ module FFI_Yajl stack.push({}) 1 end - @map_key_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t]) do |ctx, key, keylen| + @map_key_callback = ::FFI::Function.new(:int, %i{pointer string size_t}) do |ctx, key, keylen| s = key.slice(0, keylen) s.force_encoding("UTF-8") if defined? Encoding self.key = @opts[:symbolize_keys] ? s.to_sym : s |