Jörg Höhle : msvcrt: sizeof(long double) is 12 with MS, but not necessarily so on UNIX.
Alexandre Julliard
julliard at winehq.org
Thu Feb 17 13:06:36 CST 2011
Module: wine
Branch: master
Commit: c6d67fad8f6d0ac199d0945314564e39aa64644f
URL: http://source.winehq.org/git/wine.git/?a=commit;h=c6d67fad8f6d0ac199d0945314564e39aa64644f
Author: Jörg Höhle <hoehle at users.sourceforge.net>
Date: Wed Dec 1 22:26:26 2010 +0100
msvcrt: sizeof(long double) is 12 with MS, but not necessarily so on UNIX.
---
dlls/msvcrt/msvcrt.h | 2 +-
dlls/msvcrt/string.c | 20 +++++++++++++++-----
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h
index c878c08..1c7120f 100644
--- a/dlls/msvcrt/msvcrt.h
+++ b/dlls/msvcrt/msvcrt.h
@@ -86,7 +86,7 @@ typedef int (*__cdecl MSVCRT__onexit_t)(void);
typedef void (__cdecl *MSVCRT_invalid_parameter_handler)(const MSVCRT_wchar_t*, const MSVCRT_wchar_t*, const MSVCRT_wchar_t*, unsigned, MSVCRT_uintptr_t);
typedef void (__cdecl *MSVCRT_purecall_handler)(void);
-typedef struct {long double x;} MSVCRT__LDOUBLE;
+typedef struct {ULONG x80[3];} MSVCRT__LDOUBLE; /* Intel 80 bit FP format has sizeof() 12 */
struct MSVCRT_tm {
int tm_sec;
diff --git a/dlls/msvcrt/string.c b/dlls/msvcrt/string.c
index 031c3d0..2b9d41e 100644
--- a/dlls/msvcrt/string.c
+++ b/dlls/msvcrt/string.c
@@ -561,8 +561,10 @@ int CDECL MSVCRT__atoldbl(MSVCRT__LDOUBLE *value, const char *str)
{
/* FIXME needs error checking for huge/small values */
#ifdef HAVE_STRTOLD
+ long double ld;
TRACE("str %s value %p\n",str,value);
- value->x = strtold(str,0);
+ ld = strtold(str,0);
+ memcpy(value, &ld, 10);
#else
FIXME("stub, str %s value %p\n",str,value);
#endif
@@ -575,8 +577,10 @@ int CDECL MSVCRT__atoldbl(MSVCRT__LDOUBLE *value, const char *str)
int CDECL __STRINGTOLD( MSVCRT__LDOUBLE *value, char **endptr, const char *str, int flags )
{
#ifdef HAVE_STRTOLD
+ long double ld;
FIXME("%p %p %s %x partial stub\n", value, endptr, str, flags );
- value->x = strtold(str,endptr);
+ ld = strtold(str,0);
+ memcpy(value, &ld, 10);
#else
FIXME("%p %p %s %x stub\n", value, endptr, str, flags );
#endif
@@ -1281,7 +1285,7 @@ struct _I10_OUTPUT_DATA {
/*********************************************************************
* $I10_OUTPUT (MSVCRT.@)
- * ld - long double to be printed to data
+ * ld80 - long double (Intel 80 bit FP in 12 bytes) to be printed to data
* prec - precision of part, we're interested in
* flag - 0 for first prec digits, 1 for fractional part
* data - data to be populated
@@ -1294,16 +1298,22 @@ struct _I10_OUTPUT_DATA {
* Native sets last byte of data->str to '0' or '9', I don't know what
* it means. Current implementation sets it always to '0'.
*/
-int CDECL MSVCRT_I10_OUTPUT(MSVCRT__LDOUBLE ld, int prec, int flag, struct _I10_OUTPUT_DATA *data)
+int CDECL MSVCRT_I10_OUTPUT(MSVCRT__LDOUBLE ld80, int prec, int flag, struct _I10_OUTPUT_DATA *data)
{
static const char inf_str[] = "1#INF";
static const char nan_str[] = "1#QNAN";
- double d = ld.x;
+ /* MS' long double type wants 12 bytes for Intel's 80 bit FP format.
+ * Some UNIX have sizeof(long double) == 16, yet only 80 bit are used.
+ * Assume long double uses 80 bit FP, never seen 128 bit FP. */
+ long double ld = 0;
+ double d;
char format[8];
char buf[I10_OUTPUT_MAX_PREC+9]; /* 9 = strlen("0.e+0000") + '\0' */
char *p;
+ memcpy(&ld, &ld80, 10);
+ d = ld;
TRACE("(%lf %d %x %p)\n", d, prec, flag, data);
if(d<0) {
More information about the wine-cvs
mailing list