yajl-ruby 0.6.7 → 0.6.8

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of yajl-ruby might be problematic. Click here for more details.

data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.8 (January 1st, 2010)
4
+ * A couple of small performance patches
5
+ * Allow passing a string to Yajl::HttpStream methods instead of only a URI
6
+
3
7
  ## 0.6.7 (December 4th, 2009)
4
8
  * Bump internal version constant to the proper value (doh!)
5
9
  * Bring over latest from Yajl upstream
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
+ :patch: 8
2
3
  :major: 0
3
4
  :minor: 6
4
- :patch: 7
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../../lib')
2
3
 
3
- require 'rubygems'
4
4
  require 'yajl'
5
5
 
6
6
  obj = {
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../../lib')
2
3
 
3
- require 'rubygems'
4
4
  require 'yajl'
5
5
 
6
6
  obj = {
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../../lib')
2
3
 
3
- require 'rubygems'
4
4
  require 'yajl'
5
5
 
6
6
  obj = {
@@ -1,7 +1,6 @@
1
1
  # encoding: UTF-8
2
2
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../../lib')
3
3
 
4
- require 'rubygems'
5
4
  require 'yajl/http_stream'
6
5
  require 'uri'
7
6
 
@@ -1,7 +1,6 @@
1
1
  # encoding: UTF-8
2
2
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../../lib')
3
3
 
4
- require 'rubygems'
5
4
  require 'yajl/gzip'
6
5
  require 'yajl/deflate'
7
6
  require 'yajl/http_stream'
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../../lib')
2
3
 
3
- require 'rubygems'
4
4
  require 'yajl'
5
5
 
6
6
  unless file = ARGV[0]
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../../lib')
2
3
 
3
- require 'rubygems'
4
4
  require 'yajl'
5
5
 
6
6
  # Usage: cat benchmark/subjects/item.json | ruby examples/from_stdin.rb
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../../lib')
2
3
 
3
- require 'rubygems'
4
4
  require 'yajl'
5
5
  require 'stringio'
6
6
 
@@ -9,7 +9,5 @@ unless string = ARGV[0]
9
9
  exit(0)
10
10
  end
11
11
 
12
- json = StringIO.new(string)
13
-
14
- hash = Yajl::Parser.parse(json)
12
+ hash = Yajl::Parser.parse(string)
15
13
  puts hash.inspect
data/ext/extconf.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  require 'mkmf'
3
3
  require 'rbconfig'
4
4
 
5
- $CFLAGS << ' -Wall'
5
+ $CFLAGS << ' -Wall -funroll-loops'
6
6
  # $CFLAGS << ' -O0 -ggdb'
7
7
 
8
8
  create_makefile("yajl_ext")
data/ext/yajl_ext.c CHANGED
@@ -23,6 +23,31 @@
23
23
 
24
24
  #include "yajl_ext.h"
25
25
 
26
+ inline const char * strnchr(const char * s, size_t count, char c) {
27
+ for (; count-- && *s != '\0'; ++s) {
28
+ if (*s == c) {
29
+ return s;
30
+ }
31
+ }
32
+ return NULL;
33
+ }
34
+
35
+ inline double strntod(const char * s, size_t count) {
36
+ char buf[count+1];
37
+ memcpy(buf, s, count);
38
+ buf[count] = 0;
39
+
40
+ return strtod(buf, NULL);
41
+ }
42
+
43
+ inline VALUE rb_cstrn2inum(const char * s, size_t count) {
44
+ char buf[count+1];
45
+ memcpy(buf, s, count);
46
+ buf[count] = 0;
47
+
48
+ return rb_cstr2inum(buf, 10);
49
+ }
50
+
26
51
  /* Helpers for building objects */
27
52
  inline void yajl_check_and_fire_callback(void * ctx) {
28
53
  yajl_parser_wrapper * wrapper;
@@ -226,15 +251,13 @@ static int yajl_found_boolean(void * ctx, int boolean) {
226
251
  }
227
252
 
228
253
  static int yajl_found_number(void * ctx, const char * numberVal, unsigned int numberLen) {
229
- char buf[numberLen+1];
230
- memcpy(buf, numberVal, numberLen);
231
- buf[numberLen] = 0;
232
-
233
- if (strchr(buf, '.') || strchr(buf, 'e') || strchr(buf, 'E')) {
234
- yajl_set_static_value(ctx, rb_float_new(strtod(buf, NULL)));
254
+ if (strnchr(numberVal, numberLen, '.') ||
255
+ strnchr(numberVal, numberLen, 'e') ||
256
+ strnchr(numberVal, numberLen, 'E')) {
257
+ yajl_set_static_value(ctx, rb_float_new(strntod(numberVal, numberLen)));
235
258
  }
236
259
  else {
237
- yajl_set_static_value(ctx, rb_cstr2inum(buf, 10));
260
+ yajl_set_static_value(ctx, rb_cstrn2inum(numberVal, numberLen));
238
261
  }
239
262
  return 1;
240
263
  }
data/lib/yajl.rb CHANGED
@@ -13,7 +13,7 @@ require 'yajl_ext'
13
13
  #
14
14
  # Ruby bindings to the excellent Yajl (Yet Another JSON Parser) ANSI C library.
15
15
  module Yajl
16
- VERSION = "0.6.7"
16
+ VERSION = "0.6.8"
17
17
 
18
18
  # For compatibility, has the same signature of Yajl::Parser.parse
19
19
  def self.load(str_or_io, options={}, read_bufsize=nil, &block)
@@ -76,6 +76,10 @@ module Yajl
76
76
 
77
77
  protected
78
78
  def self.request(method, uri, opts = {}, &block)
79
+ if uri.is_a?(String)
80
+ uri = URI.parse(uri)
81
+ end
82
+
79
83
  user_agent = opts.has_key?('User-Agent') ? opts.delete(['User-Agent']) : "Yajl::HttpStream #{Yajl::VERSION}"
80
84
  if method == "POST" || method == "PUT"
81
85
  content_type = opts.has_key?('Content-Type') ? opts.delete(['Content-Type']) : "application/x-www-form-urlencoded"
@@ -86,6 +90,9 @@ module Yajl
86
90
  end
87
91
 
88
92
  socket = opts.has_key?(:socket) ? opts.delete(:socket) : TCPSocket.new(uri.host, uri.port)
93
+ trap("INT") {
94
+ return
95
+ }
89
96
  request = "#{method} #{uri.path}#{uri.query ? "?"+uri.query : nil} HTTP/1.1\r\n"
90
97
  request << "Host: #{uri.host}\r\n"
91
98
  request << "Authorization: Basic #{[uri.userinfo].pack('m').strip!}\r\n" unless uri.userinfo.nil?
@@ -162,7 +169,7 @@ module Yajl
162
169
  end
163
170
  end
164
171
  ensure
165
- socket.close unless socket.closed?
172
+ socket.close if !socket.nil? and !socket.closed?
166
173
  end
167
174
 
168
175
  private
@@ -40,11 +40,6 @@ describe "Yajl HTTP DELETE request" do
40
40
  @uri = 'file://'+File.expand_path(File.dirname(__FILE__) + "/fixtures/http/http.#{format}.dump")
41
41
  TCPSocket.should_receive(:new).and_return(@request)
42
42
  @request.should_receive(:write)
43
- @uri.should_receive(:host).at_least(2).times
44
- @uri.should_receive(:port)
45
- @uri.should_receive(:path)
46
- @uri.should_receive(:query)
47
- @uri.should_receive(:userinfo)
48
43
  end
49
44
 
50
45
  it "should parse a raw response" do
@@ -54,6 +49,8 @@ describe "Yajl HTTP DELETE request" do
54
49
 
55
50
  it "should parse a raw response using instance method" do
56
51
  prepare_mock_request_dump :raw
52
+ @uri.should_receive(:host)
53
+ @uri.should_receive(:port)
57
54
  stream = Yajl::HttpStream.new
58
55
  @template_hash.should == stream.delete(@uri)
59
56
  end
@@ -41,11 +41,6 @@ describe "Yajl HTTP GET request" do
41
41
  @uri = 'file://'+File.expand_path(File.dirname(__FILE__) + "/fixtures/http/http.#{format}.dump")
42
42
  TCPSocket.should_receive(:new).and_return(@request)
43
43
  @request.should_receive(:write)
44
- @uri.should_receive(:host).at_least(2).times
45
- @uri.should_receive(:port)
46
- @uri.should_receive(:path)
47
- @uri.should_receive(:query)
48
- @uri.should_receive(:userinfo)
49
44
  end
50
45
 
51
46
  it "should parse a raw response" do
@@ -60,12 +55,16 @@ describe "Yajl HTTP GET request" do
60
55
 
61
56
  it "should parse a raw response using instance method" do
62
57
  prepare_mock_request_dump :raw
58
+ @uri.should_receive(:host)
59
+ @uri.should_receive(:port)
63
60
  stream = Yajl::HttpStream.new
64
61
  @template_hash.should == stream.get(@uri)
65
62
  end
66
63
 
67
64
  it "should parse a chunked response using instance method" do
68
65
  prepare_mock_request_dump :chunked
66
+ @uri.should_receive(:host)
67
+ @uri.should_receive(:port)
69
68
  stream = Yajl::HttpStream.new
70
69
  stream.get(@uri) do |obj|
71
70
  obj.should eql(@chunked_body)
@@ -43,11 +43,6 @@ describe "Yajl HTTP POST request" do
43
43
  @uri = 'file://'+File.expand_path(File.dirname(__FILE__) + "/fixtures/http/http.#{format}.dump")
44
44
  TCPSocket.should_receive(:new).and_return(@request)
45
45
  @request.should_receive(:write)
46
- @uri.should_receive(:host).at_least(2).times
47
- @uri.should_receive(:port)
48
- @uri.should_receive(:path)
49
- @uri.should_receive(:query)
50
- @uri.should_receive(:userinfo)
51
46
  end
52
47
 
53
48
  it "should parse a raw response" do
@@ -57,6 +52,8 @@ describe "Yajl HTTP POST request" do
57
52
 
58
53
  it "should parse a raw response using instance method" do
59
54
  prepare_mock_request_dump :raw
55
+ @uri.should_receive(:host)
56
+ @uri.should_receive(:port)
60
57
  stream = Yajl::HttpStream.new
61
58
  @template_hash.should == stream.post(@uri, @body)
62
59
  end
@@ -42,11 +42,6 @@ describe "Yajl HTTP PUT request" do
42
42
  @uri = 'file://'+File.expand_path(File.dirname(__FILE__) + "/fixtures/http/http.#{format}.dump")
43
43
  TCPSocket.should_receive(:new).and_return(@request)
44
44
  @request.should_receive(:write)
45
- @uri.should_receive(:host).at_least(2).times
46
- @uri.should_receive(:port)
47
- @uri.should_receive(:path)
48
- @uri.should_receive(:query)
49
- @uri.should_receive(:userinfo)
50
45
  end
51
46
 
52
47
  it "should parse a raw response" do
@@ -56,6 +51,8 @@ describe "Yajl HTTP PUT request" do
56
51
 
57
52
  it "should parse a raw response using instance method" do
58
53
  prepare_mock_request_dump :raw
54
+ @uri.should_receive(:host)
55
+ @uri.should_receive(:port)
59
56
  stream = Yajl::HttpStream.new
60
57
  @template_hash.should == stream.put(@uri, @body)
61
58
  end
data/yajl-ruby.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{yajl-ruby}
8
- s.version = "0.6.7"
8
+ s.version = "0.6.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brian Lopez", "Lloyd Hilaiel"]
12
- s.date = %q{2009-12-04}
12
+ s.date = %q{2010-01-01}
13
13
  s.email = %q{seniorlopez@gmail.com}
14
14
  s.extensions = ["ext/extconf.rb"]
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yajl-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.7
4
+ version: 0.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Lopez
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-12-04 00:00:00 -08:00
13
+ date: 2010-01-01 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies: []
16
16