1/* clear_parameters -- Deallocate memory for function parameters.
2
3Copyright (C) 2012, 2013, 2014 INRIA
4
5This file is part of GNU MPC.
6
7GNU MPC is free software; you can redistribute it and/or modify it under
8the terms of the GNU Lesser General Public License as published by the
9Free Software Foundation; either version 3 of the License, or (at your
10option) any later version.
11
12GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15more details.
16
17You should have received a copy of the GNU Lesser General Public License
18along with this program. If not, see http://www.gnu.org/licenses/ .
19*/
20
21#include "mpc-tests.h"
22
23static void
24clear_param (mpc_operand_t* p, mpc_param_t t)
25{
26  switch (t)
27    {
28    case NATIVE_INT:
29    case NATIVE_UL:
30    case NATIVE_L:
31    case NATIVE_D:
32      break;
33
34    case GMP_Z:
35      mpz_clear (p->mpz);
36      break;
37    case GMP_Q:
38      mpq_clear (p->mpq);
39      break;
40    case GMP_F:
41      mpf_clear (p->mpf);
42      break;
43
44    case MPFR_INEX:
45      break;
46    case MPFR:
47      mpfr_clear (p->mpfr);
48      break;
49
50    case MPC_INEX:
51    case MPCC_INEX:
52      break;
53    case MPC:
54      mpc_clear (p->mpc);
55      break;
56
57    case MPFR_RND:
58    case MPC_RND:
59      break;
60
61    default:
62      fprintf (stderr, "clear_parameters: unsupported type.\n");
63      exit (1);
64    }
65}
66
67void
68clear_parameters (mpc_fun_param_t *params)
69{
70  int in, out;
71  int total = params->nbout + params->nbin;
72
73  free (params->name);
74  for (out = 0; out < params->nbout; out++)
75    {
76      clear_param (&(params->P[out]), params->T[out]);
77      clear_param (&(params->P[total + out]), params->T[out]);
78    }
79
80  for (in = params->nbout; in < total; in++)
81    {
82      clear_param (&(params->P[in]), params->T[in]);
83    }
84}
85