patches/mpfr/2.4.0/110-mpfr_snprintf.patch
author Anthony Foiani <anthony.foiani@gmail.com>
Thu May 19 23:06:16 2011 +0200 (2011-05-19)
changeset 2461 ec30b191f0e3
permissions -rw-r--r--
complibs/ppl: build only C and C++ interfaces for PPL

By default, PPL wants to build interfaces for any of a variety of
langauges it finds on the local host (python, java, possibly perl, also
more esoteric languages such as ocaml and prolog).

These extra interfaces can double the compile time for the library. For
single-process builds, I found a savings of more than 40%:

default / j1: 716s total, 143.2s avg, 0.52s stdev
just_c / j1: 406s total, 81.2s avg, 0.33s stdev
just_c_cpp / j1: 413s total, 82.6s avg, 0.22s stdev

And for multi-process builds, it approached 50%:

default / j4: 625s total, 125.0s avg, 0.57s stdev
just_c / j4: 338s total, 67.6s avg, 1.25s stdev
just_c_cpp / j4: 327s total, 65.4s avg, 0.36s stdev

Since the PPL we build within ct-ng is only used by GCC, we only need to
build the C and C++ interfaces.

Signed-Off-By: Anthony Foiani <anthony.foiani@gmail.com>
     1 diff -Naurd mpfr-2.4.0-a/PATCHES mpfr-2.4.0-b/PATCHES
     2 --- mpfr-2.4.0-a/PATCHES	2009-02-25 13:27:38.000000000 +0000
     3 +++ mpfr-2.4.0-b/PATCHES	2009-02-25 13:42:26.000000000 +0000
     4 @@ -0,0 +1 @@
     5 +mpfr_snprintf
     6 diff -Naurd mpfr-2.4.0-a/VERSION mpfr-2.4.0-b/VERSION
     7 --- mpfr-2.4.0-a/VERSION	2009-02-20 17:27:44.000000000 +0000
     8 +++ mpfr-2.4.0-b/VERSION	2009-02-25 13:41:31.000000000 +0000
     9 @@ -1 +1 @@
    10 -2.4.0-p1
    11 +2.4.0-p2
    12 diff -Naurd mpfr-2.4.0-a/mpfr.h mpfr-2.4.0-b/mpfr.h
    13 --- mpfr-2.4.0-a/mpfr.h	2009-02-20 17:27:44.000000000 +0000
    14 +++ mpfr-2.4.0-b/mpfr.h	2009-02-25 13:41:31.000000000 +0000
    15 @@ -27,7 +27,7 @@
    16  #define MPFR_VERSION_MAJOR 2
    17  #define MPFR_VERSION_MINOR 4
    18  #define MPFR_VERSION_PATCHLEVEL 0
    19 -#define MPFR_VERSION_STRING "2.4.0-p1"
    20 +#define MPFR_VERSION_STRING "2.4.0-p2"
    21  
    22  /* Macros dealing with MPFR VERSION */
    23  #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
    24 diff -Naurd mpfr-2.4.0-a/printf.c mpfr-2.4.0-b/printf.c
    25 --- mpfr-2.4.0-a/printf.c	2009-01-26 12:52:01.000000000 +0000
    26 +++ mpfr-2.4.0-b/printf.c	2009-02-25 13:41:22.000000000 +0000
    27 @@ -154,16 +154,16 @@
    28    int ret;
    29    size_t min_size;
    30  
    31 -  /* C99 allows SIZE to be null */
    32 -  if (size == 0)
    33 -    return 0;
    34 -
    35 -  MPFR_ASSERTD (buf != NULL);
    36 -
    37    GET_STR (ret, str, fmt);
    38 -  min_size = (size_t)ret < size ? (size_t)ret : size - 1;
    39 -  strncpy (buf, str, min_size);
    40 -  buf[min_size + 1] = '\0';
    41 +
    42 +  /* C99 allows SIZE to be zero */
    43 +  if (size != 0)
    44 +    {
    45 +      MPFR_ASSERTN (buf != NULL);
    46 +      min_size = (size_t)ret < size ? (size_t)ret : size - 1;
    47 +      strncpy (buf, str, min_size);
    48 +      buf[min_size] = '\0';
    49 +    }
    50  
    51    mpfr_free_str (str);
    52    return ret;
    53 @@ -176,16 +176,17 @@
    54    int ret;
    55    int min_size;
    56  
    57 -  /* C99 allows SIZE to be null */
    58 -  if (size == 0)
    59 -    return 0;
    60 +  GET_STR_VA (ret, str, fmt, ap);
    61  
    62 -  MPFR_ASSERTD (buf != NULL);
    63 +  /* C99 allows SIZE to be zero */
    64 +  if (size != 0)
    65 +    {
    66 +      MPFR_ASSERTN (buf != NULL);
    67 +      min_size = (size_t)ret < size ? (size_t)ret : size - 1;
    68 +      strncpy (buf, str, min_size);
    69 +      buf[min_size] = '\0';
    70 +    }
    71  
    72 -  GET_STR_VA (ret, str, fmt, ap);
    73 -  min_size = (size_t)ret < size ? (size_t)ret : size - 1;
    74 -  strncpy (buf, str, min_size);
    75 -  buf[min_size + 1] = '\0';
    76    mpfr_free_str (str);
    77    return ret;
    78  }
    79 diff -Naurd mpfr-2.4.0-a/tests/tsprintf.c mpfr-2.4.0-b/tests/tsprintf.c
    80 --- mpfr-2.4.0-a/tests/tsprintf.c	2009-01-26 12:52:00.000000000 +0000
    81 +++ mpfr-2.4.0-b/tests/tsprintf.c	2009-02-25 13:41:22.000000000 +0000
    82 @@ -72,21 +72,37 @@
    83  
    84    /* test mpfr_snprintf */
    85    p = (int) (randlimb () % n0);
    86 -  n1 = mpfr_snprintf (buffer, p, fmt, x);
    87 -  if ((p != 0 && n0 != n1) || (p == 0 && n1 != 0))
    88 +  if (p == 0 && (randlimb () & 1) == 0)
    89 +    {
    90 +      n1 = mpfr_snprintf (NULL, 0, fmt, x);
    91 +    }
    92 +  else
    93 +    {
    94 +      buffer[p] = 17;
    95 +      n1 = mpfr_snprintf (buffer, p, fmt, x);
    96 +      if (buffer[p] != 17)
    97 +        {
    98 +          printf ("Buffer overflow in mpfr_snprintf for p = %d!\n", p);
    99 +          exit (1);
   100 +        }
   101 +    }
   102 +  if (n0 != n1)
   103      {
   104        printf ("Error in mpfr_snprintf (s, %d, \"%s\", x) return value\n",
   105                p, fmt);
   106        printf ("expected: %d\ngot:      %d\n", n0, n1);
   107        exit (1);
   108      }
   109 -  if (strncmp (expected, buffer, p) != 0)
   110 +  if ((p > 1 && strncmp (expected, buffer, p-1) != 0)
   111 +      || (p == 1 && buffer[0] != '\0'))
   112      {
   113 -      printf ("Error in mpfr_snprintf (s, %d, \"%s\", x);\n", p, fmt);
   114 -      printf ("expected: \"%s\"\ngot:      \"%s\"\n", expected, buffer);
   115 +      char part_expected[p];
   116 +      strncpy (part_expected, expected, p);
   117 +      part_expected[p-1] = '\0';
   118 +      printf ("Error in mpfr_vsnprintf (s, %d, \"%s\", ...);\n", p, fmt);
   119 +      printf ("expected: \"%s\"\ngot:      \"%s\"\n", part_expected, buffer);
   120        exit (1);
   121      }
   122 -
   123    return n0;
   124  }
   125  
   126 @@ -116,8 +132,21 @@
   127  
   128    /* test mpfr_snprintf */
   129    p = (int) (randlimb () % n0);
   130 -  n1 = mpfr_vsnprintf (buffer, p, fmt, ap1);
   131 -  if ((p != 0 && n0 != n1) || (p == 0 && n1 != 0))
   132 +  if (p == 0 && (randlimb () & 1) == 0)
   133 +    {
   134 +      n1 = mpfr_vsnprintf (NULL, 0, fmt, ap1);
   135 +    }
   136 +  else
   137 +    {
   138 +      buffer[p] = 17;
   139 +      n1 = mpfr_vsnprintf (buffer, p, fmt, ap1);
   140 +      if (buffer[p] != 17)
   141 +        {
   142 +          printf ("Buffer overflow in mpfr_vsnprintf for p = %d!\n", p);
   143 +          exit (1);
   144 +        }
   145 +    }
   146 +  if (n0 != n1)
   147      {
   148        printf ("Error in mpfr_vsnprintf (s, %d, \"%s\", ...) return value\n",
   149                p, fmt);
   150 @@ -126,10 +155,14 @@
   151        va_end (ap1);
   152        exit (1);
   153      }
   154 -  if (strncmp (expected, buffer, p) != 0)
   155 +  if ((p > 1 && strncmp (expected, buffer, p-1) != 0)
   156 +      || (p == 1 && buffer[0] != '\0'))
   157      {
   158 +      char part_expected[p];
   159 +      strncpy (part_expected, expected, p);
   160 +      part_expected[p-1] = '\0';
   161        printf ("Error in mpfr_vsnprintf (s, %d, \"%s\", ...);\n", p, fmt);
   162 -      printf ("expected: \"%s\"\ngot:      \"%s\"\n", expected, buffer);
   163 +      printf ("expected: \"%s\"\ngot:      \"%s\"\n", part_expected, buffer);
   164  
   165        va_end (ap1);
   166        exit (1);
   167 diff -Naurd mpfr-2.4.0-a/version.c mpfr-2.4.0-b/version.c
   168 --- mpfr-2.4.0-a/version.c	2009-02-20 17:27:44.000000000 +0000
   169 +++ mpfr-2.4.0-b/version.c	2009-02-25 13:41:31.000000000 +0000
   170 @@ -25,5 +25,5 @@
   171  const char *
   172  mpfr_get_version (void)
   173  {
   174 -  return "2.4.0-p1";
   175 +  return "2.4.0-p2";
   176  }