"Fossies" - the Fresh Open Source Software Archive

Member "mpfr-4.0.2/tests/talloc.c" (7 Jan 2019, 2421 Bytes) of package /linux/misc/mpfr-4.0.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "talloc.c": 4.0.1_vs_4.0.2.

    1 /* talloc -- test file concerning memory allocation
    2 
    3 Copyright 2015-2019 Free Software Foundation, Inc.
    4 Contributed by the AriC and Caramba projects, INRIA.
    5 
    6 This file is part of the GNU MPFR Library.
    7 
    8 The GNU MPFR Library is free software; you can redistribute it and/or modify
    9 it under the terms of the GNU Lesser General Public License as published by
   10 the Free Software Foundation; either version 3 of the License, or (at your
   11 option) any later version.
   12 
   13 The GNU MPFR Library is distributed in the hope that it will be useful, but
   14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   15 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
   16 License for more details.
   17 
   18 You should have received a copy of the GNU Lesser General Public License
   19 along with the GNU MPFR Library; see the file COPYING.LESSER.  If not, see
   20 https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
   21 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
   22 
   23 #include "mpfr-test.h"
   24 
   25 /* We enable the test only when MPFR_ALLOCA_MAX is not greater than the
   26    default value: we do not want to make the test fail if the user has
   27    redefined MPFR_ALLOCA_MAX to a very large value. */
   28 
   29 /* Needed with --with-gmp-build */
   30 #ifndef MPFR_ALLOCA_MAX
   31 # define MPFR_ALLOCA_MAX 16384
   32 #endif
   33 
   34 /* ISO C99 is needed by MPFR_DECL_INIT. */
   35 #if __MPFR_STDC (199901L) && MPFR_ALLOCA_MAX <= 16384
   36 
   37 int
   38 main (void)
   39 {
   40   MPFR_DECL_INIT (x, 4 + MPFR_ALLOCA_MAX * CHAR_BIT);
   41   MPFR_DECL_INIT (y, 8 + MPFR_ALLOCA_MAX * CHAR_BIT);
   42 
   43   tests_start_mpfr ();
   44 
   45   /* We do not want to use mpfr_add1sp because if MPFR_WANT_ASSERT >= 2,
   46      mpfr_init is used. The following test is based on the fact that
   47      MPFR_TMP_LIMBS_ALLOC is used in mpfr_add1 before any other form
   48      of memory allocation. In r9454, this crashes because the memory
   49      allocation function used by this macro (under the condition that
   50      the size is > MPFR_ALLOCA_MAX) isn't defined yet. This bug comes
   51      from r8813.
   52      WARNING! Do not add MPFR calls before this test. Otherwise the
   53      mentioned problem may no longer be actually tested, making this
   54      test useless. For other allocation tests, it is better to use a
   55      different test file. */
   56   mpfr_set_ui (x, 1, MPFR_RNDN);
   57   mpfr_set_ui (y, 2, MPFR_RNDN);
   58   mpfr_add (x, x, y, MPFR_RNDN);
   59 
   60   tests_end_mpfr ();
   61   return 0;
   62 }
   63 
   64 #else
   65 
   66 int
   67 main (void)
   68 {
   69   return 77;
   70 }
   71 
   72 #endif