utilrb 1.6.4 → 1.6.5

Sign up to get free protection for your applications and to get access to all the features.
data/ext/extconf.rb CHANGED
@@ -5,7 +5,13 @@ if RUBY_VERSION >= "1.9"
5
5
  $CFLAGS += " -DRUBY_IS_19"
6
6
  end
7
7
 
8
- $LDFLAGS += " -module"
8
+ if ENV['RUBY_SOURCE_DIR']
9
+ $CFLAGS += " -DHAS_RUBY_SOURCE -I#{ENV['RUBY_SOURCE_DIR']}"
10
+ end
11
+
12
+ if try_link("int main() { }", "-module")
13
+ $LDFLAGS += " -module"
14
+ end
9
15
  create_makefile("utilrb_ext")
10
16
 
11
17
  ## WORKAROUND a problem with mkmf.rb
data/ext/utilrb_ext.cc CHANGED
@@ -109,9 +109,13 @@ static VALUE kernel_is_immediate(VALUE klass, VALUE object)
109
109
  { return IMMEDIATE_P(object) ? Qtrue : Qfalse; }
110
110
  #endif
111
111
 
112
+ static VALUE kernel_crash(VALUE klass)
113
+ { *((int*)0) = 10; }
114
+
112
115
  extern "C" void Init_value_set();
113
116
  extern "C" void Init_swap();
114
117
  extern "C" void Init_weakref(VALUE mUtilrb);
118
+ extern "C" void Init_proc();
115
119
 
116
120
  extern "C" void Init_utilrb_ext()
117
121
  {
@@ -126,12 +130,15 @@ extern "C" void Init_utilrb_ext()
126
130
  rb_define_method(rb_cProc, "line", RUBY_METHOD_FUNC(proc_line), 0);
127
131
  #endif
128
132
 
133
+ rb_define_singleton_method(rb_mKernel, "crash!", RUBY_METHOD_FUNC(kernel_crash), 0);
129
134
  rb_define_singleton_method(rb_mKernel, "immediate?", RUBY_METHOD_FUNC(kernel_is_immediate), 1);
130
135
 
131
136
  Init_swap();
132
137
  Init_weakref(mUtilrb);
133
138
  #endif
134
139
 
140
+ Init_proc();
141
+
135
142
  Init_value_set();
136
143
  }
137
144
 
data/ext/weakref.cc CHANGED
@@ -119,7 +119,7 @@ static VALUE weakref_get(VALUE self)
119
119
 
120
120
  static VALUE refcount(VALUE mod, VALUE obj)
121
121
  {
122
- if (0 == obj & FIXNUM_FLAG)
122
+ if (0 == (obj & FIXNUM_FLAG))
123
123
  obj = rb_obj_id(obj);
124
124
 
125
125
  RefFromObjID::const_iterator it = from_obj_id.find(obj);
data/lib/utilrb/common.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Utilrb
2
2
  unless defined? Utilrb::VERSION
3
- VERSION = "1.6.4"
3
+ VERSION = "1.6.5"
4
4
  RUBY_IS_19 = (RUBY_VERSION >= "1.9.2")
5
5
  RUBY_IS_191 = (RUBY_VERSION >= "1.9") && (RUBY_VERSION < "1.9.2")
6
6
  end
@@ -2,6 +2,12 @@ module Kernel
2
2
  # Raises if +object+ can accept calls with exactly +arity+ arguments.
3
3
  # object should respond to #arity
4
4
  def check_arity(object, arity)
5
+ if object.respond_to?(:lambda?) # For ruby 1.9 compatibility on blocks without arguments
6
+ if !object.lambda? && object.arity == 0
7
+ return
8
+ end
9
+ end
10
+
5
11
  unless object.arity == arity || (object.arity < 0 && object.arity > - arity - 2)
6
12
  raise ArgumentError, "#{object} does not accept to be called with #{arity} argument(s)", caller(2)
7
13
  end
@@ -1,8 +1,9 @@
1
1
  module Kernel
2
2
  # Require all .rb files in the +filename+ directory
3
- def require_dir(filename)
3
+ def require_dir(filename, exclude = nil)
4
4
  dirname = filename.gsub(/.rb$/, '')
5
5
  Dir.new(dirname).each do |file|
6
+ next if exclude && exclude === file
6
7
  if file =~ /\.rb$/
7
8
  require File.join(dirname, file)
8
9
  end
@@ -10,7 +10,7 @@ class Logger
10
10
  #
11
11
  module Forward
12
12
  [ :debug, :info, :warn, :error, :fatal, :unknown ].each do |level|
13
- class_eval <<-EOF
13
+ class_eval <<-EOF, __FILE__, __LINE__+1
14
14
  def #{level}(*args, &proc); logger.#{level}(*args, &proc) end
15
15
  EOF
16
16
  end
@@ -26,7 +26,7 @@ class Module
26
26
  class_eval do
27
27
  attribute(attr_name, &init_block)
28
28
  end
29
- class_eval <<-EOF
29
+ class_eval <<-EOF, __FILE__, __LINE__+1
30
30
  def each_#{name}(key = nil, &iterator)
31
31
  return unless #{attr_name}
32
32
  if key
@@ -11,7 +11,7 @@ class Module
11
11
  remove_method attr_name
12
12
 
13
13
  if writable
14
- class_eval "def #{attr_name}=(value); @#{attr_name} = !!value end"
14
+ class_eval "def #{attr_name}=(value); @#{attr_name} = !!value end", __FILE__, __LINE__+1
15
15
  end
16
16
  end
17
17
  end
@@ -21,7 +21,7 @@ class Module
21
21
  def cached_enum(enum_name, name, with_arg)
22
22
  include CachedValuesSupport
23
23
  if with_arg
24
- class_eval <<-EOD
24
+ class_eval <<-EOD, __FILE__, __LINE__+1
25
25
  def enum_#{name}(arg)
26
26
  @enum_#{name} ||= Hash.new
27
27
  cached_variables << :@enum_#{name}
@@ -29,7 +29,7 @@ class Module
29
29
  end
30
30
  EOD
31
31
  else
32
- class_eval <<-EOD
32
+ class_eval <<-EOD, __FILE__, __LINE__+1
33
33
  def enum_#{name}
34
34
  cached_variables << :@enum_#{name}
35
35
  @enum_#{name} ||= enum_for(:each_#{enum_name})
@@ -19,7 +19,7 @@ class Module
19
19
  # +block+ is +nil+ if no block is given during the method call
20
20
  #
21
21
  def define_method_with_block(name, &mdef)
22
- class_eval <<-EOD
22
+ class_eval <<-EOD, __FILE__, __LINE__+1
23
23
  def #{name}(*args, &block)
24
24
  dmwb_#{name}_user_definition(block, *args)
25
25
  end
@@ -1,6 +1,7 @@
1
1
  class Module
2
2
  # call-seq:
3
3
  # dsl_attribute(name)
4
+ # dsl_attribute(name,name2,name3)
4
5
  # dsl_attribute(name) { |value| ... }
5
6
  #
6
7
  # This defines a +name+ instance method on the given class which accepts zero or one argument
@@ -33,7 +34,11 @@ class Module
33
34
  # end
34
35
  # end
35
36
  #
36
- def dsl_attribute(name, &filter_block)
37
+ def dsl_attribute(*names, &filter_block)
38
+ if names.size > 1 && filter_block
39
+ raise ArgumentError, "multiple names as argument are only supported if no block is given"
40
+ end
41
+ names.each do |name|
37
42
  class_eval do
38
43
  if filter_block
39
44
  define_method("__dsl_attribute__#{name}__filter__", &filter_block)
@@ -44,7 +49,7 @@ class Module
44
49
  instance_variable_get("@#{name}")
45
50
  elsif filter_block
46
51
  if filter_block.arity >= 0 && value.size != filter_block.arity
47
- raise ArgumentError, "too much arguments. Got #{value.size}, expected #{filter_block.arity}"
52
+ raise ArgumentError, "too many arguments. Got #{value.size}, expected #{filter_block.arity}"
48
53
  end
49
54
 
50
55
  filtered_value = send("__dsl_attribute__#{name}__filter__", *value)
@@ -60,6 +65,7 @@ class Module
60
65
  end
61
66
  end
62
67
  end
68
+ end
63
69
  end
64
70
  end
65
71
 
@@ -11,13 +11,13 @@ class Module
11
11
 
12
12
  options[:enum_with] ||= :each
13
13
 
14
- class_eval <<-EOF
14
+ class_eval <<-EOF, __FILE__, __LINE__+1
15
15
  def all_#{name}; each_#{name}.to_a end
16
16
  def self_#{name}; @#{attribute_name} end
17
17
  EOF
18
18
 
19
19
  if options[:map]
20
- class_eval <<-EOF
20
+ class_eval <<-EOF, __FILE__, __LINE__+1
21
21
  def each_#{name}(key = nil, uniq = true)
22
22
  if !block_given?
23
23
  return enum_for(:each_#{name}, key, uniq)
@@ -70,7 +70,7 @@ class Module
70
70
  end
71
71
  EOF
72
72
  else
73
- class_eval <<-EOF
73
+ class_eval <<-EOF, __FILE__, __LINE__+1
74
74
  def each_#{name}
75
75
  if !block_given?
76
76
  return enum_for(:each_#{name})
@@ -26,7 +26,7 @@ Utilrb.unless_ext do
26
26
  end
27
27
  end
28
28
 
29
- class_eval <<-EOD
29
+ class_eval <<-EOD, __FILE__, __LINE__+1
30
30
  def #{name}
31
31
  if defined? @#{name} then @#{name}
32
32
  else @#{name} = #{name}_defval
@@ -55,9 +55,9 @@ Utilrb.if_ext do
55
55
  end
56
56
  end
57
57
 
58
- class_eval <<-EOD
58
+ class_eval <<-EOD, __FILE__, __LINE__+1
59
59
  def #{name}
60
- if defined? @#{name} then @#{name}
60
+ if instance_variable_defined?(:@#{name}) then @#{name}
61
61
  else @#{name} = #{name}_defval
62
62
  end
63
63
  end
@@ -304,7 +304,7 @@ module Utilrb
304
304
  end
305
305
 
306
306
  def self.define_pkgconfig_action(action) # :nodoc:
307
- class_eval <<-EOD
307
+ class_eval <<-EOD, __FILE__, __LINE__+1
308
308
  def pkgconfig_#{action.gsub(/-/, '_')}(static = false)
309
309
  if static
310
310
  `pkg-config --#{action} --static \#{name}`.strip
@@ -30,7 +30,7 @@ Utilrb.require_ext("ValueSet") do
30
30
  end
31
31
 
32
32
  def hash
33
- result = ValueSet.hash / size
33
+ result = ValueSet.hash
34
34
  for obj in self
35
35
  result = result ^ obj.hash
36
36
  end
data/lib/utilrb/yard.rb CHANGED
@@ -6,7 +6,8 @@ module Utilrb
6
6
  handles method_call(:inherited_enumerable)
7
7
  namespace_only
8
8
 
9
- def self.process(handler, name, attr_name, is_map)
9
+ def self.process(handler, name, attr_name, is_map, key_name = nil, return_type = nil)
10
+ key_type, value_type = nil
10
11
  handler.send(:push_state, :scope => :class) do
11
12
  namespace = handler.send(:namespace)
12
13
  scope = handler.send(:scope)
@@ -82,6 +83,12 @@ module Utilrb
82
83
  object.docstring.replace("Enumerates all objects registered in #{name}\n@return []\n@yield [element]\n@yieldparam [#{value_type}] element")
83
84
  end
84
85
  end
86
+
87
+ if is_map
88
+ return key_type, value_type
89
+ else
90
+ return value_type
91
+ end
85
92
  end
86
93
 
87
94
  def process
data/lib/utilrb.rb CHANGED
@@ -1,2 +1,2 @@
1
1
  require 'utilrb/kernel/require'
2
- require_dir(__FILE__)
2
+ require_dir(__FILE__, /yard|doc|rake/)
data/test/test_kernel.rb CHANGED
@@ -30,7 +30,7 @@ class TC_Kernel < Test::Unit::TestCase
30
30
  assert( !new_options.has_key?(:b) )
31
31
  end
32
32
 
33
- def test_arity
33
+ def test_arity_of_methods
34
34
  object = Class.new do
35
35
  def arity_1(a); end
36
36
  def arity_any(*a); end
@@ -49,6 +49,42 @@ class TC_Kernel < Test::Unit::TestCase
49
49
  assert_nothing_raised { check_arity(object.method(:arity_1_more), 2) }
50
50
  end
51
51
 
52
+ def test_arity_of_blocks
53
+ check_arity(Proc.new { bla }, 0)
54
+ check_arity(Proc.new { bla }, 1)
55
+ check_arity(Proc.new { bla }, 2)
56
+
57
+ assert_raises(ArgumentError) { check_arity(Proc.new { |arg| bla }, 0) }
58
+ check_arity(Proc.new { |arg| bla }, 1)
59
+ assert_raises(ArgumentError) { check_arity(Proc.new { |arg| bla }, 2) }
60
+
61
+ assert_raises(ArgumentError) { check_arity(Proc.new { |arg, *args| bla }, 0) }
62
+ check_arity(Proc.new { |arg, *args| bla }, 1)
63
+ check_arity(Proc.new { |arg, *args| bla }, 2)
64
+
65
+ check_arity(Proc.new { |*args| bla }, 0)
66
+ check_arity(Proc.new { |*args| bla }, 1)
67
+ check_arity(Proc.new { |*args| bla }, 2)
68
+ end
69
+
70
+ def test_arity_of_lambdas
71
+ check_arity(lambda { bla }, 0)
72
+ assert_raises(ArgumentError) { check_arity(lambda { bla }, 1) }
73
+ assert_raises(ArgumentError) { check_arity(lambda { bla }, 2) }
74
+
75
+ assert_raises(ArgumentError) { check_arity(lambda { |arg| bla }, 0) }
76
+ check_arity(lambda { |arg| bla }, 1)
77
+ assert_raises(ArgumentError) { check_arity(lambda { |arg| bla }, 2) }
78
+
79
+ assert_raises(ArgumentError) { check_arity(lambda { |arg, *args| bla }, 0) }
80
+ check_arity(lambda { |arg, *args| bla }, 1)
81
+ check_arity(lambda { |arg, *args| bla }, 2)
82
+
83
+ check_arity(lambda { |*args| bla }, 0)
84
+ check_arity(lambda { |*args| bla }, 1)
85
+ check_arity(lambda { |*args| bla }, 2)
86
+ end
87
+
52
88
  def test_with_module
53
89
  obj = Object.new
54
90
  c0, c1 = nil
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utilrb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 6
9
- - 4
10
- version: 1.6.4
9
+ - 5
10
+ version: 1.6.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sylvain Joyeux
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-04-19 00:00:00 Z
18
+ date: 2012-06-07 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: facets
@@ -48,34 +48,34 @@ dependencies:
48
48
  type: :runtime
49
49
  version_requirements: *id002
50
50
  - !ruby/object:Gem::Dependency
51
- name: flexmock
51
+ name: rdoc
52
52
  prerelease: false
53
53
  requirement: &id003 !ruby/object:Gem::Requirement
54
54
  none: false
55
55
  requirements:
56
- - - ">="
56
+ - - ~>
57
57
  - !ruby/object:Gem::Version
58
- hash: 51
58
+ hash: 19
59
59
  segments:
60
- - 0
61
- - 8
62
- - 6
63
- version: 0.8.6
60
+ - 3
61
+ - 10
62
+ version: "3.10"
64
63
  type: :development
65
64
  version_requirements: *id003
66
65
  - !ruby/object:Gem::Dependency
67
- name: rdoc
66
+ name: flexmock
68
67
  prerelease: false
69
68
  requirement: &id004 !ruby/object:Gem::Requirement
70
69
  none: false
71
70
  requirements:
72
- - - ~>
71
+ - - ">="
73
72
  - !ruby/object:Gem::Version
74
- hash: 19
73
+ hash: 51
75
74
  segments:
76
- - 3
77
- - 10
78
- version: "3.10"
75
+ - 0
76
+ - 8
77
+ - 6
78
+ version: 0.8.6
79
79
  type: :development
80
80
  version_requirements: *id004
81
81
  - !ruby/object:Gem::Dependency
@@ -86,11 +86,11 @@ dependencies:
86
86
  requirements:
87
87
  - - ~>
88
88
  - !ruby/object:Gem::Version
89
- hash: 35
89
+ hash: 7
90
90
  segments:
91
- - 2
92
- - 16
93
- version: "2.16"
91
+ - 3
92
+ - 0
93
+ version: "3.0"
94
94
  type: :development
95
95
  version_requirements: *id005
96
96
  description: |-
@@ -255,27 +255,27 @@ required_rubygems_version: !ruby/object:Gem::Requirement
255
255
  requirements: []
256
256
 
257
257
  rubyforge_project: utilrb
258
- rubygems_version: 1.7.2
258
+ rubygems_version: 1.8.15
259
259
  signing_key:
260
260
  specification_version: 3
261
261
  summary: Yet another Ruby toolkit
262
262
  test_files:
263
- - test/test_time.rb
264
- - test/test_weakref.rb
265
- - test/test_config.rb
266
- - test/test_array.rb
267
263
  - test/test_kernel.rb
268
- - test/test_module.rb
269
- - test/test_proc.rb
270
- - test/test_set.rb
264
+ - test/test_unbound_method.rb
271
265
  - test/test_hash.rb
272
- - test/test_pkgconfig.rb
266
+ - test/test_exception.rb
267
+ - test/test_config.rb
268
+ - test/test_time.rb
269
+ - test/test_logger.rb
270
+ - test/test_module.rb
273
271
  - test/test_objectstats.rb
274
- - test/test_unbound_method.rb
272
+ - test/test_enumerable.rb
275
273
  - test/test_gc.rb
276
- - test/test_dir.rb
277
274
  - test/test_misc.rb
278
- - test/test_enumerable.rb
279
- - test/test_exception.rb
280
- - test/test_logger.rb
281
275
  - test/test_object.rb
276
+ - test/test_array.rb
277
+ - test/test_dir.rb
278
+ - test/test_weakref.rb
279
+ - test/test_proc.rb
280
+ - test/test_set.rb
281
+ - test/test_pkgconfig.rb