[pypy-commit] pypy decimal-libmpdec: Refresh libmpdec with the version shipped with cpython-3.3.5

amauryfa noreply at buildbot.pypy.org
Sun Oct 5 20:22:56 CEST 2014


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: decimal-libmpdec
Changeset: r73794:a9f2aa1662c0
Date: 2014-09-19 00:00 +0200
http://bitbucket.org/pypy/pypy/changeset/a9f2aa1662c0/

Log:	Refresh libmpdec with the version shipped with cpython-3.3.5

diff --git a/rpython/translator/c/src/libmpdec/basearith.c b/rpython/translator/c/src/libmpdec/basearith.c
--- a/rpython/translator/c/src/libmpdec/basearith.c
+++ b/rpython/translator/c/src/libmpdec/basearith.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/basearith.h b/rpython/translator/c/src/libmpdec/basearith.h
--- a/rpython/translator/c/src/libmpdec/basearith.h
+++ b/rpython/translator/c/src/libmpdec/basearith.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/bits.h b/rpython/translator/c/src/libmpdec/bits.h
--- a/rpython/translator/c/src/libmpdec/bits.h
+++ b/rpython/translator/c/src/libmpdec/bits.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/constants.c b/rpython/translator/c/src/libmpdec/constants.c
--- a/rpython/translator/c/src/libmpdec/constants.c
+++ b/rpython/translator/c/src/libmpdec/constants.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/constants.h b/rpython/translator/c/src/libmpdec/constants.h
--- a/rpython/translator/c/src/libmpdec/constants.h
+++ b/rpython/translator/c/src/libmpdec/constants.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/context.c b/rpython/translator/c/src/libmpdec/context.c
--- a/rpython/translator/c/src/libmpdec/context.c
+++ b/rpython/translator/c/src/libmpdec/context.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/convolute.c b/rpython/translator/c/src/libmpdec/convolute.c
--- a/rpython/translator/c/src/libmpdec/convolute.c
+++ b/rpython/translator/c/src/libmpdec/convolute.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/convolute.h b/rpython/translator/c/src/libmpdec/convolute.h
--- a/rpython/translator/c/src/libmpdec/convolute.h
+++ b/rpython/translator/c/src/libmpdec/convolute.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/crt.c b/rpython/translator/c/src/libmpdec/crt.c
--- a/rpython/translator/c/src/libmpdec/crt.c
+++ b/rpython/translator/c/src/libmpdec/crt.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/crt.h b/rpython/translator/c/src/libmpdec/crt.h
--- a/rpython/translator/c/src/libmpdec/crt.h
+++ b/rpython/translator/c/src/libmpdec/crt.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/difradix2.c b/rpython/translator/c/src/libmpdec/difradix2.c
--- a/rpython/translator/c/src/libmpdec/difradix2.c
+++ b/rpython/translator/c/src/libmpdec/difradix2.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/difradix2.h b/rpython/translator/c/src/libmpdec/difradix2.h
--- a/rpython/translator/c/src/libmpdec/difradix2.h
+++ b/rpython/translator/c/src/libmpdec/difradix2.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/fnt.c b/rpython/translator/c/src/libmpdec/fnt.c
--- a/rpython/translator/c/src/libmpdec/fnt.c
+++ b/rpython/translator/c/src/libmpdec/fnt.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/fnt.h b/rpython/translator/c/src/libmpdec/fnt.h
--- a/rpython/translator/c/src/libmpdec/fnt.h
+++ b/rpython/translator/c/src/libmpdec/fnt.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/fourstep.c b/rpython/translator/c/src/libmpdec/fourstep.c
--- a/rpython/translator/c/src/libmpdec/fourstep.c
+++ b/rpython/translator/c/src/libmpdec/fourstep.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/fourstep.h b/rpython/translator/c/src/libmpdec/fourstep.h
--- a/rpython/translator/c/src/libmpdec/fourstep.h
+++ b/rpython/translator/c/src/libmpdec/fourstep.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/io.c b/rpython/translator/c/src/libmpdec/io.c
--- a/rpython/translator/c/src/libmpdec/io.c
+++ b/rpython/translator/c/src/libmpdec/io.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/io.h b/rpython/translator/c/src/libmpdec/io.h
--- a/rpython/translator/c/src/libmpdec/io.h
+++ b/rpython/translator/c/src/libmpdec/io.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/memory.c b/rpython/translator/c/src/libmpdec/memory.c
--- a/rpython/translator/c/src/libmpdec/memory.c
+++ b/rpython/translator/c/src/libmpdec/memory.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/memory.h b/rpython/translator/c/src/libmpdec/memory.h
--- a/rpython/translator/c/src/libmpdec/memory.h
+++ b/rpython/translator/c/src/libmpdec/memory.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/mpdecimal.c b/rpython/translator/c/src/libmpdec/mpdecimal.c
--- a/rpython/translator/c/src/libmpdec/mpdecimal.c
+++ b/rpython/translator/c/src/libmpdec/mpdecimal.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -97,6 +97,8 @@
                        mpd_ssize_t exp);
 static inline mpd_ssize_t _mpd_real_size(mpd_uint_t *data, mpd_ssize_t size);
 
+static int _mpd_cmp_abs(const mpd_t *a, const mpd_t *b);
+
 static void _mpd_qadd(mpd_t *result, const mpd_t *a, const mpd_t *b,
                       const mpd_context_t *ctx, uint32_t *status);
 static inline void _mpd_qmul(mpd_t *result, const mpd_t *a, const mpd_t *b,
@@ -111,6 +113,17 @@
 
 
 /******************************************************************************/
+/*                                  Version                                   */
+/******************************************************************************/
+
+const char *
+mpd_version(void)
+{
+    return MPD_VERSION;
+}
+
+
+/******************************************************************************/
 /*                  Performance critical inline functions                     */
 /******************************************************************************/
 
@@ -379,42 +392,42 @@
 
 /* Dynamic decimal */
 ALWAYS_INLINE int
-mpd_isdynamic(mpd_t *dec)
+mpd_isdynamic(const mpd_t *dec)
 {
     return !(dec->flags & MPD_STATIC);
 }
 
 /* Static decimal */
 ALWAYS_INLINE int
-mpd_isstatic(mpd_t *dec)
+mpd_isstatic(const mpd_t *dec)
 {
     return dec->flags & MPD_STATIC;
 }
 
 /* Data of decimal is dynamic */
 ALWAYS_INLINE int
-mpd_isdynamic_data(mpd_t *dec)
+mpd_isdynamic_data(const mpd_t *dec)
 {
     return !(dec->flags & MPD_DATAFLAGS);
 }
 
 /* Data of decimal is static */
 ALWAYS_INLINE int
-mpd_isstatic_data(mpd_t *dec)
+mpd_isstatic_data(const mpd_t *dec)
 {
     return dec->flags & MPD_STATIC_DATA;
 }
 
 /* Data of decimal is shared */
 ALWAYS_INLINE int
-mpd_isshared_data(mpd_t *dec)
+mpd_isshared_data(const mpd_t *dec)
 {
     return dec->flags & MPD_SHARED_DATA;
 }
 
 /* Data of decimal is const */
 ALWAYS_INLINE int
-mpd_isconst_data(mpd_t *dec)
+mpd_isconst_data(const mpd_t *dec)
 {
     return dec->flags & MPD_CONST_DATA;
 }
@@ -584,7 +597,7 @@
 
 /* Copy sign from another decimal */
 ALWAYS_INLINE void
-mpd_signcpy(mpd_t *result, mpd_t *a)
+mpd_signcpy(mpd_t *result, const mpd_t *a)
 {
     uint8_t sign = a->flags&MPD_NEG;
 
@@ -1345,6 +1358,91 @@
     return MPD_SSIZE_MAX;
 }
 
+#if defined(CONFIG_32) && !defined(LEGACY_COMPILER)
+/*
+ * Quietly get a uint64_t from a decimal. If the operation is impossible,
+ * MPD_Invalid_operation is set.
+ */
+static uint64_t
+_c32_qget_u64(int use_sign, const mpd_t *a, uint32_t *status)
+{
+    MPD_NEW_STATIC(tmp,0,0,20,3);
+    mpd_context_t maxcontext;
+    uint64_t ret;
+
+    tmp_data[0] = 709551615;
+    tmp_data[1] = 446744073;
+    tmp_data[2] = 18;
+
+    if (mpd_isspecial(a)) {
+        *status |= MPD_Invalid_operation;
+        return UINT64_MAX;
+    }
+    if (mpd_iszero(a)) {
+        return 0;
+    }
+    if (use_sign && mpd_isnegative(a)) {
+        *status |= MPD_Invalid_operation;
+        return UINT64_MAX;
+    }
+    if (!_mpd_isint(a)) {
+        *status |= MPD_Invalid_operation;
+        return UINT64_MAX;
+    }
+
+    if (_mpd_cmp_abs(a, &tmp) > 0) {
+        *status |= MPD_Invalid_operation;
+        return UINT64_MAX;
+    }
+
+    mpd_maxcontext(&maxcontext);
+    mpd_qrescale(&tmp, a, 0, &maxcontext, &maxcontext.status);
+    maxcontext.status &= ~MPD_Rounded;
+    if (maxcontext.status != 0) {
+        *status |= (maxcontext.status|MPD_Invalid_operation); /* GCOV_NOT_REACHED */
+        return UINT64_MAX; /* GCOV_NOT_REACHED */
+    }
+
+    ret = 0;
+    switch (tmp.len) {
+    case 3:
+        ret += (uint64_t)tmp_data[2] * 1000000000000000000ULL;
+    case 2:
+        ret += (uint64_t)tmp_data[1] * 1000000000ULL;
+    case 1:
+        ret += tmp_data[0];
+        break;
+    default:
+        abort(); /* GCOV_NOT_REACHED */
+    }
+
+    return ret;
+}
+
+static int64_t
+_c32_qget_i64(const mpd_t *a, uint32_t *status)
+{
+    uint64_t u;
+    int isneg;
+
+    u = _c32_qget_u64(0, a, status);
+    if (*status&MPD_Invalid_operation) {
+        return INT64_MAX;
+    }
+
+    isneg = mpd_isnegative(a);
+    if (u <= INT64_MAX) {
+        return isneg ? -((int64_t)u) : (int64_t)u;
+    }
+    else if (isneg && u+(INT64_MIN+INT64_MAX) == INT64_MAX) {
+        return INT64_MIN;
+    }
+
+    *status |= MPD_Invalid_operation;
+    return INT64_MAX;
+}
+#endif /* CONFIG_32 && !LEGACY_COMPILER */
+
 #ifdef CONFIG_64
 /* quietly get a uint64_t from a decimal */
 uint64_t
@@ -1359,7 +1457,57 @@
 {
     return mpd_qget_ssize(a, status);
 }
+
+/* quietly get a uint32_t from a decimal */
+uint32_t
+mpd_qget_u32(const mpd_t *a, uint32_t *status)
+{
+    uint64_t x = mpd_qget_uint(a, status);
+
+    if (*status&MPD_Invalid_operation) {
+        return UINT32_MAX;
+    }
+    if (x > UINT32_MAX) {
+        *status |= MPD_Invalid_operation;
+        return UINT32_MAX;
+    }
+
+    return (uint32_t)x;
+}
+
+/* quietly get an int32_t from a decimal */
+int32_t
+mpd_qget_i32(const mpd_t *a, uint32_t *status)
+{
+    int64_t x = mpd_qget_ssize(a, status);
+
+    if (*status&MPD_Invalid_operation) {
+        return INT32_MAX;
+    }
+    if (x < INT32_MIN || x > INT32_MAX) {
+        *status |= MPD_Invalid_operation;
+        return INT32_MAX;
+    }
+
+    return (int32_t)x;
+}
 #else
+#ifndef LEGACY_COMPILER
+/* quietly get a uint64_t from a decimal */
+uint64_t
+mpd_qget_u64(const mpd_t *a, uint32_t *status)
+{
+    return _c32_qget_u64(1, a, status);
+}
+
+/* quietly get an int64_t from a decimal */
+int64_t
+mpd_qget_i64(const mpd_t *a, uint32_t *status)
+{
+    return _c32_qget_i64(a, status);
+}
+#endif
+
 /* quietly get a uint32_t from a decimal */
 uint32_t
 mpd_qget_u32(const mpd_t *a, uint32_t *status)
@@ -3054,9 +3202,9 @@
 }
 
 static inline void
-_mpd_ptrswap(mpd_t **a, mpd_t **b)
-{
-    mpd_t *t = *a;
+_mpd_ptrswap(const mpd_t **a, const mpd_t **b)
+{
+    const mpd_t *t = *a;
     *a = *b;
     *b = t;
 }
@@ -3084,7 +3232,7 @@
 _mpd_qaddsub(mpd_t *result, const mpd_t *a, const mpd_t *b, uint8_t sign_b,
              const mpd_context_t *ctx, uint32_t *status)
 {
-    mpd_t *big, *small;
+    const mpd_t *big, *small;
     MPD_NEW_STATIC(big_aligned,0,0,0,0);
     MPD_NEW_CONST(tiny,0,0,1,1,1,1);
     mpd_uint_t carry;
@@ -3094,7 +3242,7 @@
 
 
     /* compare exponents */
-    big = (mpd_t *)a; small = (mpd_t *)b;
+    big = a; small = b;
     if (big->exp != small->exp) {
         if (small->exp > big->exp) {
             _mpd_ptrswap(&big, &small);
@@ -3386,6 +3534,34 @@
 {
     mpd_qadd_uint(result, a, b, ctx, status);
 }
+#elif !defined(LEGACY_COMPILER)
+/* Add decimal and int64_t. */
+void
+mpd_qadd_i64(mpd_t *result, const mpd_t *a, int64_t b,
+             const mpd_context_t *ctx, uint32_t *status)
+{
+    mpd_context_t maxcontext;
+    MPD_NEW_STATIC(bb,0,0,0,0);
+
+    mpd_maxcontext(&maxcontext);
+    mpd_qset_i64(&bb, b, &maxcontext, status);
+    mpd_qadd(result, a, &bb, ctx, status);
+    mpd_del(&bb);
+}
+
+/* Add decimal and uint64_t. */
+void
+mpd_qadd_u64(mpd_t *result, const mpd_t *a, uint64_t b,
+             const mpd_context_t *ctx, uint32_t *status)
+{
+    mpd_context_t maxcontext;
+    MPD_NEW_STATIC(bb,0,0,0,0);
+
+    mpd_maxcontext(&maxcontext);
+    mpd_qset_u64(&bb, b, &maxcontext, status);
+    mpd_qadd(result, a, &bb, ctx, status);
+    mpd_del(&bb);
+}
 #endif
 
 /* Subtract int32_t from decimal. */
@@ -3420,6 +3596,34 @@
 {
     mpd_qsub_uint(result, a, b, ctx, status);
 }
+#elif !defined(LEGACY_COMPILER)
+/* Subtract int64_t from decimal. */
+void
+mpd_qsub_i64(mpd_t *result, const mpd_t *a, int64_t b,
+             const mpd_context_t *ctx, uint32_t *status)
+{
+    mpd_context_t maxcontext;
+    MPD_NEW_STATIC(bb,0,0,0,0);
+
+    mpd_maxcontext(&maxcontext);
+    mpd_qset_i64(&bb, b, &maxcontext, status);
+    mpd_qsub(result, a, &bb, ctx, status);
+    mpd_del(&bb);
+}
+
+/* Subtract uint64_t from decimal. */
+void
+mpd_qsub_u64(mpd_t *result, const mpd_t *a, uint64_t b,
+             const mpd_context_t *ctx, uint32_t *status)
+{
+    mpd_context_t maxcontext;
+    MPD_NEW_STATIC(bb,0,0,0,0);
+
+    mpd_maxcontext(&maxcontext);
+    mpd_qset_u64(&bb, b, &maxcontext, status);
+    mpd_qsub(result, a, &bb, ctx, status);
+    mpd_del(&bb);
+}
 #endif
 
 
@@ -3871,6 +4075,34 @@
 {
     mpd_qdiv_uint(result, a, b, ctx, status);
 }
+#elif !defined(LEGACY_COMPILER)
+/* Divide decimal by int64_t. */
+void
+mpd_qdiv_i64(mpd_t *result, const mpd_t *a, int64_t b,
+             const mpd_context_t *ctx, uint32_t *status)
+{
+    mpd_context_t maxcontext;
+    MPD_NEW_STATIC(bb,0,0,0,0);
+
+    mpd_maxcontext(&maxcontext);
+    mpd_qset_i64(&bb, b, &maxcontext, status);
+    mpd_qdiv(result, a, &bb, ctx, status);
+    mpd_del(&bb);
+}
+
+/* Divide decimal by uint64_t. */
+void
+mpd_qdiv_u64(mpd_t *result, const mpd_t *a, uint64_t b,
+             const mpd_context_t *ctx, uint32_t *status)
+{
+    mpd_context_t maxcontext;
+    MPD_NEW_STATIC(bb,0,0,0,0);
+
+    mpd_maxcontext(&maxcontext);
+    mpd_qset_u64(&bb, b, &maxcontext, status);
+    mpd_qdiv(result, a, &bb, ctx, status);
+    mpd_del(&bb);
+}
 #endif
 
 /* Pad the result with trailing zeros if it has fewer digits than prec. */
@@ -4189,21 +4421,22 @@
          const mpd_context_t *ctx, uint32_t *status)
 {
     uint32_t workstatus = 0;
-    mpd_t *cc = (mpd_t *)c;
+    mpd_t *cc = NULL;
 
     if (result == c) {
         if ((cc = mpd_qncopy(c)) == NULL) {
             mpd_seterror(result, MPD_Malloc_error, status);
             return;
         }
+        c = cc;
     }
 
     _mpd_qmul(result, a, b, ctx, &workstatus);
     if (!(workstatus&MPD_Invalid_operation)) {
-        mpd_qadd(result, result, cc, ctx, &workstatus);
-    }
-
-    if (cc != c) mpd_del(cc);
+        mpd_qadd(result, result, c, ctx, &workstatus);
+    }
+
+    if (cc) mpd_del(cc);
     *status |= workstatus;
 }
 
@@ -5495,7 +5728,7 @@
 _mpd_qmul(mpd_t *result, const mpd_t *a, const mpd_t *b,
           const mpd_context_t *ctx, uint32_t *status)
 {
-    mpd_t *big = (mpd_t *)a, *small = (mpd_t *)b;
+    const mpd_t *big = a, *small = b;
     mpd_uint_t *rdata = NULL;
     mpd_uint_t rbuf[MPD_MINALLOC_MAX];
     mpd_size_t rsize, i;
@@ -5664,6 +5897,34 @@
 {
     mpd_qmul_uint(result, a, b, ctx, status);
 }
+#elif !defined(LEGACY_COMPILER)
+/* Multiply decimal and int64_t. */
+void
+mpd_qmul_i64(mpd_t *result, const mpd_t *a, int64_t b,
+             const mpd_context_t *ctx, uint32_t *status)
+{
+    mpd_context_t maxcontext;
+    MPD_NEW_STATIC(bb,0,0,0,0);
+
+    mpd_maxcontext(&maxcontext);
+    mpd_qset_i64(&bb, b, &maxcontext, status);
+    mpd_qmul(result, a, &bb, ctx, status);
+    mpd_del(&bb);
+}
+
+/* Multiply decimal and uint64_t. */
+void
+mpd_qmul_u64(mpd_t *result, const mpd_t *a, uint64_t b,
+             const mpd_context_t *ctx, uint32_t *status)
+{
+    mpd_context_t maxcontext;
+    MPD_NEW_STATIC(bb,0,0,0,0);
+
+    mpd_maxcontext(&maxcontext);
+    mpd_qset_u64(&bb, b, &maxcontext, status);
+    mpd_qmul(result, a, &bb, ctx, status);
+    mpd_del(&bb);
+}
 #endif
 
 /* Like the minus operator. */
diff --git a/rpython/translator/c/src/libmpdec/mpdecimal.h b/rpython/translator/c/src/libmpdec/mpdecimal.h
--- a/rpython/translator/c/src/libmpdec/mpdecimal.h
+++ b/rpython/translator/c/src/libmpdec/mpdecimal.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -32,7 +32,10 @@
 
 #ifdef __cplusplus
 extern "C" {
-#define __STDC_LIMIT_MACROS
+  #ifndef __STDC_LIMIT_MACROS
+    #define __STDC_LIMIT_MACROS
+    #define MPD_CLEAR_STDC_LIMIT_MACROS
+  #endif
 #endif
 
 
@@ -103,6 +106,19 @@
 
 
 /******************************************************************************/
+/*                                  Version                                   */
+/******************************************************************************/
+
+#define MPD_MAJOR_VERSION 2
+#define MPD_MINOR_VERSION 4
+#define MPD_MICRO_VERSION 0
+
+#define MPD_VERSION "2.4.0"
+
+const char *mpd_version(void);
+
+
+/******************************************************************************/
 /*                              Configuration                                 */
 /******************************************************************************/
 
@@ -244,7 +260,7 @@
 extern const char *mpd_clamp_string[MPD_CLAMP_GUARD];
 
 
-typedef struct {
+typedef struct mpd_context_t {
     mpd_ssize_t prec;   /* precision */
     mpd_ssize_t emax;   /* max positive exp */
     mpd_ssize_t emin;   /* min negative exp */
@@ -356,7 +372,7 @@
 #define MPD_DATAFLAGS (MPD_STATIC_DATA|MPD_SHARED_DATA|MPD_CONST_DATA)
 
 /* mpd_t */
-typedef struct {
+typedef struct mpd_t {
     uint8_t flags;
     mpd_ssize_t exp;
     mpd_ssize_t digits;
@@ -374,7 +390,7 @@
 /******************************************************************************/
 
 /* format specification */
-typedef struct {
+typedef struct mpd_spec_t {
     mpd_ssize_t min_width; /* minimum field width */
     mpd_ssize_t prec;      /* fraction digits or significant digits */
     char type;             /* conversion specifier */
@@ -393,7 +409,7 @@
 mpd_ssize_t mpd_to_eng_size(char **res, const mpd_t *dec, int fmt);
 int mpd_validate_lconv(mpd_spec_t *spec);
 int mpd_parse_fmt_str(mpd_spec_t *spec, const char *fmt, int caps);
-char * mpd_qformat_spec(const mpd_t *dec, const mpd_spec_t *spec, const mpd_context_t *ctx, uint32_t *status);
+char *mpd_qformat_spec(const mpd_t *dec, const mpd_spec_t *spec, const mpd_context_t *ctx, uint32_t *status);
 char *mpd_qformat(const mpd_t *dec, const char *fmt, const mpd_context_t *ctx, uint32_t *status);
 
 #define MPD_NUM_FLAGS 15
@@ -440,13 +456,19 @@
 mpd_uint_t mpd_qget_uint(const mpd_t *dec, uint32_t *status);
 mpd_uint_t mpd_qabs_uint(const mpd_t *dec, uint32_t *status);
 
+int32_t mpd_qget_i32(const mpd_t *dec, uint32_t *status);
+uint32_t mpd_qget_u32(const mpd_t *dec, uint32_t *status);
+#ifndef LEGACY_COMPILER
+int64_t mpd_qget_i64(const mpd_t *dec, uint32_t *status);
+uint64_t mpd_qget_u64(const mpd_t *dec, uint32_t *status);
+#endif
 
 /* quiet functions */
 int mpd_qcheck_nan(mpd_t *nanresult, const mpd_t *a, const mpd_context_t *ctx, uint32_t *status);
 int mpd_qcheck_nans(mpd_t *nanresult, const mpd_t *a, const mpd_t *b, const mpd_context_t *ctx, uint32_t *status);
 void mpd_qfinalize(mpd_t *result, const mpd_context_t *ctx, uint32_t *status);
 
-const char * mpd_class(const mpd_t *a, const mpd_context_t *ctx);
+const char *mpd_class(const mpd_t *a, const mpd_context_t *ctx);
 
 int mpd_qcopy(mpd_t *result, const mpd_t *a,  uint32_t *status);
 mpd_t *mpd_qncopy(const mpd_t *a);
@@ -531,6 +553,17 @@
 void mpd_qsqrt(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_t *status);
 void mpd_qinvroot(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_t *status);
 
+#ifndef LEGACY_COMPILER
+void mpd_qadd_i64(mpd_t *result, const mpd_t *a, int64_t b, const mpd_context_t *ctx, uint32_t *status);
+void mpd_qadd_u64(mpd_t *result, const mpd_t *a, uint64_t b, const mpd_context_t *ctx, uint32_t *status);
+void mpd_qsub_i64(mpd_t *result, const mpd_t *a, int64_t b, const mpd_context_t *ctx, uint32_t *status);
+void mpd_qsub_u64(mpd_t *result, const mpd_t *a, uint64_t b, const mpd_context_t *ctx, uint32_t *status);
+void mpd_qmul_i64(mpd_t *result, const mpd_t *a, int64_t b, const mpd_context_t *ctx, uint32_t *status);
+void mpd_qmul_u64(mpd_t *result, const mpd_t *a, uint64_t b, const mpd_context_t *ctx, uint32_t *status);
+void mpd_qdiv_i64(mpd_t *result, const mpd_t *a, int64_t b, const mpd_context_t *ctx, uint32_t *status);
+void mpd_qdiv_u64(mpd_t *result, const mpd_t *a, uint64_t b, const mpd_context_t *ctx, uint32_t *status);
+#endif
+
 
 size_t mpd_sizeinbase(const mpd_t *a, uint32_t base);
 void mpd_qimport_u16(mpd_t *result, const uint16_t *srcdata, size_t srclen,
@@ -549,7 +582,7 @@
 /*                           Signalling functions                             */
 /******************************************************************************/
 
-char * mpd_format(const mpd_t *dec, const char *fmt, mpd_context_t *ctx);
+char *mpd_format(const mpd_t *dec, const char *fmt, mpd_context_t *ctx);
 void mpd_import_u16(mpd_t *result, const uint16_t *srcdata, size_t srclen, uint8_t srcsign, uint32_t base, mpd_context_t *ctx);
 void mpd_import_u32(mpd_t *result, const uint32_t *srcdata, size_t srclen, uint8_t srcsign, uint32_t base, mpd_context_t *ctx);
 size_t mpd_export_u16(uint16_t **rdata, size_t rlen, uint32_t base, const mpd_t *src, mpd_context_t *ctx);
@@ -574,6 +607,12 @@
 mpd_ssize_t mpd_get_ssize(const mpd_t *a, mpd_context_t *ctx);
 mpd_uint_t mpd_get_uint(const mpd_t *a, mpd_context_t *ctx);
 mpd_uint_t mpd_abs_uint(const mpd_t *a, mpd_context_t *ctx);
+int32_t mpd_get_i32(const mpd_t *a, mpd_context_t *ctx);
+uint32_t mpd_get_u32(const mpd_t *a, mpd_context_t *ctx);
+#ifndef LEGACY_COMPILER
+int64_t mpd_get_i64(const mpd_t *a, mpd_context_t *ctx);
+uint64_t mpd_get_u64(const mpd_t *a, mpd_context_t *ctx);
+#endif
 void mpd_and(mpd_t *result, const mpd_t *a, const mpd_t *b, mpd_context_t *ctx);
 void mpd_copy(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
 void mpd_canonical(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
@@ -644,6 +683,17 @@
 void mpd_sqrt(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
 void mpd_invroot(mpd_t *result, const mpd_t *a, mpd_context_t *ctx);
 
+#ifndef LEGACY_COMPILER
+void mpd_add_i64(mpd_t *result, const mpd_t *a, int64_t b, mpd_context_t *ctx);
+void mpd_add_u64(mpd_t *result, const mpd_t *a, uint64_t b, mpd_context_t *ctx);
+void mpd_sub_i64(mpd_t *result, const mpd_t *a, int64_t b, mpd_context_t *ctx);
+void mpd_sub_u64(mpd_t *result, const mpd_t *a, uint64_t b, mpd_context_t *ctx);
+void mpd_div_i64(mpd_t *result, const mpd_t *a, int64_t b, mpd_context_t *ctx);
+void mpd_div_u64(mpd_t *result, const mpd_t *a, uint64_t b, mpd_context_t *ctx);
+void mpd_mul_i64(mpd_t *result, const mpd_t *a, int64_t b, mpd_context_t *ctx);
+void mpd_mul_u64(mpd_t *result, const mpd_t *a, uint64_t b, mpd_context_t *ctx);
+#endif
+
 
 /******************************************************************************/
 /*                          Configuration specific                            */
@@ -652,36 +702,8 @@
 #ifdef CONFIG_64
 void mpd_qsset_i64(mpd_t *result, int64_t a, const mpd_context_t *ctx, uint32_t *status);
 void mpd_qsset_u64(mpd_t *result, uint64_t a, const mpd_context_t *ctx, uint32_t *status);
-int64_t mpd_qget_i64(const mpd_t *dec, uint32_t *status);
-uint64_t mpd_qget_u64(const mpd_t *dec, uint32_t *status);
-
-void mpd_qadd_i64(mpd_t *result, const mpd_t *a, int64_t b, const mpd_context_t *ctx, uint32_t *status);
-void mpd_qadd_u64(mpd_t *result, const mpd_t *a, uint64_t b, const mpd_context_t *ctx, uint32_t *status);
-void mpd_qsub_i64(mpd_t *result, const mpd_t *a, int64_t b, const mpd_context_t *ctx, uint32_t *status);
-void mpd_qsub_u64(mpd_t *result, const mpd_t *a, uint64_t b, const mpd_context_t *ctx, uint32_t *status);
-void mpd_qmul_i64(mpd_t *result, const mpd_t *a, int64_t b, const mpd_context_t *ctx, uint32_t *status);
-void mpd_qmul_u64(mpd_t *result, const mpd_t *a, uint64_t b, const mpd_context_t *ctx, uint32_t *status);
-void mpd_qdiv_i64(mpd_t *result, const mpd_t *a, int64_t b, const mpd_context_t *ctx, uint32_t *status);
-void mpd_qdiv_u64(mpd_t *result, const mpd_t *a, uint64_t b, const mpd_context_t *ctx, uint32_t *status);
-
 void mpd_sset_i64(mpd_t *result, int64_t a, mpd_context_t *ctx);
 void mpd_sset_u64(mpd_t *result, uint64_t a, mpd_context_t *ctx);
-int64_t mpd_get_i64(const mpd_t *a, mpd_context_t *ctx);
-uint64_t mpd_get_u64(const mpd_t *a, mpd_context_t *ctx);
-
-void mpd_add_i64(mpd_t *result, const mpd_t *a, int64_t b, mpd_context_t *ctx);
-void mpd_add_u64(mpd_t *result, const mpd_t *a, uint64_t b, mpd_context_t *ctx);
-void mpd_sub_i64(mpd_t *result, const mpd_t *a, int64_t b, mpd_context_t *ctx);
-void mpd_sub_u64(mpd_t *result, const mpd_t *a, uint64_t b, mpd_context_t *ctx);
-void mpd_div_i64(mpd_t *result, const mpd_t *a, int64_t b, mpd_context_t *ctx);
-void mpd_div_u64(mpd_t *result, const mpd_t *a, uint64_t b, mpd_context_t *ctx);
-void mpd_mul_i64(mpd_t *result, const mpd_t *a, int64_t b, mpd_context_t *ctx);
-void mpd_mul_u64(mpd_t *result, const mpd_t *a, uint64_t b, mpd_context_t *ctx);
-#else
-int32_t mpd_qget_i32(const mpd_t *dec, uint32_t *status);
-uint32_t mpd_qget_u32(const mpd_t *dec, uint32_t *status);
-int32_t mpd_get_i32(const mpd_t *a, mpd_context_t *ctx);
-uint32_t mpd_get_u32(const mpd_t *a, mpd_context_t *ctx);
 #endif
 
 
@@ -731,12 +753,12 @@
 /* 1 if dec is positive, -1 if dec is negative */
 EXTINLINE int mpd_arith_sign(const mpd_t *dec);
 EXTINLINE long mpd_radix(void);
-EXTINLINE int mpd_isdynamic(mpd_t *dec);
-EXTINLINE int mpd_isstatic(mpd_t *dec);
-EXTINLINE int mpd_isdynamic_data(mpd_t *dec);
-EXTINLINE int mpd_isstatic_data(mpd_t *dec);
-EXTINLINE int mpd_isshared_data(mpd_t *dec);
-EXTINLINE int mpd_isconst_data(mpd_t *dec);
+EXTINLINE int mpd_isdynamic(const mpd_t *dec);
+EXTINLINE int mpd_isstatic(const mpd_t *dec);
+EXTINLINE int mpd_isdynamic_data(const mpd_t *dec);
+EXTINLINE int mpd_isstatic_data(const mpd_t *dec);
+EXTINLINE int mpd_isshared_data(const mpd_t *dec);
+EXTINLINE int mpd_isconst_data(const mpd_t *dec);
 EXTINLINE mpd_ssize_t mpd_trail_zeros(const mpd_t *dec);
 
 
@@ -748,7 +770,7 @@
 EXTINLINE void mpd_setdigits(mpd_t *result);
 EXTINLINE void mpd_set_sign(mpd_t *result, uint8_t sign);
 /* copy sign from another decimal */
-EXTINLINE void mpd_signcpy(mpd_t *result, mpd_t *a);
+EXTINLINE void mpd_signcpy(mpd_t *result, const mpd_t *a);
 EXTINLINE void mpd_set_infinity(mpd_t *result);
 EXTINLINE void mpd_set_qnan(mpd_t *result);
 EXTINLINE void mpd_set_snan(mpd_t *result);
@@ -815,6 +837,10 @@
 
 
 #ifdef __cplusplus
+  #ifdef MPD_CLEAR_STDC_LIMIT_MACROS
+    #undef MPD_CLEAR_STDC_LIMIT_MACROS
+    #undef __STDC_LIMIT_MACROS
+  #endif
 } /* END extern "C" */
 #endif
 
diff --git a/rpython/translator/c/src/libmpdec/numbertheory.c b/rpython/translator/c/src/libmpdec/numbertheory.c
--- a/rpython/translator/c/src/libmpdec/numbertheory.c
+++ b/rpython/translator/c/src/libmpdec/numbertheory.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/numbertheory.h b/rpython/translator/c/src/libmpdec/numbertheory.h
--- a/rpython/translator/c/src/libmpdec/numbertheory.h
+++ b/rpython/translator/c/src/libmpdec/numbertheory.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/sixstep.c b/rpython/translator/c/src/libmpdec/sixstep.c
--- a/rpython/translator/c/src/libmpdec/sixstep.c
+++ b/rpython/translator/c/src/libmpdec/sixstep.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/sixstep.h b/rpython/translator/c/src/libmpdec/sixstep.h
--- a/rpython/translator/c/src/libmpdec/sixstep.h
+++ b/rpython/translator/c/src/libmpdec/sixstep.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/transpose.c b/rpython/translator/c/src/libmpdec/transpose.c
--- a/rpython/translator/c/src/libmpdec/transpose.c
+++ b/rpython/translator/c/src/libmpdec/transpose.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -169,7 +169,7 @@
 /*
  * Transpose 2^n * 2^n matrix. For cache efficiency, the matrix is split into
  * square blocks with side length 'SIDE'. First, the blocks are transposed,
- * then a square tranposition is done on each individual block.
+ * then a square transposition is done on each individual block.
  */
 static void
 squaretrans_pow2(mpd_uint_t *matrix, mpd_size_t size)
diff --git a/rpython/translator/c/src/libmpdec/transpose.h b/rpython/translator/c/src/libmpdec/transpose.h
--- a/rpython/translator/c/src/libmpdec/transpose.h
+++ b/rpython/translator/c/src/libmpdec/transpose.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/typearith.h b/rpython/translator/c/src/libmpdec/typearith.h
--- a/rpython/translator/c/src/libmpdec/typearith.h
+++ b/rpython/translator/c/src/libmpdec/typearith.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/umodarith.h b/rpython/translator/c/src/libmpdec/umodarith.h
--- a/rpython/translator/c/src/libmpdec/umodarith.h
+++ b/rpython/translator/c/src/libmpdec/umodarith.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/vccompat.h b/rpython/translator/c/src/libmpdec/vccompat.h
--- a/rpython/translator/c/src/libmpdec/vccompat.h
+++ b/rpython/translator/c/src/libmpdec/vccompat.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+ * Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/rpython/translator/c/src/libmpdec/vcdiv64.asm b/rpython/translator/c/src/libmpdec/vcdiv64.asm
--- a/rpython/translator/c/src/libmpdec/vcdiv64.asm
+++ b/rpython/translator/c/src/libmpdec/vcdiv64.asm
@@ -1,5 +1,5 @@
 ;
-; Copyright (c) 2008-2012 Stefan Krah. All rights reserved.
+; Copyright (c) 2008-2016 Stefan Krah. All rights reserved.
 ;
 ; Redistribution and use in source and binary forms, with or without
 ; modification, are permitted provided that the following conditions


More information about the pypy-commit mailing list