Use gdbpy_ref to simplify some logic
[binutils-gdb.git] / libdecnumber / decNumber.c
index ebc7cf0fb50bffbdde33e0ab071b484bfd3bd24d..72cdbf2ac1f68ef929f3086184c7bb3f9022c005 100644 (file)
@@ -1,32 +1,27 @@
 /* Decimal number arithmetic module for the decNumber C Library.
 /* Decimal number arithmetic module for the decNumber C Library.
-   Copyright (C) 2005, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2005-2013 Free Software Foundation, Inc.
    Contributed by IBM Corporation.  Author Mike Cowlishaw.
 
    This file is part of GCC.
 
    GCC is free software; you can redistribute it and/or modify it under
    the terms of the GNU General Public License as published by the Free
    Contributed by IBM Corporation.  Author Mike Cowlishaw.
 
    This file is part of GCC.
 
    GCC is free software; you can redistribute it and/or modify it under
    the terms of the GNU General Public License as published by the Free
-   Software Foundation; either version 2, or (at your option) any later
+   Software Foundation; either version 3, or (at your option) any later
    version.
 
    version.
 
-   In addition to the permissions in the GNU General Public License,
-   the Free Software Foundation gives you unlimited permission to link
-   the compiled version of this file into combinations with other
-   programs, and to distribute those combinations without any
-   restriction coming from the use of this file.  (The General Public
-   License restrictions do apply in other respects; for example, they
-   cover modification of the file, and distribution when not linked
-   into a combine executable.)
-
    GCC is distributed in the hope that it will be useful, but WITHOUT ANY
    WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.
 
    GCC is distributed in the hope that it will be useful, but WITHOUT ANY
    WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.
 
-   You should have received a copy of the GNU General Public License
-   along with GCC; see the file COPYING.  If not, write to the Free
-   Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA.  */
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
 
 /* ------------------------------------------------------------------ */
 /* Decimal Number arithmetic module                                  */
 
 /* ------------------------------------------------------------------ */
 /* Decimal Number arithmetic module                                  */
@@ -716,7 +711,7 @@ decNumber * decNumberFromString(decNumber *dn, const char chars[],
     /* decNumberShow(dn); */
     } while(0);                        /* [for break] */
 
     /* decNumberShow(dn); */
     } while(0);                        /* [for break] */
 
-  if (allocres!=NULL) free(allocres);  /* drop any storage used */
+  free(allocres);      /* drop any storage used */
   if (status!=0) decStatus(dn, status, set);
   return dn;
   } /* decNumberFromString */
   if (status!=0) decStatus(dn, status, set);
   return dn;
   } /* decNumberFromString */
@@ -975,8 +970,8 @@ decNumber * decNumberCompareTotalMag(decNumber *res, const decNumber *lhs,
     decCompareOp(res, lhs, rhs, set, COMPTOTAL, &status);
     } while(0);                        /* end protected */
 
     decCompareOp(res, lhs, rhs, set, COMPTOTAL, &status);
     } while(0);                        /* end protected */
 
-  if (allocbufa!=NULL) free(allocbufa); /* drop any storage used */
-  if (allocbufb!=NULL) free(allocbufb); /* .. */
+  free(allocbufa); /* drop any storage used */
+  free(allocbufb); /* .. */
   if (status!=0) decStatus(res, status, set);
   return res;
   } /* decNumberCompareTotalMag */
   if (status!=0) decStatus(res, status, set);
   return res;
   } /* decNumberCompareTotalMag */
@@ -1079,7 +1074,7 @@ decNumber * decNumberExp(decNumber *res, const decNumber *rhs,
     } while(0);                        /* end protected */
 
   #if DECSUBSET
     } while(0);                        /* end protected */
 
   #if DECSUBSET
-  if (allocrhs !=NULL) free(allocrhs); /* drop any storage used */
+  free(allocrhs);      /* drop any storage used */
   #endif
   /* apply significant status */
   if (status!=0) decStatus(res, status, set);
   #endif
   /* apply significant status */
   if (status!=0) decStatus(res, status, set);
@@ -1174,7 +1169,7 @@ decNumber * decNumberFMA(decNumber *res, const decNumber *lhs,
     decAddOp(res, acc, fhs, set, 0, &status);
     } while(0);                        /* end protected */
 
     decAddOp(res, acc, fhs, set, 0, &status);
     } while(0);                        /* end protected */
 
-  if (allocbufa!=NULL) free(allocbufa); /* drop any storage used */
+  free(allocbufa); /* drop any storage used */
   if (status!=0) decStatus(res, status, set);
   #if DECCHECK
   decCheckInexact(res, set);
   if (status!=0) decStatus(res, status, set);
   #if DECCHECK
   decCheckInexact(res, set);
@@ -1301,7 +1296,7 @@ decNumber * decNumberLn(decNumber *res, const decNumber *rhs,
     } while(0);                        /* end protected */
 
   #if DECSUBSET
     } while(0);                        /* end protected */
 
   #if DECSUBSET
-  if (allocrhs !=NULL) free(allocrhs); /* drop any storage used */
+  free(allocrhs);      /* drop any storage used */
   #endif
   /* apply significant status */
   if (status!=0) decStatus(res, status, set);
   #endif
   /* apply significant status */
   if (status!=0) decStatus(res, status, set);
@@ -1514,10 +1509,10 @@ decNumber * decNumberLog10(decNumber *res, const decNumber *rhs,
     decDivideOp(res, a, b, &aset, DIVIDE, &status); /* into result */
     } while(0);                        /* [for break] */
 
     decDivideOp(res, a, b, &aset, DIVIDE, &status); /* into result */
     } while(0);                        /* [for break] */
 
-  if (allocbufa!=NULL) free(allocbufa); /* drop any storage used */
-  if (allocbufb!=NULL) free(allocbufb); /* .. */
+  free(allocbufa); /* drop any storage used */
+  free(allocbufb); /* .. */
   #if DECSUBSET
   #if DECSUBSET
-  if (allocrhs !=NULL) free(allocrhs); /* .. */
+  free(allocrhs);      /* .. */
   #endif
   /* apply significant status */
   if (status!=0) decStatus(res, status, set);
   #endif
   /* apply significant status */
   if (status!=0) decStatus(res, status, set);
@@ -2258,11 +2253,11 @@ decNumber * decNumberPower(decNumber *res, const decNumber *lhs,
     #endif
     } while(0);                        /* end protected */
 
     #endif
     } while(0);                        /* end protected */
 
-  if (allocdac!=NULL) free(allocdac);  /* drop any storage used */
-  if (allocinv!=NULL) free(allocinv);  /* .. */
+  free(allocdac);      /* drop any storage used */
+  free(allocinv);      /* .. */
   #if DECSUBSET
   #if DECSUBSET
-  if (alloclhs!=NULL) free(alloclhs);  /* .. */
-  if (allocrhs!=NULL) free(allocrhs);  /* .. */
+  free(alloclhs);      /* .. */
+  free(allocrhs);      /* .. */
   #endif
   if (status!=0) decStatus(res, status, set);
   #if DECCHECK
   #endif
   if (status!=0) decStatus(res, status, set);
   #if DECCHECK
@@ -2354,7 +2349,7 @@ decNumber * decNumberReduce(decNumber *res, const decNumber *rhs,
     } while(0);                             /* end protected */
 
   #if DECSUBSET
     } while(0);                             /* end protected */
 
   #if DECSUBSET
-  if (allocrhs !=NULL) free(allocrhs);      /* .. */
+  free(allocrhs);           /* .. */
   #endif
   if (status!=0) decStatus(res, status, set);/* then report status */
   return res;
   #endif
   if (status!=0) decStatus(res, status, set);/* then report status */
   return res;
@@ -3116,11 +3111,11 @@ decNumber * decNumberSquareRoot(decNumber *res, const decNumber *rhs,
     decNumberCopy(res, a);                  /* a is now the result */
     } while(0);                             /* end protected */
 
     decNumberCopy(res, a);                  /* a is now the result */
     } while(0);                             /* end protected */
 
-  if (allocbuff!=NULL) free(allocbuff);      /* drop any storage used */
-  if (allocbufa!=NULL) free(allocbufa);      /* .. */
-  if (allocbufb!=NULL) free(allocbufb);      /* .. */
+  free(allocbuff);      /* drop any storage used */
+  free(allocbufa);      /* .. */
+  free(allocbufb);      /* .. */
   #if DECSUBSET
   #if DECSUBSET
-  if (allocrhs !=NULL) free(allocrhs);      /* .. */
+  free(allocrhs);           /* .. */
   #endif
   if (status!=0) decStatus(res, status, set);/* then report status */
   #if DECCHECK
   #endif
   if (status!=0) decStatus(res, status, set);/* then report status */
   #if DECCHECK
@@ -4135,10 +4130,10 @@ static decNumber * decAddOp(decNumber *res, const decNumber *lhs,
       }
     } while(0);                             /* end protected */
 
       }
     } while(0);                             /* end protected */
 
-  if (allocacc!=NULL) free(allocacc);       /* drop any storage used */
+  free(allocacc);           /* drop any storage used */
   #if DECSUBSET
   #if DECSUBSET
-  if (allocrhs!=NULL) free(allocrhs);       /* .. */
-  if (alloclhs!=NULL) free(alloclhs);       /* .. */
+  free(allocrhs);           /* .. */
+  free(alloclhs);           /* .. */
   #endif
   return res;
   } /* decAddOp */
   #endif
   return res;
   } /* decAddOp */
@@ -4787,11 +4782,11 @@ static decNumber * decDivideOp(decNumber *res,
     #endif
     } while(0);                             /* end protected */
 
     #endif
     } while(0);                             /* end protected */
 
-  if (varalloc!=NULL) free(varalloc);  /* drop any storage used */
-  if (allocacc!=NULL) free(allocacc);  /* .. */
+  free(varalloc);      /* drop any storage used */
+  free(allocacc);      /* .. */
   #if DECSUBSET
   #if DECSUBSET
-  if (allocrhs!=NULL) free(allocrhs);  /* .. */
-  if (alloclhs!=NULL) free(alloclhs);  /* .. */
+  free(allocrhs);      /* .. */
+  free(alloclhs);      /* .. */
   #endif
   return res;
   } /* decDivideOp */
   #endif
   return res;
   } /* decDivideOp */
@@ -5132,14 +5127,14 @@ static decNumber * decMultiplyOp(decNumber *res, const decNumber *lhs,
     decFinish(res, set, &residue, status);   /* final cleanup */
     } while(0);                        /* end protected */
 
     decFinish(res, set, &residue, status);   /* final cleanup */
     } while(0);                        /* end protected */
 
-  if (allocacc!=NULL) free(allocacc);  /* drop any storage used */
+  free(allocacc);      /* drop any storage used */
   #if DECSUBSET
   #if DECSUBSET
-  if (allocrhs!=NULL) free(allocrhs);  /* .. */
-  if (alloclhs!=NULL) free(alloclhs);  /* .. */
+  free(allocrhs);      /* .. */
+  free(alloclhs);      /* .. */
   #endif
   #if FASTMUL
   #endif
   #if FASTMUL
-  if (allocrhi!=NULL) free(allocrhi);  /* .. */
-  if (alloclhi!=NULL) free(alloclhi);  /* .. */
+  free(allocrhi);      /* .. */
+  free(alloclhi);      /* .. */
   #endif
   return res;
   } /* decMultiplyOp */
   #endif
   return res;
   } /* decMultiplyOp */
@@ -5488,9 +5483,9 @@ decNumber * decExpOp(decNumber *res, const decNumber *rhs,
     decFinish(res, set, &residue, status);      /* cleanup/set flags */
     } while(0);                        /* end protected */
 
     decFinish(res, set, &residue, status);      /* cleanup/set flags */
     } while(0);                        /* end protected */
 
-  if (allocrhs !=NULL) free(allocrhs); /* drop any storage used */
-  if (allocbufa!=NULL) free(allocbufa); /* .. */
-  if (allocbuft!=NULL) free(allocbuft); /* .. */
+  free(allocrhs);      /* drop any storage used */
+  free(allocbufa); /* .. */
+  free(allocbuft); /* .. */
   /* [status is handled by caller] */
   return res;
   } /* decExpOp */
   /* [status is handled by caller] */
   return res;
   } /* decExpOp */
@@ -5799,8 +5794,8 @@ decNumber * decLnOp(decNumber *res, const decNumber *rhs,
     decFinish(res, set, &residue, status);      /* cleanup/set flags */
     } while(0);                        /* end protected */
 
     decFinish(res, set, &residue, status);      /* cleanup/set flags */
     } while(0);                        /* end protected */
 
-  if (allocbufa!=NULL) free(allocbufa); /* drop any storage used */
-  if (allocbufb!=NULL) free(allocbufb); /* .. */
+  free(allocbufa); /* drop any storage used */
+  free(allocbufb); /* .. */
   /* [status is handled by caller] */
   return res;
   } /* decLnOp */
   /* [status is handled by caller] */
   return res;
   } /* decLnOp */
@@ -5964,8 +5959,8 @@ static decNumber * decQuantizeOp(decNumber *res, const decNumber *lhs,
     } while(0);                        /* end protected */
 
   #if DECSUBSET
     } while(0);                        /* end protected */
 
   #if DECSUBSET
-  if (allocrhs!=NULL) free(allocrhs);  /* drop any storage used */
-  if (alloclhs!=NULL) free(alloclhs);  /* .. */
+  free(allocrhs);      /* drop any storage used */
+  free(alloclhs);      /* .. */
   #endif
   return res;
   } /* decQuantizeOp */
   #endif
   return res;
   } /* decQuantizeOp */
@@ -6147,8 +6142,8 @@ decNumber * decCompareOp(decNumber *res, const decNumber *lhs,
       }
     }
   #if DECSUBSET
       }
     }
   #if DECSUBSET
-  if (allocrhs!=NULL) free(allocrhs);  /* free any storage used */
-  if (alloclhs!=NULL) free(alloclhs);  /* .. */
+  free(allocrhs);      /* free any storage used */
+  free(alloclhs);      /* .. */
   #endif
   return res;
   } /* decCompareOp */
   #endif
   return res;
   } /* decCompareOp */
@@ -6282,7 +6277,7 @@ static Int decUnitCompare(const Unit *a, Int alength,
     result=(*u==0 ? 0 : +1);
     }
   /* clean up and return the result */
     result=(*u==0 ? 0 : +1);
     }
   /* clean up and return the result */
-  if (allocacc!=NULL) free(allocacc);  /* drop any storage used */
+  free(allocacc);      /* drop any storage used */
   return result;
   } /* decUnitCompare */
 
   return result;
   } /* decUnitCompare */