rucy 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
data/src/value.cpp.erb CHANGED
@@ -5,6 +5,7 @@
5
5
  #include <assert.h>
6
6
  #include "rucy/function.h"
7
7
  #include "rucy/exception.h"
8
+ #include "rucy/debug.h"
8
9
 
9
10
 
10
11
  namespace Rucy
@@ -101,6 +102,12 @@ namespace Rucy
101
102
  return RB_FLOAT_TYPE_P(val) || is_kind_of(rb_cFloat);
102
103
  }
103
104
 
105
+ bool
106
+ Value::is_num () const
107
+ {
108
+ return is_i() || is_f();
109
+ }
110
+
104
111
  bool
105
112
  Value::is_s () const
106
113
  {
@@ -325,13 +332,13 @@ namespace Rucy
325
332
  }
326
333
 
327
334
  Value&
328
- Value::operator [] (int i)
335
+ Value::operator [] (size_t i)
329
336
  {
330
337
  return as_array()[i];
331
338
  }
332
339
 
333
340
  const Value&
334
- Value::operator [] (int i) const
341
+ Value::operator [] (size_t i) const
335
342
  {
336
343
  return const_cast<Value*>(this)->operator[](i);
337
344
  }
@@ -339,7 +346,7 @@ namespace Rucy
339
346
  const char*
340
347
  Value::c_str () const
341
348
  {
342
- return as<const char*>(true);
349
+ return as_s(true);
343
350
  }
344
351
 
345
352
  static int
@@ -367,6 +374,12 @@ namespace Rucy
367
374
  return get_length(*this, size);
368
375
  }
369
376
 
377
+ bool
378
+ Value::empty () const
379
+ {
380
+ return size() <= 0;
381
+ }
382
+
370
383
 
371
384
  GlobalValue::GlobalValue ()
372
385
  {
@@ -433,7 +446,7 @@ namespace Rucy
433
446
  init(gc_);
434
447
  }
435
448
 
436
- GlobalValue::GlobalValue (const GlobalValue& obj, bool gc_)
449
+ GlobalValue::GlobalValue (const This& obj, bool gc_)
437
450
  : Super(obj)
438
451
  {
439
452
  init(gc_);
@@ -443,50 +456,41 @@ namespace Rucy
443
456
  GlobalValue::operator = (const Value& v)
444
457
  {
445
458
  Super::operator=(v);
446
- update_guard();
459
+ return *this;
460
+ }
461
+
462
+ GlobalValue&
463
+ GlobalValue::operator = (const This& obj)
464
+ {
465
+ Super::operator=(obj);
447
466
  return *this;
448
467
  }
449
468
 
450
469
  GlobalValue::~GlobalValue ()
451
470
  {
452
- while (gc_guarded) gc(true);
471
+ if (gc_disable_count > 0)
472
+ rb_gc_unregister_address(&val);
453
473
  }
454
474
 
455
475
  void
456
- GlobalValue::gc (bool enable) const
476
+ GlobalValue::enable_gc () const
457
477
  {
458
- gc_disable_count += enable ? -1 : +1;
459
- update_guard();
478
+ if (--gc_disable_count == 0)
479
+ rb_gc_unregister_address(const_cast<RubyValue*>(&val));
460
480
  }
461
481
 
462
482
  void
463
- GlobalValue::init (bool gc_)
483
+ GlobalValue::disable_gc () const
464
484
  {
465
- gc_disable_count = 0;
466
- gc_guarded = false;
467
- if (!gc_) gc(false);
485
+ if (++gc_disable_count == 1)
486
+ rb_gc_register_address(const_cast<RubyValue*>(&val));
468
487
  }
469
488
 
470
489
  void
471
- GlobalValue::update_guard () const
490
+ GlobalValue::init (bool gc_)
472
491
  {
473
- assert(gc_disable_count >= 0);
474
-
475
- if (IMMEDIATE_P(val))
476
- {
477
- if (gc_guarded) rb_gc_unregister_address((RubyValue*) &val);
478
- gc_guarded = false;
479
- }
480
- else if (gc_disable_count > 0)
481
- {
482
- if (!gc_guarded) rb_gc_register_address((RubyValue*) &val);
483
- gc_guarded = true;
484
- }
485
- else
486
- {
487
- if (gc_guarded) rb_gc_unregister_address((RubyValue*) &val);
488
- gc_guarded = false;
489
- }
492
+ gc_disable_count = 0;
493
+ if (!gc_) disable_gc();
490
494
  }
491
495
 
492
496
 
@@ -591,16 +595,7 @@ namespace Rucy
591
595
  {
592
596
  return Value(size, array);
593
597
  }
594
-
595
- Value
596
- value (void* ptr)
597
- {
598
- if (ptr)
599
- argument_error(__FILE__, __LINE__, "Rucy::value(void*) can take only (void*) NULL.");
600
-
601
- return nil();
602
- }
603
- % (1..10).each do |n|
598
+ % (1..16).each do |n|
604
599
 
605
600
  Value
606
601
  array (<%= params(n, ', ') {|i| "Value v#{i}"} %>)
data/test/test_class.rb CHANGED
@@ -14,10 +14,6 @@ class Temp < Rucy::Tester::Sub
14
14
  "Temp::name_overridable"
15
15
  end
16
16
 
17
- def name_overridable_faster ()
18
- "Temp::name_overridable_faster"
19
- end
20
-
21
17
  end# Temp
22
18
 
23
19
 
@@ -94,7 +90,7 @@ class TestClass < Test::Unit::TestCase
94
90
  assert_equal "Base::name", base_raw.call_name
95
91
  assert_equal "Sub::name", sub .call_name
96
92
  assert_equal "Sub::name", sub_raw .call_name
97
- assert_equal "Sub::name", temp .call_name # returns "Sub" not "Temp"!
93
+ assert_equal "Sub::name", temp .call_name# "Sub" instead of "Temp"!
98
94
  end
99
95
 
100
96
  def test_call_name_overridable ()
@@ -105,37 +101,9 @@ class TestClass < Test::Unit::TestCase
105
101
  assert_equal "Temp::name_overridable", temp .call_name_overridable
106
102
  end
107
103
 
108
- class X < Sub; end
109
-
110
- def test_is_overridden ()
111
- m = :name_overridable_faster
112
- def is_overridden (o) o.is_name_overridable_faster_overridden; end
113
-
114
- assert_equal true, is_overridden(temp)
115
-
116
- o = X.new
117
- assert_equal false, is_overridden(o)
118
- def o.name_overridable_faster () end
119
- assert_equal true, is_overridden(o)
120
-
121
- o = X.new
122
- assert_equal false, is_overridden(o)
123
- eval "class X; def #{m}; end; end"
124
- assert_equal true, is_overridden(o)
125
- eval "class X; remove_method :#{m}; end"
126
- assert_equal false, is_overridden(o)
127
-
128
- o = X.new
129
- assert_equal false, is_overridden(o)
130
- X.send(:define_method, m) {}
131
- assert_equal true, is_overridden(o)
132
- X.send :remove_method, m
133
- assert_equal false, is_overridden(o)
134
- end
135
-
136
104
  def test_gc ()
137
105
  def simple_objs (name, n = 10) ([nil] * n).map {SimpleObj.new name} end
138
- def gc (n = 10) n.times {GC.start}; print '' end
106
+ def gc () GC.start end
139
107
  rt = Rucy::Tester
140
108
 
141
109
  gc
metadata CHANGED
@@ -1,71 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rucy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
- - snori
7
+ - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-04 00:00:00.000000000 Z
11
+ date: 2019-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: xot
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - ">="
17
+ - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: '0'
19
+ version: '0.1'
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: gemcutter
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
24
+ - - "~>"
53
25
  - !ruby/object:Gem::Version
54
- version: '0'
26
+ version: '0.1'
55
27
  description: This library helps you to develop Ruby Extension by C++.
56
- email: snori@xord.org
28
+ email: xordog@gmail.com
57
29
  executables:
58
30
  - rucy2rdoc
59
31
  extensions:
60
32
  - Rakefile
61
33
  extra_rdoc_files:
34
+ - ".doc/ext/rucy/struct.cpp"
35
+ - ".doc/ext/rucy/tester.cpp"
36
+ - ".doc/ext/rucy/exception.cpp"
37
+ - ".doc/ext/rucy/function.cpp"
38
+ - ".doc/ext/rucy/value.cpp"
39
+ - ".doc/ext/rucy/class.cpp"
40
+ files:
62
41
  - ".doc/ext/rucy/class.cpp"
63
42
  - ".doc/ext/rucy/exception.cpp"
64
43
  - ".doc/ext/rucy/function.cpp"
65
44
  - ".doc/ext/rucy/struct.cpp"
66
45
  - ".doc/ext/rucy/tester.cpp"
67
46
  - ".doc/ext/rucy/value.cpp"
68
- files:
69
47
  - README.md
70
48
  - Rakefile
71
49
  - VERSION
@@ -81,6 +59,7 @@ files:
81
59
  - ext/rucy/value.cpp
82
60
  - include/rucy.h
83
61
  - include/rucy/class.h
62
+ - include/rucy/debug.h
84
63
  - include/rucy/exception.h
85
64
  - include/rucy/extension.h.erb
86
65
  - include/rucy/function.h.erb
@@ -91,6 +70,7 @@ files:
91
70
  - include/rucy/value.h.erb
92
71
  - lib/rucy.rb
93
72
  - lib/rucy/module.rb
73
+ - lib/rucy/rake.rb
94
74
  - rucy.gemspec
95
75
  - src/class.cpp
96
76
  - src/exception.cpp
@@ -107,12 +87,6 @@ files:
107
87
  - test/test_function.rb
108
88
  - test/test_struct.rb
109
89
  - test/test_value.rb
110
- - ".doc/ext/rucy/class.cpp"
111
- - ".doc/ext/rucy/exception.cpp"
112
- - ".doc/ext/rucy/function.cpp"
113
- - ".doc/ext/rucy/struct.cpp"
114
- - ".doc/ext/rucy/tester.cpp"
115
- - ".doc/ext/rucy/value.cpp"
116
90
  homepage: https://github.com/xord/rucy
117
91
  licenses: []
118
92
  metadata: {}
@@ -122,17 +96,16 @@ require_paths:
122
96
  - lib
123
97
  required_ruby_version: !ruby/object:Gem::Requirement
124
98
  requirements:
125
- - - ">="
99
+ - - "~>"
126
100
  - !ruby/object:Gem::Version
127
- version: 1.9.0
101
+ version: '2'
128
102
  required_rubygems_version: !ruby/object:Gem::Requirement
129
103
  requirements:
130
104
  - - ">="
131
105
  - !ruby/object:Gem::Version
132
106
  version: '0'
133
107
  requirements: []
134
- rubyforge_project:
135
- rubygems_version: 2.0.3
108
+ rubygems_version: 3.0.3
136
109
  signing_key:
137
110
  specification_version: 4
138
111
  summary: A Ruby C++ Extension Helper Library.