tuple 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/ext/extconf.rb +10 -0
  2. data/ext/tuple.c +35 -2
  3. metadata +26 -34
@@ -1,2 +1,12 @@
1
1
  require 'mkmf'
2
+
3
+ case RUBY_VERSION
4
+ when /\A1\.8/
5
+ $CFLAGS += ' -DRUBY_1_8_x'
6
+ when /\A1\.9/
7
+ $CFLAGS += ' -DRUBY_1_9_x'
8
+ else
9
+ raise "unsupported Ruby version: #{RUBY_VERSION}"
10
+ end
11
+
2
12
  create_makefile('tuple')
@@ -59,8 +59,15 @@ static VALUE tuple_dump(VALUE self, VALUE tuple) {
59
59
 
60
60
  if (TYPE(tuple) != T_ARRAY) tuple = rb_ary_new4(1, &tuple);
61
61
 
62
- for (i = 0; i < RARRAY(tuple)->len; i++) {
63
- item = RARRAY(tuple)->ptr[i];
62
+ #if defined(RUBY_1_9_x)
63
+ for (i = 0; i < RARRAY_LEN(tuple); i++) {
64
+ item = RARRAY_PTR(tuple)[i];
65
+ #elif defined(RUBY_1_8_x)
66
+ for (i = 0; i < RARRAY(tuple)->len; i++) {
67
+ item = RARRAY(tuple)->ptr[i];
68
+ #else
69
+ #error unsupported RUBY_VERSION
70
+ #endif
64
71
  header[0] = header[1] = header[2] = header[3] = 0;
65
72
  if (FIXNUM_P(item)) {
66
73
  fixnum = FIX2LONG(item);
@@ -80,13 +87,26 @@ static VALUE tuple_dump(VALUE self, VALUE tuple) {
80
87
  digit = htonl(sign ? digit : UINT_MAX - digit);
81
88
  rb_str_cat(data, (char*)&digit, sizeof(digit));
82
89
  } else if (TYPE(item) == T_BIGNUM) {
90
+ #if defined(RUBY_1_9_x)
91
+ sign = RBIGNUM_SIGN(item);
92
+ len = RBIGNUM_LEN(item);
93
+ #elif defined(RUBY_1_8_x)
83
94
  sign = RBIGNUM(item)->sign;
84
95
  len = RBIGNUM(item)->len;
96
+ #else
97
+ #error unsupported RUBY_VERSION
98
+ #endif
85
99
  header[2] = sign ? INTP_SORT : INTN_SORT;
86
100
  header[3] = sign ? len : UCHAR_MAX - len;
87
101
  rb_str_cat(data, (char*)&header, sizeof(header));
88
102
 
103
+ #if defined(RUBY_1_9_x)
104
+ digits = RBIGNUM_DIGITS(item);
105
+ #elif defined(RUBY_1_8_x)
89
106
  digits = BDIGITS(item);
107
+ #else
108
+ #error unsupported RUBY_VERSION
109
+ #endif
90
110
  for (j = len-1; j >= 0; j--) {
91
111
  digit = htonl(sign ? digits[j] : (UINT_MAX - digits[j]));
92
112
  rb_str_cat(data, (char*)&digit, sizeof(digit));
@@ -138,14 +158,21 @@ static VALUE tuple_dump(VALUE self, VALUE tuple) {
138
158
  }
139
159
 
140
160
  static VALUE empty_bignum(int sign, int len) {
161
+ #if defined(RUBY_1_9_x)
162
+ return rb_big_new(len, sign);
163
+ #elif defined(RUBY_1_8_x)
141
164
  /* Create an empty bignum with the right number of digits. */
142
165
  NEWOBJ(num, struct RBignum);
143
166
  OBJSETUP(num, rb_cBignum, T_BIGNUM);
167
+
144
168
  num->sign = sign ? 1 : 0;
145
169
  num->len = len;
146
170
  num->digits = ALLOC_N(BDIGIT, len);
147
171
 
148
172
  return (VALUE)num;
173
+ #else
174
+ #error unsupported RUBY_VERSION
175
+ #endif
149
176
  }
150
177
 
151
178
  static VALUE tuple_parse(void **data, int data_len) {
@@ -172,7 +199,13 @@ static VALUE tuple_parse(void **data, int data_len) {
172
199
  len = sign ? header[3] : (UCHAR_MAX - header[3]);
173
200
 
174
201
  item = empty_bignum(sign, len);
202
+ #if defined(RUBY_1_9_x)
203
+ digits = RBIGNUM_DIGITS(item);
204
+ #elif defined(RUBY_1_8_x)
175
205
  digits = BDIGITS(item);
206
+ #else
207
+ #error unsupported RUBY_VERSION
208
+ #endif
176
209
  for (i = len-1; i >= 0; i--) {
177
210
  digit = ntohl(*(u_int32_t*)ptr);
178
211
  digits[i] = sign ? digit : UINT_MAX - digit;
metadata CHANGED
@@ -1,62 +1,54 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: tuple
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - Justin Balthrop
9
+ - Ash Moran
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
-
12
- date: 2009-11-20 00:00:00 -08:00
13
- default_executable:
13
+ date: 2011-08-24 00:00:00.000000000Z
14
14
  dependencies: []
15
-
16
15
  description: Fast, binary-sortable serialization for arrays of simple Ruby types.
17
16
  email: code@justinbalthrop.com
18
17
  executables: []
19
-
20
- extensions:
18
+ extensions:
21
19
  - ext/extconf.rb
22
- extra_rdoc_files:
20
+ extra_rdoc_files:
23
21
  - LICENSE
24
22
  - README.rdoc
25
- files:
23
+ files:
26
24
  - README.rdoc
27
25
  - ext/extconf.rb
28
26
  - ext/tuple.c
29
27
  - test/test_helper.rb
30
28
  - test/tuple_test.rb
31
29
  - LICENSE
32
- has_rdoc: true
33
30
  homepage: http://github.com/ninjudd/tuple
34
31
  licenses: []
35
-
36
32
  post_install_message:
37
- rdoc_options:
38
- - --charset=UTF-8
39
- require_paths:
33
+ rdoc_options: []
34
+ require_paths:
40
35
  - ext
41
- required_ruby_version: !ruby/object:Gem::Requirement
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- version: "0"
46
- version:
47
- required_rubygems_version: !ruby/object:Gem::Requirement
48
- requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
51
- version: "0"
52
- version:
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
53
48
  requirements: []
54
-
55
49
  rubyforge_project:
56
- rubygems_version: 1.3.5
50
+ rubygems_version: 1.8.7
57
51
  signing_key:
58
52
  specification_version: 3
59
53
  summary: Tuple serialization functions.
60
- test_files:
61
- - test/test_helper.rb
62
- - test/tuple_test.rb
54
+ test_files: []