yajl-ruby 0.7.8 → 0.7.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (55) hide show
  1. data/.gitignore +2 -1
  2. data/.rspec +2 -0
  3. data/CHANGELOG.md +12 -2
  4. data/Gemfile +7 -0
  5. data/Gemfile.lock +28 -0
  6. data/MIT-LICENSE +1 -1
  7. data/Rakefile +5 -37
  8. data/VERSION.yml +2 -2
  9. data/benchmark/encode.rb +2 -1
  10. data/benchmark/encode_json_and_marshal.rb +2 -1
  11. data/benchmark/encode_json_and_yaml.rb +2 -1
  12. data/benchmark/http.rb +1 -0
  13. data/benchmark/parse.rb +2 -1
  14. data/benchmark/parse_json_and_marshal.rb +2 -1
  15. data/benchmark/parse_json_and_yaml.rb +2 -1
  16. data/benchmark/parse_stream.rb +2 -1
  17. data/examples/encoding/chunked_encoding.rb +1 -0
  18. data/examples/encoding/one_shot.rb +1 -0
  19. data/examples/encoding/to_an_io.rb +1 -0
  20. data/examples/http/twitter_search_api.rb +1 -0
  21. data/examples/http/twitter_stream_api.rb +1 -0
  22. data/examples/parsing/from_file.rb +1 -0
  23. data/examples/parsing/from_stdin.rb +1 -0
  24. data/examples/parsing/from_string.rb +1 -0
  25. data/ext/{api → yajl/api}/yajl_common.h +5 -1
  26. data/ext/{api → yajl/api}/yajl_gen.h +1 -1
  27. data/ext/{api → yajl/api}/yajl_parse.h +3 -3
  28. data/ext/yajl/api/yajl_version.h +23 -0
  29. data/ext/yajl/extconf.rb +8 -0
  30. data/ext/{yajl.c → yajl/yajl.c} +0 -0
  31. data/ext/{yajl_alloc.c → yajl/yajl_alloc.c} +0 -0
  32. data/ext/{yajl_alloc.h → yajl/yajl_alloc.h} +0 -0
  33. data/ext/{yajl_buf.c → yajl/yajl_buf.c} +0 -0
  34. data/ext/{yajl_buf.h → yajl/yajl_buf.h} +0 -0
  35. data/ext/{yajl_bytestack.h → yajl/yajl_bytestack.h} +0 -0
  36. data/ext/{yajl_encode.c → yajl/yajl_encode.c} +0 -0
  37. data/ext/{yajl_encode.h → yajl/yajl_encode.h} +0 -0
  38. data/ext/{yajl_ext.c → yajl/yajl_ext.c} +27 -13
  39. data/ext/{yajl_ext.h → yajl/yajl_ext.h} +2 -1
  40. data/ext/{yajl_gen.c → yajl/yajl_gen.c} +2 -2
  41. data/ext/{yajl_lex.c → yajl/yajl_lex.c} +4 -3
  42. data/ext/{yajl_lex.h → yajl/yajl_lex.h} +0 -0
  43. data/ext/{yajl_parser.c → yajl/yajl_parser.c} +0 -0
  44. data/ext/{yajl_parser.h → yajl/yajl_parser.h} +0 -0
  45. data/ext/yajl/yajl_version.c +7 -0
  46. data/lib/yajl.rb +2 -17
  47. data/spec/parsing/chunked_spec.rb +0 -1
  48. data/spec/spec_helper.rb +2 -1
  49. data/tasks/compile.rake +37 -0
  50. data/tasks/jeweler.rake +17 -0
  51. data/tasks/rspec.rake +16 -0
  52. data/yajl-ruby.gemspec +183 -171
  53. metadata +90 -41
  54. data/ext/extconf.rb +0 -9
  55. data/spec/spec.opts +0 -2
data/.gitignore CHANGED
@@ -6,4 +6,5 @@ benchmark/subjects/contacts.*
6
6
  *.bundle
7
7
  TODO.txt
8
8
  tmp/*
9
- pkg/*
9
+ pkg/*
10
+ vendor/gems
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --colour
data/CHANGELOG.md CHANGED
@@ -1,9 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.9 (January 11th, 2011)
4
+ * moved to rspec2
5
+ * fixed some compilation warnings on 1.9.3
6
+ * brought over latest from Yajl upstream
7
+ * finally removed the deprecated Yajl::Stream methods
8
+ * moved to rake-compiler
9
+ * moved to Bundler for development
10
+ * fix memory corruption bug when using :pretty => true and a custom indent string
11
+ * fixed memory leak when exceptions were being raised during a parse
12
+
3
13
  ## 0.7.8 (September 27th, 2010)
4
- * bugfix due to improper usage of rb_define_method
5
- * bugfix to make sure json gem compability API doesn't break ActiveSupport#to_json
6
14
  * fix a bug in chunked http response regex (thanks to http://github.com/kevn for catching this)
15
+ * Make sure json compability doesn't break ActiveSupport#to_json
16
+ * fix improper usage of rb_define_method
7
17
 
8
18
  ## 0.7.7 (July 12th, 2010)
9
19
  * full string encoding support for 1.9, respecting Encoding.default_internal
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ group :development do
4
+ gem 'rake-compiler', '>= 0.7.5'
5
+ gem 'jeweler'
6
+ gem 'rspec'
7
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.5.2)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rake (0.8.7)
11
+ rake-compiler (0.7.5)
12
+ rake
13
+ rspec (2.3.0)
14
+ rspec-core (~> 2.3.0)
15
+ rspec-expectations (~> 2.3.0)
16
+ rspec-mocks (~> 2.3.0)
17
+ rspec-core (2.3.1)
18
+ rspec-expectations (2.3.0)
19
+ diff-lcs (~> 1.1.2)
20
+ rspec-mocks (2.3.0)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ jeweler
27
+ rake-compiler (>= 0.7.5)
28
+ rspec
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008-2010 Brian Lopez - http://github.com/brianmario
1
+ Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,40 +1,8 @@
1
1
  # encoding: UTF-8
2
- begin
3
- require 'jeweler'
4
- Jeweler::Tasks.new do |gem|
5
- gem.name = "yajl-ruby"
6
- gem.summary = "Ruby C bindings to the excellent Yajl JSON stream-based parser library."
7
- gem.email = "seniorlopez@gmail.com"
8
- gem.homepage = "http://github.com/brianmario/yajl-ruby"
9
- gem.authors = ["Brian Lopez", "Lloyd Hilaiel"]
10
- gem.require_paths = ["lib", "ext"]
11
- gem.extra_rdoc_files = `git ls-files *.rdoc`.split("\n") << 'ext/yajl.c'
12
- gem.files = `git ls-files`.split("\n")
13
- gem.extensions = ["ext/extconf.rb"]
14
- gem.files.include %w(lib/jeweler/templates/.document lib/jeweler/templates/.gitignore)
15
- gem.rubyforge_project = "yajl-ruby"
16
- end
17
- rescue LoadError
18
- puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler -s http://gems.github.com"
19
- end
2
+ require 'bundler'
3
+ Bundler.setup
20
4
 
21
- begin
22
- require 'rake'
23
- require 'spec/rake/spectask'
5
+ require 'rake'
24
6
 
25
- desc "Run all examples with RCov"
26
- Spec::Rake::SpecTask.new('spec:rcov') do |t|
27
- t.spec_files = FileList['spec/']
28
- t.rcov = true
29
- t.rcov_opts = lambda do
30
- IO.readlines("spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
31
- end
32
- end
33
- Spec::Rake::SpecTask.new('spec') do |t|
34
- t.spec_files = FileList['spec/']
35
- t.libs << 'ext'
36
- t.spec_opts << '--options' << 'spec/spec.opts'
37
- end
38
- rescue LoadError
39
- puts "RSpec, or one of its dependencies, is not available. Install it with: sudo gem install rspec"
40
- end
7
+ # Load custom tasks
8
+ Dir['tasks/*.rake'].sort.each { |f| load f }
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- :patch: 8
3
- :build:
2
+ :patch: 9
4
3
  :major: 0
4
+ :build:
5
5
  :minor: 7
data/benchmark/encode.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  # encoding: UTF-8
2
2
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
3
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
4
 
4
5
  require 'rubygems'
5
6
  require 'benchmark'
6
- require 'yajl_ext'
7
+ require 'yajl'
7
8
  require 'stringio'
8
9
  begin
9
10
  require 'json'
@@ -1,9 +1,10 @@
1
1
  # encoding: UTF-8
2
2
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
3
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
4
 
4
5
  require 'rubygems'
5
6
  require 'benchmark'
6
- require 'yajl_ext'
7
+ require 'yajl'
7
8
  require 'stringio'
8
9
  begin
9
10
  require 'json'
@@ -1,9 +1,10 @@
1
1
  # encoding: UTF-8
2
2
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
3
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
4
 
4
5
  require 'rubygems'
5
6
  require 'benchmark'
6
- require 'yajl_ext'
7
+ require 'yajl'
7
8
  begin
8
9
  require 'json'
9
10
  rescue LoadError
data/benchmark/http.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # encoding: UTF-8
2
2
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
3
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
4
 
4
5
  require 'rubygems'
5
6
  require 'benchmark'
data/benchmark/parse.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  # encoding: UTF-8
2
2
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
3
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
4
 
4
5
  require 'rubygems'
5
6
  require 'benchmark'
6
- require 'yajl_ext'
7
+ require 'yajl'
7
8
  begin
8
9
  require 'json'
9
10
  rescue LoadError
@@ -1,9 +1,10 @@
1
1
  # encoding: UTF-8
2
2
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
3
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
4
 
4
5
  require 'rubygems'
5
6
  require 'benchmark'
6
- require 'yajl_ext'
7
+ require 'yajl'
7
8
  begin
8
9
  require 'json'
9
10
  rescue LoadError
@@ -1,9 +1,10 @@
1
1
  # encoding: UTF-8
2
2
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
3
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
4
 
4
5
  require 'rubygems'
5
6
  require 'benchmark'
6
- require 'yajl_ext'
7
+ require 'yajl'
7
8
  begin
8
9
  require 'json'
9
10
  rescue LoadError
@@ -1,9 +1,10 @@
1
1
  # encoding: UTF-8
2
2
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
3
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
4
 
4
5
  require 'rubygems'
5
6
  require 'benchmark'
6
- require 'yajl_ext'
7
+ require 'yajl'
7
8
  begin
8
9
  require 'json'
9
10
  rescue LoadError
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../..')
2
3
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../../lib')
3
4
 
4
5
  require 'yajl'
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../..')
2
3
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../../lib')
3
4
 
4
5
  require 'yajl'
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../..')
2
3
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../../lib')
3
4
 
4
5
  require 'yajl'
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../..')
2
3
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../../lib')
3
4
 
4
5
  require 'yajl/http_stream'
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../..')
2
3
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../../lib')
3
4
 
4
5
  require 'yajl/gzip'
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../..')
2
3
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../../lib')
3
4
 
4
5
  require 'yajl'
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../..')
2
3
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../../lib')
3
4
 
4
5
  require 'yajl'
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../..')
2
3
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../../lib')
3
4
 
4
5
  require 'yajl'
@@ -49,7 +49,11 @@ extern "C" {
49
49
  # define YAJL_API __declspec(dllimport)
50
50
  # endif
51
51
  #else
52
- # define YAJL_API
52
+ # if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303
53
+ # define YAJL_API __attribute__ ((visibility("default")))
54
+ # else
55
+ # define YAJL_API
56
+ # endif
53
57
  #endif
54
58
 
55
59
  /** pointer to a malloc function, supporting client overriding memory
@@ -134,7 +134,7 @@ extern "C" {
134
134
  const unsigned char * str,
135
135
  unsigned int len);
136
136
  YAJL_API yajl_gen_status yajl_gen_null(yajl_gen hand);
137
- YAJL_API yajl_gen_status yajl_gen_bool(yajl_gen hand, int boolean);
137
+ YAJL_API yajl_gen_status yajl_gen_bool(yajl_gen hand, int boolean);
138
138
  YAJL_API yajl_gen_status yajl_gen_map_open(yajl_gen hand);
139
139
  YAJL_API yajl_gen_status yajl_gen_map_close(yajl_gen hand);
140
140
  YAJL_API yajl_gen_status yajl_gen_array_open(yajl_gen hand);
@@ -131,12 +131,12 @@ extern "C" {
131
131
  const yajl_parser_config * config,
132
132
  const yajl_alloc_funcs * allocFuncs,
133
133
  void * ctx);
134
-
134
+
135
135
  /** allow resetting of the lexer without the need to realloc a new parser */
136
136
  void yajl_reset_parser(yajl_handle hand);
137
137
 
138
- /** free a parser handle */
139
- void YAJL_API yajl_free(yajl_handle handle);
138
+ /** free a parser handle */
139
+ YAJL_API void yajl_free(yajl_handle handle);
140
140
 
141
141
  /** Parse some json!
142
142
  * \param hand - a handle to the json parser allocated with yajl_alloc
@@ -0,0 +1,23 @@
1
+ #ifndef YAJL_VERSION_H_
2
+ #define YAJL_VERSION_H_
3
+
4
+ #include "api/yajl_common.h"
5
+
6
+ #define YAJL_MAJOR 1
7
+ #define YAJL_MINOR 0
8
+ #define YAJL_MICRO 11
9
+
10
+ #define YAJL_VERSION ((YAJL_MAJOR * 10000) + (YAJL_MINOR * 100) + YAJL_MICRO)
11
+
12
+ #ifdef __cplusplus
13
+ extern "C" {
14
+ #endif
15
+
16
+ extern int YAJL_API yajl_version(void);
17
+
18
+ #ifdef __cplusplus
19
+ }
20
+ #endif
21
+
22
+ #endif /* YAJL_VERSION_H_ */
23
+
@@ -0,0 +1,8 @@
1
+ # encoding: UTF-8
2
+ require 'mkmf'
3
+ require 'rbconfig'
4
+
5
+ $CFLAGS << ' -Wall -funroll-loops'
6
+ $CFLAGS << ' -Wextra -O0 -ggdb3' if ENV['DEBUG']
7
+
8
+ create_makefile("yajl")
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2008-2009 Brian Lopez - http://github.com/brianmario
2
+ * Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario
3
3
  *
4
4
  * Permission is hereby granted, free of charge, to any person obtaining
5
5
  * a copy of this software and associated documentation files (the
@@ -24,9 +24,9 @@
24
24
  #include "yajl_ext.h"
25
25
 
26
26
  #define YAJL_RB_TO_JSON \
27
- VALUE rb_encoder; \
27
+ VALUE rb_encoder, cls; \
28
28
  rb_scan_args(argc, argv, "01", &rb_encoder); \
29
- VALUE cls = rb_obj_class(rb_encoder); \
29
+ cls = rb_obj_class(rb_encoder); \
30
30
  if (rb_encoder == Qnil || cls != cEncoder) { \
31
31
  rb_encoder = rb_yajl_encoder_new(0, NULL, cEncoder); \
32
32
  } \
@@ -95,6 +95,9 @@ inline void yajl_set_static_value(void * ctx, VALUE val) {
95
95
  static void yajl_encoder_wrapper_free(void * wrapper) {
96
96
  yajl_encoder_wrapper * w = wrapper;
97
97
  if (w) {
98
+ if (w->indentString) {
99
+ free(w->indentString);
100
+ }
98
101
  yajl_gen_free(w->encoder);
99
102
  free(w);
100
103
  }
@@ -116,6 +119,7 @@ void yajl_encode_part(void * wrapper, VALUE obj, VALUE io) {
116
119
  const unsigned char * buffer;
117
120
  const char * cptr;
118
121
  unsigned int len;
122
+ VALUE keys, entry, keyStr;
119
123
 
120
124
  if (io != Qnil || w->on_progress_callback != Qnil) {
121
125
  status = yajl_gen_get_buf(w->encoder, &buffer, &len);
@@ -135,8 +139,7 @@ void yajl_encode_part(void * wrapper, VALUE obj, VALUE io) {
135
139
  status = yajl_gen_map_open(w->encoder);
136
140
 
137
141
  /* TODO: itterate through keys in the hash */
138
- VALUE keys = rb_funcall(obj, intern_keys, 0);
139
- VALUE entry, keyStr;
142
+ keys = rb_funcall(obj, intern_keys, 0);
140
143
  for(idx=0; idx<RARRAY_LEN(keys); idx++) {
141
144
  entry = rb_ary_entry(keys, idx);
142
145
  keyStr = rb_funcall(entry, intern_to_s, 0); /* key must be a string */
@@ -220,8 +223,9 @@ void yajl_parse_chunk(const unsigned char * chunk, unsigned int len, yajl_handle
220
223
 
221
224
  if (stat != yajl_status_ok && stat != yajl_status_insufficient_data) {
222
225
  unsigned char * str = yajl_get_error(parser, 1, chunk, len);
223
- rb_raise(cParseError, "%s", (const char *) str);
226
+ VALUE errobj = rb_exc_new2(cParseError, (const char*) str);
224
227
  yajl_free_error(parser, str);
228
+ rb_exc_raise(errobj);
225
229
  }
226
230
  }
227
231
 
@@ -269,10 +273,13 @@ static int yajl_found_string(void * ctx, const unsigned char * stringVal, unsign
269
273
 
270
274
  static int yajl_found_hash_key(void * ctx, const unsigned char * stringVal, unsigned int stringLen) {
271
275
  yajl_parser_wrapper * wrapper;
272
- GetParser((VALUE)ctx, wrapper);
273
276
  VALUE keyStr;
274
277
  #ifdef HAVE_RUBY_ENCODING_H
275
- rb_encoding *default_internal_enc = rb_default_internal_encoding();
278
+ rb_encoding *default_internal_enc;
279
+ #endif
280
+ GetParser((VALUE)ctx, wrapper);
281
+ #ifdef HAVE_RUBY_ENCODING_H
282
+ default_internal_enc = rb_default_internal_encoding();
276
283
  #endif
277
284
 
278
285
  if (wrapper->symbolizeKeys) {
@@ -488,7 +495,6 @@ static VALUE rb_yajl_parser_parse_chunk(VALUE self, VALUE chunk) {
488
495
  GetParser(self, wrapper);
489
496
  if (NIL_P(chunk)) {
490
497
  rb_raise(cParseError, "Can't parse a nil string.");
491
- return Qnil;
492
498
  }
493
499
 
494
500
  if (wrapper->parse_complete_callback != Qnil) {
@@ -526,6 +532,7 @@ static VALUE rb_yajl_parser_set_complete_cb(VALUE self, VALUE callback) {
526
532
  * The JSON stream created is written to the IO in chunks, as it's being created.
527
533
  */
528
534
 
535
+ static unsigned char * defaultIndentString = (unsigned char *)" ";
529
536
  /*
530
537
  * Document-method: new
531
538
  *
@@ -545,7 +552,7 @@ static VALUE rb_yajl_encoder_new(int argc, VALUE * argv, VALUE klass) {
545
552
  yajl_encoder_wrapper * wrapper;
546
553
  yajl_gen_config cfg;
547
554
  VALUE opts, obj, indent;
548
- const char * indentString = " ";
555
+ unsigned char *indentString = NULL, *actualIndent = NULL;
549
556
  int beautify = 0;
550
557
 
551
558
  /* Scan off config vars */
@@ -560,13 +567,20 @@ static VALUE rb_yajl_encoder_new(int argc, VALUE * argv, VALUE klass) {
560
567
  indent = rb_str_export_to_enc(indent, utf8Encoding);
561
568
  #endif
562
569
  Check_Type(indent, T_STRING);
563
- indentString = RSTRING_PTR(indent);
570
+ indentString = (unsigned char*)malloc(RSTRING_LEN(indent)+1);
571
+ memcpy(indentString, RSTRING_PTR(indent), RSTRING_LEN(indent));
572
+ indentString[RSTRING_LEN(indent)] = '\0';
573
+ actualIndent = indentString;
564
574
  }
565
575
  }
566
576
  }
567
- cfg = (yajl_gen_config){beautify, indentString};
577
+ if (!indentString) {
578
+ indentString = defaultIndentString;
579
+ }
580
+ cfg = (yajl_gen_config){beautify, (const char *)indentString};
568
581
 
569
582
  obj = Data_Make_Struct(klass, yajl_encoder_wrapper, yajl_encoder_wrapper_mark, yajl_encoder_wrapper_free, wrapper);
583
+ wrapper->indentString = actualIndent;
570
584
  wrapper->encoder = yajl_gen_alloc(&cfg, NULL);
571
585
  wrapper->on_progress_callback = Qnil;
572
586
  if (opts != Qnil && rb_funcall(opts, intern_has_key, 1, sym_terminator) == Qtrue) {
@@ -836,7 +850,7 @@ static VALUE rb_yajl_encoder_enable_json_gem_ext(VALUE klass) {
836
850
 
837
851
 
838
852
  /* Ruby Extension initializer */
839
- void Init_yajl_ext() {
853
+ void Init_yajl() {
840
854
  mYajl = rb_define_module("Yajl");
841
855
 
842
856
  cParseError = rb_define_class_under(mYajl, "ParseError", rb_eStandardError);