Env change, or iconv library self-mutated?

I have been trying to use iconv to deal with ISO-8559-1 to UTF-8
translation of web page data in rails.

I wrote a short program to test the syntax, processing one of the pages
I was having a problem with. It worked, so I transferred the code into
my rails app. Then it appeared to not work (running under webrick), so
I went back to the test script and suddenly this error started
appearing:

iconv.rb:7:in <top (required)>': uninitialized constant Iconv (NameError) from test.rb:1:inrequire’
from test.rb:1:in `’

This error persists even with a one line script:

require “iconv”

I presume nothing could have happened to change iconv.so, etc. So what
could have happened to cause this problem?

I’ve actually rebooted in the hopes that this was something temporary.
My belief that there was some general “ruby environment configuration”
that could have been altered has not panned out (AFAICT there is no so
such configuration).

I guess I could uninstall and re-build ruby 1.9.1, but presumably this
will just happen again, unless I can figure out how iconv suddenly got
broken.

Before I go and bug people with a bug report, does anyone have any
thoughts on this?

Hi,

At Thu, 4 Jun 2009 01:55:41 +0900,
Mk 27 wrote in [ruby-talk:338286]:

I wrote a short program to test the syntax, processing one of the pages
I was having a problem with. It worked, so I transferred the code into
my rails app. Then it appeared to not work (running under webrick), so
I went back to the test script and suddenly this error started
appearing:

You seem having overwritten something. Check from where
iconv.rb is loaded.

Nobuyoshi N. wrote:

Hi,

At Thu, 4 Jun 2009 01:55:41 +0900,
Mk 27 wrote in [ruby-talk:338286]:

I wrote a short program to test the syntax, processing one of the pages
I was having a problem with. It worked, so I transferred the code into
my rails app. Then it appeared to not work (running under webrick), so
I went back to the test script and suddenly this error started
appearing:

You seem having overwritten something. Check from where
iconv.rb is loaded.

iconv.rb could be generated at runtime??? since the only thing in the
library is iconv.so

It is definitely busted, it did happen spontaneously, and I certainly
did not overwrite anything myself…anyway I filed a bug at redmine.

Hi,

At Thu, 4 Jun 2009 23:22:54 +0900,
Mk 27 wrote in [ruby-talk:338369]:

iconv.rb could be generated at runtime??? since the only thing in the
library is iconv.so

Of course no. It’s generated at compile time and installed.

It is definitely busted, it did happen spontaneously, and I certainly
did not overwrite anything myself…anyway I filed a bug at redmine.

First check your environment variable RUBYLIB and RUBYOPT, and
where the iconv.rb is loaded.

Nobuyoshi N. wrote:

Hi,

At Thu, 4 Jun 2009 23:22:54 +0900,
Mk 27 wrote in [ruby-talk:338369]:

iconv.rb could be generated at runtime??? since the only thing in the
library is iconv.so

Of course no. It’s generated at compile time and installed.

I built ruby from source in /usr/local. Ruby installed two directories,
/usr/local/lib/ruby and /usr/local/include/ruby-1.9.1:

[root/usr/local/lib/ruby] find -name iconv.*
./1.9.1/x86_64-linux/iconv.so
[root/usr/local/include] cd …/include/ruby-1.9.1/
[root/usr/local/include/ruby-1.9.1] find -name iconv.*
[root/usr/local/include/ruby-1.9.1]

First check your environment variable RUBYLIB and RUBYOPT, and
where the iconv.rb is loaded.

[root~] echo $RUBYOPT

[root~] echo $RUBLIB

Notice the blank lines. I also grepped through the 3700+ html pages in
the API and did find a single reference to RUBYOPT or RUBLIB.

What’s the deal guy? Am I supposed to take you seriously?

Hi,

At Fri, 5 Jun 2009 10:57:55 +0900,
Mk 27 wrote in [ruby-talk:338438]:

Notice the blank lines. I also grepped through the 3700+ html pages in
the API and did find a single reference to RUBYOPT or RUBLIB.

OK, then can’t you show the iconv.rb which causes the problem?
`gem which -a iconv’ shows the all paths.

First of all, what’s the version?

What’s the deal guy? Am I supposed to take you seriously?

The author of ext/iconv.

Mk 27 wrote:

Of course no. It’s generated at compile time and installed.

the API and did find a single reference to RUBYOPT or RUBLIB.

What’s the deal guy? Am I supposed to take you seriously?

Nobu is one of the main Ruby developers. Yes, you should take him
seriously. He is trying to determine if the version of iconv which is
being loaded is different from what you are expecting and what it should
be.

-Justin

Nobuyoshi N. wrote:

OK, then can’t you show the iconv.rb which causes the problem?
`gem which -a iconv’ shows the all paths.

[root~/ruby/docsearch/app/controllers] gem which -a iconv
/usr/local/lib/ruby/1.9.1/x86_64-linux/iconv.so

Like i said, AFAIK there is no “iconv.rb” on my system. But the error
in my OP was the cut n’ pasted error, no typo:

iconv.rb:7:in `<top (required)>’: uninitialized constant Iconv

However, the path (which I removed) is the path of my script
(/root/ruby/) which does not contain an icon.rb either.

I am very new to ruby. I wrote the script, as I said, it worked fine,
then I moved the code to my controller and added ‘require “iconv”’ at
the top – although I am not sure if there are more caveats in rails (or
whatever, etc). Anyway, after that did not work, probably I checked the
syntax and decided that I could not see a problem, then I went to back
to the script, and probably fooled around with that for half an hour
presuming I was confused until, as mentioned, I had the problem with a
two line script, rebooted, same deal.

However, ahem I just went and tested the original test script:

require “iconv”

file=File.new("/usr/share/doc/HTML/httpd-docs-2.2.2.en/mod/mod_expires.html",“r”);
lines=file.lines.to_a
file.close

conv=Iconv.new(“UTF-8//TRANSLIT//IGNORE”,“ISO_8859-1”,)

x = Array.new
lines.each { |l|
tmp=conv.iconv(l)
x.push tmp.gsub!(/<[^>]*>/,"")
}
x.delete_if{|l| l !~ /\w/}
x.each { |l| puts l }

and it works with no complaint now.

I just want to be honest with you. I have been programming full time
for several years (C and perl) and this is the first time I have
actually filed a bug report with anybody. If this happens again, I
will try and garner more details.

Sorry – but thanks for your vigilance. Still curious about where
“iconv.rb” is tho, and why the API does not refer to the environment
variables you mention.

MK

On Jun 5, 9:52 pm, Mk 27 [email protected] wrote:

What is confusing and inconsistent is that running “iconv.rb” as itself
works sometimes but not others. Renaming it obviously prevents the
problem.

Sorry again.

Posted viahttp://www.ruby-forum.com/.

So interisting~~

I can see what happened now. The one line script which failed is this,
“test.rb”

require “iconv”

In the same directory was the script from my previous post, named
“iconv.rb”. Evidently there is some rule of precedence here whereby
when running test.rb, ruby first looked in the relative path and loaded
iconv.rb causing the error. This is consistent.

What is confusing and inconsistent is that running “iconv.rb” as itself
works sometimes but not others. Renaming it obviously prevents the
problem.

Sorry again.