Forum: Ruby env change, or iconv library self-mutated???

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
68814ed988eee4f21b2cd07353e5e445?d=identicon&s=25 Mk 27 (mk27)
on 2009-06-03 18:55
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:in `require'
  from test.rb:1:in `<main>'

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?
68814ed988eee4f21b2cd07353e5e445?d=identicon&s=25 Mk 27 (mk27)
on 2009-06-03 19:54
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?
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2009-06-04 03:44
(Received via mailing list)
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.
68814ed988eee4f21b2cd07353e5e445?d=identicon&s=25 Mk 27 (mk27)
on 2009-06-04 16:22
Nobuyoshi Nakada 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.
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2009-06-05 01:39
(Received via mailing list)
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.
68814ed988eee4f21b2cd07353e5e445?d=identicon&s=25 Mk 27 (mk27)
on 2009-06-05 03:57
Nobuyoshi Nakada 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?
6e366eb5a71be2bad7f383d42aeb4788?d=identicon&s=25 Justin Collins (Guest)
on 2009-06-05 04:12
(Received via mailing list)
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
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2009-06-05 05:02
(Received via mailing list)
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.
68814ed988eee4f21b2cd07353e5e445?d=identicon&s=25 Mk 27 (mk27)
on 2009-06-05 05:42
Nobuyoshi Nakada 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
68814ed988eee4f21b2cd07353e5e445?d=identicon&s=25 Mk 27 (mk27)
on 2009-06-05 15:52
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.
E9ed4664dfd7ea664ccc5813de4d1fd7?d=identicon&s=25 Hooopo (Guest)
on 2009-06-06 08:55
(Received via mailing list)
On Jun 5, 9:52 pm, Mk 27 <halfcountp...@intergate.com> 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~~
This topic is locked and can not be replied to.