yajl-ruby 0.6.6 → 0.6.7

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.7 (December 4th, 2009)
4
+ * Bump internal version constant to the proper value (doh!)
5
+ * Bring over latest from Yajl upstream
6
+
3
7
  ## 0.6.6 (December 1st, 2009)
4
8
  * Brought over some optimizations from Macruby's use of some yajl-ruby codez
5
9
  * Yajl::HttpStream now supports being killed for long-running requests, thanks to Filipe Giusti <filipegiusti@gmail.com>
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 6
3
- :patch: 6
4
2
  :major: 0
3
+ :minor: 6
4
+ :patch: 7
data/benchmark/encode.rb CHANGED
@@ -9,7 +9,7 @@ rescue LoadError
9
9
  end
10
10
  # Can't use ActiveSuport::JSON.encode with the JSON gem loaded
11
11
  # begin
12
- # require 'activesupport'
12
+ # require 'active_support'
13
13
  # rescue LoadError
14
14
  # end
15
15
 
data/benchmark/parse.rb CHANGED
@@ -7,7 +7,7 @@ begin
7
7
  rescue LoadError
8
8
  end
9
9
  begin
10
- require 'activesupport'
10
+ require 'active_support'
11
11
  rescue LoadError
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ begin
7
7
  rescue LoadError
8
8
  end
9
9
  begin
10
- require 'activesupport'
10
+ require 'active_support'
11
11
  rescue LoadError
12
12
  end
13
13
 
data/ext/api/yajl_gen.h CHANGED
@@ -60,12 +60,20 @@ extern "C" {
60
60
  yajl_gen_generation_complete,
61
61
  /** yajl_gen_double was passed an invalid floating point value
62
62
  * (infinity or NaN). */
63
- yajl_gen_invalid_number
63
+ yajl_gen_invalid_number,
64
+ /** A print callback was passed in, so there is no internal
65
+ * buffer to get from */
66
+ yajl_gen_no_buf
64
67
  } yajl_gen_status;
65
68
 
66
69
  /** an opaque handle to a generator */
67
70
  typedef struct yajl_gen_t * yajl_gen;
68
71
 
72
+ /** a callback used for "printing" the results. */
73
+ typedef void (*yajl_print_t)(void * ctx,
74
+ const char * str,
75
+ unsigned int len);
76
+
69
77
  /** configuration structure for the generator */
70
78
  typedef struct {
71
79
  /** generate indented (beautiful) output */
@@ -89,6 +97,28 @@ extern "C" {
89
97
  yajl_gen YAJL_API yajl_gen_alloc(const yajl_gen_config * config,
90
98
  const yajl_alloc_funcs * allocFuncs);
91
99
 
100
+ /** allocate a generator handle that will print to the specified
101
+ * callback rather than storing the results in an internal buffer.
102
+ * \param callback a pointer to a printer function. May be NULL
103
+ * in which case, the results will be store in an
104
+ * internal buffer.
105
+ * \param config a pointer to a structure containing parameters
106
+ * which configure the behavior of the json
107
+ * generator.
108
+ * \param allocFuncs an optional pointer to a structure which allows
109
+ * the client to overide the memory allocation
110
+ * used by yajl. May be NULL, in which case
111
+ * malloc/free/realloc will be used.
112
+ * \param ctx a context pointer that will be passed to the
113
+ * printer callback.
114
+ *
115
+ * \returns an allocated handle on success, NULL on failure (bad params)
116
+ */
117
+ yajl_gen YAJL_API yajl_gen_alloc2(yajl_print_t callback,
118
+ const yajl_gen_config * config,
119
+ const yajl_alloc_funcs * allocFuncs,
120
+ void * ctx);
121
+
92
122
  /** free a generator handle */
93
123
  void YAJL_API yajl_gen_free(yajl_gen handle);
94
124
 
data/ext/yajl_encode.c CHANGED
@@ -47,6 +47,15 @@ static void CharToHex(unsigned char c, char * hexBuf)
47
47
  void
48
48
  yajl_string_encode(yajl_buf buf, const unsigned char * str,
49
49
  unsigned int len)
50
+ {
51
+ yajl_string_encode2((yajl_print_t) &yajl_buf_append, buf, str, len);
52
+ }
53
+
54
+ void
55
+ yajl_string_encode2(const yajl_print_t print,
56
+ void * ctx,
57
+ const unsigned char * str,
58
+ unsigned int len)
50
59
  {
51
60
  unsigned int beg = 0;
52
61
  unsigned int end = 0;
@@ -73,14 +82,14 @@ yajl_string_encode(yajl_buf buf, const unsigned char * str,
73
82
  break;
74
83
  }
75
84
  if (escaped != NULL) {
76
- yajl_buf_append(buf, str + beg, end - beg);
77
- yajl_buf_append(buf, escaped, strlen(escaped));
85
+ print(ctx, (const char *) (str + beg), end - beg);
86
+ print(ctx, escaped, strlen(escaped));
78
87
  beg = ++end;
79
88
  } else {
80
89
  ++end;
81
90
  }
82
91
  }
83
- yajl_buf_append(buf, str + beg, end - beg);
92
+ print(ctx, (const char *) (str + beg), end - beg);
84
93
  }
85
94
 
86
95
  static void hexToDigit(unsigned int * val, const unsigned char * hex)
data/ext/yajl_encode.h CHANGED
@@ -34,6 +34,12 @@
34
34
  #define __YAJL_ENCODE_H__
35
35
 
36
36
  #include "yajl_buf.h"
37
+ #include "api/yajl_gen.h"
38
+
39
+ void yajl_string_encode2(yajl_print_t printer,
40
+ void * ctx,
41
+ const unsigned char * str,
42
+ unsigned int length);
37
43
 
38
44
  void yajl_string_encode(yajl_buf buf, const unsigned char * str,
39
45
  unsigned int length);
data/ext/yajl_gen.c CHANGED
@@ -56,7 +56,8 @@ struct yajl_gen_t
56
56
  unsigned int pretty;
57
57
  const char * indentString;
58
58
  yajl_gen_state state[YAJL_MAX_DEPTH];
59
- yajl_buf buf;
59
+ yajl_print_t print;
60
+ void * ctx; /* yajl_buf */
60
61
  /* memory allocation routines */
61
62
  yajl_alloc_funcs alloc;
62
63
  };
@@ -64,6 +65,15 @@ struct yajl_gen_t
64
65
  yajl_gen
65
66
  yajl_gen_alloc(const yajl_gen_config * config,
66
67
  const yajl_alloc_funcs * afs)
68
+ {
69
+ return yajl_gen_alloc2(NULL, config, afs, NULL);
70
+ }
71
+
72
+ yajl_gen
73
+ yajl_gen_alloc2(yajl_print_t callback,
74
+ const yajl_gen_config * config,
75
+ const yajl_alloc_funcs * afs,
76
+ void * ctx)
67
77
  {
68
78
  yajl_gen g = NULL;
69
79
  yajl_alloc_funcs afsBuffer;
@@ -88,7 +98,14 @@ yajl_gen_alloc(const yajl_gen_config * config,
88
98
  g->pretty = config->beautify;
89
99
  g->indentString = config->indentString ? config->indentString : " ";
90
100
  }
91
- g->buf = yajl_buf_alloc(&(g->alloc));
101
+
102
+ if (callback) {
103
+ g->print = callback;
104
+ g->ctx = ctx;
105
+ } else {
106
+ g->print = (yajl_print_t)&yajl_buf_append;
107
+ g->ctx = yajl_buf_alloc(&(g->alloc));
108
+ }
92
109
 
93
110
  return g;
94
111
  }
@@ -96,18 +113,18 @@ yajl_gen_alloc(const yajl_gen_config * config,
96
113
  void
97
114
  yajl_gen_free(yajl_gen g)
98
115
  {
99
- yajl_buf_free(g->buf);
116
+ if (g->print == (yajl_print_t)&yajl_buf_append) yajl_buf_free((yajl_buf)g->ctx);
100
117
  YA_FREE(&(g->alloc), g);
101
118
  }
102
119
 
103
120
  #define INSERT_SEP \
104
121
  if (g->state[g->depth] == yajl_gen_map_key || \
105
122
  g->state[g->depth] == yajl_gen_in_array) { \
106
- yajl_buf_append(g->buf, ",", 1); \
107
- if (g->pretty) yajl_buf_append(g->buf, "\n", 1); \
123
+ g->print(g->ctx, ",", 1); \
124
+ if (g->pretty) g->print(g->ctx, "\n", 1); \
108
125
  } else if (g->state[g->depth] == yajl_gen_map_val) { \
109
- yajl_buf_append(g->buf, ":", 1); \
110
- if (g->pretty) yajl_buf_append(g->buf, " ", 1); \
126
+ g->print(g->ctx, ":", 1); \
127
+ if (g->pretty) g->print(g->ctx, " ", 1); \
111
128
  }
112
129
 
113
130
  #define INSERT_WHITESPACE \
@@ -115,8 +132,8 @@ yajl_gen_free(yajl_gen g)
115
132
  if (g->state[g->depth] != yajl_gen_map_val) { \
116
133
  unsigned int _i; \
117
134
  for (_i=0;_i<g->depth;_i++) \
118
- yajl_buf_append(g->buf, g->indentString, \
119
- strlen(g->indentString)); \
135
+ g->print(g->ctx, g->indentString, \
136
+ strlen(g->indentString)); \
120
137
  } \
121
138
  }
122
139
 
@@ -161,7 +178,7 @@ yajl_gen_integer(yajl_gen g, long int number)
161
178
  char i[32];
162
179
  ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
163
180
  sprintf(i, "%ld", number);
164
- yajl_buf_append(g->buf, i, strlen(i));
181
+ g->print(g->ctx, i, strlen(i));
165
182
  APPENDED_ATOM;
166
183
  FINAL_NEWLINE;
167
184
  return yajl_gen_status_ok;
@@ -181,7 +198,7 @@ yajl_gen_double(yajl_gen g, double number)
181
198
  if (isnan(number) || isinf(number)) return yajl_gen_invalid_number;
182
199
  INSERT_SEP; INSERT_WHITESPACE;
183
200
  sprintf(i, "%g", number);
184
- yajl_buf_append(g->buf, i, strlen(i));
201
+ g->print(g->ctx, i, strlen(i));
185
202
  APPENDED_ATOM;
186
203
  FINAL_NEWLINE;
187
204
  return yajl_gen_status_ok;
@@ -191,7 +208,7 @@ yajl_gen_status
191
208
  yajl_gen_number(yajl_gen g, const char * s, unsigned int l)
192
209
  {
193
210
  ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
194
- yajl_buf_append(g->buf, s, l);
211
+ g->print(g->ctx, s, l);
195
212
  APPENDED_ATOM;
196
213
  FINAL_NEWLINE;
197
214
  return yajl_gen_status_ok;
@@ -203,13 +220,18 @@ yajl_gen_string(yajl_gen g, const unsigned char * str,
203
220
  {
204
221
  ENSURE_VALID_STATE; INSERT_SEP; INSERT_WHITESPACE;
205
222
  if (quote) {
206
- yajl_buf_append(g->buf, "\"", 1);
207
- yajl_string_encode(g->buf, str, len);
208
- yajl_buf_append(g->buf, "\"", 1);
223
+ g->print(g->ctx, "\"", 1);
224
+ yajl_string_encode2(g->print, g->ctx, str, len);
225
+ g->print(g->ctx, "\"", 1);
209
226
  } else {
210
- yajl_buf_append(g->buf, str, len);
227
+ g->print(g->ctx, (const char *)str, len);
211
228
  }
212
229
 
230
+
231
+ APPENDED_ATOM;
232
+ FINAL_NEWLINE;
233
+ return yajl_gen_status_ok;
234
+
213
235
  APPENDED_ATOM;
214
236
  FINAL_NEWLINE;
215
237
  return yajl_gen_status_ok;
@@ -219,7 +241,7 @@ yajl_gen_status
219
241
  yajl_gen_null(yajl_gen g)
220
242
  {
221
243
  ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
222
- yajl_buf_append(g->buf, "null", strlen("null"));
244
+ g->print(g->ctx, "null", strlen("null"));
223
245
  APPENDED_ATOM;
224
246
  FINAL_NEWLINE;
225
247
  return yajl_gen_status_ok;
@@ -231,7 +253,7 @@ yajl_gen_bool(yajl_gen g, int boolean)
231
253
  const char * val = boolean ? "true" : "false";
232
254
 
233
255
  ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
234
- yajl_buf_append(g->buf, val, strlen(val));
256
+ g->print(g->ctx, val, strlen(val));
235
257
  APPENDED_ATOM;
236
258
  FINAL_NEWLINE;
237
259
  return yajl_gen_status_ok;
@@ -244,8 +266,8 @@ yajl_gen_map_open(yajl_gen g)
244
266
  INCREMENT_DEPTH;
245
267
 
246
268
  g->state[g->depth] = yajl_gen_map_start;
247
- yajl_buf_append(g->buf, "{", 1);
248
- if (g->pretty) yajl_buf_append(g->buf, "\n", 1);
269
+ g->print(g->ctx, "{", 1);
270
+ if (g->pretty) g->print(g->ctx, "\n", 1);
249
271
  FINAL_NEWLINE;
250
272
  return yajl_gen_status_ok;
251
273
  }
@@ -255,10 +277,10 @@ yajl_gen_map_close(yajl_gen g)
255
277
  {
256
278
  ENSURE_VALID_STATE;
257
279
  (g->depth)--;
258
- if (g->pretty) yajl_buf_append(g->buf, "\n", 1);
280
+ if (g->pretty) g->print(g->ctx, "\n", 1);
259
281
  APPENDED_ATOM;
260
282
  INSERT_WHITESPACE;
261
- yajl_buf_append(g->buf, "}", 1);
283
+ g->print(g->ctx, "}", 1);
262
284
  FINAL_NEWLINE;
263
285
  return yajl_gen_status_ok;
264
286
  }
@@ -269,8 +291,8 @@ yajl_gen_array_open(yajl_gen g)
269
291
  ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
270
292
  INCREMENT_DEPTH;
271
293
  g->state[g->depth] = yajl_gen_array_start;
272
- yajl_buf_append(g->buf, "[", 1);
273
- if (g->pretty) yajl_buf_append(g->buf, "\n", 1);
294
+ g->print(g->ctx, "[", 1);
295
+ if (g->pretty) g->print(g->ctx, "\n", 1);
274
296
  FINAL_NEWLINE;
275
297
  return yajl_gen_status_ok;
276
298
  }
@@ -279,11 +301,11 @@ yajl_gen_status
279
301
  yajl_gen_array_close(yajl_gen g)
280
302
  {
281
303
  ENSURE_VALID_STATE;
282
- if (g->pretty) yajl_buf_append(g->buf, "\n", 1);
304
+ if (g->pretty) g->print(g->ctx, "\n", 1);
283
305
  (g->depth)--;
284
306
  APPENDED_ATOM;
285
307
  INSERT_WHITESPACE;
286
- yajl_buf_append(g->buf, "]", 1);
308
+ g->print(g->ctx, "]", 1);
287
309
  FINAL_NEWLINE;
288
310
  return yajl_gen_status_ok;
289
311
  }
@@ -292,13 +314,14 @@ yajl_gen_status
292
314
  yajl_gen_get_buf(yajl_gen g, const unsigned char ** buf,
293
315
  unsigned int * len)
294
316
  {
295
- *buf = yajl_buf_data(g->buf);
296
- *len = yajl_buf_len(g->buf);
317
+ if (g->print != (yajl_print_t)&yajl_buf_append) return yajl_gen_no_buf;
318
+ *buf = yajl_buf_data((yajl_buf)g->ctx);
319
+ *len = yajl_buf_len((yajl_buf)g->ctx);
297
320
  return yajl_gen_status_ok;
298
321
  }
299
322
 
300
323
  void
301
324
  yajl_gen_clear(yajl_gen g)
302
325
  {
303
- yajl_buf_clear(g->buf);
326
+ if (g->print == (yajl_print_t)&yajl_buf_append) yajl_buf_clear((yajl_buf)g->ctx);
304
327
  }
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.4"
16
+ VERSION = "0.6.7"
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)
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.6"
8
+ s.version = "0.6.7"
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-01}
12
+ s.date = %q{2009-12-04}
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.6
4
+ version: 0.6.7
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-01 00:00:00 -08:00
13
+ date: 2009-12-04 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies: []
16
16