Skip to content

Instantly share code, notes, and snippets.

@jonforums
Created October 16, 2012 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonforums/3902755 to your computer and use it in GitHub Desktop.
Save jonforums/3902755 to your computer and use it in GitHub Desktop.
Exploring Oj
diff --git a/ext/oj/extconf.rb b/ext/oj/extconf.rb
index dd082ef..806076a 100644
--- a/ext/oj/extconf.rb
+++ b/ext/oj/extconf.rb
@@ -1,11 +1,14 @@
require 'mkmf'
+require 'rbconfig'
extension_name = 'oj'
dir_config(extension_name)
parts = RUBY_DESCRIPTION.split(' ')
type = parts[0]
+type = type.delete('tcs-')
type = 'ree' if 'ruby' == type && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
+is_windows = RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/ ? true : false
platform = RUBY_PLATFORM
version = RUBY_VERSION.split('.')
puts ">>>>> Creating Makefile for #{type} version #{RUBY_VERSION} on #{platform} <<<<<"
@@ -26,8 +29,8 @@ dflags = {
'HAS_EXCEPTION_MAGIC' => ('ruby' == type && ('1' == version[0] && '9' == version[1]) || '2' <= version[0]) ? 0 : 1,
'HAS_PROC_WITH_BLOCK' => ('ruby' == type && ('1' == version[0] && '9' == version[1]) || '2' <= version[0]) ? 1 : 0,
'HAS_TOP_LEVEL_ST_H' => ('ree' == type || ('ruby' == type && '1' == version[0] && '8' == version[1])) ? 1 : 0,
- 'IS_WINDOWS' => ('i386-mingw32' == platform || 'tcs-ruby' == type) ? 1 : 0,
- 'SAFE_CACHE' => ('i386-mingw32' == platform || 'tcs-ruby' == type) ? 0 : 1,
+ 'IS_WINDOWS' => is_windows ? 1 : 0,
+ 'SAFE_CACHE' => is_windows ? 0 : 1,
}
# This is a monster hack to get around issues with 1.9.3-p0 on CentOS 5.4. SO
# some reason math.h and string.h contents are not processed. Might be a
@@ -38,7 +41,7 @@ if 'x86_64-linux' == RUBY_PLATFORM && '1.9.3' == RUBY_VERSION && '2011-10-30' ==
rescue Exception => e
end
else
- dflags['NEEDS_STPCPY'] = nil if 'i386-mingw32' == platform || 'tcs-ruby' == type
+ dflags['NEEDS_STPCPY'] = nil if is_windows
end
dflags.each do |k,v|
diff --git a/lib/oj/version.rb b/lib/oj/version.rb
index b83bbd9..2fb8ceb 100644
--- a/lib/oj/version.rb
+++ b/lib/oj/version.rb
@@ -1,5 +1,5 @@
module Oj
# Current version of the module.
- VERSION = '1.4.0'
+ VERSION = '1.4.1.a1'
end
C:\Users\Jon\Documents\CDev\oj-git>gem build oj.gemspec
Successfully built RubyGem
Name: oj
Version: 1.4.1.a1
File: oj-1.4.1.a1.gem
C:\Users\Jon\Documents\CDev\oj-git>ruby --version
ruby 1.9.3p296 (2012-10-16 revision 37211) [i386-mingw32]
C:\Users\Jon\Documents\CDev\oj-git>gem i oj-1.4.1.a1.gem
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
Successfully installed oj-1.4.1.a1
1 gem installed
C:\Users\Jon\Documents\CDev\oj-git>ruby --version
tcs-ruby 1.9.3p231 (2012-05-25, TCS patched 2012-05-27) [i386-mingw32]
C:\Users\Jon\Documents\CDev\oj-git>gem i oj-1.4.1.a1.gem
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
Successfully installed oj-1.4.1.a1
1 gem installed
C:\Users\Jon\Documents>ripl -roj
>> RUBY_DESCRIPTION
=> "ruby 1.9.3p296 (2012-10-16 revision 37211) [i386-mingw32]"
>> Oj::VERSION
=> "1.4.1.a1"
>> h = { 'one' => 1, 'array' => [ true, false ] }
=> {"one"=>1, "array"=>[true, false]}
>> json = Oj.dump(h)
=> "{\"one\":1,\"array\":[true,false]}"
>> h2 = Oj.load(json)
=> {"one"=>1, "array"=>[true, false]}
>> puts "Same? #{h == h2}"
Same? true
=> nil
C:\Users\Jon\Documents>irb -roj
irb(main):001:0> RUBY_DESCRIPTION
=> "tcs-ruby 1.9.3p231 (2012-05-25, TCS patched 2012-05-27) [i386-mingw32]"
irb(main):002:0> Oj::VERSION
=> "1.4.1.a1"
irb(main):003:0> h = { 'one' => 1, 'array' => [ true, false ] }
=> {"one"=>1, "array"=>[true, false]}
irb(main):004:0> json = Oj.dump(h)
=> "{\"one\":1,\"array\":[true,false]}"
irb(main):005:0> h2 = Oj.load(json)
=> {"one"=>1, "array"=>[true, false]}
irb(main):006:0> puts "Same? #{h == h2}"
Same? true
=> nil
[jon@archee ~]$ uname -a
Linux archee 3.6.2-1-ARCH #1 SMP PREEMPT Sat Oct 13 07:19:40 CEST 2012 i686 GNU/Linux
[jon@archee ~]$ gcc --version
gcc (GCC) 4.7.2
[jon@archee ~]$ gem i downloads/oj-1.4.1.a1.gem --user-install
Building native extensions. This could take a while...
Successfully installed oj-1.4.1.a1
1 gem installed
[jon@archee ~]$ ripl -roj
>> RUBY_DESCRIPTION
=> "ruby 2.0.0dev (2012-09-28 trunk 37049) [i686-linux]"
>> Oj::VERSION
=> "1.4.1.a1"
>> h = { 'one' => 1, 'array' => [ true, false ] }
=> {"one"=>1, "array"=>[true, false]}
>> json = Oj.dump(h)
=> "{\"one\":1,\"array\":[true,false]}"
>> h2 = Oj.load(json)
=> {"one"=>1, "array"=>[true, false]}
>> puts "Same? #{h == h2}"
Same? true
=> nil
Makefile-ruby was generated on a normal ruby and Makefile-tcs was generated on a tcs-ruby.
This is the diff when `type = type.delete('tcs-')` is *not* present in the extconf.rb patch.
--- Makefile-ruby 2012-10-16 23:30:44 -0400
+++ Makefile-tcs 2012-10-16 23:29:58 -0400
@@ -12,13 +12,13 @@
#### Start of system configuration section. ####
srcdir = .
-topdir = /C/ruby193/include/ruby-1.9.1
-hdrdir = /C/ruby193/include/ruby-1.9.1
-arch_hdrdir = C:/ruby193/include/ruby-1.9.1/$(arch)
+topdir = /C/ruby-test/193_tcs/include/ruby-1.9.1
+hdrdir = /C/ruby-test/193_tcs/include/ruby-1.9.1
+arch_hdrdir = C:/ruby-test/193_tcs/include/ruby-1.9.1/$(arch)
VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
DESTDIR = C:
-prefix = $(DESTDIR)/ruby193
+prefix = $(DESTDIR)/ruby-test/193_tcs
rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
exec_prefix = $(prefix)
vendorhdrdir = $(rubyhdrdir)/vendor_ruby
@@ -69,11 +69,11 @@
cflags = $(optflags) $(debugflags) $(warnflags)
optflags = -O3 -fno-omit-frame-pointer
debugflags = -g
-warnflags = -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration
+warnflags = -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration
CFLAGS = $(cflags) $(ARCH_FLAG)
INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
DEFS =
-CPPFLAGS = -DFD_SETSIZE=2048 $(DEFS) $(cppflags) -DRUBY_TYPE=ruby -DRUBY_RUBY -DRUBY_VERSION=1.9.3 -DRUBY_VERSION_MAJOR=1 -DRUBY_VERSION_MINOR=9 -DRUBY_VERSION_MICRO=3 -DHAS_RB_TIME_TIMESPEC=1 -DHAS_ENCODING_SUPPORT=1 -DHAS_NANO_TIME=1 -DHAS_RSTRUCT=1 -DHAS_IVAR_HELPERS=1 -DHAS_EXCEPTION_MAGIC=0 -DHAS_PROC_WITH_BLOCK=1 -DHAS_TOP_LEVEL_ST_H=0 -DIS_WINDOWS=1 -DSAFE_CACHE=0 -DNEEDS_STPCPY -Wall
+CPPFLAGS = -DFD_SETSIZE=32767 $(DEFS) $(cppflags) -DRUBY_TYPE=tcs-ruby -DTCS-RUBY_RUBY -DRUBY_VERSION=1.9.3 -DRUBY_VERSION_MAJOR=1 -DRUBY_VERSION_MINOR=9 -DRUBY_VERSION_MICRO=3 -DHAS_RB_TIME_TIMESPEC=0 -DHAS_ENCODING_SUPPORT=0 -DHAS_NANO_TIME=0 -DHAS_RSTRUCT=0 -DHAS_IVAR_HELPERS=0 -DHAS_EXCEPTION_MAGIC=1 -DHAS_PROC_WITH_BLOCK=0 -DHAS_TOP_LEVEL_ST_H=0 -DIS_WINDOWS=1 -DSAFE_CACHE=0 -DNEEDS_STPCPY -Wall
CXXFLAGS = $(CFLAGS) $(cxxflags)
ldflags = -L.
dldflags = -Wl,--enable-auto-image-base,--enable-auto-import $(DEFFILE)
@@ -90,7 +90,7 @@
arch = i386-mingw32
sitearch = i386-msvcrt
ruby_version = 1.9.1
-ruby = C:/ruby193/bin/ruby
+ruby = C:/ruby-test/193_tcs/bin/ruby
RUBY = $(ruby)
RM = rm -f
RM_RF = $(RUBY) -run -e rm -- -rf
@@ -117,7 +117,7 @@
extout_prefix =
target_prefix =
LOCAL_LIBS =
-LIBS = $(LIBRUBYARG_SHARED) -lshell32 -lws2_32 -limagehlp
+LIBS = $(LIBRUBYARG_SHARED) -lshell32 -lws2_32 -limagehlp -lshlwapi
SRCS = cache.c cache8.c dump.c fast.c load.c oj.c
OBJS = cache.o cache8.o dump.o fast.o load.o oj.o
TARGET = oj
@ohler55
Copy link

ohler55 commented Oct 18, 2012

Great suggestions. They will go into the next release of Oj. Look for it in the next release.

@ohler55
Copy link

ohler55 commented Oct 18, 2012

The type.delete call had to be changed to
type = type[4..-1] if type.start_with?('tcs-')
as delete() is the method to call as it deletes all characters that match any of 't', 'c', 's', or '-'.

@jonforums
Copy link
Author

Ah, another reason to say goodbye to delete. I'll try your latest master and comment on the Oj issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment