This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Constify libdecnumber take 2 (part 2/2)
- From: "Kaveh R. Ghazi" <ghazi at caipclassic dot rutgers dot edu>
- To: bje at au1 dot ibm dot com
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 6 Sep 2006 00:31:46 -0400 (EDT)
- Subject: Constify libdecnumber take 2 (part 2/2)
Here is part 2 of the libdecnumber constification split. This part
contains the one non-mechanical change. As I explained in the
original patch, constifying the parameters of decNumberPower() exposed
the fact that one of the parameters "lhs" was assigned new storage and
written to. This is technically okay, but when we constify that
parmeter this prompts a warning. My solution was to allocate the
storage to a non-const temp variable "newlhs", write to the storage
through that variable and then assign lhs = newlhs.
I verified that when this patch is applied over part 1, that it
produces the same source tree as the original patch posted here:
http://gcc.gnu.org/ml/gcc-patches/2006-08/msg00757.html
Tested on sparc-sun-solaris2.10 on top of part 1.
Ben - I only have access to sparc-solaris. So you require testing
elsewhere, I'll need to solicit a volunteer. And I'll leave it to you
to decide if it is too dangerous for stage3. However it seems pretty
trivual to me and I hate to leave one last function un-constified. :-)
OTOH, I verified part 1 could go in alone if you so desire.
Okay for mainline now or in stage1?
Thanks,
--Kaveh
2006-09-06 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* decNumber.c (decNumberPower): Constify.
* decNumber.h (decNumberPower): Likewise.
diff -rup orig/egcc-SVN20060905/libdecnumber/decNumber.c egcc-SVN20060905/libdecnumber/decNumber.c
--- orig/egcc-SVN20060905/libdecnumber/decNumber.c 2006-09-06 00:02:12.390904124 -0400
+++ egcc-SVN20060905/libdecnumber/decNumber.c 2006-09-06 00:02:17.891625772 -0400
@@ -964,13 +964,13 @@ decNumberNormalize (decNumber * res, con
/* Specification restriction: abs(n) must be <=999999999 */
/* ------------------------------------------------------------------ */
decNumber *
-decNumberPower (decNumber * res, decNumber * lhs,
- decNumber * rhs, decContext * set)
+decNumberPower (decNumber * res, const decNumber * lhs,
+ const decNumber * rhs, decContext * set)
{
decNumber *alloclhs = NULL; /* non-NULL if rounded lhs allocated */
decNumber *allocrhs = NULL; /* .., rhs */
decNumber *allocdac = NULL; /* -> allocated acc buffer, iff used */
- decNumber *inrhs = rhs; /* save original rhs */
+ const decNumber *inrhs = rhs; /* save original rhs */
Int reqdigits = set->digits; /* requested DIGITS */
Int n; /* RHS in binary */
Int i; /* work */
@@ -1117,6 +1117,7 @@ decNumberPower (decNumber * res, decNumb
/* we'll invert the lhs now rather than inverting the result later */
if (decNumberIsNegative (rhs))
{ /* was a **-n [hence digits>0] */
+ decNumber * newlhs;
decNumberCopy (&dnOne, dac); /* dnOne=1; [needed now or later] */
#if DECSUBSET
if (set->extended)
@@ -1138,13 +1139,14 @@ decNumberPower (decNumber * res, decNumb
status |= DEC_Insufficient_storage;
break;
}
- lhs = alloclhs; /* use the allocated space */
+ newlhs = alloclhs; /* use the allocated space */
}
else
- lhs = (decNumber *) lhsbuff; /* use stack storage */
+ newlhs = (decNumber *) lhsbuff; /* use stack storage */
/* [lhs now points to buffer or allocated storage] */
- decNumberCopy (lhs, dac); /* copy the 1/lhs */
+ decNumberCopy (newlhs, dac); /* copy the 1/lhs */
decNumberCopy (dac, &dnOne); /* restore acc=1 */
+ lhs = newlhs;
#if DECSUBSET
}
#endif
diff -rup orig/egcc-SVN20060905/libdecnumber/decNumber.h egcc-SVN20060905/libdecnumber/decNumber.h
--- orig/egcc-SVN20060905/libdecnumber/decNumber.h 2006-09-06 00:02:12.392471028 -0400
+++ egcc-SVN20060905/libdecnumber/decNumber.h 2006-09-06 00:02:17.893183076 -0400
@@ -152,8 +152,8 @@ decNumber *decNumberMultiply (decNumber
const decNumber *, decContext *);
decNumber *decNumberNormalize (decNumber *, const decNumber *, decContext *);
decNumber *decNumberPlus (decNumber *, const decNumber *, decContext *);
-decNumber *decNumberPower (decNumber *, decNumber *, decNumber *,
- decContext *);
+decNumber *decNumberPower (decNumber *, const decNumber *,
+ const decNumber *, decContext *);
decNumber *decNumberQuantize (decNumber *, const decNumber *,
const decNumber *, decContext *);
decNumber *decNumberRemainder (decNumber *, const decNumber *,