rtype-native 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a5d14f3ae8593646d772106c340e8d41b594c4f
4
- data.tar.gz: ec5849c75b6a42d8c30dfe41bf2eb48a0fe54bb5
3
+ metadata.gz: 7628a99152b791414bf7a6651d3fec5229718c2c
4
+ data.tar.gz: 1fe92f38dc1995a88342ce8d9a80c7dca9de5a6d
5
5
  SHA512:
6
- metadata.gz: fddff4c61beacc969280f481972b339231b20dcc617f6c7f941d76b7b4c92d2baa70b2b20d5357ea0ff653abe2c6961e002dac0b2b8321be2a7efc3f31a70cc5
7
- data.tar.gz: 23f5bc94ee53094bdeef9ea2f98073086bc9ac08a1f63d4d27b77e152acfdc267fc92b130d97a9da722fc560f1a854008e67ff61e9133311597af922123aa19e
6
+ metadata.gz: 9ecde7d0cebc9796d8e29845f341fe8f913d1e1cd3a424741c7b8c35ab16083a305a5b7c695e3a70d5da9606f552825e7a6cc110bed4553f6c20746a6d958e74
7
+ data.tar.gz: c06b26503bd67776e2592d2bc956ae9a83879b04d81bee393312433f7c66d7219f2c469cc9230cb572053e744f086fb06a63dbf43516a12095da734d4829595c
data/README.md CHANGED
@@ -31,7 +31,10 @@ Test::invert(state: 0)
31
31
 
32
32
  ## Requirements
33
33
  - Ruby >= 2.1
34
- - MRI or RBX if native extension is used. Rtype itself without it is pure-ruby gem, therefore you can use Rtype in JRuby, etc.
34
+ - MRI or RBX
35
+ - If C native extension is used, otherwise it is not required
36
+ - JRuby
37
+ - If Java extension is used, otherwise it is not required
35
38
 
36
39
  ## Features
37
40
  - Provide type checking for argument and return
@@ -49,12 +52,29 @@ require 'rtype'
49
52
  ```
50
53
 
51
54
  ### Native extension
52
- Rtype itself is pure-ruby gem. but you can make it more faster by native extension.
55
+ Rtype itself is pure-ruby gem. but you can make it more faster by using native extension.
53
56
 
54
- Just run `gem install rtype-native` or add `gem 'rtype-native'` to your `Gemfile`, then Rtype use it.
55
- (Do not `require 'rtype-native'`)
57
+ #### Native extension for MRI, RBX
58
+ Just run
59
+ ```ruby
60
+ gem install rtype-native
61
+ ```
62
+ or add to your `Gemfile`:
63
+ ```ruby
64
+ gem 'rtype-native'
65
+ ```
66
+ then, Rtype use it. (Do not `require 'rtype-native'`)
56
67
 
57
- It is only for MRI or RBX. JRuby extension not supported yet.
68
+ #### Java extension for JRuby
69
+ Just run
70
+ ```ruby
71
+ gem install rtype-java
72
+ ```
73
+ or add to your `Gemfile`:
74
+ ```ruby
75
+ gem 'rtype-java'
76
+ ```
77
+ then, Rtype use it. (Do not `require 'rtype-java'`)
58
78
 
59
79
  ## Usage
60
80
 
@@ -370,68 +390,70 @@ Result of `rake benchmark` ([source](https://github.com/sputnikgugja/rtype/tree/
370
390
 
371
391
  ### MRI
372
392
  ```
393
+ Rtype with C native extension
373
394
  Ruby version: 2.1.7
374
395
  Ruby engine: ruby
375
396
  Ruby description: ruby 2.1.7p400 (2015-08-18 revision 51632) [x64-mingw32]
376
- Rtype version: 0.2.0
397
+ Rtype version: 0.3.0
377
398
  Rubype version: 0.3.1
378
399
  Sig version: 1.0.1
379
400
  Contracts version: 0.13.0
380
401
  Typecheck version: 0.1.2
381
402
  Warming up --------------------------------------
382
- pure 85.600k i/100ms
383
- rtype 25.735k i/100ms
384
- rubype 20.922k i/100ms
385
- sig 8.960k i/100ms
386
- contracts 4.659k i/100ms
387
- typecheck 1.102k i/100ms
403
+ pure 85.328k i/100ms
404
+ rtype 25.665k i/100ms
405
+ rubype 21.414k i/100ms
406
+ sig 8.921k i/100ms
407
+ contracts 4.638k i/100ms
408
+ typecheck 1.110k i/100ms
388
409
  Calculating -------------------------------------
389
- pure 3.273M (± 2.4%) i/s - 16.435M
390
- rtype 340.376k1.9%) i/s - 1.724M
391
- rubype 268.253k4.2%) i/s - 1.339M
392
- sig 100.050k (± 1.9%) i/s - 501.760k
393
- contracts 50.027k2.0%) i/s - 251.586k
394
- typecheck 11.317k (± 1.4%) i/s - 57.304k
410
+ pure 3.282M (± 2.7%) i/s - 16.468M
411
+ rtype 339.065k2.6%) i/s - 1.720M
412
+ rubype 266.893k5.9%) i/s - 1.349M
413
+ sig 99.952k2.1%) i/s - 499.576k
414
+ contracts 49.693k1.5%) i/s - 250.452k
415
+ typecheck 11.356k (± 1.6%) i/s - 57.720k
395
416
 
396
417
  Comparison:
397
- pure: 3272978.0 i/s
398
- rtype: 340375.8 i/s - 9.62x slower
399
- rubype: 268252.5 i/s - 12.20x slower
400
- sig: 100050.1 i/s - 32.71x slower
401
- contracts: 50026.9 i/s - 65.42x slower
402
- typecheck: 11317.1 i/s - 289.21x slower
418
+ pure: 3282431.9 i/s
419
+ rtype: 339064.9 i/s - 9.68x slower
420
+ rubype: 266892.9 i/s - 12.30x slower
421
+ sig: 99952.2 i/s - 32.84x slower
422
+ contracts: 49693.0 i/s - 66.05x slower
423
+ typecheck: 11355.9 i/s - 289.05x slower
403
424
  ```
404
425
 
405
426
  ### JRuby
406
427
  Without Rubype that doesn't support JRuby
407
428
 
408
429
  ```
430
+ Rtype with Java extension
409
431
  Ruby version: 2.2.3
410
432
  Ruby engine: jruby
411
433
  Ruby description: jruby 9.0.5.0 (2.2.3) 2016-01-26 7bee00d Java HotSpot(TM) 64-Bit Server VM 25.60-b23 on 1.8.0_60-b27 +jit [Windows 10-amd64]
412
- Rtype version: 0.2.0
434
+ Rtype version: 0.3.0
413
435
  Sig version: 1.0.1
414
436
  Contracts version: 0.13.0
415
437
  Typecheck version: 0.1.2
416
438
  Warming up --------------------------------------
417
- pure 29.127k i/100ms
418
- rtype 4.566k i/100ms
419
- sig 4.162k i/100ms
420
- contracts 776.000 i/100ms
421
- typecheck 981.000 i/100ms
439
+ pure 9.994k i/100ms
440
+ rtype 6.181k i/100ms
441
+ sig 4.041k i/100ms
442
+ contracts 951.000 i/100ms
443
+ typecheck 970.000 i/100ms
422
444
  Calculating -------------------------------------
423
- pure 6.705M (±12.0%) i/s - 32.826M
424
- rtype 89.262k (± 3.3%) i/s - 447.468k
425
- sig 74.070k (± 2.0%) i/s - 370.418k
426
- contracts 25.399k (± 2.9%) i/s - 127.264k
427
- typecheck 12.461k (± 9.0%) i/s - 61.803k
445
+ pure 7.128M (?±35.6%) i/s - 30.831M
446
+ rtype 121.556k ( 6.2%) i/s - 605.738k
447
+ sig 72.187k ( 6.4%) i/s - 359.649k
448
+ contracts 24.984k ( 3.9%) i/s - 125.532k
449
+ typecheck 12.041k ( 9.5%) i/s - 60.140k
428
450
 
429
451
  Comparison:
430
- pure: 6705166.5 i/s
431
- rtype: 89262.5 i/s - 75.12x slower
432
- sig: 74070.1 i/s - 90.52x slower
433
- contracts: 25398.9 i/s - 263.99x slower
434
- typecheck: 12460.7 i/s - 538.10x slower
452
+ pure: 7128373.0 i/s
453
+ rtype: 121555.8 i/s - 58.64x slower
454
+ sig: 72186.8 i/s - 98.75x slower
455
+ contracts: 24984.5 i/s - 285.31x slower
456
+ typecheck: 12041.0 i/s - 592.01x slower
435
457
  ```
436
458
 
437
459
  ## Rubype, Sig
File without changes
@@ -37,10 +37,10 @@ rb_rtype_valid(VALUE self, VALUE expected, VALUE value) {
37
37
  case T_FALSE:
38
38
  return !RTEST(value) ? Qtrue : Qfalse;
39
39
  default:
40
- if(CLASS_OF(expected) == rb_cRange) {
40
+ if(rb_obj_is_kind_of(expected, rb_cRange)) {
41
41
  return rb_funcall(expected, rb_intern("include?"), 1, value);
42
42
  }
43
- else if(CLASS_OF(expected) == rb_cProc) {
43
+ else if(rb_obj_is_kind_of(expected, rb_cProc)) {
44
44
  return RTEST(rb_funcall(expected, rb_intern("call"), 1, value)) ? Qtrue : Qfalse;
45
45
  }
46
46
  else if( RTEST(rb_obj_is_kind_of(expected, rb_cRtypeBehaviorBase)) ) {
@@ -95,13 +95,13 @@ rb_rtype_assert_return_type(VALUE self, VALUE expected, VALUE result) {
95
95
  if(expected == Qnil) {
96
96
  if(result != Qnil) {
97
97
  VALUE msg = rb_funcall(rb_mRtype, rb_intern("type_error_message"), 2, expected, result);
98
- rb_raise(rb_eRtypeReturnTypeError, "for return:\n %s", StringValueCStr(msg));
98
+ rb_raise(rb_eRtypeReturnTypeError, "for return:\n%s", StringValueCStr(msg));
99
99
  }
100
100
  }
101
101
  else {
102
102
  if( !RTEST(rb_rtype_valid(self, expected, result)) ) {
103
103
  VALUE msg = rb_funcall(rb_mRtype, rb_intern("type_error_message"), 2, expected, result);
104
- rb_raise(rb_eRtypeReturnTypeError, "for return:\n %s", StringValueCStr(msg));
104
+ rb_raise(rb_eRtypeReturnTypeError, "for return:\n%s", StringValueCStr(msg));
105
105
  }
106
106
  }
107
107
  return Qnil;
@@ -115,8 +115,8 @@ void Init_rtype_native(void) {
115
115
  rb_eRtypeTypeSignatureError = rb_define_class_under(rb_mRtype, "TypeSignatureError", rb_eArgError);
116
116
  rb_eRtypeReturnTypeError = rb_define_class_under(rb_mRtype, "ReturnTypeError", rb_eStandardError);
117
117
 
118
- rb_define_singleton_method(rb_mRtype, "valid?", rb_rtype_valid, 2);
119
- rb_define_singleton_method(rb_mRtype, "assert_arguments_type", rb_rtype_assert_arguments_type, 2);
120
- rb_define_singleton_method(rb_mRtype, "assert_arguments_type_with_keywords", rb_rtype_assert_arguments_type_with_keywords, 4);
121
- rb_define_singleton_method(rb_mRtype, "assert_return_type", rb_rtype_assert_return_type, 2);
118
+ rb_define_method(rb_mRtype, "valid?", rb_rtype_valid, 2);
119
+ rb_define_method(rb_mRtype, "assert_arguments_type", rb_rtype_assert_arguments_type, 2);
120
+ rb_define_method(rb_mRtype, "assert_arguments_type_with_keywords", rb_rtype_assert_arguments_type_with_keywords, 4);
121
+ rb_define_method(rb_mRtype, "assert_return_type", rb_rtype_assert_return_type, 2);
122
122
  }
File without changes
data/spec/rtype_spec.rb CHANGED
@@ -236,29 +236,35 @@ describe Rtype do
236
236
  describe 'true' do
237
237
  it "is right" do
238
238
  klass.send :rtype, :return_arg, [true] => Any
239
+ instance.return_arg(true)
239
240
  instance.return_arg(123)
240
241
  end
241
242
  it "is wrong args" do
242
243
  klass.send :rtype, :return_arg, [true] => Any
244
+ expect {instance.return_arg(false)}.to raise_error Rtype::ArgumentTypeError
243
245
  expect {instance.return_arg(nil)}.to raise_error Rtype::ArgumentTypeError
244
246
  end
245
247
  it "is wrong result" do
246
- klass.send :rtype, :return_nil, [Any] => true
247
- expect {instance.return_nil(123)}.to raise_error Rtype::ReturnTypeError
248
+ klass.send :rtype, :return_arg, [Any] => true
249
+ expect {instance.return_arg(false)}.to raise_error Rtype::ReturnTypeError
250
+ expect {instance.return_arg(nil)}.to raise_error Rtype::ReturnTypeError
248
251
  end
249
252
  end
250
253
 
251
254
  describe 'false' do
252
255
  it "is right" do
253
256
  klass.send :rtype, :return_arg, [false] => Any
257
+ instance.return_arg(false)
254
258
  instance.return_arg(nil)
255
259
  end
256
260
  it "is wrong args" do
257
261
  klass.send :rtype, :return_arg, [false] => Any
262
+ expect {instance.return_arg(true)}.to raise_error Rtype::ArgumentTypeError
258
263
  expect {instance.return_arg(123)}.to raise_error Rtype::ArgumentTypeError
259
264
  end
260
265
  it "is wrong result" do
261
266
  klass.send :rtype, :return_arg, [Any] => false
267
+ expect {instance.return_arg(true)}.to raise_error Rtype::ReturnTypeError
262
268
  expect {instance.return_arg(123)}.to raise_error Rtype::ReturnTypeError
263
269
  end
264
270
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rtype-native
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sputnik Gugja
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-26 00:00:00.000000000 Z
11
+ date: 2016-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rtype
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.0
19
+ version: 0.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.0
26
+ version: 0.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -71,7 +71,7 @@ email:
71
71
  - sputnikgugja@gmail.com
72
72
  executables: []
73
73
  extensions:
74
- - ext/rtype/extconf.rb
74
+ - ext/rtype/c/extconf.rb
75
75
  extra_rdoc_files: []
76
76
  files:
77
77
  - Gemfile
@@ -79,9 +79,9 @@ files:
79
79
  - README.md
80
80
  - Rakefile
81
81
  - benchmark/benchmark.rb
82
- - ext/rtype/extconf.rb
83
- - ext/rtype/rtype.c
84
- - ext/rtype/rtype.h
82
+ - ext/rtype/c/extconf.rb
83
+ - ext/rtype/c/rtype.c
84
+ - ext/rtype/c/rtype.h
85
85
  - spec/rtype_spec.rb
86
86
  - spec/spec_helper.rb
87
87
  homepage: https://github.com/sputnikgugja/rtype