This is the mail archive of the
newlib@sources.redhat.com
mailing list for the newlib project.
enable long long and long double support in printf/scanf
- From: "Artem B. Bityuckiy" <abityuckiy at yandex dot ru>
- To: newlib at sources dot redhat dot com
- Cc: "Artem B. Bityuckiy" <abitytsky at softminecorp dot com>
- Date: Wed, 12 May 2004 16:00:05 +0400
- Subject: enable long long and long double support in printf/scanf
Hello.
Here is the patch that:
1. Adds --enable-newlib-io-long-long and --enable-newlib-io-long-double
configure script options to allow users to enable long long and long
double types support in printf/scanf series functions.
2. Removes direct passing -DWANT_PRINTF_LONG_LONG and -DWANT_IO_LONG_DBL
command line arguments when compiling Newlib (see configure.host).
3. Adds new _WANT_IO_LONG_LONG and _WANT_IO_LONG_DOUBLE macros to newlib.hin
4. Uses new _WANT_IO_LONG_LONG and _WANT_IO_LONG_DOUBLE macros from
newlib.h instead of old WANT_PRINTF_LONG_LONG and WANT_IO_LONG_DBL macros.
Also, there are 2 small changes:
1. Include <reent.h> in powerpc's printf/scanf
2. Remove junk newlib_cflags=${newlib_cflags} from configure.host
Note: aclocal.m4 and configure form newlib/ directory should be regenerated.
Please, see and commit if consider necessary.
--
Best Regards,
Artem B. Bityuckiy,
St.-Petersburg, Russia.
diff --exclude=CVS --exclude=configure --exclude=aclocal.m4 -auNr newlib-snapshot-pure/newlib/acinclude.m4 newlib-snapshot/newlib/acinclude.m4
--- newlib-snapshot-pure/newlib/acinclude.m4 2004-05-12 15:46:31.000000000 +0400
+++ newlib-snapshot/newlib/acinclude.m4 2004-05-12 15:41:13.000000000 +0400
@@ -35,6 +35,24 @@
*) AC_MSG_ERROR(bad value ${enableval} for malloc-debugging option) ;;
esac], [malloc_debugging=])dnl
+dnl Support --enable-newlib-io-long-long
+AC_ARG_ENABLE(newlib-io-long-long,
+[ --enable-newlib-io-long-long enable long long type support in IO functions like printf/scanf],
+[case "${enableval}" in
+ yes) newlib_io_long_long=yes;;
+ no) newlib_io_long_long=no ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for newlib-io-long-long option) ;;
+ esac], [newlib_io_long_long=])dnl
+
+dnl Support --enable-newlib-io-long-double
+AC_ARG_ENABLE(newlib-io-long-double,
+[ --enable-newlib-io-long-long enable long double type support in IO functions printf/scanf],
+[case "${enableval}" in
+ yes) newlib_io_long_double=yes;;
+ no) newlib_io_long_double=no ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for newlib-io-long-double option) ;;
+ esac], [newlib_io_long_double=])dnl
+
dnl Support --enable-newlib-mb
AC_ARG_ENABLE(newlib-mb,
[ --enable-newlib-mb enable multibyte support],
diff --exclude=CVS --exclude=configure --exclude=aclocal.m4 -auNr newlib-snapshot-pure/newlib/configure.host newlib-snapshot/newlib/configure.host
--- newlib-snapshot-pure/newlib/configure.host 2004-05-12 15:46:34.000000000 +0400
+++ newlib-snapshot/newlib/configure.host 2004-05-12 15:49:36.000000000 +0400
@@ -24,6 +24,8 @@
# target_optspace --enable-target-optspace ("yes", "no", "")
# newlib_multithread --enable-newlib-multithread ("yes", "no", "yes")
# newlib_elix_level --enable-newlib-elix-level ("1","2","3","4") ("4")
+# newlib_io_long_long --enable-newlib-io-long-long ("yes", "no", "")
+# newlib_io_long_double --enable-newlib-io-long-double ("yes", "no", "")
# It sets the following shell variables:
# newlib_cflags Special CFLAGS to use when building
@@ -343,11 +345,12 @@
crt1=crt1.o
crt1_dir=libc/sys/${sys_dir}
gcc_dir=`gcc -print-search-dirs | awk '/^install:/{print $2}'`
+ newlib_io_long_double="yes"
#newlib_cflags="${newlib_cflags} -Werror" # DEBUGGING ONLY;BREAKS BUILD
newlib_cflags="${newlib_cflags} -Wall"
newlib_cflags="${newlib_cflags} -D_I386MACH_ALLOW_HW_INTERRUPTS"
newlib_cflags="${newlib_cflags} -DHAVE_FCNTL"
- newlib_cflags="${newlib_cflags} -DWANT_IO_POS_ARGS -DWANT_IO_LONG_DBL"
+ newlib_cflags="${newlib_cflags} -DWANT_IO_POS_ARGS"
# --- Required when building a shared library ------------------------
newlib_cflags="${newlib_cflags} -fPIC -D_I386MACH_NEED_SOTYPE_FUNCTION"
# --- The three lines below are optional ------------------------------
@@ -431,7 +434,9 @@
*-*-cygwin*)
test -z "$cygwin_srcdir" && cygwin_srcdir=`cd ${srcdir}/../winsup/cygwin; pwd`
export cygwin_srcdir
- newlib_cflags="${newlib_cflags} -DHAVE_OPENDIR -DHAVE_RENAME -DSIGNAL_PROVIDED -DWANT_IO_POS_ARGS -DWANT_IO_LONG_DBL -DWANT_PRINTF_LONG_LONG -D_COMPILING_NEWLIB -DHAVE_FCNTL -DMALLOC_PROVIDED -I${cygwin_srcdir}/include"
+ newlib_io_long_long="yes"
+ newlib_io_long_double="yes"
+ newlib_cflags="${newlib_cflags} -DHAVE_OPENDIR -DHAVE_RENAME -DSIGNAL_PROVIDED -DWANT_IO_POS_ARGS -D_COMPILING_NEWLIB -DHAVE_FCNTL -DMALLOC_PROVIDED -I${cygwin_srcdir}/include"
syscall_dir=syscalls
;;
# RTEMS supplies its own versions of some routines:
@@ -442,7 +447,8 @@
#
# NOTE: When newlib malloc uses a semaphore, RTEMS will switch to that.
*-*-rtems*)
- newlib_cflags="${newlib_cflags} -DHAVE_GETTIMEOFDAY -DMALLOC_PROVIDED -DEXIT_PROVIDED -DMISSING_SYSCALL_NAMES -DSIGNAL_PROVIDED -DREENTRANT_SYSCALLS_PROVIDED -DHAVE_OPENDIR -DNO_EXEC -DWANT_PRINTF_LONG_LONG -DHAVE_FCNTL"
+ newlib_io_long_long="yes"
+ newlib_cflags="${newlib_cflags} -DHAVE_GETTIMEOFDAY -DMALLOC_PROVIDED -DEXIT_PROVIDED -DMISSING_SYSCALL_NAMES -DSIGNAL_PROVIDED -DREENTRANT_SYSCALLS_PROVIDED -DHAVE_OPENDIR -DNO_EXEC -DHAVE_FCNTL"
;;
# VxWorks supplies its own version of malloc, and the newlib one
# doesn't work because VxWorks does not have sbrk.
@@ -491,12 +497,11 @@
newlib_cflags="${newlib_cflags} -DARM_RDI_MONITOR"
;;
fr30-*-*)
- newlib_cflags="${newlib_cflags}"
syscall_dir=syscalls
;;
frv-*-*)
syscall_dir=syscalls
- newlib_cflags="${newlib_cflags} -DWANT_PRINTF_LONG_LONG"
+ newlib_io_long_long="yes"
;;
h8300*-*-*)
syscall_dir=syscalls
@@ -517,7 +522,7 @@
;;
iq2000*)
syscall_dir=syscalls
- newlib_cflags="${newlib_cflags} -DWANT_PRINTF_LONG_LONG"
+ newlib_io_long_long="yes"
;;
m32r-*-*)
# Pass -msdata=sdata so _impure_ptr goes in .sdata.
@@ -531,11 +536,11 @@
newlib_cflags="${newlib_cflags} -DNO_EXEC -DABORT_PROVIDED -DSMALL_MEMORY -DMISSING_SYSCALL_NAMES"
;;
mcore-*-*)
- newlib_cflags="${newlib_cflags}"
syscall_dir=syscalls
;;
mips64vr*-*-*)
- newlib_cflags="${newlib_cflags} -DWANT_PRINTF_LONG_LONG -DMISSING_SYSCALL_NAMES"
+ newlib_io_long_long="yes"
+ newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
;;
mmix-*)
syscall_dir=syscalls
@@ -547,10 +552,12 @@
syscall_dir=syscalls
;;
powerpc*-*-eabialtivec*)
- newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES -DWANT_PRINTF_LONG_LONG"
+ newlib_io_long_long="yes"
+ newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
;;
powerpc*-*-eabispe*)
- newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES -DWANT_PRINTF_LONG_LONG"
+ newlib_io_long_long="yes"
+ newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
;;
powerpc*-*-eabi* | \
powerpc*-*-elf* | \
@@ -558,14 +565,16 @@
powerpc*-*-rtem* | \
powerpc*-*-sysv* | \
powerpc*-*-solaris*)
- newlib_cflags="${newlib_cflags} -mrelocatable-lib -mno-eabi -mstrict-align -DMISSING_SYSCALL_NAMES -DWANT_PRINTF_LONG_LONG"
+ newlib_io_long_long="yes"
+ newlib_cflags="${newlib_cflags} -mrelocatable-lib -mno-eabi -mstrict-align -DMISSING_SYSCALL_NAMES"
;;
powerpcle-*-pe)
newlib_cflags="${newlib_cflags} -DHAVE_OPENDIR -DHAVE_RENAME -DHAVE_FCNTL"
syscall_dir=syscalls
;;
sh*-*-*)
- newlib_cflags="${newlib_cflags} -DHAVE_GETTIMEOFDAY -DWANT_PRINTF_LONG_LONG"
+ newlib_io_long_long="yes"
+ newlib_cflags="${newlib_cflags} -DHAVE_GETTIMEOFDAY"
syscall_dir=syscalls
;;
sparc-sun-sunos*)
diff --exclude=CVS --exclude=configure --exclude=aclocal.m4 -auNr newlib-snapshot-pure/newlib/configure.in newlib-snapshot/newlib/configure.in
--- newlib-snapshot-pure/newlib/configure.in 2004-05-12 15:46:34.000000000 +0400
+++ newlib-snapshot/newlib/configure.in 2004-05-12 15:41:13.000000000 +0400
@@ -144,6 +144,14 @@
AC_DEFINE_UNQUOTED(_ELIX_LEVEL,${newlib_elix_level})
fi
+if test "${newlib_io_long_long}" = "yes"; then
+AC_DEFINE_UNQUOTED(_WANT_IO_LONG_LONG)
+fi
+
+if test "${newlib_io_long_double}" = "yes"; then
+AC_DEFINE_UNQUOTED(_WANT_IO_LONG_DOUBLE)
+fi
+
if test "${newlib_mb}" = "yes"; then
AC_DEFINE_UNQUOTED(_MB_CAPABLE)
AC_DEFINE_UNQUOTED(_MB_LEN_MAX,8)
diff --exclude=CVS --exclude=configure --exclude=aclocal.m4 -auNr newlib-snapshot-pure/newlib/libc/machine/powerpc/vfprintf.c newlib-snapshot/newlib/libc/machine/powerpc/vfprintf.c
--- newlib-snapshot-pure/newlib/libc/machine/powerpc/vfprintf.c 2004-05-12 15:46:35.000000000 +0400
+++ newlib-snapshot/newlib/libc/machine/powerpc/vfprintf.c 2004-05-12 15:41:08.000000000 +0400
@@ -155,11 +155,6 @@
#endif
#endif
-#define _NO_LONGLONG
-#if defined WANT_PRINTF_LONG_LONG && defined __GNUC__
-# undef _NO_LONGLONG
-#endif
-
#include <_ansi.h>
#include <limits.h>
#include <stdio.h>
@@ -186,10 +181,15 @@
This could be changed in the future should the _ldtoa_r code be
preferred over _dtoa_r. */
#define _NO_LONGDBL
-#if defined WANT_IO_LONG_DBL && (LDBL_MANT_DIG > DBL_MANT_DIG)
+#if defined _WANT_IO_LONG_DOUBLE && (LDBL_MANT_DIG > DBL_MANT_DIG)
#undef _NO_LONGDBL
#endif
+#define _NO_LONGLONG
+#if defined _WANT_IO_LONG_LONG && defined __GNUC__
+# undef _NO_LONGLONG
+#endif
+
#ifdef __ALTIVEC__
typedef union
{
diff --exclude=CVS --exclude=configure --exclude=aclocal.m4 -auNr newlib-snapshot-pure/newlib/libc/machine/powerpc/vfscanf.c newlib-snapshot/newlib/libc/machine/powerpc/vfscanf.c
--- newlib-snapshot-pure/newlib/libc/machine/powerpc/vfscanf.c 2004-05-12 15:46:36.000000000 +0400
+++ newlib-snapshot/newlib/libc/machine/powerpc/vfscanf.c 2004-05-12 15:41:08.000000000 +0400
@@ -103,6 +103,7 @@
*/
#include <_ansi.h>
+#include <reent.h>
#include <newlib.h>
#include <ctype.h>
#include <stdio.h>
@@ -128,13 +129,13 @@
This could be changed in the future should the _ldtoa_r code be
preferred over _dtoa_r. */
#define _NO_LONGDBL
-#if defined WANT_IO_LONG_DBL && (LDBL_MANT_DIG > DBL_MANT_DIG)
+#if defined _WANT_IO_LONG_DOUBLE && (LDBL_MANT_DIG > DBL_MANT_DIG)
#undef _NO_LONGDBL
extern _LONG_DOUBLE _strtold _PARAMS((char *s, char **sptr));
#endif
#define _NO_LONGLONG
-#if defined WANT_PRINTF_LONG_LONG && defined __GNUC__
+#if defined _WANT_IO_LONG_LONG && defined __GNUC__
# undef _NO_LONGLONG
#endif
diff --exclude=CVS --exclude=configure --exclude=aclocal.m4 -auNr newlib-snapshot-pure/newlib/libc/stdio/vfieeefp.h newlib-snapshot/newlib/libc/stdio/vfieeefp.h
--- newlib-snapshot-pure/newlib/libc/stdio/vfieeefp.h 2004-05-12 15:46:36.000000000 +0400
+++ newlib-snapshot/newlib/libc/stdio/vfieeefp.h 2004-05-12 15:41:08.000000000 +0400
@@ -29,6 +29,7 @@
/* This header file is a modification of mprec.h that only contains floating
point union code. */
+#include <newlib.h>
#include <ieeefp.h>
#include <math.h>
#include <float.h>
@@ -57,7 +58,7 @@
Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined.
#endif
-#ifdef WANT_IO_LONG_DBL
+#ifdef _WANT_IO_LONG_DOUBLE
/* If we are going to examine or modify specific bits in a long double using
the lword0 or lwordx macros, then we must wrap the long double inside
a union. This is necessary to avoid undefined behavior according to
@@ -134,7 +135,7 @@
};
#endif /* LDBL_MANT_DIG */
#endif /* !IEEE_8087 */
-#endif /* WANT_IO_LONG_DBL */
+#endif /* _WANT_IO_LONG_DOUBLE */
/* If we are going to examine or modify specific bits in a double using
the word0 and/or word1 macros, then we must wrap the double inside
diff --exclude=CVS --exclude=configure --exclude=aclocal.m4 -auNr newlib-snapshot-pure/newlib/libc/stdio/vfprintf.c newlib-snapshot/newlib/libc/stdio/vfprintf.c
--- newlib-snapshot-pure/newlib/libc/stdio/vfprintf.c 2004-05-12 15:46:37.000000000 +0400
+++ newlib-snapshot/newlib/libc/stdio/vfprintf.c 2004-05-12 15:41:08.000000000 +0400
@@ -169,17 +169,13 @@
#endif
#endif
-#define _NO_LONGLONG
-#if defined WANT_PRINTF_LONG_LONG && defined __GNUC__
-# undef _NO_LONGLONG
-#endif
-
#define _NO_POS_ARGS
#if defined WANT_IO_POS_ARGS
# undef _NO_POS_ARGS
#endif
#include <_ansi.h>
+#include <reent.h>
#include <newlib.h>
#include <reent.h>
#include <stdio.h>
@@ -202,10 +198,15 @@
This could be changed in the future should the _ldtoa_r code be
preferred over _dtoa_r. */
#define _NO_LONGDBL
-#if defined WANT_IO_LONG_DBL && (LDBL_MANT_DIG > DBL_MANT_DIG)
+#if defined _WANT_IO_LONG_DOUBLE && (LDBL_MANT_DIG > DBL_MANT_DIG)
#undef _NO_LONGDBL
#endif
+#define _NO_LONGLONG
+#if defined _WANT_IO_LONG_LONG && defined __GNUC__
+# undef _NO_LONGLONG
+#endif
+
/*
* Flush out all the vectors defined by the given uio,
* then reset it so that it can be reused.
diff --exclude=CVS --exclude=configure --exclude=aclocal.m4 -auNr newlib-snapshot-pure/newlib/libc/stdio/vfscanf.c newlib-snapshot/newlib/libc/stdio/vfscanf.c
--- newlib-snapshot-pure/newlib/libc/stdio/vfscanf.c 2004-05-12 15:46:39.000000000 +0400
+++ newlib-snapshot/newlib/libc/stdio/vfscanf.c 2004-05-12 15:41:08.000000000 +0400
@@ -103,8 +103,8 @@
*/
#include <_ansi.h>
-#include <newlib.h>
#include <reent.h>
+#include <newlib.h>
#include <ctype.h>
#include <wctype.h>
#include <stdio.h>
@@ -130,13 +130,13 @@
This could be changed in the future should the _ldtoa_r code be
preferred over _dtoa_r. */
#define _NO_LONGDBL
-#if defined WANT_IO_LONG_DBL && (LDBL_MANT_DIG > DBL_MANT_DIG)
+#if defined _WANT_IO_LONG_DOUBLE && (LDBL_MANT_DIG > DBL_MANT_DIG)
#undef _NO_LONGDBL
extern _LONG_DOUBLE _strtold _PARAMS((char *s, char **sptr));
#endif
#define _NO_LONGLONG
-#if defined WANT_PRINTF_LONG_LONG && defined __GNUC__
+#if defined _WANT_IO_LONG_LONG && defined __GNUC__
# undef _NO_LONGLONG
#endif
diff --exclude=CVS --exclude=configure --exclude=aclocal.m4 -auNr newlib-snapshot-pure/newlib/newlib.hin newlib-snapshot/newlib/newlib.hin
--- newlib-snapshot-pure/newlib/newlib.hin 2004-05-12 15:46:34.000000000 +0400
+++ newlib-snapshot/newlib/newlib.hin 2004-05-12 15:41:13.000000000 +0400
@@ -8,6 +8,12 @@
/* Newlib version */
#undef _NEWLIB_VERSION
+/* long long type support in IO functions like printf/scanf enabled */
+#undef _WANT_IO_LONG_LONG
+
+/* long double type support in IO functions like printf/scanf enabled */
+#undef _WANT_IO_LONG_DOUBLE
+
/* Multibyte supported */
#undef _MB_CAPABLE