[PATCH] libport: Move rint fallback implementations from msvcrt to libport.
Alex Henrie
alexhenrie24 at gmail.com
Mon Nov 6 20:01:13 CST 2017
Signed-off-by: Alex Henrie <alexhenrie24 at gmail.com>
---
Fixes https://bugs.winehq.org/show_bug.cgi?id=43000
This supersedes the dsound patch. Matteo is right that it's better to
add these functions to libport because we use lrint and lrintf in
multiple DLLs.
---
dlls/dsound/dsound_convert.c | 1 +
dlls/msvcrt/math.c | 24 ----------------
include/wine/port.h | 24 ++++++++++++++++
libs/port/Makefile.in | 1 +
libs/port/rint.c | 66 ++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 92 insertions(+), 24 deletions(-)
create mode 100644 libs/port/rint.c
diff --git a/dlls/dsound/dsound_convert.c b/dlls/dsound/dsound_convert.c
index 6887bae558..26dbb3220a 100644
--- a/dlls/dsound/dsound_convert.c
+++ b/dlls/dsound/dsound_convert.c
@@ -35,6 +35,7 @@
*/
#include "config.h"
+#include "wine/port.h"
#include <stdarg.h>
#include <math.h>
diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c
index 60ce4e659f..b7288cf6cf 100644
--- a/dlls/msvcrt/math.c
+++ b/dlls/msvcrt/math.c
@@ -2604,11 +2604,7 @@ LDOUBLE CDECL MSVCR120_log2l(LDOUBLE x)
*/
double CDECL MSVCR120_rint(double x)
{
-#ifdef HAVE_RINT
return rint(x);
-#else
- return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
-#endif
}
/*********************************************************************
@@ -2616,11 +2612,7 @@ double CDECL MSVCR120_rint(double x)
*/
float CDECL MSVCR120_rintf(float x)
{
-#ifdef HAVE_RINTF
return rintf(x);
-#else
- return MSVCR120_rint(x);
-#endif
}
/*********************************************************************
@@ -2636,11 +2628,7 @@ LDOUBLE CDECL MSVCR120_rintl(LDOUBLE x)
*/
MSVCRT_long CDECL MSVCR120_lrint(double x)
{
-#ifdef HAVE_LRINT
return lrint(x);
-#else
- return MSVCR120_rint(x);
-#endif
}
/*********************************************************************
@@ -2648,11 +2636,7 @@ MSVCRT_long CDECL MSVCR120_lrint(double x)
*/
MSVCRT_long CDECL MSVCR120_lrintf(float x)
{
-#ifdef HAVE_LRINTF
return lrintf(x);
-#else
- return MSVCR120_lrint(x);
-#endif
}
/*********************************************************************
@@ -2668,11 +2652,7 @@ MSVCRT_long CDECL MSVCR120_lrintl(LDOUBLE x)
*/
MSVCRT_longlong CDECL MSVCR120_llrint(double x)
{
-#ifdef HAVE_LLRINT
return llrint(x);
-#else
- return MSVCR120_rint(x);
-#endif
}
/*********************************************************************
@@ -2680,11 +2660,7 @@ MSVCRT_longlong CDECL MSVCR120_llrint(double x)
*/
MSVCRT_longlong CDECL MSVCR120_llrintf(float x)
{
-#ifdef HAVE_LLRINTF
return llrintf(x);
-#else
- return MSVCR120_llrint(x);
-#endif
}
/*********************************************************************
diff --git a/include/wine/port.h b/include/wine/port.h
index 2989b39dcb..addece0448 100644
--- a/include/wine/port.h
+++ b/include/wine/port.h
@@ -272,6 +272,22 @@ int isinf(double x);
int isnan(double x);
#endif
+#ifndef HAVE_LLRINT
+__int64 llrint(double x);
+#endif
+
+#ifndef HAVE_LLRINTF
+__int64 llrintf(float x);
+#endif
+
+#ifndef HAVE_LRINT
+long lrint(double x);
+#endif
+
+#ifndef HAVE_LRINTF
+long lrintf(float x);
+#endif
+
#ifndef HAVE_LSTAT
int lstat(const char *file_name, struct stat *buf);
#endif /* HAVE_LSTAT */
@@ -308,6 +324,14 @@ ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
int readlink( const char *path, char *buf, size_t size );
#endif /* HAVE_READLINK */
+#ifndef HAVE_RINT
+double rint(double x);
+#endif
+
+#ifndef HAVE_RINTF
+float rintf(float x);
+#endif
+
#ifndef HAVE_STATVFS
int statvfs( const char *path, struct statvfs *buf );
#endif
diff --git a/libs/port/Makefile.in b/libs/port/Makefile.in
index 9d7e44f970..7fefda150a 100644
--- a/libs/port/Makefile.in
+++ b/libs/port/Makefile.in
@@ -96,6 +96,7 @@ C_SRCS = \
pread.c \
pwrite.c \
readlink.c \
+ rint.c \
spawn.c \
statvfs.c \
strcasecmp.c \
diff --git a/libs/port/rint.c b/libs/port/rint.c
new file mode 100644
index 0000000000..a99c00be43
--- /dev/null
+++ b/libs/port/rint.c
@@ -0,0 +1,66 @@
+/*
+ * rint family
+ *
+ * Copyright 2017 Alex Henrie
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#include <math.h>
+
+#ifndef HAVE_RINT
+double rint(double x)
+{
+ return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
+}
+#endif
+
+#ifndef HAVE_RINTF
+float rintf(float x)
+{
+ return rintf(x);
+}
+#endif
+
+#ifndef HAVE_LRINT
+long lrint(double x)
+{
+ return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
+}
+#endif
+
+#ifndef HAVE_LRINTF
+long lrintf(float x)
+{
+ return lrint(x);
+}
+#endif
+
+#ifndef HAVE_LLRINT
+__int64 llrint(double x)
+{
+ return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
+}
+#endif
+
+#ifndef HAVE_LLRINTF
+__int64 llrintf(float x)
+{
+ return llrint(x);
+}
+#endif
--
2.14.2
More information about the wine-patches
mailing list