]> granicus.if.org Git - postgresql/blobdiff - src/backend/utils/adt/int8.c
Remove all the special-case code for INT64_IS_BUSTED, per decision that
[postgresql] / src / backend / utils / adt / int8.c
index 550c06f5d079c80e824c0ca56efe3f588a70104a..6707b79e5485cc65b86ad7f29e57cebd34937b3a 100644 (file)
@@ -3,11 +3,11 @@
  * int8.c
  *       Internal 64-bit integer operations
  *
- * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/adt/int8.c,v 1.71 2008/10/05 23:18:37 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/adt/int8.c,v 1.77 2010/01/07 04:53:34 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -76,15 +76,12 @@ scanint8(const char *str, bool errorOK, int64 *result)
                 * Do an explicit check for INT64_MIN.  Ugly though this is, it's
                 * cleaner than trying to get the loop below to handle it portably.
                 */
-#ifndef INT64_IS_BUSTED
                if (strncmp(ptr, "9223372036854775808", 19) == 0)
                {
                        tmp = -INT64CONST(0x7fffffffffffffff) - 1;
                        ptr += 19;
                        goto gotdigits;
                }
-#endif
-
                sign = -1;
        }
        else if (*ptr == '+')
@@ -575,12 +572,9 @@ int8mul(PG_FUNCTION_ARGS)
         * Since the division is likely much more expensive than the actual
         * multiplication, we'd like to skip it where possible.  The best bang for
         * the buck seems to be to check whether both inputs are in the int32
-        * range; if so, no overflow is possible.  (But that only works if we
-        * really have a 64-bit int64 datatype...)
+        * range; if so, no overflow is possible.
         */
-#ifndef INT64_IS_BUSTED
        if (arg1 != (int64) ((int32) arg1) || arg2 != (int64) ((int32) arg2))
-#endif
        {
                if (arg2 != 0 &&
                        (result / arg2 != arg1 || (arg2 == -1 && arg1 < 0 && result < 0)))
@@ -608,7 +602,7 @@ int8div(PG_FUNCTION_ARGS)
        /*
         * Overflow check.      The only possible overflow case is for arg1 =
         * INT64_MIN, arg2 = -1, where the correct result is -INT64_MIN, which
-        * can't be represented on a two's-complement machine.  Most machines
+        * can't be represented on a two's-complement machine.  Most machines
         * produce INT64_MIN but it seems some produce zero.
         */
        if (arg2 == -1 && arg1 < 0 && result <= 0)
@@ -661,12 +655,14 @@ int8inc(PG_FUNCTION_ARGS)
        /*
         * When int8 is pass-by-reference, we provide this special case to avoid
         * palloc overhead for COUNT(): when called from nodeAgg, we know that the
-        * argument is modifiable local storage, so just update it in-place.
-        * (If int8 is pass-by-value, then of course this is useless as well
-        * as incorrect, so just ifdef it out.)
+        * argument is modifiable local storage, so just update it in-place. (If
+        * int8 is pass-by-value, then of course this is useless as well as
+        * incorrect, so just ifdef it out.)
         */
 #ifndef USE_FLOAT8_BYVAL               /* controls int8 too */
-       if (fcinfo->context && IsA(fcinfo->context, AggState))
+       if (fcinfo->context &&
+               (IsA(fcinfo->context, AggState) ||
+                IsA(fcinfo->context, WindowAggState)))
        {
                int64      *arg = (int64 *) PG_GETARG_POINTER(0);
                int64           result;
@@ -831,7 +827,7 @@ int84div(PG_FUNCTION_ARGS)
        /*
         * Overflow check.      The only possible overflow case is for arg1 =
         * INT64_MIN, arg2 = -1, where the correct result is -INT64_MIN, which
-        * can't be represented on a two's-complement machine.  Most machines
+        * can't be represented on a two's-complement machine.  Most machines
         * produce INT64_MIN but it seems some produce zero.
         */
        if (arg2 == -1 && arg1 < 0 && result <= 0)
@@ -917,9 +913,14 @@ int48div(PG_FUNCTION_ARGS)
        int64           arg2 = PG_GETARG_INT64(1);
 
        if (arg2 == 0)
+       {
                ereport(ERROR,
                                (errcode(ERRCODE_DIVISION_BY_ZERO),
                                 errmsg("division by zero")));
+               /* ensure compiler realizes we mustn't reach the division (gcc bug) */
+               PG_RETURN_NULL();
+       }
+
        /* No overflow is possible */
        PG_RETURN_INT64((int64) arg1 / arg2);
 }
@@ -1010,7 +1011,7 @@ int82div(PG_FUNCTION_ARGS)
        /*
         * Overflow check.      The only possible overflow case is for arg1 =
         * INT64_MIN, arg2 = -1, where the correct result is -INT64_MIN, which
-        * can't be represented on a two's-complement machine.  Most machines
+        * can't be represented on a two's-complement machine.  Most machines
         * produce INT64_MIN but it seems some produce zero.
         */
        if (arg2 == -1 && arg1 < 0 && result <= 0)
@@ -1096,9 +1097,14 @@ int28div(PG_FUNCTION_ARGS)
        int64           arg2 = PG_GETARG_INT64(1);
 
        if (arg2 == 0)
+       {
                ereport(ERROR,
                                (errcode(ERRCODE_DIVISION_BY_ZERO),
                                 errmsg("division by zero")));
+               /* ensure compiler realizes we mustn't reach the division (gcc bug) */
+               PG_RETURN_NULL();
+       }
+
        /* No overflow is possible */
        PG_RETURN_INT64((int64) arg1 / arg2);
 }