[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Standard Library Warnings

James Gray

7/11/2005 5:03:00 PM

I keep running into some warning message from standard libraries. I
always use warnings so they are driving me crazy.

With the latest release of HighLine, I actually had to build a work-
around that captures, disables, and later resets the warning level
when calling into readline, because it's my opinion that the warning
breaks auto-completion (the warning appears in the middle of your
completed word).

Given that, I thought I would post some warning firing examples in
the attempt to get some Ruby core hacker to feel sorry for me and
apply a patch or two. I looked at patching set.rb myself but it
seems that there is a hack in there to work around this warning and I
couldn't figure out why it doesn't work.

Here are my examples:

$ ruby -v
ruby 1.8.2 (2004-12-25) [powerpc-darwin7.7.0]
$ cat set_example.rb
require "set"

SortedSet.new
$ ruby -w set_example.rb
(eval):2: warning: method redefined; discarding old initialize
$ cat prog_ruby_example_723.rb
# Sample code from Programing Ruby, page 723
require 'readline'
include Readline

require 'abbrev'

COMMANDS = %w{ exit inc dec }

ABBREV = COMMANDS.abbrev

Readline.completion_proc = proc do |string|
ABBREV[string]
end

value = 0

loop do

cmd = readline("wibble [#{value}]: ", true)

break if cmd.nil?

case cmd.strip
when "exit"
break
when "inc"
value += 1
when "dec"
value -= 1
else
puts "Invalid command #{cmd}"
end

end
$ ruby -w prog_ruby_example_723.rb
wibble [0]: dprog_ruby_example_723.rb:19: warning: instance variable
completion_case_fold not initialized
ec

In that last example, I pushed d then tab to trigger the warning.

Let me know if I can answer any questions and thanks in advance for
taking pity on a warnings-allergic coder.

James Edward Gray II



8 Answers

Craig Moran

7/11/2005 7:11:00 PM

0

On 7/11/05, James Edward Gray II <james@grayproductions.net> wrote:
> I keep running into some warning message from standard libraries. I
> always use warnings so they are driving me crazy.
>
> With the latest release of HighLine, I actually had to build a work-
> around that captures, disables, and later resets the warning level
> when calling into readline, because it's my opinion that the warning
> breaks auto-completion (the warning appears in the middle of your
> completed word).
>
> Given that, I thought I would post some warning firing examples in
> the attempt to get some Ruby core hacker to feel sorry for me and
> apply a patch or two. I looked at patching set.rb myself but it
> seems that there is a hack in there to work around this warning and I
> couldn't figure out why it doesn't work.
>
> Here are my examples:
>
> $ ruby -v
> ruby 1.8.2 (2004-12-25) [powerpc-darwin7.7.0]
> $ cat set_example.rb
> require "set"
>
> SortedSet.new
> $ ruby -w set_example.rb
> (eval):2: warning: method redefined; discarding old initialize
> $ cat prog_ruby_example_723.rb
> # Sample code from Programing Ruby, page 723
> require 'readline'
> include Readline
>
> require 'abbrev'
>
> COMMANDS = %w{ exit inc dec }
>
> ABBREV = COMMANDS.abbrev
>
> Readline.completion_proc = proc do |string|
> ABBREV[string]
> end
>
> value = 0
>
> loop do
>
> cmd = readline("wibble [#{value}]: ", true)
>
> break if cmd.nil?
>
> case cmd.strip
> when "exit"
> break
> when "inc"
> value += 1
> when "dec"
> value -= 1
> else
> puts "Invalid command #{cmd}"
> end
>
> end
> $ ruby -w prog_ruby_example_723.rb
> wibble [0]: dprog_ruby_example_723.rb:19: warning: instance variable
> completion_case_fold not initialized
> ec
>
> In that last example, I pushed d then tab to trigger the warning.
>
> Let me know if I can answer any questions and thanks in advance for
> taking pity on a warnings-allergic coder.
>
> James Edward Gray II
>
>
>


Craig Moran

7/11/2005 7:26:00 PM

0

Apologies for the blank messages. Google's HTML email freaked out on me and
sent these by mistake. Sorry again for the blank "noise."
Craig

On 7/11/05, Craig Moran <craig.m.moran.ruby@gmail.com> wrote:
>
> On 7/11/05, James Edward Gray II <james@grayproductions.net> wrote:
> > I keep running into some warning message from standard libraries. I
> > always use warnings so they are driving me crazy.
> >
> > With the latest release of HighLine, I actually had to build a work-
> > around that captures, disables, and later resets the warning level
> > when calling into readline, because it's my opinion that the warning
> > breaks auto-completion (the warning appears in the middle of your
> > completed word).
> >
> > Given that, I thought I would post some warning firing examples in
> > the attempt to get some Ruby core hacker to feel sorry for me and
> > apply a patch or two. I looked at patching set.rb myself but it
> > seems that there is a hack in there to work around this warning and I
> > couldn't figure out why it doesn't work.
> >
> > Here are my examples:
> >
> > $ ruby -v
> > ruby 1.8.2 (2004-12-25) [powerpc-darwin7.7.0]
> > $ cat set_example.rb
> > require "set"
> >
> > SortedSet.new
> > $ ruby -w set_example.rb
> > (eval):2: warning: method redefined; discarding old initialize
> > $ cat prog_ruby_example_723.rb
> > # Sample code from Programing Ruby, page 723
> > require 'readline'
> > include Readline
> >
> > require 'abbrev'
> >
> > COMMANDS = %w{ exit inc dec }
> >
> > ABBREV = COMMANDS.abbrev
> >
> > Readline.completion_proc = proc do |string|
> > ABBREV[string]
> > end
> >
> > value = 0
> >
> > loop do
> >
> > cmd = readline("wibble [#{value}]: ", true)
> >
> > break if cmd.nil?
> >
> > case cmd.strip
> > when "exit"
> > break
> > when "inc"
> > value += 1
> > when "dec"
> > value -= 1
> > else
> > puts "Invalid command #{cmd}"
> > end
> >
> > end
> > $ ruby -w prog_ruby_example_723.rb
> > wibble [0]: dprog_ruby_example_723.rb:19: warning: instance variable
> > completion_case_fold not initialized
> > ec
> >
> > In that last example, I pushed d then tab to trigger the warning.
> >
> > Let me know if I can answer any questions and thanks in advance for
> > taking pity on a warnings-allergic coder.
> >
> > James Edward Gray II
> >
> >
> >
>
>

daz

7/12/2005 2:28:00 PM

0


James Edward Gray II wrote:
> I keep running into some warning message from standard libraries. I
> always use warnings so they are driving me crazy.
>
> [...] I looked at patching set.rb myself but it seems that
> there is a hack in there to work around this warning and I
> couldn't figure out why it doesn't work.
>

Are you referring to this as the hack (in Class SortedSet) ?
def setup # :nodoc:
(:nodoc: is an RDoc instruction)


> $ ruby -w set_example.rb
> (eval):2: warning: method redefined; discarding old initialize

Trying #remove_method before redefine gains a different warning:-/

lib/ruby/1.8/set.rb:457: warning: removing `initialize' may cause serious problem

Only option seems to be temporary "$VERBOSE = false".
Just 4 lines to add:


--- set_ORIG.rb 2004-12-18 04:07:28.000000000 +-0100
+++ set.rb 2005-07-12 15:21:48.000000000 +-0100
@@ -440,19 +440,22 @@
def setup # :nodoc:
@@setup and return

begin
require 'rbtree'

+ $VERBOSE, verbose = false, $VERBOSE
module_eval %{
def initialize(*args, &block)
@hash = RBTree.new
super
end
}
+ $VERBOSE = verbose
rescue LoadError
+ $VERBOSE, verbose = false, $VERBOSE
module_eval %{
def initialize(*args, &block)
@keys = nil
super
end

@@ -497,12 +500,13 @@

def to_a
(@keys = @hash.keys).sort! unless @keys
@keys
end
}
+ $VERBOSE = verbose
end

@@setup = true
end
end



> $ ruby -w prog_ruby_example_723.rb
> wibble [0]: dprog_ruby_example_723.rb:19: warning: instance variable
> completion_case_fold not initialized
> ec
>

This and others were fixed around 2005-01-16 - too late for you :-(
> ruby 1.8.2 (2004-12-25) [powerpc-darwin7.7.0]

If I add this line before the loop in your script, it goes away:

Readline.completion_case_fold = false


>
> James Edward Gray II
>

daz



James Gray

7/12/2005 3:01:00 PM

0

On Jul 12, 2005, at 9:30 AM, daz wrote:

> Are you referring to this as the hack (in Class SortedSet) ?
> def setup # :nodoc:
> (:nodoc: is an RDoc instruction)

No, I was referring to the one just a few lines down:

module_eval {
# a hack to shut up warning
alias old_init initialize
remove_method :old_init
}


>> $ ruby -w set_example.rb
>> (eval):2: warning: method redefined; discarding old initialize
>>
>
> Trying #remove_method before redefine gains a different warning:-/
>
> lib/ruby/1.8/set.rb:457: warning: removing `initialize' may cause
> serious problem
>
> Only option seems to be temporary "$VERBOSE = false".
> Just 4 lines to add:
>
>
> --- set_ORIG.rb 2004-12-18 04:07:28.000000000 +-0100
> +++ set.rb 2005-07-12 15:21:48.000000000 +-0100
> @@ -440,19 +440,22 @@
> def setup # :nodoc:
> @@setup and return
>
> begin
> require 'rbtree'
>
> + $VERBOSE, verbose = false, $VERBOSE
> module_eval %{
> def initialize(*args, &block)
> @hash = RBTree.new
> super
> end
> }
> + $VERBOSE = verbose
> rescue LoadError
> + $VERBOSE, verbose = false, $VERBOSE
> module_eval %{
> def initialize(*args, &block)
> @keys = nil
> super
> end
>
> @@ -497,12 +500,13 @@
>
> def to_a
> (@keys = @hash.keys).sort! unless @keys
> @keys
> end
> }
> + $VERBOSE = verbose
> end
>
> @@setup = true
> end
> end

I hope someone will apply that to Ruby. Thanks for looking into it!

James Edward Gray II



daz

7/12/2005 4:46:00 PM

0


James Edward Gray II wrote:
> On Jul 12, 2005, at 9:30 AM, daz wrote:
>
> > Are you referring to this as the hack (in Class SortedSet) ?
> > def setup # :nodoc:
>
> No, I was referring to the one just a few lines down:
>
> module_eval {
> # a hack to shut up warning
> alias old_init initialize
> remove_method :old_init
> }


Ah. That's not in my freeride build.


>
> James Edward Gray II
>

OK

daz


James Gray

7/12/2005 6:33:00 PM

0

On Jul 12, 2005, at 11:50 AM, daz wrote:

>
> James Edward Gray II wrote:
>
>> On Jul 12, 2005, at 9:30 AM, daz wrote:
>>
>>
>>> Are you referring to this as the hack (in Class SortedSet) ?
>>> def setup # :nodoc:
>>>
>>
>> No, I was referring to the one just a few lines down:
>>
>> module_eval {
>> # a hack to shut up warning
>> alias old_init initialize
>> remove_method :old_init
>> }
>>
>
>
> Ah. That's not in my freeride build.

Thank you. The was the hint I needed.

The above hack is missing in the current versions of Ruby. I found
it in my old CVS checkout, so it was it there once upon a time.
Using it DOES eliminate the warning, which is why I couldn't figure
out what to patch. ;)

Can any Ruby core gurus tell me why this was removed?

James Edward Gray II



daz

7/13/2005 4:46:00 AM

0


James Edward Gray II wrote:
> On Jul 12, 2005, at 11:50 AM, daz wrote:
>
> >
> >> No, I was referring to the one just a few lines down:
> >>
> >> module_eval {
> >> # a hack to shut up warning
> >> alias old_init initialize
> >> remove_method :old_init
> >> }
> >
> > Ah. That's not in my freeride build.
>
> Thank you. The was the hint I needed.
>
> The above hack is missing in the current versions of Ruby. I found
> it in my old CVS checkout, so it was it there once upon a time.
> Using it DOES eliminate the warning, which is why I couldn't figure
> out what to patch. ;)
>


This fix has been in the MAIN (1.9) and 1.8 CVS branches
since Mar 04 (looking at the ChangeLog).

Perhaps you saw it here and applied it yourself at one point:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...


I would copy /lib/ruby/1.8/set.rb to /lib/ruby/site_ruby/1.8/set.rb
and patch there.

/site_ruby/ contains stuff _you've_ installed to the base
and it's earlier in the search path ( puts $: ).

On reinstall, it's not going to be overwritten but it can
catch you out if you install a newer version in the default
location. For that reason, at the same time as patching, I'll
add a puts "** MOD ** #{__FILE__}" at the top of the script
so that it appears when I do a require 'set'. This can be
mildly irritating ;-) but also a useful prompt. - YMMV


daz


James Gray

7/13/2005 1:27:00 PM

0

On Jul 12, 2005, at 11:45 PM, daz wrote:

> This fix has been in the MAIN (1.9) and 1.8 CVS branches
> since Mar 04 (looking at the ChangeLog).

So the moral of the story is that both of my complaints are already
fixed? Well, that's good news.

Thanks for pointing out the changes.

> Perhaps you saw it here and applied it yourself at one point:
> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...

No, I must have just updated my CVS checkout more recently than I
thought. That's where I found it.

> I would copy /lib/ruby/1.8/set.rb to /lib/ruby/site_ruby/1.8/set.rb
> and patch there.
>
> /site_ruby/ contains stuff _you've_ installed to the base
> and it's earlier in the search path ( puts $: ).

Yuck. ;) I would much rather just get the problems fixed in Ruby
(which it seems they are), so we can all benefit.

Thanks for the advice though.

James Edward Gray II