ninjudd-tuple 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION.yml +1 -1
  2. data/ext/tuple.c +19 -4
  3. data/test/test_helper.rb +12 -0
  4. metadata +2 -2
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 10
4
+ :patch: 11
data/ext/tuple.c CHANGED
@@ -1,4 +1,5 @@
1
1
  #include "ruby.h"
2
+ #include <netinet/in.h>
2
3
 
3
4
  VALUE mTuple;
4
5
  VALUE rb_cDate;
@@ -26,6 +27,19 @@ static void null_pad(VALUE data, int len) {
26
27
  }
27
28
  }
28
29
 
30
+
31
+ u_int32_t split64(int64_t num, int word) {
32
+ u_int32_t *split = (u_int32_t*)(void*)&num;
33
+
34
+ static int i = 1;
35
+ if (*(char *)&i == 1) word = word ? 1: 0;
36
+ else word = word ? 0: 1;
37
+
38
+ return split[word];
39
+ }
40
+
41
+
42
+
29
43
  /*
30
44
  * call-seq:
31
45
  * Tuple.dump(tuple) -> string
@@ -42,6 +56,7 @@ static VALUE tuple_dump(VALUE self, VALUE tuple) {
42
56
  int64_t fixnum;
43
57
  BDIGIT *digits;
44
58
 
59
+
45
60
  if (TYPE(tuple) != T_ARRAY) tuple = rb_ary_new4(1, &tuple);
46
61
 
47
62
  for (i = 0; i < RARRAY(tuple)->len; i++) {
@@ -54,14 +69,14 @@ static VALUE tuple_dump(VALUE self, VALUE tuple) {
54
69
  len = fixnum > UINT_MAX ? 2 : 1;
55
70
  header[2] = sign ? INTP_SORT : INTN_SORT;
56
71
  header[3] = sign ? len : UCHAR_MAX - len;
57
- rb_str_cat(data, (char*)&header, sizeof(header));
72
+ rb_str_cat(data, (char*)&header, sizeof(header));
58
73
 
59
74
  if (len == 2) {
60
- digit = ((u_int32_t *)(&fixnum))[_QUAD_HIGHWORD];
75
+ digit = split64(fixnum, 1);
61
76
  digit = htonl(sign ? digit : UINT_MAX - digit);
62
77
  rb_str_cat(data, (char*)&digit, sizeof(digit));
63
78
  }
64
- digit = ((u_int32_t *)(&fixnum))[_QUAD_LOWWORD];
79
+ digit = split64(fixnum, 0);
65
80
  digit = htonl(sign ? digit : UINT_MAX - digit);
66
81
  rb_str_cat(data, (char*)&digit, sizeof(digit));
67
82
  } else if (TYPE(item) == T_BIGNUM) {
@@ -209,7 +224,7 @@ static VALUE tuple_load(VALUE self, VALUE data) {
209
224
  }
210
225
 
211
226
  static VALUE array_compare(VALUE self, VALUE other) {
212
- rb_funcall(tuple_dump(mTuple, self), rb_intern("<=>"), 1, tuple_dump(mTuple, other));
227
+ return rb_funcall(tuple_dump(mTuple, self), rb_intern("<=>"), 1, tuple_dump(mTuple, other));
213
228
  }
214
229
 
215
230
  VALUE mTuple;
data/test/test_helper.rb CHANGED
@@ -6,5 +6,17 @@ require 'mocha'
6
6
  $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../ext')
7
7
  require 'tuple'
8
8
 
9
+ if not [].respond_to?(:shuffle)
10
+ class Array
11
+ def shuffle
12
+ t_self = self.dup
13
+ t_size = self.size
14
+ result=[]
15
+ t_size.times { result << t_self.slice!(rand(t_self.size)) }
16
+ result
17
+ end
18
+ end
19
+ end
20
+
9
21
  class Test::Unit::TestCase
10
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ninjudd-tuple
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Balthrop
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-21 00:00:00 -07:00
12
+ date: 2009-09-22 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15