-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: Locale-independent strtod #5988
Conversation
Nice! We also need this for |
yep. please wait... |
... done. But seems to not work on linux (according to travis) |
The functions are there, but not exposed by standard headers.
This seems pretty sketchy and I don't know how portable it will be. |
Some sources seem to define |
newlocale is posix and after including locale.h (instead of xlocale.h on OSX) travis only has problems with |
hmm still no luck despite the usage of |
On linux let's just manually add the prototypes for |
They are mentioned in headers, and I seem to be able to look up their addresses with dlsym. |
I experimented with your branch. This patch seems to fix it: diff --git a/src/support/strtod.c b/src/support/strtod.c
index fdc99a4..abe005a 100644
--- a/src/support/strtod.c
+++ b/src/support/strtod.c
@@ -30,7 +30,7 @@ LOCALE_T get_c_locale()
#if defined(_OS_WINDOWS_)
c_locale = _create_locale(LC_ALL,"C");
#else
- c_locale = newlocale(LC_ALL_MASK, NULL, NULL);
+ c_locale = newlocale(LC_ALL_MASK, "C", NULL);
#endif
}
return c_locale; |
Great I think we got it. Just for reference: https://developer.apple.com/library/ios/documentation/System/Conceptual/ManPages_iPhoneOS/man3/newlocale.3.html#//apple_ref/doc/man/3/newlocale "In order to create a C locale_t value, use newlocale(LC_ALL_MASK, NULL, NULL)" Now we just need someone to check if this is working on Windows. |
We might want to use |
Not sure about that. We also use |
Ok, good. |
looks like the exports aren't quite right:
|
Ah, I see those are library functions. Supposedly Wine crt has them but I'll have to dig around and see why they are not found in my cross compile. |
Wow. I go to get a snack and before I get back you have something to test. :) Looks like you have it figured out, but I'll look it over anyway, |
Friends -- in all locales -- I have to vigorously agree with @StefanKarpinski in his comment on #5928. And I was going to write about my commercial experience with this exact discussion, until I realized I would sound like a ranting old FORTR^H^H^H^H^H codger. Instead I'll just say that I prefer to live with the problem in exchange for unambiguous portability of code and data. GUIs are a different story of course. But if I'm wrong and people really want this, I'll help test and file off any rough edges. |
Yeah, this appears to be problematic. MinGW doesn't have |
|
@ihnorton Avoid MSVCR at all costs unless you're developing on Windows for Windows only. There is no return from that path. :) On this point, the GPL got it right. |
So this means that we don't use the native C library on windows? Because http://msdn.microsoft.com/de-de/library/kxsfc1ab(v=vs.90).aspx indicates that the function should be there. Anyway, maybe the next step is to try the C++ solution but it has a little different interface. In particular I don't see how it will be possible to maintain the second parameter to |
Just for the record. The C++ version would look something like the following. @JeffBezanson I have not looked in detail on the usages of
|
They have |
In |
That makes sense, but AFAIK would still require linking against MSVC runtime. |
Is the MSVC runtime not available on all windows systems? |
IIRC the MSVC runtime was removed from the Windows base OS some time ago, and its license prohibits redistribution in binary form. |
http://support.microsoft.com/kb/326922 "The shared CRT DLL has been distributed by Microsoft in the past as a shared system component. This may cause problems when you run applications that are linked to a different version of the CRT on computers that do not have the correct versions of the CRT DLL installed. This is commonly referred to as the "DLL Conflict" problem. To address this issue, the CRT DLL is no longer considered a system file, therefore, distribute the CRT DLL with any application that relies on it." |
wow, i had no idea this would be so crazy to implement (PS. is it some deep secret that we have always linked against |
static locale_t c_locale; | ||
|
||
locale_t get_c_locale() | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for BSD, it should be safe to always return NULL
, according to the xlocale man page
@vtjnash If we link against |
@vtjnash maybe you can explain why On Windows 7: (as per my first comment in this thread), MinGW's
|
Why would it be? Quoting mingw.org,
Or for mingw-w64, http://sourceforge.net/apps/trac/mingw-w64/wiki/download%20filename%20structure
|
This was bound to happen sooner or later, but this change broke building on RHEL/CentOS 5, where the newest version of GCC available from the package manager is 4.4. Error messages are here, That distribution is terrible and should really come with a warning label that all the software versions are already obsolete as soon as you buy the machine, and annoyingly difficult to upgrade. But it's unfortunately still fairly common in the wild and difficult to replace for users who didn't know any better to pick a different distribution. Can anyone suggest a fix? If not, I'll try searching for a yum repo with newer GCC and document my findings in the relevant section of Readme.md. |
@tkelman: This should be fixable. There is a big |
Yeah, that was fairly simple. Changing the (Found a yum repo here http://superuser.com/questions/381160/install-gcc-4-7-on-centos that looks promising, haven't tried building julia with it yet though) |
Does not work on OSX as it uses the wrong branch. Unfortunately I don't have access to linux and cannot test it |
Works on old-GCC Linux, and neither define is set in MinGW or MSVC. Someone else will have to chime in about recent-GCC or Clang with Linux. |
Cool. For testing on Linux it it is important to check that the right branch is taken! To the |
Yeah, it may be more useful to just compile and report the output of something dumb like
|
If you use |
I think issue is dead and done with, but I'll just mention that double-conversion has a strtod implementation. Not sure if there would be any advantages to doing a julia implementation (it would use some of my new grisu code machinery), but it wouldn't be too much work if we wanted it for some reason. |
@quinnj Does your julia implementation has hex support? This was/is one major issue here. But much more fundamental, |
The Grisu algorithm is serious overkill for base 2^k printing – that's very straightforward, I just never got around to implementing it. Having support for other non-power-of-two bases would be super cool though :-) |
@tknopp, unfortunately it sounds like no hex support from the strtod.h // The buffer must only contain digits in the range [0-9]. It must not
// contain a dot or a sign. It must not start with '0', and must not be empty.
double Strtod(Vector<const char> buffer, int exponent); To your next point, have you seen JuliaParser? :) @StefanKarpinski, I'm not sure I understand your point; should we special case certain floats to print faster than calling grisu? |
@tknopp was asking about hex printing – my point was just that the Grisu algorithm is serious overkill for printing floats in base 16. |
Implement and use locale-independent
strtod
function. fixes #5928. Should also work on windows but I cannot test.