[#7872] Nonblocking socket-connect — "Francis Cianfrocca" <garbagecat10@...>

All, I needed a nonblocking socket connect for my asynchronous-event

18 messages 2006/05/14
[#7873] Re: Nonblocking socket-connect — Tanaka Akira <akr@...17n.org> 2006/05/14

In article <3a94cf510605140559l7baa0205le341dac4f47d424b@mail.gmail.com>,

[#7874] Re: Nonblocking socket-connect — "Francis Cianfrocca" <garbagecat10@...> 2006/05/15

How about introducing the method Socket#set_nonblocking, or alternatively

[#7875] Re: Nonblocking socket-connect — Yukihiro Matsumoto <matz@...> 2006/05/15

Hi,

[#7876] Re: Nonblocking socket-connect — "Francis Cianfrocca" <garbagecat10@...> 2006/05/15

Well, it's ok then. I'm comfortable adding in the nonblocking

[#7877] Re: Nonblocking socket-connect — Yukihiro Matsumoto <matz@...> 2006/05/15

Hi,

[PATCH] SCRIPT_LINES__ issue when loading a file more than once

From: Mauricio Fernandez <mfp@...>
Date: 2006-05-19 09:46:05 UTC
List: ruby-core #7909
SCRIPT_LINES__ is an obscure feature very few people care about, but I happen
to use it in the rcov code coverage tool to obtain the source code of the
program in execution[1], and ran into the following issue.

When a file ("the same" or with changing contents) is loaded more than once,
its contents get appended to SCRIPT_LINES__[filename] repeatedly:

$ cat tst.rb 
SCRIPT_LINES__ = {}
4.times{ load "foo.rb" }
p SCRIPT_LINES__["./foo.rb"]
$ cat foo.rb 
a = 1
$ ruby19 tst.rb 
["a = 1\n", "a = 1\n", "a = 1\n", "a = 1\n"]
$ ruby tst.rb 
["a = 1\n", "a = 1\n", "a = 1\n", "a = 1\n"]

I think it would make more sense to make it work in such way that the above
example returns either

(a)
[["a = 1\n"], ["a = 1\n"], ["a = 1\n"], ["a = 1\n"]]

that is, turning SCRIPT_LINES__[fname] into an array to which ruby appends
arrays holding the contents of the files with that name as it parses them, or

(b)
["a = 1\n"]

i.e. discarding all the previous data and keeping the contents from the last
parse.

I believe (a) could be implemented in HEAD; the ruby_1_8 branch could get (a)
or, if it's deemed too radical a change, (b).

Here's the patch for (a):


diff -p -u -r1.435 parse.y
--- parse.y     13 May 2006 08:55:39 -0000      1.435
+++ parse.y     19 May 2006 09:25:00 -0000
@@ -4556,15 +4556,19 @@ yycompile(VALUE vparser, const char *f, 
     Data_Get_Struct(vparser, struct parser_params, parser);
     if (!compile_for_eval && rb_safe_level() == 0 &&
        rb_const_defined(rb_cObject, rb_intern("SCRIPT_LINES__"))) {
-       VALUE hash, fname;
+       VALUE hash, fname, arr;
 
        hash = rb_const_get(rb_cObject, rb_intern("SCRIPT_LINES__"));
        if (TYPE(hash) == T_HASH) {
            fname = rb_str_new2(f);
-           ruby_debug_lines = rb_hash_aref(hash, fname);
-           if (NIL_P(ruby_debug_lines)) {
+           arr = rb_hash_aref(hash, fname);
+           if (NIL_P(arr)) {
+               arr = rb_ary_new();
+               rb_hash_aset(hash, fname, arr);
+           }
+           if(TYPE(arr) == T_ARRAY) {
                ruby_debug_lines = rb_ary_new();
-               rb_hash_aset(hash, fname, ruby_debug_lines);
+               rb_ary_push(arr, ruby_debug_lines);
            }
        }
        if (line > 1) {


After applying:

$ ruby19 -v tst.rb 
ruby 1.9.0 (2006-05-18) [i686-linux]
[["a = 1\n"], ["a = 1\n"], ["a = 1\n"], ["a = 1\n"]]


The patch for (b) is attached to this message.

After applying:

$ ruby -v tst.rb 
ruby 1.8.4 (2006-05-18) [i686-linux]
["a = 1\n"]


[1] I need that to generate meaningful reports; it's AFAIK the most robust
way to get the source code in pure Ruby.

-- 
Mauricio Fernandez  -   http://eigenclass.org   -  singular Ruby

Attachments (1)

diff -p -u -r1.307.2.34 parse.y
--- parse.y     19 Apr 2006 04:57:55 -0000      1.307.2.34
+++ parse.y     19 May 2006 09:30:49 -0000
@@ -2583,11 +2583,8 @@ yycompile(f, line)
        hash = rb_const_get(rb_cObject, rb_intern("SCRIPT_LINES__"));
        if (TYPE(hash) == T_HASH) {
            fname = rb_str_new2(f);
-           ruby_debug_lines = rb_hash_aref(hash, fname);
-           if (NIL_P(ruby_debug_lines)) {
-               ruby_debug_lines = rb_ary_new();
-               rb_hash_aset(hash, fname, ruby_debug_lines);
-           }
+           ruby_debug_lines = rb_ary_new();
+           rb_hash_aset(hash, fname, ruby_debug_lines);
        }
        if (line > 1) {
            VALUE str = rb_str_new(0,0);

In This Thread

Prev Next