summaryrefslogtreecommitdiff
path: root/patches/mpfr
diff options
context:
space:
mode:
authorYann E. MORIN" <yann.morin.1998@anciens.enib.fr>2009-03-08 17:27:02 (GMT)
committerYann E. MORIN" <yann.morin.1998@anciens.enib.fr>2009-03-08 17:27:02 (GMT)
commit357c8c3fbec9b5b831be318069a9f5e75596e7fb (patch)
tree56ee2bdbbef6eda9620a221704611a1e7a5b46ed /patches/mpfr
parent6a2fed26d1097cdf856e8a33be0bc4ff13fea35f (diff)
Add MPFR-2.4.1.
Add patchset for MPFR 2.4.0 and 2.4.1, from upstream. /trunk/config/gmp_mpfr/mpfr.in | 8 6 2 0 + /trunk/patches/mpfr/2.4.0/100-printf-hh-ll.patch | 359 359 0 0 +++++++++++++++++++++++++++++ /trunk/patches/mpfr/2.4.0/110-mpfr_snprintf.patch | 176 176 0 0 ++++++++++++++ /trunk/patches/mpfr/2.4.1/100-remainder-neg.patch | 123 123 0 0 ++++++++++ /trunk/patches/mpfr/2.4.1/110-assert.patch | 45 45 0 0 ++++ 5 files changed, 709 insertions(+), 2 deletions(-)
Diffstat (limited to 'patches/mpfr')
-rw-r--r--patches/mpfr/2.4.0/100-printf-hh-ll.patch359
-rw-r--r--patches/mpfr/2.4.0/110-mpfr_snprintf.patch176
-rw-r--r--patches/mpfr/2.4.1/100-remainder-neg.patch123
-rw-r--r--patches/mpfr/2.4.1/110-assert.patch45
4 files changed, 703 insertions, 0 deletions
diff --git a/patches/mpfr/2.4.0/100-printf-hh-ll.patch b/patches/mpfr/2.4.0/100-printf-hh-ll.patch
new file mode 100644
index 0000000..e2a9f81
--- /dev/null
+++ b/patches/mpfr/2.4.0/100-printf-hh-ll.patch
@@ -0,0 +1,359 @@
+diff -Naurd mpfr-2.4.0-a/PATCHES mpfr-2.4.0-b/PATCHES
+--- mpfr-2.4.0-a/PATCHES 2009-01-26 12:52:01.000000000 +0000
++++ mpfr-2.4.0-b/PATCHES 2009-02-20 17:27:44.000000000 +0000
+@@ -0,0 +1 @@
++printf-hh-ll
+diff -Naurd mpfr-2.4.0-a/VERSION mpfr-2.4.0-b/VERSION
+--- mpfr-2.4.0-a/VERSION 2009-01-26 12:52:01.000000000 +0000
++++ mpfr-2.4.0-b/VERSION 2009-02-20 17:27:44.000000000 +0000
+@@ -1 +1 @@
+-2.4.0
++2.4.0-p1
+diff -Naurd mpfr-2.4.0-a/acinclude.m4 mpfr-2.4.0-b/acinclude.m4
+--- mpfr-2.4.0-a/acinclude.m4 2009-01-26 12:52:01.000000000 +0000
++++ mpfr-2.4.0-b/acinclude.m4 2009-01-26 12:52:01.000000000 +0000
+@@ -722,6 +722,16 @@
+ [AC_DEFINE([NPRINTF_J], 1, [gmp_printf cannot read intmax_t])])
+ fi
+
++MPFR_FUNC_PRINTF_SPEC([%hhd], [char], [
++#include <gmp.h>
++ ], [gmp_],,
++ [AC_DEFINE([NPRINTF_HH], 1, [gmp_printf cannot use 'hh' length modifier])])
++
++MPFR_FUNC_PRINTF_SPEC([%lld], [long long int], [
++#include <gmp.h>
++ ], [gmp_],,
++ [AC_DEFINE([NPRINTF_LL], 1, [gmp_printf cannot read long long int])])
++
+ MPFR_FUNC_PRINTF_SPEC([%.0Lf], [long double], [
+ #include <gmp.h>
+ ], [gmp_],,
+diff -Naurd mpfr-2.4.0-a/configure mpfr-2.4.0-b/configure
+--- mpfr-2.4.0-a/configure 2009-01-26 12:54:36.000000000 +0000
++++ mpfr-2.4.0-b/configure 2009-02-20 17:38:36.000000000 +0000
+@@ -24874,6 +24874,170 @@
+ fi
+
+
++{ $as_echo "$as_me:$LINENO: checking if gmp_printf supports \"%hhd\"" >&5
++$as_echo_n "checking if gmp_printf supports \"%hhd\"... " >&6; }
++if test "$cross_compiling" = yes; then
++ { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
++$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
++{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling
++See \`config.log' for more details." >&5
++$as_echo "$as_me: error: cannot run test program while cross compiling
++See \`config.log' for more details." >&2;}
++ { (exit 1); exit 1; }; }; }
++else
++ cat >conftest.$ac_ext <<_ACEOF
++/* confdefs.h. */
++_ACEOF
++cat confdefs.h >>conftest.$ac_ext
++cat >>conftest.$ac_ext <<_ACEOF
++/* end confdefs.h. */
++
++#include <stdio.h>
++
++#include <gmp.h>
++
++
++int
++main ()
++{
++
++ char s[256];
++ char a = 0;
++ return (gmp_sprintf (s, "%hhd", a) != 1) ? 1 : 0;
++
++ ;
++ return 0;
++}
++_ACEOF
++rm -f conftest$ac_exeext
++if { (ac_try="$ac_link"
++case "(($ac_try" in
++ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
++ *) ac_try_echo=$ac_try;;
++esac
++eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
++$as_echo "$ac_try_echo") >&5
++ (eval "$ac_link") 2>&5
++ ac_status=$?
++ $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
++ (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
++ { (case "(($ac_try" in
++ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
++ *) ac_try_echo=$ac_try;;
++esac
++eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
++$as_echo "$ac_try_echo") >&5
++ (eval "$ac_try") 2>&5
++ ac_status=$?
++ $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
++ (exit $ac_status); }; }; then
++ { $as_echo "$as_me:$LINENO: result: yes" >&5
++$as_echo "yes" >&6; }
++
++else
++ $as_echo "$as_me: program exited with status $ac_status" >&5
++$as_echo "$as_me: failed program was:" >&5
++sed 's/^/| /' conftest.$ac_ext >&5
++
++( exit $ac_status )
++{ $as_echo "$as_me:$LINENO: result: no" >&5
++$as_echo "no" >&6; }
++
++cat >>confdefs.h <<\_ACEOF
++#define NPRINTF_HH 1
++_ACEOF
++
++fi
++rm -rf conftest.dSYM
++rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
++fi
++
++
++
++
++
++{ $as_echo "$as_me:$LINENO: checking if gmp_printf supports \"%lld\"" >&5
++$as_echo_n "checking if gmp_printf supports \"%lld\"... " >&6; }
++if test "$cross_compiling" = yes; then
++ { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
++$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
++{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling
++See \`config.log' for more details." >&5
++$as_echo "$as_me: error: cannot run test program while cross compiling
++See \`config.log' for more details." >&2;}
++ { (exit 1); exit 1; }; }; }
++else
++ cat >conftest.$ac_ext <<_ACEOF
++/* confdefs.h. */
++_ACEOF
++cat confdefs.h >>conftest.$ac_ext
++cat >>conftest.$ac_ext <<_ACEOF
++/* end confdefs.h. */
++
++#include <stdio.h>
++
++#include <gmp.h>
++
++
++int
++main ()
++{
++
++ char s[256];
++ long long int a = 0;
++ return (gmp_sprintf (s, "%lld", a) != 1) ? 1 : 0;
++
++ ;
++ return 0;
++}
++_ACEOF
++rm -f conftest$ac_exeext
++if { (ac_try="$ac_link"
++case "(($ac_try" in
++ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
++ *) ac_try_echo=$ac_try;;
++esac
++eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
++$as_echo "$ac_try_echo") >&5
++ (eval "$ac_link") 2>&5
++ ac_status=$?
++ $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
++ (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
++ { (case "(($ac_try" in
++ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
++ *) ac_try_echo=$ac_try;;
++esac
++eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
++$as_echo "$ac_try_echo") >&5
++ (eval "$ac_try") 2>&5
++ ac_status=$?
++ $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
++ (exit $ac_status); }; }; then
++ { $as_echo "$as_me:$LINENO: result: yes" >&5
++$as_echo "yes" >&6; }
++
++else
++ $as_echo "$as_me: program exited with status $ac_status" >&5
++$as_echo "$as_me: failed program was:" >&5
++sed 's/^/| /' conftest.$ac_ext >&5
++
++( exit $ac_status )
++{ $as_echo "$as_me:$LINENO: result: no" >&5
++$as_echo "no" >&6; }
++
++cat >>confdefs.h <<\_ACEOF
++#define NPRINTF_LL 1
++_ACEOF
++
++fi
++rm -rf conftest.dSYM
++rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
++fi
++
++
++
++
++
+ { $as_echo "$as_me:$LINENO: checking if gmp_printf supports \"%.0Lf\"" >&5
+ $as_echo_n "checking if gmp_printf supports \"%.0Lf\"... " >&6; }
+ if test "$cross_compiling" = yes; then
+diff -Naurd mpfr-2.4.0-a/mpfr.h mpfr-2.4.0-b/mpfr.h
+--- mpfr-2.4.0-a/mpfr.h 2009-01-26 12:52:01.000000000 +0000
++++ mpfr-2.4.0-b/mpfr.h 2009-02-20 17:27:44.000000000 +0000
+@@ -27,7 +27,7 @@
+ #define MPFR_VERSION_MAJOR 2
+ #define MPFR_VERSION_MINOR 4
+ #define MPFR_VERSION_PATCHLEVEL 0
+-#define MPFR_VERSION_STRING "2.4.0"
++#define MPFR_VERSION_STRING "2.4.0-p1"
+
+ /* Macros dealing with MPFR VERSION */
+ #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
+diff -Naurd mpfr-2.4.0-a/tests/tfprintf.c mpfr-2.4.0-b/tests/tfprintf.c
+--- mpfr-2.4.0-a/tests/tfprintf.c 2009-01-26 12:52:00.000000000 +0000
++++ mpfr-2.4.0-b/tests/tfprintf.c 2009-02-20 16:31:02.000000000 +0000
+@@ -146,6 +146,7 @@
+ short sh = -1;
+ unsigned short ush = 1;
+ int i = -1;
++ int j = 1;
+ unsigned int ui = 1;
+ long lo = -1;
+ unsigned long ulo = 1;
+@@ -179,12 +180,11 @@
+
+ limb[0] = limb[1] = limb[2] = ~ (mp_limb_t) 0;
+
+- check_vfprintf (fout, "a. %Ra, b. %hhu, c. %u, d. %lx%hhn", mpfr, uch, ui,
+- ulo, &uch);
+- check_length (1, uch, 28, hhu);
+- check_vfprintf (fout, "a. %hhi, b. %Rb, c. %u, d. %li%ln", sch, mpfr, i,
++ check_vfprintf (fout, "a. %Ra, b. %u, c. %lx%n", mpfr, ui, ulo, &j);
++ check_length (1, j, 22, d);
++ check_vfprintf (fout, "a. %c, b. %Rb, c. %u, d. %li%ln", i, mpfr, i,
+ lo, &ulo);
+- check_length (2, ulo, 37, lu);
++ check_length (2, ulo, 36, lu);
+ check_vfprintf (fout, "a. %hi, b. %*f, c. %Re%hn", ush, 3, f, mpfr, &ush);
+ check_length (3, ush, 29, hu);
+ check_vfprintf (fout, "a. %hi, b. %f, c. %#.2Rf%n", sh, d, mpfr, &i);
+@@ -208,13 +208,18 @@
+ check_length (9, sz, 30, zu);
+ #endif
+
++#ifndef NPRINTF_HH
++ check_vfprintf (fout, "a. %hhi, b.%RA, c. %hhu%hhn", sch, mpfr, uch, &uch);
++ check_length (10, uch, 21, hhu);
++#endif
++
+ #if (__GNU_MP_VERSION * 10 + __GNU_MP_VERSION_MINOR) >= 42
+ /* The 'M' specifier was added in gmp 4.2.0 */
+ check_vfprintf (fout, "a. %Mx b. %Re%Mn", limb[0], mpfr, &limb[0]);
+ if (limb[0] != 14 + BITS_PER_MP_LIMB / 4 || limb[1] != ~ (mp_limb_t) 0
+ || limb[2] != ~ (mp_limb_t) 0)
+ {
+- printf ("Error in test #10: mpfr_vfprintf did not print %d characters"
++ printf ("Error in test #11: mpfr_vfprintf did not print %d characters"
+ " as expected\n", 14 + (int) BITS_PER_MP_LIMB / 4);
+ exit (1);
+ }
+@@ -227,13 +232,13 @@
+ if (limb[0] != 14 + 3 * BITS_PER_MP_LIMB / 4 || limb[1] != (mp_limb_t) 0
+ || limb[2] != ~ (mp_limb_t) 0)
+ {
+- printf ("Error in test #11: mpfr_vfprintf did not print %d characters"
++ printf ("Error in test #12: mpfr_vfprintf did not print %d characters"
+ " as expected\n", 14 + (int) BITS_PER_MP_LIMB / 4);
+ exit (1);
+ }
+ #endif
+
+-#ifdef HAVE_LONG_LONG
++#if defined(HAVE_LONG_LONG) && !defined(NPRINTF_LL)
+ {
+ long long llo = -1;
+ unsigned long long ullo = 1;
+diff -Naurd mpfr-2.4.0-a/tests/tprintf.c mpfr-2.4.0-b/tests/tprintf.c
+--- mpfr-2.4.0-a/tests/tprintf.c 2009-01-26 12:52:00.000000000 +0000
++++ mpfr-2.4.0-b/tests/tprintf.c 2009-02-20 16:31:02.000000000 +0000
+@@ -150,6 +150,7 @@
+ short sh = -1;
+ unsigned short ush = 1;
+ int i = -1;
++ int j = 1;
+ unsigned int ui = 1;
+ long lo = -1;
+ unsigned long ulo = 1;
+@@ -178,11 +179,10 @@
+ mpfr_set_f (mpfr, mpf, GMP_RNDN);
+ prec = mpfr_get_prec (mpfr);
+
+- check_vprintf ("a. %Ra, b. %hhu, c. %u, d. %lx%hhn", mpfr, uch, ui, ulo,
+- &uch);
+- check_length (1, uch, 28, hhu);
+- check_vprintf ("a. %hhi, b. %Rb, c. %u, d. %li%ln", sch, mpfr, i, lo, &ulo);
+- check_length (2, ulo, 37, lu);
++ check_vprintf ("a. %Ra, b. %u, c. %lx%n", mpfr, ui, ulo, &j);
++ check_length (1, j, 22, d);
++ check_vprintf ("a. %c, b. %Rb, c. %u, d. %li%ln", i, mpfr, i, lo, &ulo);
++ check_length (2, ulo, 36, lu);
+ check_vprintf ("a. %hi, b. %*f, c. %Re%hn", ush, 3, f, mpfr, &ush);
+ check_length (3, ush, 29, hu);
+ check_vprintf ("a. %hi, b. %f, c. %#.2Rf%n", sh, d, mpfr, &i);
+@@ -204,7 +204,12 @@
+ check_length (9, sz, 30, zu);
+ #endif
+
+-#ifdef HAVE_LONG_LONG
++#ifndef NPRINTF_HH
++ check_vprintf ("a. %hhi, b. %Ra, c. %hhu%hhn", sch, mpfr, uch, &uch);
++ check_length (10, uch, 22, hhu);
++#endif
++
++#if defined(HAVE_LONG_LONG) && !defined(NPRINTF_LL)
+ {
+ long long llo = -1;
+ unsigned long long ullo = 1;
+diff -Naurd mpfr-2.4.0-a/vasprintf.c mpfr-2.4.0-b/vasprintf.c
+--- mpfr-2.4.0-a/vasprintf.c 2009-01-26 12:52:01.000000000 +0000
++++ mpfr-2.4.0-b/vasprintf.c 2009-02-20 16:31:02.000000000 +0000
+@@ -235,10 +235,14 @@
+ break;
+ case 'h':
+ if (*++format == 'h')
++#ifndef NPRINTF_HH
+ {
+ ++format;
+ specinfo->arg_type = CHAR_ARG;
+ }
++#else
++ specinfo->arg_type = UNSUPPORTED;
++#endif
+ else
+ specinfo->arg_type = SHORT_ARG;
+ break;
+@@ -246,7 +250,7 @@
+ if (*++format == 'l')
+ {
+ ++format;
+-#ifdef HAVE_LONG_LONG
++#if defined (HAVE_LONG_LONG) && !defined(NPRINTF_LL)
+ specinfo->arg_type = LONG_LONG_ARG;
+ #else
+ specinfo->arg_type = UNSUPPORTED;
+diff -Naurd mpfr-2.4.0-a/version.c mpfr-2.4.0-b/version.c
+--- mpfr-2.4.0-a/version.c 2009-01-26 12:52:01.000000000 +0000
++++ mpfr-2.4.0-b/version.c 2009-02-20 17:27:44.000000000 +0000
+@@ -25,5 +25,5 @@
+ const char *
+ mpfr_get_version (void)
+ {
+- return "2.4.0";
++ return "2.4.0-p1";
+ }
diff --git a/patches/mpfr/2.4.0/110-mpfr_snprintf.patch b/patches/mpfr/2.4.0/110-mpfr_snprintf.patch
new file mode 100644
index 0000000..92af137
--- /dev/null
+++ b/patches/mpfr/2.4.0/110-mpfr_snprintf.patch
@@ -0,0 +1,176 @@
+diff -Naurd mpfr-2.4.0-a/PATCHES mpfr-2.4.0-b/PATCHES
+--- mpfr-2.4.0-a/PATCHES 2009-02-25 13:27:38.000000000 +0000
++++ mpfr-2.4.0-b/PATCHES 2009-02-25 13:42:26.000000000 +0000
+@@ -0,0 +1 @@
++mpfr_snprintf
+diff -Naurd mpfr-2.4.0-a/VERSION mpfr-2.4.0-b/VERSION
+--- mpfr-2.4.0-a/VERSION 2009-02-20 17:27:44.000000000 +0000
++++ mpfr-2.4.0-b/VERSION 2009-02-25 13:41:31.000000000 +0000
+@@ -1 +1 @@
+-2.4.0-p1
++2.4.0-p2
+diff -Naurd mpfr-2.4.0-a/mpfr.h mpfr-2.4.0-b/mpfr.h
+--- mpfr-2.4.0-a/mpfr.h 2009-02-20 17:27:44.000000000 +0000
++++ mpfr-2.4.0-b/mpfr.h 2009-02-25 13:41:31.000000000 +0000
+@@ -27,7 +27,7 @@
+ #define MPFR_VERSION_MAJOR 2
+ #define MPFR_VERSION_MINOR 4
+ #define MPFR_VERSION_PATCHLEVEL 0
+-#define MPFR_VERSION_STRING "2.4.0-p1"
++#define MPFR_VERSION_STRING "2.4.0-p2"
+
+ /* Macros dealing with MPFR VERSION */
+ #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
+diff -Naurd mpfr-2.4.0-a/printf.c mpfr-2.4.0-b/printf.c
+--- mpfr-2.4.0-a/printf.c 2009-01-26 12:52:01.000000000 +0000
++++ mpfr-2.4.0-b/printf.c 2009-02-25 13:41:22.000000000 +0000
+@@ -154,16 +154,16 @@
+ int ret;
+ size_t min_size;
+
+- /* C99 allows SIZE to be null */
+- if (size == 0)
+- return 0;
+-
+- MPFR_ASSERTD (buf != NULL);
+-
+ GET_STR (ret, str, fmt);
+- min_size = (size_t)ret < size ? (size_t)ret : size - 1;
+- strncpy (buf, str, min_size);
+- buf[min_size + 1] = '\0';
++
++ /* C99 allows SIZE to be zero */
++ if (size != 0)
++ {
++ MPFR_ASSERTN (buf != NULL);
++ min_size = (size_t)ret < size ? (size_t)ret : size - 1;
++ strncpy (buf, str, min_size);
++ buf[min_size] = '\0';
++ }
+
+ mpfr_free_str (str);
+ return ret;
+@@ -176,16 +176,17 @@
+ int ret;
+ int min_size;
+
+- /* C99 allows SIZE to be null */
+- if (size == 0)
+- return 0;
++ GET_STR_VA (ret, str, fmt, ap);
+
+- MPFR_ASSERTD (buf != NULL);
++ /* C99 allows SIZE to be zero */
++ if (size != 0)
++ {
++ MPFR_ASSERTN (buf != NULL);
++ min_size = (size_t)ret < size ? (size_t)ret : size - 1;
++ strncpy (buf, str, min_size);
++ buf[min_size] = '\0';
++ }
+
+- GET_STR_VA (ret, str, fmt, ap);
+- min_size = (size_t)ret < size ? (size_t)ret : size - 1;
+- strncpy (buf, str, min_size);
+- buf[min_size + 1] = '\0';
+ mpfr_free_str (str);
+ return ret;
+ }
+diff -Naurd mpfr-2.4.0-a/tests/tsprintf.c mpfr-2.4.0-b/tests/tsprintf.c
+--- mpfr-2.4.0-a/tests/tsprintf.c 2009-01-26 12:52:00.000000000 +0000
++++ mpfr-2.4.0-b/tests/tsprintf.c 2009-02-25 13:41:22.000000000 +0000
+@@ -72,21 +72,37 @@
+
+ /* test mpfr_snprintf */
+ p = (int) (randlimb () % n0);
+- n1 = mpfr_snprintf (buffer, p, fmt, x);
+- if ((p != 0 && n0 != n1) || (p == 0 && n1 != 0))
++ if (p == 0 && (randlimb () & 1) == 0)
++ {
++ n1 = mpfr_snprintf (NULL, 0, fmt, x);
++ }
++ else
++ {
++ buffer[p] = 17;
++ n1 = mpfr_snprintf (buffer, p, fmt, x);
++ if (buffer[p] != 17)
++ {
++ printf ("Buffer overflow in mpfr_snprintf for p = %d!\n", p);
++ exit (1);
++ }
++ }
++ if (n0 != n1)
+ {
+ printf ("Error in mpfr_snprintf (s, %d, \"%s\", x) return value\n",
+ p, fmt);
+ printf ("expected: %d\ngot: %d\n", n0, n1);
+ exit (1);
+ }
+- if (strncmp (expected, buffer, p) != 0)
++ if ((p > 1 && strncmp (expected, buffer, p-1) != 0)
++ || (p == 1 && buffer[0] != '\0'))
+ {
+- printf ("Error in mpfr_snprintf (s, %d, \"%s\", x);\n", p, fmt);
+- printf ("expected: \"%s\"\ngot: \"%s\"\n", expected, buffer);
++ char part_expected[p];
++ strncpy (part_expected, expected, p);
++ part_expected[p-1] = '\0';
++ printf ("Error in mpfr_vsnprintf (s, %d, \"%s\", ...);\n", p, fmt);
++ printf ("expected: \"%s\"\ngot: \"%s\"\n", part_expected, buffer);
+ exit (1);
+ }
+-
+ return n0;
+ }
+
+@@ -116,8 +132,21 @@
+
+ /* test mpfr_snprintf */
+ p = (int) (randlimb () % n0);
+- n1 = mpfr_vsnprintf (buffer, p, fmt, ap1);
+- if ((p != 0 && n0 != n1) || (p == 0 && n1 != 0))
++ if (p == 0 && (randlimb () & 1) == 0)
++ {
++ n1 = mpfr_vsnprintf (NULL, 0, fmt, ap1);
++ }
++ else
++ {
++ buffer[p] = 17;
++ n1 = mpfr_vsnprintf (buffer, p, fmt, ap1);
++ if (buffer[p] != 17)
++ {
++ printf ("Buffer overflow in mpfr_vsnprintf for p = %d!\n", p);
++ exit (1);
++ }
++ }
++ if (n0 != n1)
+ {
+ printf ("Error in mpfr_vsnprintf (s, %d, \"%s\", ...) return value\n",
+ p, fmt);
+@@ -126,10 +155,14 @@
+ va_end (ap1);
+ exit (1);
+ }
+- if (strncmp (expected, buffer, p) != 0)
++ if ((p > 1 && strncmp (expected, buffer, p-1) != 0)
++ || (p == 1 && buffer[0] != '\0'))
+ {
++ char part_expected[p];
++ strncpy (part_expected, expected, p);
++ part_expected[p-1] = '\0';
+ printf ("Error in mpfr_vsnprintf (s, %d, \"%s\", ...);\n", p, fmt);
+- printf ("expected: \"%s\"\ngot: \"%s\"\n", expected, buffer);
++ printf ("expected: \"%s\"\ngot: \"%s\"\n", part_expected, buffer);
+
+ va_end (ap1);
+ exit (1);
+diff -Naurd mpfr-2.4.0-a/version.c mpfr-2.4.0-b/version.c
+--- mpfr-2.4.0-a/version.c 2009-02-20 17:27:44.000000000 +0000
++++ mpfr-2.4.0-b/version.c 2009-02-25 13:41:31.000000000 +0000
+@@ -25,5 +25,5 @@
+ const char *
+ mpfr_get_version (void)
+ {
+- return "2.4.0-p1";
++ return "2.4.0-p2";
+ }
diff --git a/patches/mpfr/2.4.1/100-remainder-neg.patch b/patches/mpfr/2.4.1/100-remainder-neg.patch
new file mode 100644
index 0000000..ae92788
--- /dev/null
+++ b/patches/mpfr/2.4.1/100-remainder-neg.patch
@@ -0,0 +1,123 @@
+diff -Naurd mpfr-2.4.1-a/PATCHES mpfr-2.4.1-b/PATCHES
+--- mpfr-2.4.1-a/PATCHES 2009-02-20 09:43:17.000000000 +0000
++++ mpfr-2.4.1-b/PATCHES 2009-02-27 16:56:29.000000000 +0000
+@@ -0,0 +1 @@
++remainder-neg
+diff -Naurd mpfr-2.4.1-a/VERSION mpfr-2.4.1-b/VERSION
+--- mpfr-2.4.1-a/VERSION 2009-02-25 16:16:08.000000000 +0000
++++ mpfr-2.4.1-b/VERSION 2009-02-27 16:55:37.000000000 +0000
+@@ -1 +1 @@
+-2.4.1
++2.4.1-p1
+diff -Naurd mpfr-2.4.1-a/mpfr.h mpfr-2.4.1-b/mpfr.h
+--- mpfr-2.4.1-a/mpfr.h 2009-02-25 16:16:08.000000000 +0000
++++ mpfr-2.4.1-b/mpfr.h 2009-02-27 16:55:38.000000000 +0000
+@@ -27,7 +27,7 @@
+ #define MPFR_VERSION_MAJOR 2
+ #define MPFR_VERSION_MINOR 4
+ #define MPFR_VERSION_PATCHLEVEL 1
+-#define MPFR_VERSION_STRING "2.4.1"
++#define MPFR_VERSION_STRING "2.4.1-p1"
+
+ /* Macros dealing with MPFR VERSION */
+ #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
+diff -Naurd mpfr-2.4.1-a/rem1.c mpfr-2.4.1-b/rem1.c
+--- mpfr-2.4.1-a/rem1.c 2009-02-20 09:43:17.000000000 +0000
++++ mpfr-2.4.1-b/rem1.c 2009-02-27 16:55:15.000000000 +0000
+@@ -170,7 +170,12 @@
+ }
+
+ if (mpz_cmp_ui (r, 0) == 0)
+- inex = mpfr_set_ui (rem, 0, GMP_RNDN);
++ {
++ inex = mpfr_set_ui (rem, 0, GMP_RNDN);
++ /* take into account sign of x */
++ if (signx < 0)
++ mpfr_neg (rem, rem, GMP_RNDN);
++ }
+ else
+ {
+ if (rnd_q == GMP_RNDN)
+@@ -190,6 +195,9 @@
+ *quo += 1;
+ }
+ }
++ /* take into account sign of x */
++ if (signx < 0)
++ mpz_neg (r, r);
+ inex = mpfr_set_z (rem, r, rnd);
+ /* if ex > ey, rem should be multiplied by 2^ey, else by 2^ex */
+ MPFR_EXP (rem) += (ex > ey) ? ey : ex;
+@@ -198,13 +206,6 @@
+ if (quo)
+ *quo *= sign;
+
+- /* take into account sign of x */
+- if (signx < 0)
+- {
+- mpfr_neg (rem, rem, GMP_RNDN);
+- inex = -inex;
+- }
+-
+ mpz_clear (mx);
+ mpz_clear (my);
+ mpz_clear (r);
+diff -Naurd mpfr-2.4.1-a/tests/tremquo.c mpfr-2.4.1-b/tests/tremquo.c
+--- mpfr-2.4.1-a/tests/tremquo.c 2009-02-20 09:43:15.000000000 +0000
++++ mpfr-2.4.1-b/tests/tremquo.c 2009-02-27 16:55:15.000000000 +0000
+@@ -25,6 +25,36 @@
+
+ #include "mpfr-test.h"
+
++static void
++bug20090227 (void)
++{
++ mpfr_t x, y, r1, r2;
++ int inex1, inex2;
++
++ mpfr_init2 (x, 118);
++ mpfr_init2 (y, 181);
++ mpfr_init2 (r1, 140);
++ mpfr_init2 (r2, 140);
++ mpfr_set_si (x, -1, GMP_RNDN);
++ mpfr_set_str_binary (y, "1.100100100001111110110101010001000100001011010001100001000110100110001001100011001100010100010111000000011011100000111001101000100101001000000100100111000001000100010100110011111010");
++ inex1 = mpfr_remainder (r1, x, y, GMP_RNDU);
++ /* since the quotient is -1, r1 is the rounding of x+y */
++ inex2 = mpfr_add (r2, x, y, GMP_RNDU);
++ if (mpfr_cmp (r1, r2))
++ {
++ printf ("Error in mpfr_remainder (bug20090227)\n");
++ printf ("Expected ");
++ mpfr_dump (r2);
++ printf ("Got ");
++ mpfr_dump (r1);
++ exit (1);
++ }
++ mpfr_clear (x);
++ mpfr_clear (y);
++ mpfr_clear (r1);
++ mpfr_clear (r2);
++}
++
+ int
+ main (int argc, char *argv[])
+ {
+@@ -50,6 +80,8 @@
+
+ tests_start_mpfr ();
+
++ bug20090227 ();
++
+ mpfr_init (x);
+ mpfr_init (y);
+ mpfr_init (r);
+diff -Naurd mpfr-2.4.1-a/version.c mpfr-2.4.1-b/version.c
+--- mpfr-2.4.1-a/version.c 2009-02-25 16:16:08.000000000 +0000
++++ mpfr-2.4.1-b/version.c 2009-02-27 16:55:38.000000000 +0000
+@@ -25,5 +25,5 @@
+ const char *
+ mpfr_get_version (void)
+ {
+- return "2.4.1";
++ return "2.4.1-p1";
+ }
diff --git a/patches/mpfr/2.4.1/110-assert.patch b/patches/mpfr/2.4.1/110-assert.patch
new file mode 100644
index 0000000..c6b6aac
--- /dev/null
+++ b/patches/mpfr/2.4.1/110-assert.patch
@@ -0,0 +1,45 @@
+diff -Naurd mpfr-2.4.1-a/PATCHES mpfr-2.4.1-b/PATCHES
+--- mpfr-2.4.1-a/PATCHES 2009-03-04 13:15:05.000000000 +0000
++++ mpfr-2.4.1-b/PATCHES 2009-03-04 13:17:04.000000000 +0000
+@@ -0,0 +1 @@
++assert
+diff -Naurd mpfr-2.4.1-a/VERSION mpfr-2.4.1-b/VERSION
+--- mpfr-2.4.1-a/VERSION 2009-02-27 16:55:37.000000000 +0000
++++ mpfr-2.4.1-b/VERSION 2009-03-04 13:16:46.000000000 +0000
+@@ -1 +1 @@
+-2.4.1-p1
++2.4.1-p2
+diff -Naurd mpfr-2.4.1-a/mpfr-gmp.c mpfr-2.4.1-b/mpfr-gmp.c
+--- mpfr-2.4.1-a/mpfr-gmp.c 2009-02-20 09:43:17.000000000 +0000
++++ mpfr-2.4.1-b/mpfr-gmp.c 2009-03-04 13:16:39.000000000 +0000
+@@ -301,7 +301,7 @@
+ if (linenum != -1)
+ fprintf (stderr, "%d: ", linenum);
+ }
+- fprintf (stderr, " assertion failed: %s\n", expr);
++ fprintf (stderr, "MPFR assertion failed: %s\n", expr);
+ abort();
+ }
+
+diff -Naurd mpfr-2.4.1-a/mpfr.h mpfr-2.4.1-b/mpfr.h
+--- mpfr-2.4.1-a/mpfr.h 2009-02-27 16:55:38.000000000 +0000
++++ mpfr-2.4.1-b/mpfr.h 2009-03-04 13:16:46.000000000 +0000
+@@ -27,7 +27,7 @@
+ #define MPFR_VERSION_MAJOR 2
+ #define MPFR_VERSION_MINOR 4
+ #define MPFR_VERSION_PATCHLEVEL 1
+-#define MPFR_VERSION_STRING "2.4.1-p1"
++#define MPFR_VERSION_STRING "2.4.1-p2"
+
+ /* Macros dealing with MPFR VERSION */
+ #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
+diff -Naurd mpfr-2.4.1-a/version.c mpfr-2.4.1-b/version.c
+--- mpfr-2.4.1-a/version.c 2009-02-27 16:55:38.000000000 +0000
++++ mpfr-2.4.1-b/version.c 2009-03-04 13:16:46.000000000 +0000
+@@ -25,5 +25,5 @@
+ const char *
+ mpfr_get_version (void)
+ {
+- return "2.4.1-p1";
++ return "2.4.1-p2";
+ }