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

strtold() conflicting with MSVCRT #728

Closed
kinke opened this issue Sep 27, 2014 · 2 comments
Closed

strtold() conflicting with MSVCRT #728

kinke opened this issue Sep 27, 2014 · 2 comments

Comments

@kinke
Copy link
Member

kinke commented Sep 27, 2014

Microsoft's C runtime includes a strtold() implementation (returning a 64-bit double) since VS 2013. druntime defines its own strtold() (returning a real) in core.stdc.stdlib, leading obviously to linking conflicts.

In the long run, we should define real as 64-bit double on Windows x64 due to the lack of x87 support in MSVCRT.

Until then, the following patch redirects strtold to the renamed druntime wrapper with the correct signature:

diff --git a/src/core/stdc/stdlib.d b/src/core/stdc/stdlib.d
index 3e73137..96ea21b 100644
--- a/src/core/stdc/stdlib.d
+++ b/src/core/stdc/stdlib.d
@@ -72,10 +72,20 @@ ulong   strtoull(in char* nptr, char** endptr, int base);

 version (Win64)
 {
-    real strtold(in char* nptr, char** endptr)
-    {   // Fake it 'till we make it
-        return strtod(nptr, endptr);
-    }
+  version (none)
+  {
+    // requires MSVCRT >= 12 (VS 2013) and real to be defined as 64-bit double
+    static assert(real.sizeof == double.sizeof);
+    real strtold(in char* nptr, char** endptr);
+  }
+  else
+  {
+     real strtold_druntime(in char* nptr, char** endptr)
+     {   // Fake it 'till we make it
+         return strtod(nptr, endptr);
+     }
+     alias strtold_druntime strtold;
+  }
 }
 else version (MinGW)
 {
redstar pushed a commit that referenced this issue Sep 27, 2014
Fix issue 11519 - race in core.thread unit test
@kinke
Copy link
Member Author

kinke commented Sep 28, 2014

This is fixed in upstream: dlang/druntime@98215d6

Relevant piece:

-    real strtold(in char* nptr, char** endptr)
+    // strtold exists starting from VS2013, so we make this a template to avoid link errors
+    real strtold()(in char* nptr, char** endptr)

redstar added a commit that referenced this issue Oct 12, 2014
- Create template for strtold() on Win64 (issue #728)
- Fix an assembler warning on Linux/PPC64le
@redstar
Copy link
Member

redstar commented Oct 12, 2014

Fixed in master. I only included the relevant code from the mentioned commit.

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

2 participants