zscan 1.3 → 2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/benchmark/vs-unpack.rb +5 -4
- data/ext/bspec.c +34 -22
- data/ext/bspec_exec.inc +48 -11
- data/ext/bspec_init.inc +3 -3
- data/ext/extconf.rb +13 -2
- data/ext/pack/COPYING +56 -0
- data/ext/pack/COPYING.ja +51 -0
- data/ext/pack/internal.h +419 -0
- data/ext/pack/pack.c +2295 -0
- data/ext/zscan.c +37 -6
- data/ext/zscan.h +4 -0
- data/generate/bspec.rb +48 -0
- data/generate/bspec_exec.inc +29 -0
- data/generate/bspec_init.inc +2 -0
- data/generate/generate.rb +147 -0
- data/lib/zscan.rb +4 -37
- data/lib/zscan/bspec.rb +168 -0
- data/rakefile +29 -139
- data/readme.md +69 -24
- data/spec/binary_scan_spec.rb +35 -11
- data/spec/typed_scan_spec.rb +6 -0
- data/spec/zscan_spec.rb +8 -0
- data/zscan.gemspec +2 -2
- metadata +11 -3
- data/lib/zscan/instructions.rb +0 -147
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0789acb7433df9d0317d6a251d806493aa759d4c
|
4
|
+
data.tar.gz: b6d7b9277d6663684c8e993315942c829fafd994
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73b6e41a15da25c3ac4475ed3ec41fd383b096ff7536c51aae0647db663c270026d4bddd4b79a85132eec496f5379b9134fd89ca31a6827bf3c4a199dea4f5ac
|
7
|
+
data.tar.gz: 6558b04a492b1ae055b2bf5a3c64cd055330077e74fe3e75df1ef57816164404fbc2a98b9303c688714b6c5fade50b0b3a925bdd2fec4bfc939eddce49828713
|
data/benchmark/vs-unpack.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require_relative "../lib/zscan"
|
2
2
|
require "benchmark"
|
3
3
|
|
4
|
-
spec = ZScan.
|
4
|
+
spec = ZScan::BSpec.new do
|
5
5
|
int8
|
6
|
-
double_le
|
6
|
+
double_le
|
7
|
+
double_le
|
7
8
|
single_be
|
8
9
|
end
|
9
10
|
|
@@ -15,7 +16,7 @@ puts 'reference nop group'
|
|
15
16
|
puts Benchmark.measure{ 100000.times{ z.pos = 0 } }
|
16
17
|
puts 'ZScan#unpack'
|
17
18
|
puts Benchmark.measure{ 100000.times{ z.pos = 0; z.unpack 'cE2g' } }
|
18
|
-
puts 'ZScan#
|
19
|
-
puts Benchmark.measure{ 100000.times{ z.pos = 0; z.
|
19
|
+
puts 'ZScan#scan_bytes'
|
20
|
+
puts Benchmark.measure{ 100000.times{ z.pos = 0; z.scan_bytes spec } }
|
20
21
|
puts 'String#unpack'
|
21
22
|
puts Benchmark.measure{ 100000.times{ z.pos = 0; str.unpack 'cE2g' } }
|
data/ext/bspec.c
CHANGED
@@ -8,6 +8,7 @@ typedef struct {
|
|
8
8
|
long s_size;
|
9
9
|
long a_size;
|
10
10
|
long a_cap;
|
11
|
+
long curr;
|
11
12
|
void** code;
|
12
13
|
} BSpec;
|
13
14
|
|
@@ -23,7 +24,7 @@ static size_t bspec_memsize(const void* pp) {
|
|
23
24
|
}
|
24
25
|
|
25
26
|
static const rb_data_type_t bspec_type = {
|
26
|
-
"ZScan::
|
27
|
+
"ZScan::BSpec",
|
27
28
|
{NULL, bspec_free, bspec_memsize}
|
28
29
|
};
|
29
30
|
|
@@ -32,6 +33,7 @@ static VALUE bspec_alloc(VALUE klass) {
|
|
32
33
|
bs->s_size = 0;
|
33
34
|
bs->a_cap = 4;
|
34
35
|
bs->a_size = 0;
|
36
|
+
bs->curr = 0;
|
35
37
|
bs->code = (void**)malloc(bs->a_cap * sizeof(void*));
|
36
38
|
for (long i = 0; i < bs->a_cap; i++) {
|
37
39
|
bs->code[i] = bspec_opcodes[0];
|
@@ -39,15 +41,8 @@ static VALUE bspec_alloc(VALUE klass) {
|
|
39
41
|
return TypedData_Wrap_Struct(klass, &bspec_type, bs);
|
40
42
|
}
|
41
43
|
|
42
|
-
static
|
43
|
-
|
44
|
-
long i = NUM2LONG(v_i);
|
45
|
-
if (i < 0 || i >= bspec_opcodes_size) {
|
46
|
-
rb_raise(rb_eArgError, "bad opcode index");
|
47
|
-
}
|
48
|
-
|
49
|
-
// ensure size
|
50
|
-
if (bs->a_size == bs->a_cap - 1) { // end with 0:RET, always terminate
|
44
|
+
static void bspec_ensure_size(BSpec* bs) {
|
45
|
+
if (bs->curr == bs->a_cap - 1) { // end with 0:RET, always terminate
|
51
46
|
bs->code = (void**)realloc(bs->code, bs->a_cap * 2 * sizeof(void*));
|
52
47
|
long j = bs->a_cap;
|
53
48
|
bs->a_cap *= 2;
|
@@ -55,12 +50,31 @@ static VALUE bspec_append(VALUE self, VALUE v_i) {
|
|
55
50
|
bs->code[j] = bspec_opcodes[0];
|
56
51
|
}
|
57
52
|
}
|
53
|
+
}
|
54
|
+
|
55
|
+
static VALUE bspec_append(VALUE klass, VALUE self, VALUE v_i) {
|
56
|
+
BSpec* bs = rb_check_typeddata(self, &bspec_type);
|
57
|
+
long i = NUM2LONG(v_i);
|
58
|
+
if (i < 0 || i >= bspec_opcodes_size) {
|
59
|
+
rb_raise(rb_eArgError, "bad opcode index");
|
60
|
+
}
|
58
61
|
|
59
|
-
bs
|
62
|
+
bspec_ensure_size(bs);
|
63
|
+
bs->a_size++;
|
64
|
+
bs->code[bs->curr++] = bspec_opcodes[i];
|
60
65
|
bs->s_size += bspec_s_sizes[i];
|
61
66
|
return self;
|
62
67
|
}
|
63
68
|
|
69
|
+
static VALUE bspec_append_expect(VALUE klass, VALUE self, VALUE expect) {
|
70
|
+
BSpec* bs = rb_check_typeddata(self, &bspec_type);
|
71
|
+
bspec_ensure_size(bs);
|
72
|
+
bs->code[bs->curr] = 0;
|
73
|
+
memcpy(bs->code + bs->curr, RSTRING_PTR(expect), RSTRING_LEN(expect));
|
74
|
+
bs->curr++;
|
75
|
+
return self;
|
76
|
+
}
|
77
|
+
|
64
78
|
static VALUE bspec_big_endian_p(VALUE self) {
|
65
79
|
# ifdef DYNAMIC_ENDIAN
|
66
80
|
/* for universal binary of NEXTSTEP and MacOS X */
|
@@ -133,12 +147,8 @@ static VALUE bspec_inspect_opcodes(VALUE bspec, VALUE self) {
|
|
133
147
|
return a;
|
134
148
|
}
|
135
149
|
|
136
|
-
static VALUE
|
150
|
+
static VALUE zscan_scan_bytes(VALUE self, VALUE spec) {
|
137
151
|
ZScan* p = rb_check_typeddata(self, zscan_type);
|
138
|
-
if (!rb_enc_str_asciicompat_p(p->s)) {
|
139
|
-
rb_raise(rb_eRuntimeError, "encoding of source string should be ascii-compatible");
|
140
|
-
return Qnil;
|
141
|
-
}
|
142
152
|
BSpec* bs = rb_check_typeddata(spec, &bspec_type);
|
143
153
|
if (bs->a_size == 0) {
|
144
154
|
return rb_ary_new();
|
@@ -148,21 +158,23 @@ static VALUE zscan_scan_binary(VALUE self, VALUE spec) {
|
|
148
158
|
return Qnil;
|
149
159
|
}
|
150
160
|
volatile VALUE a = rb_ary_new2(bs->a_size - 1);
|
151
|
-
bspec_exec(bs->code, RSTRING_PTR(p->s) + p->bytepos, a);
|
152
|
-
|
153
|
-
|
161
|
+
a = bspec_exec(bs->code, RSTRING_PTR(p->s) + p->bytepos, a);
|
162
|
+
if (a != Qnil) {
|
163
|
+
zscan_bytepos_eq(self, LONG2NUM(p->bytepos + s_size));
|
164
|
+
}
|
154
165
|
return a;
|
155
166
|
}
|
156
167
|
|
157
168
|
void Init_zscan_bspec(VALUE zscan, const rb_data_type_t* _zscan_type) {
|
158
169
|
zscan_type = _zscan_type;
|
159
|
-
rb_define_method(zscan, "
|
170
|
+
rb_define_method(zscan, "scan_bytes", zscan_scan_bytes, 1);
|
160
171
|
|
161
172
|
bspec_opcodes = (void**)bspec_exec(NULL, NULL, Qnil);
|
162
|
-
VALUE bs = rb_define_class_under(zscan, "
|
173
|
+
VALUE bs = rb_define_class_under(zscan, "BSpec", rb_cObject);
|
174
|
+
rb_define_singleton_method(bs, "_append", bspec_append, 2);
|
175
|
+
rb_define_singleton_method(bs, "_append_expect", bspec_append_expect, 2);
|
163
176
|
rb_define_singleton_method(bs, "big_endian?", bspec_big_endian_p, 0);
|
164
177
|
rb_define_singleton_method(bs, "_opcodes_to_a", bspec_opcodes_to_a, 0);
|
165
178
|
rb_define_singleton_method(bs, "_inspect_opcodes", bspec_inspect_opcodes, 1);
|
166
179
|
rb_define_alloc_func(bs, bspec_alloc);
|
167
|
-
rb_define_method(bs, "append", bspec_append, 1);
|
168
180
|
}
|
data/ext/bspec_exec.inc
CHANGED
@@ -1,14 +1,51 @@
|
|
1
|
-
//
|
2
|
-
#line 2 "ext/bspec_exec.inc"
|
1
|
+
// generated by rake gen
|
3
2
|
__attribute__((__noinline__))
|
4
3
|
static VALUE bspec_exec(void** ip, char* s, VALUE a) {
|
5
|
-
static void* opcodes[] = { &&BS_RET, &&BS_INT8, &&BS_INT16, &&BS_INT16_SWAP, &&BS_INT32, &&BS_INT32_SWAP, &&BS_INT64, &&BS_INT64_SWAP, &&
|
4
|
+
static void* opcodes[] = { &&BS_RET, &&BS_EXPECT8, &&BS_EXPECT16, &&BS_EXPECT32, &&BS_EXPECT64, &&BS_INT8, &&BS_UINT8, &&BS_INT16, &&BS_INT16_SWAP, &&BS_INT32, &&BS_INT32_SWAP, &&BS_INT64, &&BS_INT64_SWAP, &&BS_UINT16, &&BS_UINT16_SWAP, &&BS_UINT32, &&BS_UINT32_SWAP, &&BS_UINT64, &&BS_UINT64_SWAP, &&BS_SINGLE, &&BS_SINGLE_SWAP, &&BS_DOUBLE, &&BS_DOUBLE_SWAP };
|
6
5
|
if (ip == NULL) {
|
7
6
|
return (VALUE)opcodes;
|
8
7
|
}
|
9
8
|
goto **(ip++);
|
10
9
|
BS_RET:
|
11
10
|
return a;
|
11
|
+
|
12
|
+
BS_EXPECT8:
|
13
|
+
{
|
14
|
+
char* expect = (char*)(ip++);
|
15
|
+
if (strncmp(s, expect, 1)) {
|
16
|
+
return Qnil;
|
17
|
+
}
|
18
|
+
goto **(ip++);
|
19
|
+
}
|
20
|
+
|
21
|
+
BS_EXPECT16:
|
22
|
+
{
|
23
|
+
char* expect = (char*)(ip++);
|
24
|
+
if (strncmp(s, expect, 2)) {
|
25
|
+
return Qnil;
|
26
|
+
}
|
27
|
+
goto **(ip++);
|
28
|
+
}
|
29
|
+
|
30
|
+
BS_EXPECT32:
|
31
|
+
{
|
32
|
+
char* expect = (char*)(ip++);
|
33
|
+
if (strncmp(s, expect, 4)) {
|
34
|
+
return Qnil;
|
35
|
+
}
|
36
|
+
goto **(ip++);
|
37
|
+
}
|
38
|
+
|
39
|
+
BS_EXPECT64:
|
40
|
+
{
|
41
|
+
char* expect = (char*)(ip++);
|
42
|
+
if (strncmp(s, expect, 8)) {
|
43
|
+
return Qnil;
|
44
|
+
}
|
45
|
+
goto **(ip++);
|
46
|
+
}
|
47
|
+
|
48
|
+
|
12
49
|
BS_INT8:
|
13
50
|
{
|
14
51
|
uint8_t r = ((uint8_t*)s)[0];
|
@@ -17,6 +54,14 @@ BS_INT8:
|
|
17
54
|
goto **(ip++);
|
18
55
|
}
|
19
56
|
|
57
|
+
BS_UINT8:
|
58
|
+
{
|
59
|
+
uint8_t r = ((uint8_t*)s)[0];
|
60
|
+
rb_ary_push(a, INT2FIX(CAST(r, uint8_t)));
|
61
|
+
s += 1;
|
62
|
+
goto **(ip++);
|
63
|
+
}
|
64
|
+
|
20
65
|
BS_INT16:
|
21
66
|
{
|
22
67
|
uint16_t r = ((uint16_t*)s)[0];
|
@@ -65,14 +110,6 @@ BS_INT64_SWAP:
|
|
65
110
|
goto **(ip++);
|
66
111
|
}
|
67
112
|
|
68
|
-
BS_UINT8:
|
69
|
-
{
|
70
|
-
uint8_t r = ((uint8_t*)s)[0];
|
71
|
-
rb_ary_push(a, INT2FIX(CAST(r, uint8_t)));
|
72
|
-
s += 1;
|
73
|
-
goto **(ip++);
|
74
|
-
}
|
75
|
-
|
76
113
|
BS_UINT16:
|
77
114
|
{
|
78
115
|
uint16_t r = ((uint16_t*)s)[0];
|
data/ext/bspec_init.inc
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
//
|
2
|
-
static const long bspec_s_sizes[] = {0, 1, 2, 2, 4, 4, 8, 8,
|
3
|
-
static const long bspec_opcodes_size =
|
1
|
+
// generated by rake gen
|
2
|
+
static const long bspec_s_sizes[] = {0, 0, 0, 0, 0, 1, 1, 2, 2, 4, 4, 8, 8, 2, 2, 4, 4, 8, 8, 4, 4, 8, 8};
|
3
|
+
static const long bspec_opcodes_size = 23;
|
data/ext/extconf.rb
CHANGED
@@ -2,7 +2,18 @@ require "mkmf"
|
|
2
2
|
|
3
3
|
create_makefile 'zscan'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
makefile = File.read 'Makefile'
|
6
|
+
lines = makefile.lines.map do |line|
|
7
|
+
if line.start_with?('ORIG_SRCS =')
|
8
|
+
line.sub /$/, ' pack/pack.c'
|
9
|
+
elsif line.start_with?('OBJS =')
|
10
|
+
line.sub /$/, ' pack/pack.o'
|
11
|
+
else
|
12
|
+
line
|
13
|
+
end
|
14
|
+
end
|
15
|
+
headers = Dir.glob('**/*.h').join ' '
|
16
|
+
File.open 'Makefile', 'w' do |f|
|
17
|
+
f.puts lines
|
7
18
|
f.puts "\n$(OBJS): #{headers}"
|
8
19
|
end
|
data/ext/pack/COPYING
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
|
2
|
+
You can redistribute it and/or modify it under either the terms of the
|
3
|
+
2-clause BSDL (see the file BSDL), or the conditions below:
|
4
|
+
|
5
|
+
1. You may make and give away verbatim copies of the source form of the
|
6
|
+
software without restriction, provided that you duplicate all of the
|
7
|
+
original copyright notices and associated disclaimers.
|
8
|
+
|
9
|
+
2. You may modify your copy of the software in any way, provided that
|
10
|
+
you do at least ONE of the following:
|
11
|
+
|
12
|
+
a) place your modifications in the Public Domain or otherwise
|
13
|
+
make them Freely Available, such as by posting said
|
14
|
+
modifications to Usenet or an equivalent medium, or by allowing
|
15
|
+
the author to include your modifications in the software.
|
16
|
+
|
17
|
+
b) use the modified software only within your corporation or
|
18
|
+
organization.
|
19
|
+
|
20
|
+
c) give non-standard binaries non-standard names, with
|
21
|
+
instructions on where to get the original software distribution.
|
22
|
+
|
23
|
+
d) make other distribution arrangements with the author.
|
24
|
+
|
25
|
+
3. You may distribute the software in object code or binary form,
|
26
|
+
provided that you do at least ONE of the following:
|
27
|
+
|
28
|
+
a) distribute the binaries and library files of the software,
|
29
|
+
together with instructions (in the manual page or equivalent)
|
30
|
+
on where to get the original distribution.
|
31
|
+
|
32
|
+
b) accompany the distribution with the machine-readable source of
|
33
|
+
the software.
|
34
|
+
|
35
|
+
c) give non-standard binaries non-standard names, with
|
36
|
+
instructions on where to get the original software distribution.
|
37
|
+
|
38
|
+
d) make other distribution arrangements with the author.
|
39
|
+
|
40
|
+
4. You may modify and include the part of the software into any other
|
41
|
+
software (possibly commercial). But some files in the distribution
|
42
|
+
are not written by the author, so that they are not under these terms.
|
43
|
+
|
44
|
+
For the list of those files and their copying conditions, see the
|
45
|
+
file LEGAL.
|
46
|
+
|
47
|
+
5. The scripts and library files supplied as input to or produced as
|
48
|
+
output from the software do not automatically fall under the
|
49
|
+
copyright of the software, but belong to whomever generated them,
|
50
|
+
and may be sold commercially, and may be aggregated with this
|
51
|
+
software.
|
52
|
+
|
53
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
54
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
55
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
56
|
+
PURPOSE.
|
data/ext/pack/COPYING.ja
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
本プログラムはフリーソフトウェアです.2-clause BSDL
|
2
|
+
または以下に示す条件で本プログラムを再配布できます
|
3
|
+
2-clause BSDLについてはBSDLファイルを参照して下さい.
|
4
|
+
|
5
|
+
1. 複製は制限なく自由です.
|
6
|
+
|
7
|
+
2. 以下の条件のいずれかを満たす時に本プログラムのソースを
|
8
|
+
自由に変更できます.
|
9
|
+
|
10
|
+
(a) ネットニューズにポストしたり,作者に変更を送付する
|
11
|
+
などの方法で,変更を公開する.
|
12
|
+
|
13
|
+
(b) 変更した本プログラムを自分の所属する組織内部だけで
|
14
|
+
使う.
|
15
|
+
|
16
|
+
(c) 変更点を明示したうえ,ソフトウェアの名前を変更する.
|
17
|
+
そのソフトウェアを配布する時には変更前の本プログラ
|
18
|
+
ムも同時に配布する.または変更前の本プログラムのソー
|
19
|
+
スの入手法を明示する.
|
20
|
+
|
21
|
+
(d) その他の変更条件を作者と合意する.
|
22
|
+
|
23
|
+
3. 以下の条件のいずれかを満たす時に本プログラムをコンパイ
|
24
|
+
ルしたオブジェクトコードや実行形式でも配布できます.
|
25
|
+
|
26
|
+
(a) バイナリを受け取った人がソースを入手できるように,
|
27
|
+
ソースの入手法を明示する.
|
28
|
+
|
29
|
+
(b) 機械可読なソースコードを添付する.
|
30
|
+
|
31
|
+
(c) 変更を行ったバイナリは名前を変更したうえ,オリジナ
|
32
|
+
ルのソースコードの入手法を明示する.
|
33
|
+
|
34
|
+
(d) その他の配布条件を作者と合意する.
|
35
|
+
|
36
|
+
4. 他のプログラムへの引用はいかなる目的であれ自由です.た
|
37
|
+
だし,本プログラムに含まれる他の作者によるコードは,そ
|
38
|
+
れぞれの作者の意向による制限が加えられる場合があります.
|
39
|
+
|
40
|
+
それらファイルの一覧とそれぞれの配布条件などに付いては
|
41
|
+
LEGALファイルを参照してください.
|
42
|
+
|
43
|
+
5. 本プログラムへの入力となるスクリプトおよび,本プログラ
|
44
|
+
ムからの出力の権利は本プログラムの作者ではなく,それぞ
|
45
|
+
れの入出力を生成した人に属します.また,本プログラムに
|
46
|
+
組み込まれるための拡張ライブラリについても同様です.
|
47
|
+
|
48
|
+
6. 本プログラムは無保証です.作者は本プログラムをサポート
|
49
|
+
する意志はありますが,プログラム自身のバグあるいは本プ
|
50
|
+
ログラムの実行などから発生するいかなる損害に対しても責
|
51
|
+
任を持ちません.
|
data/ext/pack/internal.h
ADDED
@@ -0,0 +1,419 @@
|
|
1
|
+
/**********************************************************************
|
2
|
+
|
3
|
+
internal.h -
|
4
|
+
|
5
|
+
$Author$
|
6
|
+
created at: Tue May 17 11:42:20 JST 2011
|
7
|
+
|
8
|
+
Copyright (C) 2011 Yukihiro Matsumoto
|
9
|
+
|
10
|
+
**********************************************************************/
|
11
|
+
|
12
|
+
#ifndef RUBY_INTERNAL_H
|
13
|
+
#define RUBY_INTERNAL_H 1
|
14
|
+
|
15
|
+
#if defined(__cplusplus)
|
16
|
+
extern "C" {
|
17
|
+
#if 0
|
18
|
+
} /* satisfy cc-mode */
|
19
|
+
#endif
|
20
|
+
#endif
|
21
|
+
|
22
|
+
#define GCC_VERSION_SINCE(major, minor, patchlevel) \
|
23
|
+
(defined(__GNUC__) && !defined(__INTEL_COMPILER) && \
|
24
|
+
((__GNUC__ > (major)) || \
|
25
|
+
(__GNUC__ == (major) && __GNUC_MINOR__ > (minor)) || \
|
26
|
+
(__GNUC__ == (major) && __GNUC_MINOR__ == (minor) && __GNUC_PATCHLEVEL__ >= (patchlevel))))
|
27
|
+
|
28
|
+
#if SIGNEDNESS_OF_TIME_T < 0 /* signed */
|
29
|
+
# define TIMET_MAX (time_t)((~(unsigned_time_t)0) >> 1)
|
30
|
+
# define TIMET_MIN (time_t)(((unsigned_time_t)1) << (sizeof(time_t) * CHAR_BIT - 1))
|
31
|
+
#elif SIGNEDNESS_OF_TIME_T > 0 /* unsigned */
|
32
|
+
# define TIMET_MAX (time_t)(~(unsigned_time_t)0)
|
33
|
+
# define TIMET_MIN (time_t)0
|
34
|
+
#endif
|
35
|
+
#define TIMET_MAX_PLUS_ONE (2*(double)(TIMET_MAX/2+1))
|
36
|
+
|
37
|
+
#define MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, min, max) ( \
|
38
|
+
(a) == 0 ? 0 : \
|
39
|
+
(a) == -1 ? (b) < -(max) : \
|
40
|
+
(a) > 0 ? \
|
41
|
+
((b) > 0 ? (max) / (a) < (b) : (min) / (a) > (b)) : \
|
42
|
+
((b) > 0 ? (min) / (a) < (b) : (max) / (a) > (b)))
|
43
|
+
#define MUL_OVERFLOW_FIXNUM_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, FIXNUM_MIN, FIXNUM_MAX)
|
44
|
+
#define MUL_OVERFLOW_LONG_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, LONG_MIN, LONG_MAX)
|
45
|
+
#define MUL_OVERFLOW_INT_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, INT_MIN, INT_MAX)
|
46
|
+
|
47
|
+
struct rb_deprecated_classext_struct {
|
48
|
+
char conflict[sizeof(VALUE) * 3];
|
49
|
+
};
|
50
|
+
|
51
|
+
struct rb_classext_struct {
|
52
|
+
VALUE super;
|
53
|
+
struct st_table *iv_tbl;
|
54
|
+
struct st_table *const_tbl;
|
55
|
+
VALUE origin;
|
56
|
+
VALUE refined_class;
|
57
|
+
rb_alloc_func_t allocator;
|
58
|
+
};
|
59
|
+
|
60
|
+
#undef RCLASS_SUPER
|
61
|
+
#define RCLASS_EXT(c) (RCLASS(c)->ptr)
|
62
|
+
#define RCLASS_SUPER(c) (RCLASS_EXT(c)->super)
|
63
|
+
#define RCLASS_IV_TBL(c) (RCLASS_EXT(c)->iv_tbl)
|
64
|
+
#define RCLASS_CONST_TBL(c) (RCLASS_EXT(c)->const_tbl)
|
65
|
+
#define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
|
66
|
+
#define RCLASS_IV_INDEX_TBL(c) (RCLASS(c)->iv_index_tbl)
|
67
|
+
#define RCLASS_ORIGIN(c) (RCLASS_EXT(c)->origin)
|
68
|
+
#define RCLASS_REFINED_CLASS(c) (RCLASS_EXT(c)->refined_class)
|
69
|
+
|
70
|
+
struct vtm; /* defined by timev.h */
|
71
|
+
|
72
|
+
/* array.c */
|
73
|
+
VALUE rb_ary_last(int, VALUE *, VALUE);
|
74
|
+
void rb_ary_set_len(VALUE, long);
|
75
|
+
VALUE rb_ary_cat(VALUE, const VALUE *, long);
|
76
|
+
void rb_ary_delete_same(VALUE, VALUE);
|
77
|
+
|
78
|
+
/* bignum.c */
|
79
|
+
VALUE rb_big_fdiv(VALUE x, VALUE y);
|
80
|
+
VALUE rb_big_uminus(VALUE x);
|
81
|
+
VALUE rb_integer_float_cmp(VALUE x, VALUE y);
|
82
|
+
VALUE rb_integer_float_eq(VALUE x, VALUE y);
|
83
|
+
|
84
|
+
/* class.c */
|
85
|
+
VALUE rb_obj_methods(int argc, VALUE *argv, VALUE obj);
|
86
|
+
VALUE rb_obj_protected_methods(int argc, VALUE *argv, VALUE obj);
|
87
|
+
VALUE rb_obj_private_methods(int argc, VALUE *argv, VALUE obj);
|
88
|
+
VALUE rb_obj_public_methods(int argc, VALUE *argv, VALUE obj);
|
89
|
+
int rb_obj_basic_to_s_p(VALUE);
|
90
|
+
VALUE rb_special_singleton_class(VALUE);
|
91
|
+
VALUE rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach);
|
92
|
+
void Init_class_hierarchy(void);
|
93
|
+
|
94
|
+
/* compar.c */
|
95
|
+
VALUE rb_invcmp(VALUE, VALUE);
|
96
|
+
|
97
|
+
/* compile.c */
|
98
|
+
int rb_dvar_defined(ID);
|
99
|
+
int rb_local_defined(ID);
|
100
|
+
int rb_parse_in_eval(void);
|
101
|
+
int rb_parse_in_main(void);
|
102
|
+
const char * rb_insns_name(int i);
|
103
|
+
VALUE rb_insns_name_array(void);
|
104
|
+
|
105
|
+
/* cont.c */
|
106
|
+
VALUE rb_obj_is_fiber(VALUE);
|
107
|
+
void rb_fiber_reset_root_local_storage(VALUE);
|
108
|
+
|
109
|
+
/* debug.c */
|
110
|
+
PRINTF_ARGS(void ruby_debug_printf(const char*, ...), 1, 2);
|
111
|
+
|
112
|
+
/* dmyext.c */
|
113
|
+
void Init_ext(void);
|
114
|
+
|
115
|
+
/* encoding.c */
|
116
|
+
ID rb_id_encoding(void);
|
117
|
+
|
118
|
+
/* encoding.c */
|
119
|
+
void rb_gc_mark_encodings(void);
|
120
|
+
|
121
|
+
/* error.c */
|
122
|
+
NORETURN(PRINTF_ARGS(void rb_compile_bug(const char*, int, const char*, ...), 3, 4));
|
123
|
+
VALUE rb_check_backtrace(VALUE);
|
124
|
+
NORETURN(void rb_async_bug_errno(const char *,int));
|
125
|
+
const char *rb_builtin_type_name(int t);
|
126
|
+
const char *rb_builtin_class_name(VALUE x);
|
127
|
+
|
128
|
+
/* eval.c */
|
129
|
+
VALUE rb_refinement_module_get_refined_class(VALUE module);
|
130
|
+
|
131
|
+
/* eval_error.c */
|
132
|
+
void ruby_error_print(void);
|
133
|
+
VALUE rb_get_backtrace(VALUE info);
|
134
|
+
|
135
|
+
/* eval_jump.c */
|
136
|
+
void rb_call_end_proc(VALUE data);
|
137
|
+
void rb_mark_end_proc(void);
|
138
|
+
|
139
|
+
/* file.c */
|
140
|
+
VALUE rb_home_dir(const char *user, VALUE result);
|
141
|
+
VALUE rb_realpath_internal(VALUE basedir, VALUE path, int strict);
|
142
|
+
void rb_file_const(const char*, VALUE);
|
143
|
+
int rb_file_load_ok(const char *);
|
144
|
+
VALUE rb_file_expand_path_fast(VALUE, VALUE);
|
145
|
+
VALUE rb_file_expand_path_internal(VALUE, VALUE, int, int, VALUE);
|
146
|
+
VALUE rb_get_path_check_to_string(VALUE, int);
|
147
|
+
VALUE rb_get_path_check_convert(VALUE, VALUE, int);
|
148
|
+
void Init_File(void);
|
149
|
+
|
150
|
+
#ifdef RUBY_FUNCTION_NAME_STRING
|
151
|
+
# if defined __GNUC__ && __GNUC__ >= 4
|
152
|
+
# pragma GCC visibility push(default)
|
153
|
+
# endif
|
154
|
+
NORETURN(void rb_sys_fail_path_in(const char *func_name, VALUE path));
|
155
|
+
# if defined __GNUC__ && __GNUC__ >= 4
|
156
|
+
# pragma GCC visibility pop
|
157
|
+
# endif
|
158
|
+
# define rb_sys_fail_path(path) rb_sys_fail_path_in(RUBY_FUNCTION_NAME_STRING, path)
|
159
|
+
#else
|
160
|
+
# define rb_sys_fail_path(path) rb_sys_fail_str(path)
|
161
|
+
#endif
|
162
|
+
|
163
|
+
#ifdef _WIN32
|
164
|
+
/* file.c, win32/file.c */
|
165
|
+
void rb_w32_init_file(void);
|
166
|
+
#endif
|
167
|
+
|
168
|
+
/* gc.c */
|
169
|
+
void Init_heap(void);
|
170
|
+
void *ruby_mimmalloc(size_t size);
|
171
|
+
|
172
|
+
/* inits.c */
|
173
|
+
void rb_call_inits(void);
|
174
|
+
|
175
|
+
/* io.c */
|
176
|
+
const char *ruby_get_inplace_mode(void);
|
177
|
+
void ruby_set_inplace_mode(const char *);
|
178
|
+
ssize_t rb_io_bufread(VALUE io, void *buf, size_t size);
|
179
|
+
void rb_stdio_set_default_encoding(void);
|
180
|
+
void rb_write_error_str(VALUE mesg);
|
181
|
+
|
182
|
+
/* iseq.c */
|
183
|
+
VALUE rb_iseq_clone(VALUE iseqval, VALUE newcbase);
|
184
|
+
|
185
|
+
/* load.c */
|
186
|
+
VALUE rb_get_load_path(void);
|
187
|
+
VALUE rb_get_expanded_load_path(void);
|
188
|
+
NORETURN(void rb_load_fail(VALUE, const char*));
|
189
|
+
|
190
|
+
/* math.c */
|
191
|
+
VALUE rb_math_atan2(VALUE, VALUE);
|
192
|
+
VALUE rb_math_cos(VALUE);
|
193
|
+
VALUE rb_math_cosh(VALUE);
|
194
|
+
VALUE rb_math_exp(VALUE);
|
195
|
+
VALUE rb_math_hypot(VALUE, VALUE);
|
196
|
+
VALUE rb_math_log(int argc, VALUE *argv);
|
197
|
+
VALUE rb_math_sin(VALUE);
|
198
|
+
VALUE rb_math_sinh(VALUE);
|
199
|
+
VALUE rb_math_sqrt(VALUE);
|
200
|
+
|
201
|
+
/* newline.c */
|
202
|
+
void Init_newline(void);
|
203
|
+
|
204
|
+
/* numeric.c */
|
205
|
+
int rb_num_to_uint(VALUE val, unsigned int *ret);
|
206
|
+
VALUE ruby_num_interval_step_size(VALUE from, VALUE to, VALUE step, int excl);
|
207
|
+
int ruby_float_step(VALUE from, VALUE to, VALUE step, int excl);
|
208
|
+
double ruby_float_mod(double x, double y);
|
209
|
+
int rb_num_negative_p(VALUE);
|
210
|
+
VALUE rb_int_succ(VALUE num);
|
211
|
+
VALUE rb_int_pred(VALUE num);
|
212
|
+
|
213
|
+
/* object.c */
|
214
|
+
VALUE rb_obj_equal(VALUE obj1, VALUE obj2);
|
215
|
+
VALUE rb_obj_hide(VALUE obj);
|
216
|
+
|
217
|
+
/* parse.y */
|
218
|
+
VALUE rb_parser_get_yydebug(VALUE);
|
219
|
+
VALUE rb_parser_set_yydebug(VALUE, VALUE);
|
220
|
+
int rb_is_const_name(VALUE name);
|
221
|
+
int rb_is_class_name(VALUE name);
|
222
|
+
int rb_is_global_name(VALUE name);
|
223
|
+
int rb_is_instance_name(VALUE name);
|
224
|
+
int rb_is_attrset_name(VALUE name);
|
225
|
+
int rb_is_local_name(VALUE name);
|
226
|
+
int rb_is_method_name(VALUE name);
|
227
|
+
int rb_is_junk_name(VALUE name);
|
228
|
+
void rb_gc_mark_parser(void);
|
229
|
+
void rb_gc_mark_symbols(void);
|
230
|
+
|
231
|
+
/* proc.c */
|
232
|
+
VALUE rb_proc_location(VALUE self);
|
233
|
+
st_index_t rb_hash_proc(st_index_t hash, VALUE proc);
|
234
|
+
|
235
|
+
/* process.c */
|
236
|
+
#define RB_MAX_GROUPS (65536)
|
237
|
+
|
238
|
+
struct rb_execarg {
|
239
|
+
int use_shell;
|
240
|
+
union {
|
241
|
+
struct {
|
242
|
+
VALUE shell_script;
|
243
|
+
} sh;
|
244
|
+
struct {
|
245
|
+
VALUE command_name;
|
246
|
+
VALUE command_abspath; /* full path string or nil */
|
247
|
+
VALUE argv_str;
|
248
|
+
VALUE argv_buf;
|
249
|
+
} cmd;
|
250
|
+
} invoke;
|
251
|
+
VALUE redirect_fds;
|
252
|
+
VALUE envp_str;
|
253
|
+
VALUE envp_buf;
|
254
|
+
VALUE dup2_tmpbuf;
|
255
|
+
unsigned pgroup_given : 1;
|
256
|
+
unsigned umask_given : 1;
|
257
|
+
unsigned unsetenv_others_given : 1;
|
258
|
+
unsigned unsetenv_others_do : 1;
|
259
|
+
unsigned close_others_given : 1;
|
260
|
+
unsigned close_others_do : 1;
|
261
|
+
unsigned chdir_given : 1;
|
262
|
+
unsigned new_pgroup_given : 1;
|
263
|
+
unsigned new_pgroup_flag : 1;
|
264
|
+
unsigned uid_given : 1;
|
265
|
+
unsigned gid_given : 1;
|
266
|
+
rb_pid_t pgroup_pgid; /* asis(-1), new pgroup(0), specified pgroup (0<V). */
|
267
|
+
VALUE rlimit_limits; /* Qfalse or [[rtype, softlim, hardlim], ...] */
|
268
|
+
mode_t umask_mask;
|
269
|
+
rb_uid_t uid;
|
270
|
+
rb_gid_t gid;
|
271
|
+
VALUE fd_dup2;
|
272
|
+
VALUE fd_close;
|
273
|
+
VALUE fd_open;
|
274
|
+
VALUE fd_dup2_child;
|
275
|
+
int close_others_maxhint;
|
276
|
+
VALUE env_modification; /* Qfalse or [[k1,v1], ...] */
|
277
|
+
VALUE chdir_dir;
|
278
|
+
};
|
279
|
+
|
280
|
+
/* argv_str contains extra two elements.
|
281
|
+
* The beginning one is for /bin/sh used by exec_with_sh.
|
282
|
+
* The last one for terminating NULL used by execve.
|
283
|
+
* See rb_exec_fillarg() in process.c. */
|
284
|
+
#define ARGVSTR2ARGC(argv_str) (RSTRING_LEN(argv_str) / sizeof(char *) - 2)
|
285
|
+
#define ARGVSTR2ARGV(argv_str) ((char **)RSTRING_PTR(argv_str) + 1)
|
286
|
+
|
287
|
+
rb_pid_t rb_fork_ruby(int *status);
|
288
|
+
void rb_last_status_clear(void);
|
289
|
+
|
290
|
+
/* rational.c */
|
291
|
+
VALUE rb_lcm(VALUE x, VALUE y);
|
292
|
+
VALUE rb_rational_reciprocal(VALUE x);
|
293
|
+
|
294
|
+
/* re.c */
|
295
|
+
VALUE rb_reg_compile(VALUE str, int options, const char *sourcefile, int sourceline);
|
296
|
+
VALUE rb_reg_check_preprocess(VALUE);
|
297
|
+
|
298
|
+
/* signal.c */
|
299
|
+
int rb_get_next_signal(void);
|
300
|
+
int rb_sigaltstack_size(void);
|
301
|
+
|
302
|
+
/* strftime.c */
|
303
|
+
#ifdef RUBY_ENCODING_H
|
304
|
+
size_t rb_strftime_timespec(char *s, size_t maxsize, const char *format, rb_encoding *enc,
|
305
|
+
const struct vtm *vtm, struct timespec *ts, int gmt);
|
306
|
+
size_t rb_strftime(char *s, size_t maxsize, const char *format, rb_encoding *enc,
|
307
|
+
const struct vtm *vtm, VALUE timev, int gmt);
|
308
|
+
#endif
|
309
|
+
|
310
|
+
/* string.c */
|
311
|
+
int rb_str_buf_cat_escaped_char(VALUE result, unsigned int c, int unicode_p);
|
312
|
+
int rb_str_symname_p(VALUE);
|
313
|
+
VALUE rb_str_quote_unprintable(VALUE);
|
314
|
+
VALUE rb_id_quote_unprintable(ID);
|
315
|
+
#define QUOTE(str) rb_str_quote_unprintable(str)
|
316
|
+
#define QUOTE_ID(id) rb_id_quote_unprintable(id)
|
317
|
+
|
318
|
+
/* struct.c */
|
319
|
+
VALUE rb_struct_init_copy(VALUE copy, VALUE s);
|
320
|
+
|
321
|
+
/* time.c */
|
322
|
+
struct timeval rb_time_timeval(VALUE);
|
323
|
+
|
324
|
+
/* thread.c */
|
325
|
+
VALUE rb_obj_is_mutex(VALUE obj);
|
326
|
+
VALUE rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg);
|
327
|
+
void rb_thread_execute_interrupts(VALUE th);
|
328
|
+
void rb_clear_trace_func(void);
|
329
|
+
VALUE rb_get_coverages(void);
|
330
|
+
VALUE rb_thread_shield_new(void);
|
331
|
+
VALUE rb_thread_shield_wait(VALUE self);
|
332
|
+
VALUE rb_thread_shield_release(VALUE self);
|
333
|
+
VALUE rb_thread_shield_destroy(VALUE self);
|
334
|
+
void rb_mutex_allow_trap(VALUE self, int val);
|
335
|
+
VALUE rb_uninterruptible(VALUE (*b_proc)(ANYARGS), VALUE data);
|
336
|
+
VALUE rb_mutex_owned_p(VALUE self);
|
337
|
+
void ruby_kill(rb_pid_t pid, int sig);
|
338
|
+
|
339
|
+
/* thread_pthread.c, thread_win32.c */
|
340
|
+
void Init_native_thread(void);
|
341
|
+
|
342
|
+
/* vm.c */
|
343
|
+
VALUE rb_obj_is_thread(VALUE obj);
|
344
|
+
void rb_vm_mark(void *ptr);
|
345
|
+
void Init_BareVM(void);
|
346
|
+
VALUE rb_vm_top_self(void);
|
347
|
+
void rb_thread_recycle_stack_release(VALUE *);
|
348
|
+
void rb_vm_change_state(void);
|
349
|
+
void rb_vm_inc_const_missing_count(void);
|
350
|
+
void rb_thread_mark(void *th);
|
351
|
+
const void **rb_vm_get_insns_address_table(void);
|
352
|
+
VALUE rb_sourcefilename(void);
|
353
|
+
|
354
|
+
/* vm_dump.c */
|
355
|
+
void rb_vm_bugreport(void);
|
356
|
+
void rb_print_backtrace(void);
|
357
|
+
|
358
|
+
/* vm_eval.c */
|
359
|
+
void Init_vm_eval(void);
|
360
|
+
VALUE rb_current_realfilepath(void);
|
361
|
+
VALUE rb_check_block_call(VALUE, ID, int, VALUE *, VALUE (*)(ANYARGS), VALUE);
|
362
|
+
typedef void rb_check_funcall_hook(int, VALUE, ID, int, VALUE *, VALUE);
|
363
|
+
VALUE rb_check_funcall_with_hook(VALUE recv, ID mid, int argc, VALUE *argv,
|
364
|
+
rb_check_funcall_hook *hook, VALUE arg);
|
365
|
+
|
366
|
+
/* vm_method.c */
|
367
|
+
void Init_eval_method(void);
|
368
|
+
int rb_method_defined_by(VALUE obj, ID mid, VALUE (*cfunc)(ANYARGS));
|
369
|
+
|
370
|
+
/* miniprelude.c, prelude.c */
|
371
|
+
void Init_prelude(void);
|
372
|
+
|
373
|
+
/* vm_backtrace.c */
|
374
|
+
void Init_vm_backtrace(void);
|
375
|
+
VALUE rb_vm_thread_backtrace(int argc, VALUE *argv, VALUE thval);
|
376
|
+
VALUE rb_vm_thread_backtrace_locations(int argc, VALUE *argv, VALUE thval);
|
377
|
+
|
378
|
+
VALUE rb_make_backtrace(void);
|
379
|
+
void rb_backtrace_print_as_bugreport(void);
|
380
|
+
int rb_backtrace_p(VALUE obj);
|
381
|
+
VALUE rb_backtrace_to_str_ary(VALUE obj);
|
382
|
+
VALUE rb_vm_backtrace_object();
|
383
|
+
|
384
|
+
RUBY_SYMBOL_EXPORT_BEGIN
|
385
|
+
const char *rb_objspace_data_type_name(VALUE obj);
|
386
|
+
|
387
|
+
/* Temporary. This API will be removed (renamed). */
|
388
|
+
VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd);
|
389
|
+
|
390
|
+
/* io.c */
|
391
|
+
void rb_maygvl_fd_fix_cloexec(int fd);
|
392
|
+
|
393
|
+
/* process.c */
|
394
|
+
int rb_exec_async_signal_safe(const struct rb_execarg *e, char *errmsg, size_t errmsg_buflen);
|
395
|
+
rb_pid_t rb_fork_async_signal_safe(int *status, int (*chfunc)(void*, char *, size_t), void *charg, VALUE fds, char *errmsg, size_t errmsg_buflen);
|
396
|
+
VALUE rb_execarg_new(int argc, VALUE *argv, int accept_shell);
|
397
|
+
struct rb_execarg *rb_execarg_get(VALUE execarg_obj); /* dangerous. needs GC guard. */
|
398
|
+
VALUE rb_execarg_init(int argc, VALUE *argv, int accept_shell, VALUE execarg_obj);
|
399
|
+
int rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val);
|
400
|
+
void rb_execarg_fixup(VALUE execarg_obj);
|
401
|
+
int rb_execarg_run_options(const struct rb_execarg *e, struct rb_execarg *s, char* errmsg, size_t errmsg_buflen);
|
402
|
+
VALUE rb_execarg_extract_options(VALUE execarg_obj, VALUE opthash);
|
403
|
+
void rb_execarg_setenv(VALUE execarg_obj, VALUE env);
|
404
|
+
|
405
|
+
/* variable.c */
|
406
|
+
void rb_gc_mark_global_tbl(void);
|
407
|
+
void rb_mark_generic_ivar(VALUE);
|
408
|
+
void rb_mark_generic_ivar_tbl(void);
|
409
|
+
|
410
|
+
RUBY_SYMBOL_EXPORT_END
|
411
|
+
|
412
|
+
#if defined(__cplusplus)
|
413
|
+
#if 0
|
414
|
+
{ /* satisfy cc-mode */
|
415
|
+
#endif
|
416
|
+
} /* extern "C" { */
|
417
|
+
#endif
|
418
|
+
|
419
|
+
#endif /* RUBY_INTERNAL_H */
|