Standard Library Warnings

  • Thread starter James Edward Gray II
  • Start date
J

James Edward Gray II

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
 
C

Craig Moran

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

Craig Moran

------=_Part_2968_6527735.1121109948562
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

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

=20
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 =3D %w{ exit inc dec }

ABBREV =3D COMMANDS.abbrev

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

value =3D 0

loop do

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

break if cmd.nil?

case cmd.strip
when "exit"
break
when "inc"
value +=3D 1
when "dec"
value -=3D 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
=20

------=_Part_2968_6527735.1121109948562--
 
D

daz

James said:
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
 
J

James Edward Gray II

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 :eek:ld_init
}

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
 
J

James Edward Gray II

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
 
D

daz

James said:
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-talk/132868


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
 
J

James Edward Gray II

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-talk/132868

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,128
Latest member
ElwoodPhil
Top