Skip to content

Commit

Permalink
* eval.c (rb_load): allow interrupt during loaded program
Browse files Browse the repository at this point in the history
  evaluation.  [ruby-dev:21834]

* hash.c (rb_hash_fetch): always warn if default argument and a
  block are supplied at the same time. [ruby-dev:21842]

* hash.c (env_fetch): ditto.

* array.c (rb_ary_fetch): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4910 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Nov 6, 2003
1 parent 113423b commit 818d6a1
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 50 deletions.
12 changes: 12 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ Wed Nov 5 22:55:16 2003 Hidetoshi NAGAI <[email protected]>
* ext/tk/lib/tk.rb : add TkMenu#set_focus support Tcl/Tk's
tk_menuSetFocus

Wed Nov 5 17:33:45 2003 Yukihiro Matsumoto <[email protected]>

* eval.c (rb_load): allow interrupt during loaded program
evaluation. [ruby-dev:21834]

* hash.c (rb_hash_fetch): always warn if default argument and a
block are supplied at the same time. [ruby-dev:21842]

* hash.c (env_fetch): ditto.

* array.c (rb_ary_fetch): ditto.

Wed Nov 5 19:08:47 2003 Nobuyoshi Nakada <[email protected]>

* lib/optparse.rb (OptionParser::Switch::PlacedArgument::parse):
Expand Down
12 changes: 6 additions & 6 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,21 +595,21 @@ rb_ary_fetch(argc, argv, ary)
VALUE ary;
{
VALUE pos, ifnone;
long block_given;
long idx;

rb_scan_args(argc, argv, "11", &pos, &ifnone);
block_given = rb_block_given_p();
if (block_given && argc == 2) {
rb_warn("block supersedes default value argument");
}
idx = NUM2LONG(pos);

if (idx < 0) {
idx += RARRAY(ary)->len;
}
if (idx < 0 || RARRAY(ary)->len <= idx) {
if (rb_block_given_p()) {
if (argc > 1) {
rb_raise(rb_eArgError, "wrong number of arguments");
}
return rb_yield(pos);
}
if (block_given) return rb_yield(pos);
if (argc == 1) {
rb_raise(rb_eIndexError, "index %ld out of array", idx);
}
Expand Down
19 changes: 1 addition & 18 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -5836,11 +5836,11 @@ rb_load(fname, wrap)
ruby_in_eval--;
node = ruby_eval_tree;
rb_thread_critical = critical;
ALLOW_INTS;
if (ruby_nerrs == 0) {
eval_node(self, node);
}
}
ALLOW_INTS;
ruby_frame->last_func = last_func;
ruby_current_node = last_node;
ruby_sourcefile = 0;
Expand Down Expand Up @@ -9812,22 +9812,6 @@ rb_thread_trap_eval(cmd, sig)
VALUE cmd;
int sig;
{
#if 0
rb_thread_critical = 0;
if (!rb_thread_dead(curr_thread)) {
rb_thread_ready(curr_thread);
rb_trap_eval(cmd, sig);
return;
}
rb_thread_ready(main_thread);
if (THREAD_SAVE_CONTEXT(curr_thread)) {
return;
}
th_cmd = cmd;
th_sig = sig;
curr_thread = main_thread;
rb_thread_restore_context(curr_thread, RESTORE_TRAP);
#else
rb_thread_critical = 0;
if (!rb_thread_dead(curr_thread)) {
if (THREAD_SAVE_CONTEXT(curr_thread)) {
Expand All @@ -9838,7 +9822,6 @@ rb_thread_trap_eval(cmd, sig)
th_sig = sig;
curr_thread = main_thread;
rb_thread_restore_context(curr_thread, RESTORE_TRAP);
#endif
}

static VALUE
Expand Down
15 changes: 7 additions & 8 deletions ext/pty/expect_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
# by A. Ito
#
# This program reports the latest version of ruby interpreter
# by connecting to ftp server at netlab.co.jp.
# by connecting to ftp server at ruby-lang.org.
#
require 'pty'
require 'expect'

fnames = []
PTY.spawn("ftp ftp.netlab.co.jp") do
|r_f,w_f,pid|
PTY.spawn("ftp ftp.ruby-lang.org") do |r_f,w_f,pid|
w_f.sync = true

$expect_verbose = true
$expect_verbose = false

r_f.expect(/^Name.*: /) do
w_f.print "ftp\n"
Expand All @@ -31,14 +30,14 @@
r_f.expect('word:') do
w_f.print username+"@\n"
end
r_f.expect("ftp> ") do
w_f.print "cd pub/lang/ruby\n"
r_f.expect("> ") do
w_f.print "cd pub/ruby\n"
end
r_f.expect("ftp> ") do
r_f.expect("> ") do
w_f.print "dir\n"
end

r_f.expect("ftp> ") do |output|
r_f.expect("> ") do |output|
for x in output[0].split("\n")
if x =~ /(ruby.*\.tar\.gz)/ then
fnames.push $1
Expand Down
24 changes: 12 additions & 12 deletions hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,16 +300,16 @@ rb_hash_fetch(argc, argv, hash)
{
VALUE key, if_none;
VALUE val;
long block_given;

rb_scan_args(argc, argv, "11", &key, &if_none);

block_given = rb_block_given_p();
if (block_given && argc == 2) {
rb_warn("block supersedes default value argument");
}
if (!st_lookup(RHASH(hash)->tbl, key, &val)) {
if (rb_block_given_p()) {
if (argc > 1) {
rb_raise(rb_eArgError, "wrong number of arguments");
}
return rb_yield(key);
}
if (block_given) return rb_yield(key);
if (argc == 1) {
rb_raise(rb_eIndexError, "key not found");
}
Expand Down Expand Up @@ -1086,22 +1086,22 @@ env_fetch(argc, argv)
VALUE *argv;
{
VALUE key, if_none;
long block_given;
char *nam, *env;

rb_scan_args(argc, argv, "11", &key, &if_none);
block_given = rb_block_given_p();
if (block_given && argc == 2) {
rb_warn("block supersedes default value argument");
}
StringValue(key);
nam = RSTRING(key)->ptr;
if (strlen(nam) != RSTRING(key)->len) {
rb_raise(rb_eArgError, "bad environment variable name");
}
env = getenv(nam);
if (!env) {
if (rb_block_given_p()) {
if (argc > 1) {
rb_raise(rb_eArgError, "wrong number of arguments");
}
return rb_yield(key);
}
if (block_given) return rb_yield(key);
if (argc == 1) {
rb_raise(rb_eIndexError, "key not found");
}
Expand Down
16 changes: 10 additions & 6 deletions lib/cgi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ def read_multipart(boundary, content_length)
raise EOFError, "bad content body"
end

until -1 == content_length
loop do
head = nil
if 10240 < content_length
require "tempfile"
Expand Down Expand Up @@ -1020,14 +1020,13 @@ def read_multipart(boundary, content_length)
else
stdinput.read(content_length) or ''
end
buf += c
buf.concat(c)
content_length -= c.size

end

buf = buf.sub(/\A((?:.|\n)*?)(?:#{EOL})?#{boundary}(#{EOL}|--)/n) do
body.print $1
if "--" == $2 or EOL == $2
if "--" == $2
content_length = -1
end
""
Expand Down Expand Up @@ -1072,7 +1071,8 @@ def body.content_type
else
params[name] = [body]
end

break if buf.size == 0
break if content_length === -1
end

params
Expand Down Expand Up @@ -1115,6 +1115,7 @@ def initialize_query()
@multipart = true
@params = read_multipart(boundary, Integer(env_table['CONTENT_LENGTH']))
else
@multipart = false
@params = CGI::parse(
case env_table['REQUEST_METHOD']
when "GET", "HEAD"
Expand All @@ -1133,10 +1134,13 @@ def initialize_query()
end

@cookies = CGI::Cookie::parse((env_table['HTTP_COOKIE'] or env_table['COOKIE']))

end
private :initialize_query

def multipart?
@multipart
end

class Value < String # :nodoc:
def initialize(str, params)
@params = params
Expand Down
1 change: 1 addition & 0 deletions lib/drb/drb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,7 @@ def kill_sub_thread
end

def run
raise if Thread.critical
Thread.start do
begin
while true
Expand Down
4 changes: 4 additions & 0 deletions lib/test/unit/autorunner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def self.run(current_file=nil, default_dir=nil, &block)
require 'test/unit/ui/fox/testrunner'
Test::Unit::UI::Fox::TestRunner.run(r.suite)
end,
:tk => proc do |r|
require 'test/unit/ui/tk/testrunner'
Test::Unit::UI::Tk::TestRunner.run(r.suite)
end,
}

OUTPUT_LEVELS = {
Expand Down
Loading

0 comments on commit 818d6a1

Please sign in to comment.