rcstorable 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +11 -0
- data/LICENSE +20 -0
- data/Rakefile +34 -0
- data/VERSION +1 -0
- data/ext/Makefile +157 -0
- data/ext/extconf.rb +5 -0
- data/ext/rcstorable.bundle +0 -0
- data/ext/rcstorable.c +209 -0
- data/ext/rcstorable.o +0 -0
- metadata +63 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Burke Libbey, Thorkelson Consulting Ltd.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
task :gem => :build
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'jeweler'
|
8
|
+
Jeweler::Tasks.new do |gem|
|
9
|
+
gem.name = "rcstorable"
|
10
|
+
gem.summary = "Ruby C implementation of perl Storable's thaw"
|
11
|
+
gem.description = "Super-fast Ruby C implementation of perl Storable's thaw"
|
12
|
+
gem.email = "burke.libbey@canadadrugs.com"
|
13
|
+
gem.homepage = "http://canadadrugs.com"
|
14
|
+
gem.authors = ["Burke Libbey"]
|
15
|
+
gem.files.include '{spec,lib,ext}/**/*'
|
16
|
+
gem.extensions = ["ext/extconf.rb"]
|
17
|
+
end
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
begin
|
23
|
+
require 'rcov/rcovtask'
|
24
|
+
Rcov::RcovTask.new do |test|
|
25
|
+
test.libs << 'spec'
|
26
|
+
test.pattern = 'spec/**/*_spec.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
rescue LoadError
|
30
|
+
task :rcov do
|
31
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
data/ext/Makefile
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
|
2
|
+
SHELL = /bin/sh
|
3
|
+
|
4
|
+
#### Start of system configuration section. ####
|
5
|
+
|
6
|
+
srcdir = .
|
7
|
+
topdir = /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin10.0
|
8
|
+
hdrdir = $(topdir)
|
9
|
+
VPATH = $(srcdir):$(topdir):$(hdrdir)
|
10
|
+
exec_prefix = $(prefix)
|
11
|
+
prefix = $(DESTDIR)/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr
|
12
|
+
sharedstatedir = $(prefix)/com
|
13
|
+
mandir = $(DESTDIR)/usr/share/man
|
14
|
+
psdir = $(docdir)
|
15
|
+
oldincludedir = $(DESTDIR)/usr/include
|
16
|
+
localedir = $(datarootdir)/locale
|
17
|
+
bindir = $(exec_prefix)/bin
|
18
|
+
libexecdir = $(exec_prefix)/libexec
|
19
|
+
sitedir = $(DESTDIR)/Library/Ruby/Site
|
20
|
+
htmldir = $(docdir)
|
21
|
+
vendorarchdir = $(vendorlibdir)/$(sitearch)
|
22
|
+
includedir = $(prefix)/include
|
23
|
+
infodir = $(DESTDIR)/usr/share/info
|
24
|
+
vendorlibdir = $(vendordir)/$(ruby_version)
|
25
|
+
sysconfdir = $(prefix)/etc
|
26
|
+
libdir = $(exec_prefix)/lib
|
27
|
+
sbindir = $(exec_prefix)/sbin
|
28
|
+
rubylibdir = $(libdir)/ruby/$(ruby_version)
|
29
|
+
docdir = $(datarootdir)/doc/$(PACKAGE)
|
30
|
+
dvidir = $(docdir)
|
31
|
+
vendordir = $(libdir)/ruby/vendor_ruby
|
32
|
+
datarootdir = $(prefix)/share
|
33
|
+
pdfdir = $(docdir)
|
34
|
+
archdir = $(rubylibdir)/$(arch)
|
35
|
+
sitearchdir = $(sitelibdir)/$(sitearch)
|
36
|
+
datadir = $(datarootdir)
|
37
|
+
localstatedir = $(prefix)/var
|
38
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
39
|
+
|
40
|
+
CC = gcc
|
41
|
+
LIBRUBY = $(LIBRUBY_SO)
|
42
|
+
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
43
|
+
LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
|
44
|
+
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)
|
45
|
+
|
46
|
+
RUBY_EXTCONF_H =
|
47
|
+
CFLAGS = -fno-common -arch i386 -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE -fno-common -pipe -fno-common $(cflags)
|
48
|
+
INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
|
49
|
+
DEFS =
|
50
|
+
CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE $(DEFS) $(cppflags)
|
51
|
+
CXXFLAGS = $(CFLAGS)
|
52
|
+
ldflags = -L. -arch i386 -arch x86_64
|
53
|
+
dldflags =
|
54
|
+
archflag =
|
55
|
+
DLDFLAGS = $(ldflags) $(dldflags) $(archflag)
|
56
|
+
LDSHARED = cc -arch i386 -arch x86_64 -pipe -bundle -undefined dynamic_lookup
|
57
|
+
AR = ar
|
58
|
+
EXEEXT =
|
59
|
+
|
60
|
+
RUBY_INSTALL_NAME = ruby
|
61
|
+
RUBY_SO_NAME = ruby
|
62
|
+
arch = universal-darwin10.0
|
63
|
+
sitearch = universal-darwin10.0
|
64
|
+
ruby_version = 1.8
|
65
|
+
ruby = /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
|
66
|
+
RUBY = $(ruby)
|
67
|
+
RM = rm -f
|
68
|
+
MAKEDIRS = mkdir -p
|
69
|
+
INSTALL = /usr/bin/install -c
|
70
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
71
|
+
INSTALL_DATA = $(INSTALL) -m 644
|
72
|
+
COPY = cp
|
73
|
+
|
74
|
+
#### End of system configuration section. ####
|
75
|
+
|
76
|
+
preload =
|
77
|
+
|
78
|
+
libpath = . $(libdir)
|
79
|
+
LIBPATH = -L. -L$(libdir)
|
80
|
+
DEFFILE =
|
81
|
+
|
82
|
+
CLEANFILES = mkmf.log
|
83
|
+
DISTCLEANFILES =
|
84
|
+
|
85
|
+
extout =
|
86
|
+
extout_prefix =
|
87
|
+
target_prefix =
|
88
|
+
LOCAL_LIBS =
|
89
|
+
LIBS = $(LIBRUBYARG_SHARED) -lpthread -ldl
|
90
|
+
SRCS = rcstorable.c
|
91
|
+
OBJS = rcstorable.o
|
92
|
+
TARGET = rcstorable
|
93
|
+
DLLIB = $(TARGET).bundle
|
94
|
+
EXTSTATIC =
|
95
|
+
STATIC_LIB =
|
96
|
+
|
97
|
+
BINDIR = $(bindir)
|
98
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
99
|
+
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
100
|
+
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
101
|
+
|
102
|
+
TARGET_SO = $(DLLIB)
|
103
|
+
CLEANLIBS = $(TARGET).bundle $(TARGET).il? $(TARGET).tds $(TARGET).map
|
104
|
+
CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
|
105
|
+
|
106
|
+
all: $(DLLIB)
|
107
|
+
static: $(STATIC_LIB)
|
108
|
+
|
109
|
+
clean:
|
110
|
+
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
111
|
+
|
112
|
+
distclean: clean
|
113
|
+
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
114
|
+
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
115
|
+
|
116
|
+
realclean: distclean
|
117
|
+
install: install-so install-rb
|
118
|
+
|
119
|
+
install-so: $(RUBYARCHDIR)
|
120
|
+
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
121
|
+
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
122
|
+
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
123
|
+
install-rb: pre-install-rb install-rb-default
|
124
|
+
install-rb-default: pre-install-rb-default
|
125
|
+
pre-install-rb: Makefile
|
126
|
+
pre-install-rb-default: Makefile
|
127
|
+
$(RUBYARCHDIR):
|
128
|
+
$(MAKEDIRS) $@
|
129
|
+
|
130
|
+
site-install: site-install-so site-install-rb
|
131
|
+
site-install-so: install-so
|
132
|
+
site-install-rb: install-rb
|
133
|
+
|
134
|
+
.SUFFIXES: .c .m .cc .cxx .cpp .C .o
|
135
|
+
|
136
|
+
.cc.o:
|
137
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
138
|
+
|
139
|
+
.cxx.o:
|
140
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
141
|
+
|
142
|
+
.cpp.o:
|
143
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
144
|
+
|
145
|
+
.C.o:
|
146
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
147
|
+
|
148
|
+
.c.o:
|
149
|
+
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
|
150
|
+
|
151
|
+
$(DLLIB): $(OBJS)
|
152
|
+
@-$(RM) $@
|
153
|
+
$(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
$(OBJS): ruby.h defines.h
|
data/ext/extconf.rb
ADDED
Binary file
|
data/ext/rcstorable.c
ADDED
@@ -0,0 +1,209 @@
|
|
1
|
+
#include <stdbool.h>
|
2
|
+
#include <stdio.h>
|
3
|
+
#include <string.h>
|
4
|
+
|
5
|
+
#include "ruby.h"
|
6
|
+
|
7
|
+
VALUE thaw(VALUE, VALUE);
|
8
|
+
VALUE read_object();
|
9
|
+
int read_extended_size();
|
10
|
+
int read_compact_size();
|
11
|
+
void read_n_hash_pairs(VALUE, int);
|
12
|
+
void read_n_array_entries(VALUE, int);
|
13
|
+
VALUE read_string(bool);
|
14
|
+
void read_magic_numbers();
|
15
|
+
|
16
|
+
enum states
|
17
|
+
{
|
18
|
+
READ_EXTENDED_SIZE,
|
19
|
+
READ_COMPACT_SIZE,
|
20
|
+
READ_NEW_OBJECT
|
21
|
+
};
|
22
|
+
|
23
|
+
enum object_types
|
24
|
+
{
|
25
|
+
O_STR = 1,
|
26
|
+
O_ARRAY = 2,
|
27
|
+
O_HASH = 3,
|
28
|
+
O_UNDEFINED = 5
|
29
|
+
};
|
30
|
+
|
31
|
+
enum hash_key_types
|
32
|
+
{
|
33
|
+
H_VECTOR = 4,
|
34
|
+
H_EMPTY = 5,
|
35
|
+
H_STRING = 10,
|
36
|
+
H_STRING_ALT = 23
|
37
|
+
};
|
38
|
+
|
39
|
+
// Used globally. Raptors. I know.
|
40
|
+
unsigned char *serialized;
|
41
|
+
|
42
|
+
VALUE
|
43
|
+
thaw(VALUE self, VALUE str)
|
44
|
+
{
|
45
|
+
Check_Type(str, T_STRING);
|
46
|
+
extern unsigned char *serialized;
|
47
|
+
|
48
|
+
serialized = RSTRING_PTR(str);
|
49
|
+
|
50
|
+
read_magic_numbers();
|
51
|
+
|
52
|
+
return read_object();
|
53
|
+
}
|
54
|
+
|
55
|
+
void
|
56
|
+
read_magic_numbers()
|
57
|
+
{
|
58
|
+
serialized++;
|
59
|
+
serialized++;
|
60
|
+
}
|
61
|
+
|
62
|
+
VALUE
|
63
|
+
read_object()
|
64
|
+
{
|
65
|
+
extern unsigned char *serialized;
|
66
|
+
int type = *serialized++;
|
67
|
+
int size = read_extended_size();
|
68
|
+
|
69
|
+
VALUE object;
|
70
|
+
|
71
|
+
switch(type) {
|
72
|
+
case O_HASH:
|
73
|
+
object = rb_hash_new();
|
74
|
+
read_n_hash_pairs(object, size);
|
75
|
+
break;
|
76
|
+
case O_ARRAY:
|
77
|
+
object = rb_ary_new();
|
78
|
+
read_n_array_entries(object, size);
|
79
|
+
break;
|
80
|
+
case O_UNDEFINED:
|
81
|
+
object = Qnil;
|
82
|
+
break;
|
83
|
+
}
|
84
|
+
|
85
|
+
return object;
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
void
|
90
|
+
read_n_hash_pairs(VALUE hash, int num)
|
91
|
+
{
|
92
|
+
extern unsigned char *serialized;
|
93
|
+
|
94
|
+
if (num == 0) {
|
95
|
+
return;
|
96
|
+
}
|
97
|
+
|
98
|
+
int type = *serialized++;
|
99
|
+
VALUE temp;
|
100
|
+
VALUE str;
|
101
|
+
|
102
|
+
switch(type) {
|
103
|
+
case H_EMPTY:
|
104
|
+
rb_hash_aset(hash, read_string(true), Qnil);
|
105
|
+
break;
|
106
|
+
case H_VECTOR:
|
107
|
+
temp = read_object();
|
108
|
+
str = read_string(true);
|
109
|
+
rb_hash_aset(hash, str, temp);
|
110
|
+
break;
|
111
|
+
case H_STRING:
|
112
|
+
case H_STRING_ALT:
|
113
|
+
temp = read_string(false);
|
114
|
+
rb_hash_aset(hash, read_string(true), temp);
|
115
|
+
break;
|
116
|
+
}
|
117
|
+
|
118
|
+
read_n_hash_pairs(hash, num-1);
|
119
|
+
}
|
120
|
+
|
121
|
+
void
|
122
|
+
read_n_array_entries(VALUE array, int num)
|
123
|
+
{
|
124
|
+
extern unsigned char *serialized;
|
125
|
+
|
126
|
+
if (num == 0) {
|
127
|
+
return;
|
128
|
+
}
|
129
|
+
|
130
|
+
VALUE item = Qnil;
|
131
|
+
int type = *serialized++;
|
132
|
+
|
133
|
+
switch(type) {
|
134
|
+
case O_STR:
|
135
|
+
item = read_string(true);
|
136
|
+
break;
|
137
|
+
}
|
138
|
+
|
139
|
+
rb_ary_push(array, item);
|
140
|
+
|
141
|
+
read_n_array_entries(array, num-1);
|
142
|
+
}
|
143
|
+
|
144
|
+
|
145
|
+
VALUE
|
146
|
+
read_string(bool extended_size)
|
147
|
+
{
|
148
|
+
extern unsigned char *serialized;
|
149
|
+
|
150
|
+
int size = extended_size ? read_extended_size() : read_compact_size();
|
151
|
+
int actual_size = 0;
|
152
|
+
int rem;
|
153
|
+
char *tp = serialized;
|
154
|
+
|
155
|
+
if (size == 319) { // apparently Storable uses \000\000\001\077 to mean "read until n<10"
|
156
|
+
while (*tp++ >= 10) {
|
157
|
+
actual_size++;
|
158
|
+
}
|
159
|
+
size = actual_size;
|
160
|
+
}
|
161
|
+
|
162
|
+
rem = size;
|
163
|
+
|
164
|
+
char *np = malloc(size * sizeof(char) + 1);
|
165
|
+
char *cnp = np;
|
166
|
+
|
167
|
+
while (rem > 0) {
|
168
|
+
rem--;
|
169
|
+
*cnp++ = *serialized++;
|
170
|
+
}
|
171
|
+
|
172
|
+
*cnp++ = '\0';
|
173
|
+
|
174
|
+
return rb_str_new(np, size);
|
175
|
+
}
|
176
|
+
|
177
|
+
/*
|
178
|
+
* Extended sizes are given as [w,x,y,z], where the size is 256*y + z.
|
179
|
+
*/
|
180
|
+
int
|
181
|
+
read_extended_size()
|
182
|
+
{
|
183
|
+
extern unsigned char *serialized;
|
184
|
+
int size = 0;
|
185
|
+
|
186
|
+
serialized++;
|
187
|
+
serialized++;
|
188
|
+
size += 256*(*serialized++);
|
189
|
+
size += *serialized++;
|
190
|
+
|
191
|
+
return size;
|
192
|
+
}
|
193
|
+
|
194
|
+
/*
|
195
|
+
* Just one byte.
|
196
|
+
*/
|
197
|
+
int
|
198
|
+
read_compact_size() {
|
199
|
+
extern unsigned char *serialized;
|
200
|
+
return *serialized++;
|
201
|
+
}
|
202
|
+
|
203
|
+
|
204
|
+
void
|
205
|
+
Init_rcstorable()
|
206
|
+
{
|
207
|
+
VALUE mRcstorable = rb_define_module("RCStorable");
|
208
|
+
rb_define_singleton_method(mRcstorable, "thaw", thaw, 1);
|
209
|
+
}
|
data/ext/rcstorable.o
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rcstorable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Burke Libbey
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-13 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Super-fast Ruby C implementation of perl Storable's thaw
|
17
|
+
email: burke.libbey@canadadrugs.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions:
|
21
|
+
- ext/extconf.rb
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
files:
|
25
|
+
- .gitignore
|
26
|
+
- LICENSE
|
27
|
+
- Rakefile
|
28
|
+
- VERSION
|
29
|
+
- ext/Makefile
|
30
|
+
- ext/extconf.rb
|
31
|
+
- ext/rcstorable.bundle
|
32
|
+
- ext/rcstorable.c
|
33
|
+
- ext/rcstorable.o
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://canadadrugs.com
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options:
|
40
|
+
- --charset=UTF-8
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.3.5
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: Ruby C implementation of perl Storable's thaw
|
62
|
+
test_files: []
|
63
|
+
|