Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic linking breaks if locale is not english #93

Closed
esamattis opened this issue Dec 10, 2012 · 3 comments
Closed

Dynamic linking breaks if locale is not english #93

esamattis opened this issue Dec 10, 2012 · 3 comments

Comments

@esamattis
Copy link

I'm trying to link to libc on fairly standard Ubuntu Quantal installation
with finnish translations and locales.

var ffi = require("ffi");
var libc = ffi.Library("libc", {
  "setlocale": [ "string", ["int", "string"] ]
});

And I'm getting following error:

Dynamic Linking Error: /usr/lib/i386-linux-gnu/libc.so: virheellinen ELF-otsikko"

This works fine if I change the language to english from gnome-control-center.

The reason for this is very obvious after looking at this:

https://github.com/rbranson/node-ffi/blob/a4f2caa15dcafb7c317a9636bef50b2ffb8e3322/lib/dynamic_library.js#L66

It assumes that the error message is always in english, but unfortunaly that's
not the case. For example I have here "virheellinen ELF-otsikko" instead of
"invalid ELF header".

I'm running into this only when I'm using node-webkit. Plain node seems to be
unaffected for some reason. It might be because node-webkit does some extra
locale digging on startup:
https://github.com/rogerwang/node-webkit/wiki/Play-with-window (the last section).

But nevertheless node-ffi should not never rely on error message strings which
might get translated. The reason for this implementation seems to be the lack of
proper error codes in dlopen(3) API, but I hope we could figure out some more
robust implementation for this.

@TooTallNate
Copy link
Member

Interesting find! I suppose we're gonna have to find a way to fix this. Patches welcome of course. Figuring out how to add a test case for this will be interesting as well...

@unbornchikken
Copy link
Member

@TooTallNate if we match

/^(([^ \t()])+\.so([^ \t:()])*):([ \t])*/

without the English text, and then do the retry, it would resolve that issue. If it match another dlopen error accidentally, then what happens? We get another error, and nothing else, we could throw the original one, and everything works like before.

@TooTallNate
Copy link
Member

Fixed in v2.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants