bin_utils 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/bin_utils/extconf.rb +4 -2
- data/ext/bin_utils/native.c +18 -5
- data/lib/bin_utils.rb +8 -3
- data/lib/bin_utils/version.rb +1 -1
- data/test/benchmark.rb +5 -0
- data/test/test_bin_utils.rb +1 -1
- metadata +23 -8
data/ext/bin_utils/extconf.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
if RUBY_ENGINE == 'ruby'
|
1
|
+
if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
|
2
2
|
require 'mkmf'
|
3
|
-
|
3
|
+
# rubinius has no rb_str_drop_bytes
|
4
|
+
have_func('rb_str_drop_bytes')
|
5
|
+
create_makefile("bin_utils")
|
4
6
|
else
|
5
7
|
File.open(File.dirname(__FILE__) + "/Makefile", 'w') do |f|
|
6
8
|
f.write("install:\n\t#nothing to build")
|
data/ext/bin_utils/native.c
CHANGED
@@ -59,13 +59,24 @@ typedef unsigned long long uint64_t;
|
|
59
59
|
|
60
60
|
ID rshft;
|
61
61
|
ID band;
|
62
|
+
#ifndef HAVE_RB_STR_DROP_BYTES
|
63
|
+
/* rubinius has no rb_str_drop_bytes */
|
64
|
+
ID aset;
|
65
|
+
static VALUE
|
66
|
+
rb_str_drop_bytes(VALUE str, long bytes)
|
67
|
+
{
|
68
|
+
VALUE args[3] = {INT2FIX(0), INT2FIX(bytes), rb_str_new(0, 0)};
|
69
|
+
rb_funcall2(str, aset, 3, args);
|
70
|
+
return str;
|
71
|
+
}
|
72
|
+
#endif
|
62
73
|
|
63
74
|
static long
|
64
75
|
check_size(long i, long strlen, long ilen)
|
65
76
|
{
|
66
77
|
if (i < 0) { i += strlen; }
|
67
78
|
if (i > strlen - ilen || i < 0) {
|
68
|
-
rb_raise(rb_eArgError, "index %ld be in range 0..%ld or in range -%ld..-%ld for string of size %ld", i, strlen-ilen, strlen, -ilen, strlen);
|
79
|
+
rb_raise(rb_eArgError, "index %ld should be in range 0..%ld or in range -%ld..-%ld for string of size %ld", i, strlen-ilen, strlen, -ilen, strlen);
|
69
80
|
}
|
70
81
|
return i;
|
71
82
|
}
|
@@ -94,7 +105,6 @@ get_int16_le(VALUE rstr, VALUE ri)
|
|
94
105
|
long i = NUM2LONG(ri);
|
95
106
|
const uint8_t *ptr;
|
96
107
|
uint32_t byte0, byte1;
|
97
|
-
int32_t res;
|
98
108
|
StringValue(rstr);
|
99
109
|
i = check_size(i, RSTRING_LEN(rstr), 2);
|
100
110
|
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
@@ -481,7 +491,7 @@ get_ber(VALUE rstr, VALUE ri)
|
|
481
491
|
StringValue(rstr);
|
482
492
|
len = RSTRING_LEN(rstr);
|
483
493
|
i = check_size(i, len, 1);
|
484
|
-
ptr = RSTRING_PTR(rstr) + i;
|
494
|
+
ptr = (const uint8_t*)RSTRING_PTR(rstr) + i;
|
485
495
|
return parse_ber(ptr, len, &i);
|
486
496
|
}
|
487
497
|
|
@@ -953,7 +963,7 @@ slice_ber(VALUE rstr, long *i)
|
|
953
963
|
const uint8_t *ptr;
|
954
964
|
StringValue(rstr);
|
955
965
|
len = RSTRING_LEN(rstr);
|
956
|
-
ptr = RSTRING_PTR(rstr);
|
966
|
+
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
957
967
|
return parse_ber(ptr, len, i);
|
958
968
|
}
|
959
969
|
|
@@ -1583,12 +1593,15 @@ append_int_int(32, 24, be)
|
|
1583
1593
|
/** APPEND COMPLEX END **/
|
1584
1594
|
|
1585
1595
|
void
|
1586
|
-
|
1596
|
+
Init_bin_utils()
|
1587
1597
|
{
|
1588
1598
|
VALUE mod_bin_utils = rb_define_module("BinUtils");
|
1589
1599
|
VALUE mod_native = rb_define_module_under(mod_bin_utils, "Native");
|
1590
1600
|
rshft = rb_intern(">>");
|
1591
1601
|
band = rb_intern("&");
|
1602
|
+
#ifndef HAVE_RB_STR_DROP_BYTES
|
1603
|
+
aset = rb_intern("[]=");
|
1604
|
+
#endif
|
1592
1605
|
|
1593
1606
|
rb_define_method(mod_native, "get_ber", rb_get_ber, -1);
|
1594
1607
|
rb_define_method(mod_native, "get_int8", rb_get_int8, -1);
|
data/lib/bin_utils.rb
CHANGED
@@ -2,12 +2,17 @@ require "bin_utils/version"
|
|
2
2
|
|
3
3
|
module BinUtils
|
4
4
|
begin
|
5
|
-
|
6
|
-
|
5
|
+
if RUBY_ENGINE == 'jruby'
|
6
|
+
require 'bin_utils/bin_utils.jar'
|
7
|
+
else
|
8
|
+
require 'bin_utils/bin_utils'
|
9
|
+
end
|
10
|
+
extend ::BinUtils::Native
|
7
11
|
rescue LoadError
|
12
|
+
raise
|
8
13
|
require 'bin_utils/pure_ruby'
|
9
14
|
extend PureRuby
|
10
|
-
if RUBY_ENGINE == 'ruby'
|
15
|
+
if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'jruby'
|
11
16
|
$stderr.puts "Attention: pure ruby version of BinUtils is used"
|
12
17
|
end
|
13
18
|
end
|
data/lib/bin_utils/version.rb
CHANGED
data/test/benchmark.rb
CHANGED
@@ -68,6 +68,11 @@ Benchmark.bmbm(6) do |x|
|
|
68
68
|
i, i2 = b.unpack(_Vv)
|
69
69
|
b[0, 6] = EMPTY
|
70
70
|
} }
|
71
|
+
x.report('cut unpack i32le i16le') { N.times{|_|
|
72
|
+
b = a.dup
|
73
|
+
i, i2 = b.unpack(_Vv)
|
74
|
+
b.replace b[6..-1]
|
75
|
+
} }
|
71
76
|
x.report('cut unpack i32le i16le ber') { N.times{|_|
|
72
77
|
b = a.dup
|
73
78
|
i, i2, i3 = b.unpack(_Vvw)
|
data/test/test_bin_utils.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bin_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.3
|
5
4
|
prerelease:
|
5
|
+
version: 0.0.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Sokolov Yura 'funny-falcon'
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
12
|
+
date: 2013-02-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
prerelease: false
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
none: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
none: false
|
28
|
+
type: :development
|
29
|
+
name: rake-compiler
|
14
30
|
description: utils for extracting binary integers from binary string and packing them
|
15
31
|
back
|
16
32
|
email:
|
@@ -20,13 +36,13 @@ extensions:
|
|
20
36
|
- ext/bin_utils/extconf.rb
|
21
37
|
extra_rdoc_files: []
|
22
38
|
files:
|
23
|
-
- ext/bin_utils/extconf.rb
|
24
|
-
- ext/bin_utils/native.c
|
25
39
|
- lib/bin_utils.rb
|
26
40
|
- lib/bin_utils/pure_ruby.rb
|
27
41
|
- lib/bin_utils/version.rb
|
28
42
|
- test/benchmark.rb
|
29
43
|
- test/test_bin_utils.rb
|
44
|
+
- ext/bin_utils/extconf.rb
|
45
|
+
- ext/bin_utils/native.c
|
30
46
|
homepage: https://github.com/funny-falcon/bin_utils
|
31
47
|
licenses: []
|
32
48
|
post_install_message:
|
@@ -35,17 +51,17 @@ require_paths:
|
|
35
51
|
- lib
|
36
52
|
- ext
|
37
53
|
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
-
none: false
|
39
54
|
requirements:
|
40
55
|
- - ! '>='
|
41
56
|
- !ruby/object:Gem::Version
|
42
57
|
version: 1.9.1
|
43
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
58
|
none: false
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
60
|
requirements:
|
46
61
|
- - ! '>='
|
47
62
|
- !ruby/object:Gem::Version
|
48
63
|
version: '0'
|
64
|
+
none: false
|
49
65
|
requirements: []
|
50
66
|
rubyforge_project:
|
51
67
|
rubygems_version: 1.8.24
|
@@ -56,4 +72,3 @@ summary: Faster alternative to String#unpack and Array#unpack, though not as com
|
|
56
72
|
test_files:
|
57
73
|
- test/benchmark.rb
|
58
74
|
- test/test_bin_utils.rb
|
59
|
-
has_rdoc:
|