utilrb 2.0.1 → 2.0.2.b1

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -8,6 +8,7 @@ bm/allocation.rb
8
8
  bm/speed.rb
9
9
  ext/utilrb/extconf.rb
10
10
  ext/utilrb/proc.c
11
+ ext/utilrb/readline.c
11
12
  ext/utilrb/ruby_allocator.hh
12
13
  ext/utilrb/utilrb.cc
13
14
  ext/utilrb/value_set.cc
data/Rakefile CHANGED
@@ -10,12 +10,21 @@ begin
10
10
  developer "Sylvain Joyeux", "sylvain.joyeux@m4x.org"
11
11
  self.readme_file = 'README.rd'
12
12
 
13
+
13
14
  extra_deps <<
14
15
  ['facets', '>= 2.4.0'] <<
15
16
  ['rake', '>= 0.9'] <<
16
- ["rake-compiler", "~> 0.8.0"] <<
17
+ ["hoe", ">= 3.7.1"] <<
17
18
  ["hoe-yard", ">= 0.1.2"]
18
19
 
20
+ if RUBY_VERSION < '2.0'
21
+ spec_extras[:required_ruby_version] = '~> 1.9'
22
+ extra_deps << ["rake-compiler", '~> 0.8.0']
23
+ else
24
+ spec_extras[:required_ruby_version] = '>= 2.0'
25
+ extra_deps << ["rake-compiler"]
26
+ end
27
+
19
28
  extra_dev_deps <<
20
29
  ['flexmock', '>= 0.8.6'] <<
21
30
  ['debugger-ruby_core_source', '>= 0']
@@ -36,7 +45,6 @@ begin
36
45
  ext.name = 'utilrb'
37
46
  ext.ext_dir = 'ext/utilrb'
38
47
  ext.lib_dir = 'lib/utilrb'
39
- ext.config_options << "-DRUBINIUS"
40
48
  ext.source_pattern ="*.{c,cc,cpp}"
41
49
  end
42
50
 
@@ -5,6 +5,7 @@ if try_link("int main() { }", "-module")
5
5
  $LDFLAGS += " -module"
6
6
  end
7
7
 
8
+ $LDFLAGS += " -lreadline"
8
9
  if RUBY_VERSION < "1.9"
9
10
  $CFLAGS += " -DRUBY_IS_18"
10
11
  puts "not building with core source"
@@ -12,10 +13,11 @@ if RUBY_VERSION < "1.9"
12
13
  else
13
14
  begin
14
15
  require 'debugger/ruby_core_source'
15
- $CFLAGS += " -DHAS_RUBY_SOURCE"
16
16
  hdrs = lambda { try_compile("#include <vm_core.h>") }
17
+ $CFLAGS += " -DHAS_RUBY_SOURCE"
17
18
  Debugger::RubyCoreSource.create_makefile_with_core(hdrs, "utilrb/utilrb")
18
- rescue LoadError
19
+ rescue Exception
20
+ $CFLAGS.gsub!(/ -DHAS_RUBY_SOURCE/, '')
19
21
  puts "not building with core source"
20
22
  create_makefile("utilrb/utilrb")
21
23
  end
@@ -0,0 +1,52 @@
1
+ #include <stdio.h>
2
+ #include <readline/readline.h>
3
+ #include <ruby.h>
4
+
5
+ static VALUE readline_save_prompt(VALUE self)
6
+ {
7
+ rl_save_prompt();
8
+ return Qnil;
9
+ }
10
+
11
+ static VALUE readline_message(VALUE self, VALUE msg)
12
+ {
13
+ rl_message("%s", StringValuePtr(msg));
14
+ rl_redisplay();
15
+ return Qnil;
16
+ }
17
+
18
+ static VALUE readline_print(VALUE self, VALUE msg)
19
+ {
20
+ int need_hack = (rl_readline_state & RL_STATE_READCMD) > 0;
21
+ char *saved_line;
22
+ int saved_point;
23
+ if (need_hack)
24
+ {
25
+ saved_point = rl_point;
26
+ saved_line = rl_copy_text(0, rl_end);
27
+ rl_save_prompt();
28
+ rl_replace_line("", 0);
29
+ rl_redisplay();
30
+ }
31
+
32
+ printf("%s", StringValuePtr(msg));
33
+
34
+ if (need_hack)
35
+ {
36
+ rl_restore_prompt();
37
+ rl_replace_line(saved_line, 0);
38
+ rl_point = saved_point;
39
+ rl_redisplay();
40
+ free(saved_line);
41
+ }
42
+ return Qnil;
43
+ }
44
+
45
+ extern void Init_utilrb_readline()
46
+ {
47
+ VALUE mReadline = rb_define_module("Readline");
48
+ rb_define_singleton_method(mReadline, "save_prompt", readline_save_prompt, 0);
49
+ rb_define_singleton_method(mReadline, "message", readline_message, 1);
50
+ rb_define_singleton_method(mReadline, "print", readline_print, 1);
51
+ }
52
+
data/ext/utilrb/utilrb.cc CHANGED
@@ -55,6 +55,7 @@ static VALUE kernel_crash(VALUE klass)
55
55
  extern "C" void Init_value_set();
56
56
  extern "C" void Init_weakref(VALUE mUtilrb);
57
57
  extern "C" void Init_proc();
58
+ extern "C" void Init_utilrb_readline();
58
59
 
59
60
  extern "C" void Init_utilrb()
60
61
  {
@@ -73,5 +74,6 @@ extern "C" void Init_utilrb()
73
74
  Init_proc();
74
75
 
75
76
  Init_value_set();
77
+ Init_utilrb_readline();
76
78
  }
77
79
 
data/lib/utilrb/common.rb CHANGED
@@ -3,9 +3,7 @@
3
3
  # the standard class extensions used by www.rock-robotics.org projects.
4
4
  module Utilrb
5
5
  unless defined? Utilrb::VERSION
6
- VERSION = "2.0.1"
7
- RUBY_IS_19 = (RUBY_VERSION >= "1.9.2")
8
- RUBY_IS_191 = (RUBY_VERSION >= "1.9") && (RUBY_VERSION < "1.9.2")
6
+ VERSION = "2.0.2.b1"
9
7
  end
10
8
 
11
9
  LIB_DIR = File.expand_path(File.dirname(__FILE__))
@@ -16,6 +14,8 @@ module Utilrb
16
14
  STDERR.puts "Utilrb: not loading the C extension"
17
15
  else
18
16
  begin
17
+ # We need readline
18
+ require 'readline'
19
19
  require 'utilrb/utilrb'
20
20
  UTILRB_EXT_MODE = true
21
21
  STDERR.puts "Utilrb: loaded C extension" if ENV['UTILRB_EXT_MODE']
@@ -231,6 +231,11 @@ module Utilrb
231
231
  thread_pool.sync(sync_key,*args,&block)
232
232
  end
233
233
 
234
+ # (see ThreadPool#sync_timeout)
235
+ def sync_timeout(sync_key,timeout,*args,&block)
236
+ thread_pool.sync_timeout(sync_key,timeout,*args,&block)
237
+ end
238
+
234
239
  def pretty_print(pp) # :nodoc:
235
240
  pp.text "EventLoop "
236
241
  end
@@ -160,10 +160,7 @@ module Kernel
160
160
  end
161
161
  end
162
162
 
163
- old_constants, new_constants = nil
164
- if !Utilrb::RUBY_IS_191
165
- old_constants = Kernel.constants
166
- end
163
+ old_constants, new_constants = Kernel.constants, nil
167
164
 
168
165
  sandbox = sandbox.new(proxied_object)
169
166
  sandbox.with_module(*context) do
@@ -184,7 +181,7 @@ module Kernel
184
181
 
185
182
  # Check if the user defined new constants by using class K and/or
186
183
  # mod Mod
187
- if !Utilrb::RUBY_IS_191 && !new_constants
184
+ if !new_constants
188
185
  new_constants = Kernel.constants
189
186
  end
190
187
 
@@ -1,19 +1,5 @@
1
1
  require 'utilrb/common'
2
2
  module Kernel
3
- if Utilrb::RUBY_IS_191
4
- def with_module(*consts, &blk)
5
- slf = self
6
-
7
- l = if !block_given? && consts.last.respond_to?(:to_str)
8
- eval_string = consts.pop
9
- lambda { slf.instance_eval(eval_string) }
10
- else
11
- lambda { slf.instance_eval(&blk) }
12
- end
13
-
14
- consts.inject(l) {|l, k| lambda { k.class_eval(&l) } }.call
15
- end
16
- else
17
3
  module WithModuleConstResolutionExtension
18
4
  def const_missing(const_name)
19
5
  if with_module_setup = Thread.current[:__with_module__]
@@ -48,6 +34,5 @@ module Kernel
48
34
  ensure
49
35
  Thread.current[:__with_module__].pop
50
36
  end
51
- end
52
37
  end
53
38
 
@@ -42,7 +42,7 @@ class Logger
42
42
  def self.Root(progname, base_level, &block)
43
43
  begin
44
44
  base_level = ENV['BASE_LOG_LEVEL'].upcase.to_sym if ENV['BASE_LOG_LEVEL']
45
- base_level = Logger.const_get( base_level ) if base_level.is_a? Symbol
45
+ base_level = ::Logger.const_get( base_level ) if base_level.is_a? Symbol
46
46
  rescue Exception => e
47
47
  raise ArgumentError, "Log level #{base_level} is not available in the ruby Logger"
48
48
  end
@@ -58,8 +58,8 @@ class Logger
58
58
  end
59
59
 
60
60
  Module.new do
61
- include Logger::Forward
62
- include Logger::HierarchyElement
61
+ include ::Logger::Forward
62
+ include ::Logger::HierarchyElement
63
63
 
64
64
  def has_own_logger?; true end
65
65
 
@@ -1,12 +1,6 @@
1
1
  require 'utilrb/common'
2
2
  class Module
3
- if Utilrb::RUBY_IS_191 || Utilrb::RUBY_IS_19
4
3
  def const_defined_here?(name)
5
4
  const_defined?(name, false)
6
5
  end
7
- else
8
- def const_defined_here?(name)
9
- const_defined?(name)
10
- end
11
- end
12
6
  end
@@ -1,17 +1,8 @@
1
1
  require 'utilrb/common'
2
2
  require 'utilrb/kernel/with_module'
3
3
  class Object
4
- if Utilrb::RUBY_IS_191
5
- def scoped_eval(type = :instance_eval, &b)
6
- modules = b.binding.eval "Module.nesting"
7
- with_module(*modules) do
8
- send(type, &b)
9
- end
10
- end
11
- else
12
- def scoped_eval(type = :instance_eval, &b)
13
- send(type, &b)
14
- end
4
+ def scoped_eval(type = :instance_eval, &b)
5
+ send(type, &b)
15
6
  end
16
7
  end
17
8
 
@@ -50,16 +50,16 @@ module Utilrb
50
50
  end
51
51
  @loaded_packages = Hash.new
52
52
 
53
- def self.load(path)
53
+ def self.load(path, preset_variables)
54
54
  pkg_name = File.basename(path, ".pc")
55
55
  pkg = Class.instance_method(:new).bind(PkgConfig).call(pkg_name)
56
- pkg.load(path)
56
+ pkg.load(path, preset_variables)
57
57
  pkg
58
58
  end
59
59
 
60
60
  # Returns the pkg-config object that matches the given name, and
61
61
  # optionally a version string
62
- def self.get(name, version_spec = nil)
62
+ def self.get(name, version_spec = nil, preset_variables = Hash.new)
63
63
  if !(candidates = loaded_packages[name])
64
64
  paths = find_all_package_files(name)
65
65
  if paths.empty?
@@ -68,7 +68,7 @@ module Utilrb
68
68
 
69
69
  candidates = loaded_packages[name] = Array.new
70
70
  paths.each do |p|
71
- candidates << PkgConfig.load(p)
71
+ candidates << PkgConfig.load(p, preset_variables)
72
72
  end
73
73
  end
74
74
 
@@ -84,8 +84,8 @@ module Utilrb
84
84
  # ...
85
85
  # @return [PkgConfig] the pkg-config description
86
86
  # @raise [NotFound] if the package is not found
87
- def self.new(name, version_spec = nil)
88
- get(name, version_spec)
87
+ def self.new(name, version_spec = nil, options = Hash.new)
88
+ get(name, version_spec, options)
89
89
  end
90
90
 
91
91
  # Returns the first package in +candidates+ that match the given version
@@ -206,11 +206,11 @@ module Utilrb
206
206
  SHELL_VARS = %w{Cflags Libs Libs.private}
207
207
 
208
208
  # Loads the information contained in +path+
209
- def load(path)
209
+ def load(path, preset_variables = Hash.new)
210
210
  @path = path
211
211
  @file = File.readlines(path).map(&:strip)
212
212
 
213
- raw_variables = Hash.new
213
+ raw_variables = preset_variables.dup
214
214
  raw_fields = Hash.new
215
215
 
216
216
  running_line = nil
data/lib/utilrb/spawn.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'fcntl'
2
+
1
3
  module Utilrb
2
4
  class SpawnFailed < RuntimeError; end
3
5
  def self.spawn(*cmdline)
@@ -1,6 +1,7 @@
1
1
  require 'thread'
2
2
  require 'set'
3
3
  require 'utilrb/kernel/options'
4
+ require 'timeout'
4
5
 
5
6
  module Utilrb
6
7
  # ThreadPool implementation inspired by
@@ -448,6 +449,36 @@ module Utilrb
448
449
  result
449
450
  end
450
451
 
452
+ # Same as sync but raises Timeout::Error if sync_key cannot be obtained after
453
+ # the given execution time.
454
+ #
455
+ # @param [Object] sync_key The sync key
456
+ # @param [Float] timeout The timeout
457
+ # @yield [*args] the code block block
458
+ # @return [Object] The result of the code block
459
+ def sync_timeout(sync_key,timeout,*args,&block)
460
+ raise ArgumentError,"no sync key" unless sync_key
461
+
462
+ Timeout::timeout(timeout) do
463
+ @mutex.synchronize do
464
+ while(!@sync_keys.add?(sync_key))
465
+ @cond_sync_key.wait @mutex #wait until someone has removed a key
466
+ end
467
+ end
468
+ end
469
+ begin
470
+ result = block.call(*args)
471
+ ensure
472
+ @mutex.synchronize do
473
+ @sync_keys.delete sync_key
474
+ end
475
+ @cond_sync_key.signal
476
+ @cond.signal # worker threads are just waiting for work no matter if it is
477
+ # because of a deletion of a sync_key or a task was added
478
+ end
479
+ result
480
+ end
481
+
451
482
  # Processes the given {Task} as soon as the next thread is available
452
483
  #
453
484
  # @param [Task] task The task.
data/test/test_kernel.rb CHANGED
@@ -180,32 +180,6 @@ class TC_Kernel < Test::Unit::TestCase
180
180
  end
181
181
  end
182
182
 
183
- if !Utilrb::RUBY_IS_19
184
- def test_eval_dsl_file_does_not_allow_class_definition
185
- obj = Class.new do
186
- def real_method
187
- @real_method_called = true
188
- end
189
- end.new
190
-
191
- Tempfile.open('test_eval_dsl_file') do |io|
192
- io.puts <<-EOD
193
- class NewClass
194
- end
195
- EOD
196
- io.flush
197
-
198
- begin
199
- eval_dsl_file(io.path, obj, [], false)
200
- flunk("NewClass has been defined")
201
- rescue NameError => e
202
- assert e.message =~ /NewClass/, e.message
203
- assert e.backtrace.first =~ /#{io.path}:1/, "wrong backtrace when checking constant definition detection: #{e.backtrace[0]}, expected #{io.path}:1"
204
- end
205
- end
206
- end
207
- end
208
-
209
183
  def test_dsl_exec
210
184
  obj = Class.new do
211
185
  def real_method_called?; !!@real_method_called end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utilrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
5
- prerelease:
4
+ version: 2.0.2.b1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sylvain Joyeux
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-18 00:00:00.000000000 Z
12
+ date: 2014-06-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: facets
@@ -44,21 +44,21 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0.9'
46
46
  - !ruby/object:Gem::Dependency
47
- name: rake-compiler
47
+ name: hoe
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ~>
51
+ - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
- version: 0.8.0
53
+ version: 3.7.1
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ~>
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
- version: 0.8.0
61
+ version: 3.7.1
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: hoe-yard
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -76,29 +76,29 @@ dependencies:
76
76
  - !ruby/object:Gem::Version
77
77
  version: 0.1.2
78
78
  - !ruby/object:Gem::Dependency
79
- name: flexmock
79
+ name: rake-compiler
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
- - - ! '>='
83
+ - - ~>
84
84
  - !ruby/object:Gem::Version
85
- version: 0.8.6
86
- type: :development
85
+ version: 0.8.0
86
+ type: :runtime
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
- - - ! '>='
91
+ - - ~>
92
92
  - !ruby/object:Gem::Version
93
- version: 0.8.6
93
+ version: 0.8.0
94
94
  - !ruby/object:Gem::Dependency
95
- name: debugger-ruby_core_source
95
+ name: flexmock
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
99
  - - ! '>='
100
100
  - !ruby/object:Gem::Version
101
- version: '0'
101
+ version: 0.8.6
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,23 +106,23 @@ dependencies:
106
106
  requirements:
107
107
  - - ! '>='
108
108
  - !ruby/object:Gem::Version
109
- version: '0'
109
+ version: 0.8.6
110
110
  - !ruby/object:Gem::Dependency
111
- name: hoe
111
+ name: debugger-ruby_core_source
112
112
  requirement: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements:
115
- - - ~>
115
+ - - ! '>='
116
116
  - !ruby/object:Gem::Version
117
- version: '3.7'
117
+ version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  none: false
122
122
  requirements:
123
- - - ~>
123
+ - - ! '>='
124
124
  - !ruby/object:Gem::Version
125
- version: '3.7'
125
+ version: '0'
126
126
  description: ! 'Utilrb is yet another Ruby toolkit, in the spirit of facets. It includes
127
127
  all
128
128
 
@@ -147,6 +147,7 @@ files:
147
147
  - bm/speed.rb
148
148
  - ext/utilrb/extconf.rb
149
149
  - ext/utilrb/proc.c
150
+ - ext/utilrb/readline.c
150
151
  - ext/utilrb/ruby_allocator.hh
151
152
  - ext/utilrb/utilrb.cc
152
153
  - ext/utilrb/value_set.cc
@@ -274,41 +275,41 @@ require_paths:
274
275
  required_ruby_version: !ruby/object:Gem::Requirement
275
276
  none: false
276
277
  requirements:
277
- - - ! '>='
278
+ - - ~>
278
279
  - !ruby/object:Gem::Version
279
- version: '0'
280
+ version: '1.9'
280
281
  required_rubygems_version: !ruby/object:Gem::Requirement
281
282
  none: false
282
283
  requirements:
283
- - - ! '>='
284
+ - - ! '>'
284
285
  - !ruby/object:Gem::Version
285
- version: '0'
286
+ version: 1.3.1
286
287
  requirements: []
287
- rubyforge_project: utilrb
288
+ rubyforge_project:
288
289
  rubygems_version: 1.8.23
289
290
  signing_key:
290
291
  specification_version: 3
291
292
  summary: Utilrb is yet another Ruby toolkit, in the spirit of facets
292
293
  test_files:
294
+ - test/test_objectstats.rb
295
+ - test/test_gc.rb
296
+ - test/test_array.rb
297
+ - test/test_enumerable.rb
293
298
  - test/test_weakref.rb
299
+ - test/test_config.rb
300
+ - test/test_event_loop.rb
294
301
  - test/test_unbound_method.rb
295
- - test/test_enumerable.rb
296
- - test/test_exception.rb
297
- - test/test_objectstats.rb
302
+ - test/test_set.rb
298
303
  - test/test_models.rb
299
- - test/test_dir.rb
300
304
  - test/test_time.rb
301
- - test/test_misc.rb
302
- - test/test_set.rb
303
- - test/test_config.rb
304
- - test/test_logger.rb
305
+ - test/test_kernel.rb
305
306
  - test/test_proc.rb
306
- - test/test_hash.rb
307
- - test/test_array.rb
308
307
  - test/test_object.rb
309
308
  - test/test_thread_pool.rb
309
+ - test/test_dir.rb
310
+ - test/test_hash.rb
311
+ - test/test_exception.rb
312
+ - test/test_logger.rb
313
+ - test/test_misc.rb
310
314
  - test/test_module.rb
311
- - test/test_event_loop.rb
312
- - test/test_kernel.rb
313
315
  - test/test_pkgconfig.rb
314
- - test/test_gc.rb