diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:39 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:39 +0300 |
commit | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch) | |
tree | 64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Modules/_decimal/libmpdec | |
parent | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff) | |
download | ydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Modules/_decimal/libmpdec')
31 files changed, 835 insertions, 835 deletions
diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/basearith.c b/contrib/tools/python3/src/Modules/_decimal/libmpdec/basearith.c index ce8a84586c..85c608fadf 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/basearith.c +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/basearith.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,11 +27,11 @@ #include "mpdecimal.h" - -#include <assert.h> + +#include <assert.h> #include <stdio.h> - -#include "basearith.h" + +#include "basearith.h" #include "constants.h" #include "typearith.h" @@ -337,7 +337,7 @@ _mpd_basedivmod(mpd_uint_t *q, mpd_uint_t *r, /* D2: loop */ for (j=m; j != MPD_SIZE_MAX; j--) { - assert(2 <= j+n && j+n <= nplusm); /* annotation for scan-build */ + assert(2 <= j+n && j+n <= nplusm); /* annotation for scan-build */ /* D3: calculate qhat and rhat */ rhat = _mpd_shortdiv(w2, u+j+n-1, 2, v[n-1]); diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/basearith.h b/contrib/tools/python3/src/Modules/_decimal/libmpdec/basearith.h index 0aac9ba0f9..d35925aadd 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/basearith.h +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/basearith.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,8 +26,8 @@ */ -#ifndef LIBMPDEC_BASEARITH_H_ -#define LIBMPDEC_BASEARITH_H_ +#ifndef LIBMPDEC_BASEARITH_H_ +#define LIBMPDEC_BASEARITH_H_ #include "mpdecimal.h" @@ -215,4 +215,4 @@ _mpd_isallnine(const mpd_uint_t *data, mpd_ssize_t len) MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif /* LIBMPDEC_BASEARITH_H_ */ +#endif /* LIBMPDEC_BASEARITH_H_ */ diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/bits.h b/contrib/tools/python3/src/Modules/_decimal/libmpdec/bits.h index 85ad10ad3a..aa9c3e7798 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/bits.h +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/bits.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,8 +26,8 @@ */ -#ifndef LIBMPDEC_BITS_H_ -#define LIBMPDEC_BITS_H_ +#ifndef LIBMPDEC_BITS_H_ +#define LIBMPDEC_BITS_H_ #include "mpdecimal.h" @@ -185,4 +185,4 @@ mpd_bsf(mpd_size_t a) #endif /* BSR/BSF */ -#endif /* LIBMPDEC_BITS_H_ */ +#endif /* LIBMPDEC_BITS_H_ */ diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/constants.c b/contrib/tools/python3/src/Modules/_decimal/libmpdec/constants.c index c5dcfdb582..4c4de622bc 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/constants.c +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/constants.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 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/contrib/tools/python3/src/Modules/_decimal/libmpdec/constants.h b/contrib/tools/python3/src/Modules/_decimal/libmpdec/constants.h index 48fc359a06..7c1db839c2 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/constants.h +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/constants.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,15 +26,15 @@ */ -#ifndef LIBMPDEC_CONSTANTS_H_ -#define LIBMPDEC_CONSTANTS_H_ +#ifndef LIBMPDEC_CONSTANTS_H_ +#define LIBMPDEC_CONSTANTS_H_ #include "mpdecimal.h" -#include <stdint.h> +#include <stdint.h> + - /* Internal header file: all symbols have local scope in the DSO */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) @@ -86,4 +86,4 @@ extern const mpd_uint_t UH_P1P2; MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif /* LIBMPDEC_CONSTANTS_H_ */ +#endif /* LIBMPDEC_CONSTANTS_H_ */ diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/context.c b/contrib/tools/python3/src/Modules/_decimal/libmpdec/context.c index cc2e965e49..9cbc205095 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/context.c +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/context.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,16 +27,16 @@ #include "mpdecimal.h" - -#include <signal.h> + +#include <signal.h> #include <stdio.h> #include <string.h> void -mpd_dflt_traphandler(mpd_context_t *ctx) +mpd_dflt_traphandler(mpd_context_t *ctx) { - (void)ctx; + (void)ctx; raise(SIGFPE); } diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/convolute.c b/contrib/tools/python3/src/Modules/_decimal/libmpdec/convolute.c index 5de2570538..4bc8e8b5fd 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/convolute.c +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/convolute.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,7 +29,7 @@ #include "mpdecimal.h" #include "bits.h" #include "constants.h" -#include "convolute.h" +#include "convolute.h" #include "fnt.h" #include "fourstep.h" #include "numbertheory.h" diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/convolute.h b/contrib/tools/python3/src/Modules/_decimal/libmpdec/convolute.h index 18716b23ff..62edb3e457 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/convolute.h +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/convolute.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,8 +26,8 @@ */ -#ifndef LIBMPDEC_CONVOLUTE_H_ -#define LIBMPDEC_CONVOLUTE_H_ +#ifndef LIBMPDEC_CONVOLUTE_H_ +#define LIBMPDEC_CONVOLUTE_H_ #include "mpdecimal.h" @@ -46,4 +46,4 @@ int fnt_autoconvolute(mpd_uint_t *c1, mpd_size_t n, int modnum); MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif /* LIBMPDEC_CONVOLUTE_H_ */ +#endif /* LIBMPDEC_CONVOLUTE_H_ */ diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/crt.c b/contrib/tools/python3/src/Modules/_decimal/libmpdec/crt.c index dd8418671d..613274ee0c 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/crt.c +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/crt.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,14 +27,14 @@ #include "mpdecimal.h" - + #include <assert.h> - -#include "constants.h" -#include "crt.h" + +#include "constants.h" +#include "crt.h" #include "numbertheory.h" #include "umodarith.h" -#include "typearith.h" +#include "typearith.h" /* Bignum: Chinese Remainder Theorem, extends the maximum transform length. */ diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/crt.h b/contrib/tools/python3/src/Modules/_decimal/libmpdec/crt.h index ae0765ee10..15a347d4cb 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/crt.h +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/crt.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,8 +26,8 @@ */ -#ifndef LIBMPDEC_CRT_H_ -#define LIBMPDEC_CRT_H_ +#ifndef LIBMPDEC_CRT_H_ +#define LIBMPDEC_CRT_H_ #include "mpdecimal.h" @@ -43,4 +43,4 @@ void crt3(mpd_uint_t *x1, mpd_uint_t *x2, mpd_uint_t *x3, mpd_size_t nmemb); MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif /* LIBMPDEC_CRT_H_ */ +#endif /* LIBMPDEC_CRT_H_ */ diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/difradix2.c b/contrib/tools/python3/src/Modules/_decimal/libmpdec/difradix2.c index 661783cc15..049ecff65b 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/difradix2.c +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/difradix2.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,12 +27,12 @@ #include "mpdecimal.h" - + #include <assert.h> - + #include "bits.h" -#include "constants.h" -#include "difradix2.h" +#include "constants.h" +#include "difradix2.h" #include "numbertheory.h" #include "umodarith.h" diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/difradix2.h b/contrib/tools/python3/src/Modules/_decimal/libmpdec/difradix2.h index 868878e439..cdcbcf9a71 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/difradix2.h +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/difradix2.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,8 +26,8 @@ */ -#ifndef LIBMPDEC_DIFRADIX2_H_ -#define LIBMPDEC_DIFRADIX2_H_ +#ifndef LIBMPDEC_DIFRADIX2_H_ +#define LIBMPDEC_DIFRADIX2_H_ #include "mpdecimal.h" @@ -44,4 +44,4 @@ void fnt_dif2(mpd_uint_t a[], mpd_size_t n, struct fnt_params *tparams); MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif /* LIBMPDEC_DIFRADIX2_H_ */ +#endif /* LIBMPDEC_DIFRADIX2_H_ */ diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/fnt.c b/contrib/tools/python3/src/Modules/_decimal/libmpdec/fnt.c index 56f39dcfda..0dbe98fc71 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/fnt.c +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/fnt.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,13 +27,13 @@ #include "mpdecimal.h" - -#include <assert.h> + +#include <assert.h> #include <stdio.h> - + #include "bits.h" #include "difradix2.h" -#include "fnt.h" +#include "fnt.h" #include "numbertheory.h" diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/fnt.h b/contrib/tools/python3/src/Modules/_decimal/libmpdec/fnt.h index 92f352d43d..5222c476a3 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/fnt.h +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/fnt.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,8 +26,8 @@ */ -#ifndef LIBMPDEC_FNT_H_ -#define LIBMPDEC_FNT_H_ +#ifndef LIBMPDEC_FNT_H_ +#define LIBMPDEC_FNT_H_ #include "mpdecimal.h" @@ -44,4 +44,4 @@ int std_inv_fnt(mpd_uint_t a[], mpd_size_t n, int modnum); MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif /* LIBMPDEC_FNT_H_ */ +#endif /* LIBMPDEC_FNT_H_ */ diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/fourstep.c b/contrib/tools/python3/src/Modules/_decimal/libmpdec/fourstep.c index c54f39561d..fb173ed5a5 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/fourstep.c +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/fourstep.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,11 +27,11 @@ #include "mpdecimal.h" - + #include <assert.h> - -#include "constants.h" -#include "fourstep.h" + +#include "constants.h" +#include "fourstep.h" #include "numbertheory.h" #include "sixstep.h" #include "umodarith.h" @@ -189,7 +189,7 @@ four_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum) #if 0 /* An unordered transform is sufficient for convolution. */ /* Transpose the matrix. */ - #include "transpose.h" + #include "transpose.h" transpose_3xpow2(a, R, C); #endif @@ -220,7 +220,7 @@ inv_four_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum) #if 0 /* An unordered transform is sufficient for convolution. */ /* Transpose the matrix, producing an R*C matrix. */ - #include "transpose.h" + #include "transpose.h" transpose_3xpow2(a, C, R); #endif diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/fourstep.h b/contrib/tools/python3/src/Modules/_decimal/libmpdec/fourstep.h index 123d59b57b..5ffb6fcc8e 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/fourstep.h +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/fourstep.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,8 +26,8 @@ */ -#ifndef LIBMPDEC_FOURSTEP_H_ -#define LIBMPDEC_FOURSTEP_H_ +#ifndef LIBMPDEC_FOURSTEP_H_ +#define LIBMPDEC_FOURSTEP_H_ #include "mpdecimal.h" @@ -44,4 +44,4 @@ int inv_four_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum); MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif /* LIBMPDEC_FOURSTEP_H_ */ +#endif /* LIBMPDEC_FOURSTEP_H_ */ diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/io.c b/contrib/tools/python3/src/Modules/_decimal/libmpdec/io.c index c873fd1670..03f2acfc1a 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/io.c +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/io.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,16 +27,16 @@ #include "mpdecimal.h" - -#include <assert.h> -#include <ctype.h> -#include <errno.h> -#include <limits.h> -#include <locale.h> + +#include <assert.h> +#include <ctype.h> +#include <errno.h> +#include <limits.h> +#include <locale.h> #include <stdio.h> #include <stdlib.h> #include <string.h> - + #include "typearith.h" #include "mpd_io.h" @@ -277,7 +277,7 @@ mpd_qset_string(mpd_t *dec, const char *s, const mpd_context_t *ctx, } } - digits = end - coeff; + digits = end - coeff; if (dpoint) { size_t fracdigits = end-dpoint-1; if (dpoint > coeff) digits--; @@ -326,22 +326,22 @@ conversion_error: mpd_seterror(dec, MPD_Conversion_syntax, status); } -/* convert a character string to a decimal, use a maxcontext for conversion */ -void -mpd_qset_string_exact(mpd_t *dec, const char *s, uint32_t *status) -{ - mpd_context_t maxcontext; - - mpd_maxcontext(&maxcontext); - mpd_qset_string(dec, s, &maxcontext, status); - - if (*status & (MPD_Inexact|MPD_Rounded|MPD_Clamped)) { - /* we want exact results */ - mpd_seterror(dec, MPD_Invalid_operation, status); - } - *status &= MPD_Errors; -} - +/* convert a character string to a decimal, use a maxcontext for conversion */ +void +mpd_qset_string_exact(mpd_t *dec, const char *s, uint32_t *status) +{ + mpd_context_t maxcontext; + + mpd_maxcontext(&maxcontext); + mpd_qset_string(dec, s, &maxcontext, status); + + if (*status & (MPD_Inexact|MPD_Rounded|MPD_Clamped)) { + /* we want exact results */ + mpd_seterror(dec, MPD_Invalid_operation, status); + } + *status &= MPD_Errors; +} + /* Print word x with n decimal digits to string s. dot is either NULL or the location of a decimal point. */ #define EXTRACT_DIGIT(s, x, d, dot) \ @@ -555,8 +555,8 @@ _mpd_to_string(char **result, const mpd_t *dec, int flags, mpd_ssize_t dplace) dplace = -1 + mod_mpd_ssize_t(dec->exp+2, 3); } else { /* ldigits-1 is the adjusted exponent, which - * should be divisible by three. If not, move - * dplace one or two places to the right. */ + * should be divisible by three. If not, move + * dplace one or two places to the right. */ dplace += mod_mpd_ssize_t(ldigits-1, 3); } } @@ -1263,7 +1263,7 @@ mpd_qformat_spec(const mpd_t *dec, const mpd_spec_t *spec, } if (isupper((uchar)type)) { - type = (char)tolower((uchar)type); + type = (char)tolower((uchar)type); flags |= MPD_FMT_UPPER; } if (spec->sign == ' ') { @@ -1281,7 +1281,7 @@ mpd_qformat_spec(const mpd_t *dec, const mpd_spec_t *spec, stackspec.align = '>'; spec = &stackspec; } - assert(strlen(spec->fill) == 1); /* annotation for scan-build */ + assert(strlen(spec->fill) == 1); /* annotation for scan-build */ if (type == '%') { flags |= MPD_FMT_PERCENT; } diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/mpalloc.c b/contrib/tools/python3/src/Modules/_decimal/libmpdec/mpalloc.c index 04a42e7058..eb5ee7a807 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/mpalloc.c +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/mpalloc.c @@ -1,356 +1,356 @@ -/* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - -#include "mpdecimal.h" - -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "mpalloc.h" -#include "typearith.h" - - -#if defined(_MSC_VER) - #pragma warning(disable : 4232) -#endif - - -/* Guaranteed minimum allocation for a coefficient. May be changed once - at program start using mpd_setminalloc(). */ -mpd_ssize_t MPD_MINALLOC = MPD_MINALLOC_MIN; - -/* Custom allocation and free functions */ -void *(* mpd_mallocfunc)(size_t size) = malloc; -void *(* mpd_reallocfunc)(void *ptr, size_t size) = realloc; -void *(* mpd_callocfunc)(size_t nmemb, size_t size) = calloc; -void (* mpd_free)(void *ptr) = free; - - -/* emulate calloc if it is not available */ -void * -mpd_callocfunc_em(size_t nmemb, size_t size) -{ - void *ptr; - size_t req; - mpd_size_t overflow; - -#if MPD_SIZE_MAX < SIZE_MAX - /* full_coverage test only */ - if (nmemb > MPD_SIZE_MAX || size > MPD_SIZE_MAX) { - return NULL; - } -#endif - - req = mul_size_t_overflow((mpd_size_t)nmemb, (mpd_size_t)size, - &overflow); - if (overflow) { - return NULL; - } - - ptr = mpd_mallocfunc(req); - if (ptr == NULL) { - return NULL; - } - /* used on uint32_t or uint64_t */ - memset(ptr, 0, req); - - return ptr; -} - - -/* malloc with overflow checking */ -void * -mpd_alloc(mpd_size_t nmemb, mpd_size_t size) -{ - mpd_size_t req, overflow; - - req = mul_size_t_overflow(nmemb, size, &overflow); - if (overflow) { - return NULL; - } - - return mpd_mallocfunc(req); -} - -/* calloc with overflow checking */ -void * -mpd_calloc(mpd_size_t nmemb, mpd_size_t size) -{ - mpd_size_t overflow; - - (void)mul_size_t_overflow(nmemb, size, &overflow); - if (overflow) { - return NULL; - } - - return mpd_callocfunc(nmemb, size); -} - -/* realloc with overflow checking */ -void * -mpd_realloc(void *ptr, mpd_size_t nmemb, mpd_size_t size, uint8_t *err) -{ - void *new; - mpd_size_t req, overflow; - - req = mul_size_t_overflow(nmemb, size, &overflow); - if (overflow) { - *err = 1; - return ptr; - } - - new = mpd_reallocfunc(ptr, req); - if (new == NULL) { - *err = 1; - return ptr; - } - - return new; -} - -/* struct hack malloc with overflow checking */ -void * -mpd_sh_alloc(mpd_size_t struct_size, mpd_size_t nmemb, mpd_size_t size) -{ - mpd_size_t req, overflow; - - req = mul_size_t_overflow(nmemb, size, &overflow); - if (overflow) { - return NULL; - } - - req = add_size_t_overflow(req, struct_size, &overflow); - if (overflow) { - return NULL; - } - - return mpd_mallocfunc(req); -} - - -/* Allocate a new decimal with a coefficient of length 'nwords'. In case - of an error the return value is NULL. */ -mpd_t * -mpd_qnew_size(mpd_ssize_t nwords) -{ - mpd_t *result; - - nwords = (nwords < MPD_MINALLOC) ? MPD_MINALLOC : nwords; - - result = mpd_alloc(1, sizeof *result); - if (result == NULL) { - return NULL; - } - - result->data = mpd_alloc(nwords, sizeof *result->data); - if (result->data == NULL) { - mpd_free(result); - return NULL; - } - - result->flags = 0; - result->exp = 0; - result->digits = 0; - result->len = 0; - result->alloc = nwords; - - return result; -} - -/* Allocate a new decimal with a coefficient of length MPD_MINALLOC. - In case of an error the return value is NULL. */ -mpd_t * -mpd_qnew(void) -{ - return mpd_qnew_size(MPD_MINALLOC); -} - -/* Allocate new decimal. Caller can check for NULL or MPD_Malloc_error. - Raises on error. */ -mpd_t * -mpd_new(mpd_context_t *ctx) -{ - mpd_t *result; - - result = mpd_qnew(); - if (result == NULL) { - mpd_addstatus_raise(ctx, MPD_Malloc_error); - } - return result; -} - -/* - * Input: 'result' is a static mpd_t with a static coefficient. - * Assumption: 'nwords' >= result->alloc. - * - * Resize the static coefficient to a larger dynamic one and copy the - * existing data. If successful, the value of 'result' is unchanged. - * Otherwise, set 'result' to NaN and update 'status' with MPD_Malloc_error. - */ -int -mpd_switch_to_dyn(mpd_t *result, mpd_ssize_t nwords, uint32_t *status) -{ - mpd_uint_t *p = result->data; - - assert(nwords >= result->alloc); - - result->data = mpd_alloc(nwords, sizeof *result->data); - if (result->data == NULL) { - result->data = p; - mpd_set_qnan(result); - mpd_set_positive(result); - result->exp = result->digits = result->len = 0; - *status |= MPD_Malloc_error; - return 0; - } - - memcpy(result->data, p, result->alloc * (sizeof *result->data)); - result->alloc = nwords; - mpd_set_dynamic_data(result); - return 1; -} - -/* - * Input: 'result' is a static mpd_t with a static coefficient. - * - * Convert the coefficient to a dynamic one that is initialized to zero. If - * malloc fails, set 'result' to NaN and update 'status' with MPD_Malloc_error. - */ -int -mpd_switch_to_dyn_zero(mpd_t *result, mpd_ssize_t nwords, uint32_t *status) -{ - mpd_uint_t *p = result->data; - - result->data = mpd_calloc(nwords, sizeof *result->data); - if (result->data == NULL) { - result->data = p; - mpd_set_qnan(result); - mpd_set_positive(result); - result->exp = result->digits = result->len = 0; - *status |= MPD_Malloc_error; - return 0; - } - - result->alloc = nwords; - mpd_set_dynamic_data(result); - - return 1; -} - -/* - * Input: 'result' is a static or a dynamic mpd_t with a dynamic coefficient. - * Resize the coefficient to length 'nwords': - * Case nwords > result->alloc: - * If realloc is successful: - * 'result' has a larger coefficient but the same value. Return 1. - * Otherwise: - * Set 'result' to NaN, update status with MPD_Malloc_error and return 0. - * Case nwords < result->alloc: - * If realloc is successful: - * 'result' has a smaller coefficient. result->len is undefined. Return 1. - * Otherwise (unlikely): - * 'result' is unchanged. Reuse the now oversized coefficient. Return 1. - */ -int -mpd_realloc_dyn(mpd_t *result, mpd_ssize_t nwords, uint32_t *status) -{ - uint8_t err = 0; - - result->data = mpd_realloc(result->data, nwords, sizeof *result->data, &err); - if (!err) { - result->alloc = nwords; - } - else if (nwords > result->alloc) { - mpd_set_qnan(result); - mpd_set_positive(result); - result->exp = result->digits = result->len = 0; - *status |= MPD_Malloc_error; - return 0; - } - - return 1; -} - -/* - * Input: 'result' is a static mpd_t with a static coefficient. - * Assumption: 'nwords' >= result->alloc. - * - * Resize the static coefficient to a larger dynamic one and copy the - * existing data. - * - * On failure the value of 'result' is unchanged. - */ -int -mpd_switch_to_dyn_cxx(mpd_t *result, mpd_ssize_t nwords) -{ - assert(nwords >= result->alloc); - - mpd_uint_t *data = mpd_alloc(nwords, sizeof *result->data); - if (data == NULL) { - return 0; - } - - memcpy(data, result->data, result->alloc * (sizeof *result->data)); - result->data = data; - result->alloc = nwords; - mpd_set_dynamic_data(result); - return 1; -} - -/* - * Input: 'result' is a static or a dynamic mpd_t with a dynamic coefficient. - * Resize the coefficient to length 'nwords': - * Case nwords > result->alloc: - * If realloc is successful: - * 'result' has a larger coefficient but the same value. Return 1. - * Otherwise: - * 'result' has a the same coefficient. Return 0. - * Case nwords < result->alloc: - * If realloc is successful: - * 'result' has a smaller coefficient. result->len is undefined. Return 1. - * Otherwise (unlikely): - * 'result' is unchanged. Reuse the now oversized coefficient. Return 1. - */ -int -mpd_realloc_dyn_cxx(mpd_t *result, mpd_ssize_t nwords) -{ - uint8_t err = 0; - - mpd_uint_t *p = mpd_realloc(result->data, nwords, sizeof *result->data, &err); - if (!err) { - result->data = p; - result->alloc = nwords; - } - else if (nwords > result->alloc) { - return 0; - } - - return 1; -} +/* + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + +#include "mpdecimal.h" + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "mpalloc.h" +#include "typearith.h" + + +#if defined(_MSC_VER) + #pragma warning(disable : 4232) +#endif + + +/* Guaranteed minimum allocation for a coefficient. May be changed once + at program start using mpd_setminalloc(). */ +mpd_ssize_t MPD_MINALLOC = MPD_MINALLOC_MIN; + +/* Custom allocation and free functions */ +void *(* mpd_mallocfunc)(size_t size) = malloc; +void *(* mpd_reallocfunc)(void *ptr, size_t size) = realloc; +void *(* mpd_callocfunc)(size_t nmemb, size_t size) = calloc; +void (* mpd_free)(void *ptr) = free; + + +/* emulate calloc if it is not available */ +void * +mpd_callocfunc_em(size_t nmemb, size_t size) +{ + void *ptr; + size_t req; + mpd_size_t overflow; + +#if MPD_SIZE_MAX < SIZE_MAX + /* full_coverage test only */ + if (nmemb > MPD_SIZE_MAX || size > MPD_SIZE_MAX) { + return NULL; + } +#endif + + req = mul_size_t_overflow((mpd_size_t)nmemb, (mpd_size_t)size, + &overflow); + if (overflow) { + return NULL; + } + + ptr = mpd_mallocfunc(req); + if (ptr == NULL) { + return NULL; + } + /* used on uint32_t or uint64_t */ + memset(ptr, 0, req); + + return ptr; +} + + +/* malloc with overflow checking */ +void * +mpd_alloc(mpd_size_t nmemb, mpd_size_t size) +{ + mpd_size_t req, overflow; + + req = mul_size_t_overflow(nmemb, size, &overflow); + if (overflow) { + return NULL; + } + + return mpd_mallocfunc(req); +} + +/* calloc with overflow checking */ +void * +mpd_calloc(mpd_size_t nmemb, mpd_size_t size) +{ + mpd_size_t overflow; + + (void)mul_size_t_overflow(nmemb, size, &overflow); + if (overflow) { + return NULL; + } + + return mpd_callocfunc(nmemb, size); +} + +/* realloc with overflow checking */ +void * +mpd_realloc(void *ptr, mpd_size_t nmemb, mpd_size_t size, uint8_t *err) +{ + void *new; + mpd_size_t req, overflow; + + req = mul_size_t_overflow(nmemb, size, &overflow); + if (overflow) { + *err = 1; + return ptr; + } + + new = mpd_reallocfunc(ptr, req); + if (new == NULL) { + *err = 1; + return ptr; + } + + return new; +} + +/* struct hack malloc with overflow checking */ +void * +mpd_sh_alloc(mpd_size_t struct_size, mpd_size_t nmemb, mpd_size_t size) +{ + mpd_size_t req, overflow; + + req = mul_size_t_overflow(nmemb, size, &overflow); + if (overflow) { + return NULL; + } + + req = add_size_t_overflow(req, struct_size, &overflow); + if (overflow) { + return NULL; + } + + return mpd_mallocfunc(req); +} + + +/* Allocate a new decimal with a coefficient of length 'nwords'. In case + of an error the return value is NULL. */ +mpd_t * +mpd_qnew_size(mpd_ssize_t nwords) +{ + mpd_t *result; + + nwords = (nwords < MPD_MINALLOC) ? MPD_MINALLOC : nwords; + + result = mpd_alloc(1, sizeof *result); + if (result == NULL) { + return NULL; + } + + result->data = mpd_alloc(nwords, sizeof *result->data); + if (result->data == NULL) { + mpd_free(result); + return NULL; + } + + result->flags = 0; + result->exp = 0; + result->digits = 0; + result->len = 0; + result->alloc = nwords; + + return result; +} + +/* Allocate a new decimal with a coefficient of length MPD_MINALLOC. + In case of an error the return value is NULL. */ +mpd_t * +mpd_qnew(void) +{ + return mpd_qnew_size(MPD_MINALLOC); +} + +/* Allocate new decimal. Caller can check for NULL or MPD_Malloc_error. + Raises on error. */ +mpd_t * +mpd_new(mpd_context_t *ctx) +{ + mpd_t *result; + + result = mpd_qnew(); + if (result == NULL) { + mpd_addstatus_raise(ctx, MPD_Malloc_error); + } + return result; +} + +/* + * Input: 'result' is a static mpd_t with a static coefficient. + * Assumption: 'nwords' >= result->alloc. + * + * Resize the static coefficient to a larger dynamic one and copy the + * existing data. If successful, the value of 'result' is unchanged. + * Otherwise, set 'result' to NaN and update 'status' with MPD_Malloc_error. + */ +int +mpd_switch_to_dyn(mpd_t *result, mpd_ssize_t nwords, uint32_t *status) +{ + mpd_uint_t *p = result->data; + + assert(nwords >= result->alloc); + + result->data = mpd_alloc(nwords, sizeof *result->data); + if (result->data == NULL) { + result->data = p; + mpd_set_qnan(result); + mpd_set_positive(result); + result->exp = result->digits = result->len = 0; + *status |= MPD_Malloc_error; + return 0; + } + + memcpy(result->data, p, result->alloc * (sizeof *result->data)); + result->alloc = nwords; + mpd_set_dynamic_data(result); + return 1; +} + +/* + * Input: 'result' is a static mpd_t with a static coefficient. + * + * Convert the coefficient to a dynamic one that is initialized to zero. If + * malloc fails, set 'result' to NaN and update 'status' with MPD_Malloc_error. + */ +int +mpd_switch_to_dyn_zero(mpd_t *result, mpd_ssize_t nwords, uint32_t *status) +{ + mpd_uint_t *p = result->data; + + result->data = mpd_calloc(nwords, sizeof *result->data); + if (result->data == NULL) { + result->data = p; + mpd_set_qnan(result); + mpd_set_positive(result); + result->exp = result->digits = result->len = 0; + *status |= MPD_Malloc_error; + return 0; + } + + result->alloc = nwords; + mpd_set_dynamic_data(result); + + return 1; +} + +/* + * Input: 'result' is a static or a dynamic mpd_t with a dynamic coefficient. + * Resize the coefficient to length 'nwords': + * Case nwords > result->alloc: + * If realloc is successful: + * 'result' has a larger coefficient but the same value. Return 1. + * Otherwise: + * Set 'result' to NaN, update status with MPD_Malloc_error and return 0. + * Case nwords < result->alloc: + * If realloc is successful: + * 'result' has a smaller coefficient. result->len is undefined. Return 1. + * Otherwise (unlikely): + * 'result' is unchanged. Reuse the now oversized coefficient. Return 1. + */ +int +mpd_realloc_dyn(mpd_t *result, mpd_ssize_t nwords, uint32_t *status) +{ + uint8_t err = 0; + + result->data = mpd_realloc(result->data, nwords, sizeof *result->data, &err); + if (!err) { + result->alloc = nwords; + } + else if (nwords > result->alloc) { + mpd_set_qnan(result); + mpd_set_positive(result); + result->exp = result->digits = result->len = 0; + *status |= MPD_Malloc_error; + return 0; + } + + return 1; +} + +/* + * Input: 'result' is a static mpd_t with a static coefficient. + * Assumption: 'nwords' >= result->alloc. + * + * Resize the static coefficient to a larger dynamic one and copy the + * existing data. + * + * On failure the value of 'result' is unchanged. + */ +int +mpd_switch_to_dyn_cxx(mpd_t *result, mpd_ssize_t nwords) +{ + assert(nwords >= result->alloc); + + mpd_uint_t *data = mpd_alloc(nwords, sizeof *result->data); + if (data == NULL) { + return 0; + } + + memcpy(data, result->data, result->alloc * (sizeof *result->data)); + result->data = data; + result->alloc = nwords; + mpd_set_dynamic_data(result); + return 1; +} + +/* + * Input: 'result' is a static or a dynamic mpd_t with a dynamic coefficient. + * Resize the coefficient to length 'nwords': + * Case nwords > result->alloc: + * If realloc is successful: + * 'result' has a larger coefficient but the same value. Return 1. + * Otherwise: + * 'result' has a the same coefficient. Return 0. + * Case nwords < result->alloc: + * If realloc is successful: + * 'result' has a smaller coefficient. result->len is undefined. Return 1. + * Otherwise (unlikely): + * 'result' is unchanged. Reuse the now oversized coefficient. Return 1. + */ +int +mpd_realloc_dyn_cxx(mpd_t *result, mpd_ssize_t nwords) +{ + uint8_t err = 0; + + mpd_uint_t *p = mpd_realloc(result->data, nwords, sizeof *result->data, &err); + if (!err) { + result->data = p; + result->alloc = nwords; + } + else if (nwords > result->alloc) { + return 0; + } + + return 1; +} diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/mpalloc.h b/contrib/tools/python3/src/Modules/_decimal/libmpdec/mpalloc.h index f8f3ae2e5c..186808457b 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/mpalloc.h +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/mpalloc.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,15 +26,15 @@ */ -#ifndef LIBMPDEC_MPALLOC_H_ -#define LIBMPDEC_MPALLOC_H_ +#ifndef LIBMPDEC_MPALLOC_H_ +#define LIBMPDEC_MPALLOC_H_ #include "mpdecimal.h" -#include <stdint.h> +#include <stdint.h> + - /* Internal header file: all symbols have local scope in the DSO */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) @@ -43,11 +43,11 @@ int mpd_switch_to_dyn(mpd_t *result, mpd_ssize_t size, uint32_t *status); int mpd_switch_to_dyn_zero(mpd_t *result, mpd_ssize_t size, uint32_t *status); int mpd_realloc_dyn(mpd_t *result, mpd_ssize_t size, uint32_t *status); -int mpd_switch_to_dyn_cxx(mpd_t *result, mpd_ssize_t size); -int mpd_realloc_dyn_cxx(mpd_t *result, mpd_ssize_t size); +int mpd_switch_to_dyn_cxx(mpd_t *result, mpd_ssize_t size); +int mpd_realloc_dyn_cxx(mpd_t *result, mpd_ssize_t size); + - MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif /* LIBMPDEC_MPALLOC_H_ */ +#endif /* LIBMPDEC_MPALLOC_H_ */ diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/mpd_io.h b/contrib/tools/python3/src/Modules/_decimal/libmpdec/mpd_io.h index 2c7a37c3dd..79d7c05ce3 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/mpd_io.h +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/mpd_io.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,20 +26,20 @@ */ -#ifndef LIBMPDEC_IO_H_ -#define LIBMPDEC_IO_H_ +#ifndef LIBMPDEC_IO_H_ +#define LIBMPDEC_IO_H_ #include "mpdecimal.h" -#include <stdint.h> +#include <stdint.h> + - #if SIZE_MAX == MPD_SIZE_MAX #define mpd_strtossize _mpd_strtossize #else -#include <errno.h> - +#include <errno.h> + static inline mpd_ssize_t mpd_strtossize(const char *s, char **end, int base) { @@ -59,4 +59,4 @@ mpd_strtossize(const char *s, char **end, int base) #endif -#endif /* LIBMPDEC_IO_H_ */ +#endif /* LIBMPDEC_IO_H_ */ diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/mpdecimal.c b/contrib/tools/python3/src/Modules/_decimal/libmpdec/mpdecimal.c index a73d20bd68..28b639ccb4 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/mpdecimal.c +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/mpdecimal.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,17 +27,17 @@ #include "mpdecimal.h" - -#include <assert.h> -#include <limits.h> -#include <math.h> + +#include <assert.h> +#include <limits.h> +#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> - + #include "basearith.h" #include "bits.h" -#include "constants.h" +#include "constants.h" #include "convolute.h" #include "crt.h" #include "mpalloc.h" @@ -64,7 +64,7 @@ #if defined(_MSC_VER) #define ALWAYS_INLINE __forceinline -#elif defined(__IBMC__) || defined(LEGACY_COMPILER) +#elif defined(__IBMC__) || defined(LEGACY_COMPILER) #define ALWAYS_INLINE #undef inline #define inline @@ -244,7 +244,7 @@ mpd_lsd(mpd_uint_t word) } /* Coefficient size needed to store 'digits' */ -mpd_ssize_t +mpd_ssize_t mpd_digits_to_size(mpd_ssize_t digits) { mpd_ssize_t q, r; @@ -263,9 +263,9 @@ mpd_exp_digits(mpd_ssize_t exp) /* Canonical */ ALWAYS_INLINE int -mpd_iscanonical(const mpd_t *dec) +mpd_iscanonical(const mpd_t *dec) { - (void)dec; + (void)dec; return 1; } @@ -516,28 +516,28 @@ mpd_qresize(mpd_t *result, mpd_ssize_t nwords, uint32_t *status) return mpd_realloc_dyn(result, nwords, status); } -/* Same as mpd_qresize, but do not set the result no NaN on failure. */ -static ALWAYS_INLINE int -mpd_qresize_cxx(mpd_t *result, mpd_ssize_t nwords) -{ - assert(!mpd_isconst_data(result)); /* illegal operation for a const */ - assert(!mpd_isshared_data(result)); /* illegal operation for a shared */ - assert(MPD_MINALLOC <= result->alloc); - - nwords = (nwords <= MPD_MINALLOC) ? MPD_MINALLOC : nwords; - if (nwords == result->alloc) { - return 1; - } - if (mpd_isstatic_data(result)) { - if (nwords > result->alloc) { - return mpd_switch_to_dyn_cxx(result, nwords); - } - return 1; - } - - return mpd_realloc_dyn_cxx(result, nwords); -} - +/* Same as mpd_qresize, but do not set the result no NaN on failure. */ +static ALWAYS_INLINE int +mpd_qresize_cxx(mpd_t *result, mpd_ssize_t nwords) +{ + assert(!mpd_isconst_data(result)); /* illegal operation for a const */ + assert(!mpd_isshared_data(result)); /* illegal operation for a shared */ + assert(MPD_MINALLOC <= result->alloc); + + nwords = (nwords <= MPD_MINALLOC) ? MPD_MINALLOC : nwords; + if (nwords == result->alloc) { + return 1; + } + if (mpd_isstatic_data(result)) { + if (nwords > result->alloc) { + return mpd_switch_to_dyn_cxx(result, nwords); + } + return 1; + } + + return mpd_realloc_dyn_cxx(result, nwords); +} + /* Same as mpd_qresize, but the complete coefficient (including the old * memory area!) is initialized to zero. */ ALWAYS_INLINE int @@ -1218,7 +1218,7 @@ _c32setu64(mpd_t *result, uint64_t u, uint8_t sign, uint32_t *status) result->data[i] = w[i]; } - mpd_set_flags(result, sign); + mpd_set_flags(result, sign); result->exp = 0; result->len = len; mpd_setdigits(result); @@ -1270,26 +1270,26 @@ mpd_qset_i64(mpd_t *result, int64_t a, const mpd_context_t *ctx, #endif } -/* quietly set a decimal from an int64_t, use a maxcontext for conversion */ -void -mpd_qset_i64_exact(mpd_t *result, int64_t a, uint32_t *status) -{ - mpd_context_t maxcontext; - - mpd_maxcontext(&maxcontext); -#ifdef CONFIG_64 - mpd_qset_ssize(result, a, &maxcontext, status); -#else - _c32_qset_i64(result, a, &maxcontext, status); -#endif - - if (*status & (MPD_Inexact|MPD_Rounded|MPD_Clamped)) { - /* we want exact results */ - mpd_seterror(result, MPD_Invalid_operation, status); - } - *status &= MPD_Errors; -} - +/* quietly set a decimal from an int64_t, use a maxcontext for conversion */ +void +mpd_qset_i64_exact(mpd_t *result, int64_t a, uint32_t *status) +{ + mpd_context_t maxcontext; + + mpd_maxcontext(&maxcontext); +#ifdef CONFIG_64 + mpd_qset_ssize(result, a, &maxcontext, status); +#else + _c32_qset_i64(result, a, &maxcontext, status); +#endif + + if (*status & (MPD_Inexact|MPD_Rounded|MPD_Clamped)) { + /* we want exact results */ + mpd_seterror(result, MPD_Invalid_operation, status); + } + *status &= MPD_Errors; +} + /* quietly set a decimal from a uint64_t */ void mpd_qset_u64(mpd_t *result, uint64_t a, const mpd_context_t *ctx, @@ -1301,26 +1301,26 @@ mpd_qset_u64(mpd_t *result, uint64_t a, const mpd_context_t *ctx, _c32_qset_u64(result, a, ctx, status); #endif } - -/* quietly set a decimal from a uint64_t, use a maxcontext for conversion */ -void -mpd_qset_u64_exact(mpd_t *result, uint64_t a, uint32_t *status) -{ - mpd_context_t maxcontext; - - mpd_maxcontext(&maxcontext); -#ifdef CONFIG_64 - mpd_qset_uint(result, a, &maxcontext, status); -#else - _c32_qset_u64(result, a, &maxcontext, status); -#endif - - if (*status & (MPD_Inexact|MPD_Rounded|MPD_Clamped)) { - /* we want exact results */ - mpd_seterror(result, MPD_Invalid_operation, status); - } - *status &= MPD_Errors; -} + +/* quietly set a decimal from a uint64_t, use a maxcontext for conversion */ +void +mpd_qset_u64_exact(mpd_t *result, uint64_t a, uint32_t *status) +{ + mpd_context_t maxcontext; + + mpd_maxcontext(&maxcontext); +#ifdef CONFIG_64 + mpd_qset_uint(result, a, &maxcontext, status); +#else + _c32_qset_u64(result, a, &maxcontext, status); +#endif + + if (*status & (MPD_Inexact|MPD_Rounded|MPD_Clamped)) { + /* we want exact results */ + mpd_seterror(result, MPD_Invalid_operation, status); + } + *status &= MPD_Errors; +} #endif /* !LEGACY_COMPILER */ /* @@ -1410,13 +1410,13 @@ mpd_qabs_uint(const mpd_t *a, uint32_t *status) mpd_ssize_t mpd_qget_ssize(const mpd_t *a, uint32_t *status) { - uint32_t workstatus = 0; + uint32_t workstatus = 0; mpd_uint_t u; int isneg; - u = mpd_qabs_uint(a, &workstatus); - if (workstatus&MPD_Invalid_operation) { - *status |= workstatus; + u = mpd_qabs_uint(a, &workstatus); + if (workstatus&MPD_Invalid_operation) { + *status |= workstatus; return MPD_SSIZE_MAX; } @@ -1536,11 +1536,11 @@ mpd_qget_i64(const mpd_t *a, uint32_t *status) uint32_t mpd_qget_u32(const mpd_t *a, uint32_t *status) { - uint32_t workstatus = 0; - uint64_t x = mpd_qget_uint(a, &workstatus); + uint32_t workstatus = 0; + uint64_t x = mpd_qget_uint(a, &workstatus); - if (workstatus&MPD_Invalid_operation) { - *status |= workstatus; + if (workstatus&MPD_Invalid_operation) { + *status |= workstatus; return UINT32_MAX; } if (x > UINT32_MAX) { @@ -1555,11 +1555,11 @@ mpd_qget_u32(const mpd_t *a, uint32_t *status) int32_t mpd_qget_i32(const mpd_t *a, uint32_t *status) { - uint32_t workstatus = 0; - int64_t x = mpd_qget_ssize(a, &workstatus); + uint32_t workstatus = 0; + int64_t x = mpd_qget_ssize(a, &workstatus); - if (workstatus&MPD_Invalid_operation) { - *status |= workstatus; + if (workstatus&MPD_Invalid_operation) { + *status |= workstatus; return INT32_MAX; } if (x < INT32_MIN || x > INT32_MAX) { @@ -1575,20 +1575,20 @@ mpd_qget_i32(const mpd_t *a, uint32_t *status) uint64_t mpd_qget_u64(const mpd_t *a, uint32_t *status) { - uint32_t workstatus = 0; - uint64_t x = _c32_qget_u64(1, a, &workstatus); - *status |= workstatus; - return x; + uint32_t workstatus = 0; + uint64_t x = _c32_qget_u64(1, a, &workstatus); + *status |= workstatus; + return x; } /* quietly get an int64_t from a decimal */ int64_t mpd_qget_i64(const mpd_t *a, uint32_t *status) { - uint32_t workstatus = 0; - int64_t x = _c32_qget_i64(a, &workstatus); - *status |= workstatus; - return x; + uint32_t workstatus = 0; + int64_t x = _c32_qget_i64(a, &workstatus); + *status |= workstatus; + return x; } #endif @@ -2014,25 +2014,25 @@ mpd_qcopy(mpd_t *result, const mpd_t *a, uint32_t *status) return 1; } -/* Same as mpd_qcopy, but do not set the result to NaN on failure. */ -int -mpd_qcopy_cxx(mpd_t *result, const mpd_t *a) -{ - if (result == a) return 1; - - if (!mpd_qresize_cxx(result, a->len)) { - return 0; - } - - mpd_copy_flags(result, a); - result->exp = a->exp; - result->digits = a->digits; - result->len = a->len; - memcpy(result->data, a->data, a->len * (sizeof *result->data)); - - return 1; -} - +/* Same as mpd_qcopy, but do not set the result to NaN on failure. */ +int +mpd_qcopy_cxx(mpd_t *result, const mpd_t *a) +{ + if (result == a) return 1; + + if (!mpd_qresize_cxx(result, a->len)) { + return 0; + } + + mpd_copy_flags(result, a); + result->exp = a->exp; + result->digits = a->digits; + result->len = a->len; + memcpy(result->data, a->data, a->len * (sizeof *result->data)); + + return 1; +} + /* * Copy to a decimal with a static buffer. The caller has to make sure that * the buffer is big enough. Cannot fail. @@ -3876,72 +3876,72 @@ void mpd_qdiv(mpd_t *q, const mpd_t *a, const mpd_t *b, const mpd_context_t *ctx, uint32_t *status) { - MPD_NEW_STATIC(aa,0,0,0,0); - MPD_NEW_STATIC(bb,0,0,0,0); - uint32_t xstatus = 0; - - if (q == a) { - if (!mpd_qcopy(&aa, a, status)) { - mpd_seterror(q, MPD_Malloc_error, status); - goto out; - } - a = &aa; - } - - if (q == b) { - if (!mpd_qcopy(&bb, b, status)) { - mpd_seterror(q, MPD_Malloc_error, status); - goto out; - } - b = &bb; - } - - _mpd_qdiv(SET_IDEAL_EXP, q, a, b, ctx, &xstatus); - - if (xstatus & (MPD_Malloc_error|MPD_Division_impossible)) { - /* Inexact quotients (the usual case) fill the entire context precision, - * which can lead to the above errors for very high precisions. Retry - * the operation with a lower precision in case the result is exact. - * - * We need an upper bound for the number of digits of a_coeff / b_coeff - * when the result is exact. If a_coeff' * 1 / b_coeff' is in lowest - * terms, then maxdigits(a_coeff') + maxdigits(1 / b_coeff') is a suitable - * bound. - * - * 1 / b_coeff' is exact iff b_coeff' exclusively has prime factors 2 or 5. - * The largest amount of digits is generated if b_coeff' is a power of 2 or - * a power of 5 and is less than or equal to log5(b_coeff') <= log2(b_coeff'). - * - * We arrive at a total upper bound: - * - * maxdigits(a_coeff') + maxdigits(1 / b_coeff') <= - * log10(a_coeff) + log2(b_coeff) = - * log10(a_coeff) + log10(b_coeff) / log10(2) <= - * a->digits + b->digits * 4; - */ - mpd_context_t workctx = *ctx; - uint32_t ystatus = 0; - - workctx.prec = a->digits + b->digits * 4; - if (workctx.prec >= ctx->prec) { - *status |= (xstatus&MPD_Errors); - goto out; /* No point in retrying, keep the original error. */ - } - - _mpd_qdiv(SET_IDEAL_EXP, q, a, b, &workctx, &ystatus); - if (ystatus != 0) { - ystatus = *status | ((ystatus|xstatus)&MPD_Errors); - mpd_seterror(q, ystatus, status); - } - } - else { - *status |= xstatus; - } - - -out: - mpd_del(&aa); - mpd_del(&bb); + MPD_NEW_STATIC(aa,0,0,0,0); + MPD_NEW_STATIC(bb,0,0,0,0); + uint32_t xstatus = 0; + + if (q == a) { + if (!mpd_qcopy(&aa, a, status)) { + mpd_seterror(q, MPD_Malloc_error, status); + goto out; + } + a = &aa; + } + + if (q == b) { + if (!mpd_qcopy(&bb, b, status)) { + mpd_seterror(q, MPD_Malloc_error, status); + goto out; + } + b = &bb; + } + + _mpd_qdiv(SET_IDEAL_EXP, q, a, b, ctx, &xstatus); + + if (xstatus & (MPD_Malloc_error|MPD_Division_impossible)) { + /* Inexact quotients (the usual case) fill the entire context precision, + * which can lead to the above errors for very high precisions. Retry + * the operation with a lower precision in case the result is exact. + * + * We need an upper bound for the number of digits of a_coeff / b_coeff + * when the result is exact. If a_coeff' * 1 / b_coeff' is in lowest + * terms, then maxdigits(a_coeff') + maxdigits(1 / b_coeff') is a suitable + * bound. + * + * 1 / b_coeff' is exact iff b_coeff' exclusively has prime factors 2 or 5. + * The largest amount of digits is generated if b_coeff' is a power of 2 or + * a power of 5 and is less than or equal to log5(b_coeff') <= log2(b_coeff'). + * + * We arrive at a total upper bound: + * + * maxdigits(a_coeff') + maxdigits(1 / b_coeff') <= + * log10(a_coeff) + log2(b_coeff) = + * log10(a_coeff) + log10(b_coeff) / log10(2) <= + * a->digits + b->digits * 4; + */ + mpd_context_t workctx = *ctx; + uint32_t ystatus = 0; + + workctx.prec = a->digits + b->digits * 4; + if (workctx.prec >= ctx->prec) { + *status |= (xstatus&MPD_Errors); + goto out; /* No point in retrying, keep the original error. */ + } + + _mpd_qdiv(SET_IDEAL_EXP, q, a, b, &workctx, &ystatus); + if (ystatus != 0) { + ystatus = *status | ((ystatus|xstatus)&MPD_Errors); + mpd_seterror(q, ystatus, status); + } + } + else { + *status |= xstatus; + } + + +out: + mpd_del(&aa); + mpd_del(&bb); } /* Internal function. */ @@ -4031,7 +4031,7 @@ _mpd_qdivmod(mpd_t *q, mpd_t *r, const mpd_t *a, const mpd_t *b, } if (b->len == 1) { - assert(b->data[0] != 0); /* annotation for scan-build */ + assert(b->data[0] != 0); /* annotation for scan-build */ if (a->len == 1) { _mpd_div_word(&q->data[0], &r->data[0], a->data[0], b->data[0]); } @@ -6376,11 +6376,11 @@ _mpd_qpow_int(mpd_t *result, const mpd_t *base, const mpd_t *exp, workctx.round = MPD_ROUND_HALF_EVEN; workctx.clamp = 0; if (mpd_isnegative(exp)) { - uint32_t workstatus = 0; + uint32_t workstatus = 0; workctx.prec += 1; - mpd_qdiv(&tbase, &one, base, &workctx, &workstatus); - *status |= workstatus; - if (workstatus&MPD_Errors) { + mpd_qdiv(&tbase, &one, base, &workctx, &workstatus); + *status |= workstatus; + if (workstatus&MPD_Errors) { mpd_setspecial(result, MPD_POS, MPD_NAN); goto finish; } @@ -7115,8 +7115,8 @@ mpd_qrem_near(mpd_t *r, const mpd_t *a, const mpd_t *b, mpd_ssize_t expdiff, qdigits; int cmp, isodd, allnine; - assert(r != NULL); /* annotation for scan-build */ - + assert(r != NULL); /* annotation for scan-build */ + if (mpd_isspecial(a) || mpd_isspecial(b)) { if (mpd_qcheck_nans(r, a, b, ctx, status)) { return; @@ -7347,11 +7347,11 @@ void mpd_qtrunc(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_t *status) { - if (mpd_isspecial(a)) { - mpd_seterror(result, MPD_Invalid_operation, status); - return; - } - + if (mpd_isspecial(a)) { + mpd_seterror(result, MPD_Invalid_operation, status); + return; + } + (void)_mpd_qround_to_integral(TO_INT_TRUNC, result, a, ctx, status); } @@ -7360,12 +7360,12 @@ mpd_qfloor(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_t *status) { mpd_context_t workctx = *ctx; - - if (mpd_isspecial(a)) { - mpd_seterror(result, MPD_Invalid_operation, status); - return; - } - + + if (mpd_isspecial(a)) { + mpd_seterror(result, MPD_Invalid_operation, status); + return; + } + workctx.round = MPD_ROUND_FLOOR; (void)_mpd_qround_to_integral(TO_INT_SILENT, result, a, &workctx, status); @@ -7376,12 +7376,12 @@ mpd_qceil(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, uint32_t *status) { mpd_context_t workctx = *ctx; - - if (mpd_isspecial(a)) { - mpd_seterror(result, MPD_Invalid_operation, status); - return; - } - + + if (mpd_isspecial(a)) { + mpd_seterror(result, MPD_Invalid_operation, status); + return; + } + workctx.round = MPD_ROUND_CEILING; (void)_mpd_qround_to_integral(TO_INT_SILENT, result, a, &workctx, status); @@ -7885,9 +7885,9 @@ mpd_qinvroot(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, /* END LIBMPDEC_ONLY */ /* Algorithm from decimal.py */ -static void -_mpd_qsqrt(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, - uint32_t *status) +static void +_mpd_qsqrt(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, + uint32_t *status) { mpd_context_t maxcontext; MPD_NEW_STATIC(c,0,0,0,0); @@ -8019,57 +8019,57 @@ malloc_error: goto out; } -void -mpd_qsqrt(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, - uint32_t *status) -{ - MPD_NEW_STATIC(aa,0,0,0,0); - uint32_t xstatus = 0; - - if (result == a) { - if (!mpd_qcopy(&aa, a, status)) { - mpd_seterror(result, MPD_Malloc_error, status); - goto out; - } - a = &aa; - } - - _mpd_qsqrt(result, a, ctx, &xstatus); - - if (xstatus & (MPD_Malloc_error|MPD_Division_impossible)) { - /* The above conditions can occur at very high context precisions - * if intermediate values get too large. Retry the operation with - * a lower context precision in case the result is exact. - * - * If the result is exact, an upper bound for the number of digits - * is the number of digits in the input. - * - * NOTE: sqrt(40e9) = 2.0e+5 /\ digits(40e9) = digits(2.0e+5) = 2 - */ - uint32_t ystatus = 0; - mpd_context_t workctx = *ctx; - - workctx.prec = a->digits; - if (workctx.prec >= ctx->prec) { - *status |= (xstatus|MPD_Errors); - goto out; /* No point in repeating this, keep the original error. */ - } - - _mpd_qsqrt(result, a, &workctx, &ystatus); - if (ystatus != 0) { - ystatus = *status | ((xstatus|ystatus)&MPD_Errors); - mpd_seterror(result, ystatus, status); - } - } - else { - *status |= xstatus; - } - -out: - mpd_del(&aa); -} - - +void +mpd_qsqrt(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, + uint32_t *status) +{ + MPD_NEW_STATIC(aa,0,0,0,0); + uint32_t xstatus = 0; + + if (result == a) { + if (!mpd_qcopy(&aa, a, status)) { + mpd_seterror(result, MPD_Malloc_error, status); + goto out; + } + a = &aa; + } + + _mpd_qsqrt(result, a, ctx, &xstatus); + + if (xstatus & (MPD_Malloc_error|MPD_Division_impossible)) { + /* The above conditions can occur at very high context precisions + * if intermediate values get too large. Retry the operation with + * a lower context precision in case the result is exact. + * + * If the result is exact, an upper bound for the number of digits + * is the number of digits in the input. + * + * NOTE: sqrt(40e9) = 2.0e+5 /\ digits(40e9) = digits(2.0e+5) = 2 + */ + uint32_t ystatus = 0; + mpd_context_t workctx = *ctx; + + workctx.prec = a->digits; + if (workctx.prec >= ctx->prec) { + *status |= (xstatus|MPD_Errors); + goto out; /* No point in repeating this, keep the original error. */ + } + + _mpd_qsqrt(result, a, &workctx, &ystatus); + if (ystatus != 0) { + ystatus = *status | ((xstatus|ystatus)&MPD_Errors); + mpd_seterror(result, ystatus, status); + } + } + else { + *status |= xstatus; + } + +out: + mpd_del(&aa); +} + + /******************************************************************************/ /* Base conversions */ /******************************************************************************/ @@ -8080,7 +8080,7 @@ mpd_sizeinbase(const mpd_t *a, uint32_t base) { double x; size_t digits; - double upper_bound; + double upper_bound; assert(mpd_isinteger(a)); assert(base >= 2); @@ -8097,14 +8097,14 @@ mpd_sizeinbase(const mpd_t *a, uint32_t base) if (digits > 2711437152599294ULL) { return SIZE_MAX; } - - upper_bound = (double)((1ULL<<53)-1); -#else - upper_bound = (double)(SIZE_MAX-1); + + upper_bound = (double)((1ULL<<53)-1); +#else + upper_bound = (double)(SIZE_MAX-1); #endif x = (double)digits / log10(base); - return (x > upper_bound) ? SIZE_MAX : (size_t)x + 1; + return (x > upper_bound) ? SIZE_MAX : (size_t)x + 1; } /* Space needed to import a base 'base' integer of length 'srclen'. */ @@ -8112,7 +8112,7 @@ static mpd_ssize_t _mpd_importsize(size_t srclen, uint32_t base) { double x; - double upper_bound; + double upper_bound; assert(srclen > 0); assert(base >= 2); @@ -8121,15 +8121,15 @@ _mpd_importsize(size_t srclen, uint32_t base) if (srclen > (1ULL<<53)) { return MPD_SSIZE_MAX; } - - assert((1ULL<<53) <= MPD_MAXIMPORT); - upper_bound = (double)((1ULL<<53)-1); -#else - upper_bound = MPD_MAXIMPORT-1; + + assert((1ULL<<53) <= MPD_MAXIMPORT); + upper_bound = (double)((1ULL<<53)-1); +#else + upper_bound = MPD_MAXIMPORT-1; #endif x = (double)srclen * (log10(base)/MPD_RDIGITS); - return (x > upper_bound) ? MPD_SSIZE_MAX : (mpd_ssize_t)x + 1; + return (x > upper_bound) ? MPD_SSIZE_MAX : (mpd_ssize_t)x + 1; } static uint8_t diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/mpdecimal.h b/contrib/tools/python3/src/Modules/_decimal/libmpdec/mpdecimal.h index 10adca58de..f66f6e5920 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/mpdecimal.h +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/mpdecimal.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,42 +26,42 @@ */ -#ifndef LIBMPDEC_MPDECIMAL_H_ -#define LIBMPDEC_MPDECIMAL_H_ +#ifndef LIBMPDEC_MPDECIMAL_H_ +#define LIBMPDEC_MPDECIMAL_H_ -#ifndef _MSC_VER - #include "pyconfig.h" -#endif - +#ifndef _MSC_VER + #include "pyconfig.h" +#endif + #ifdef __cplusplus - #include <cinttypes> - #include <climits> - #include <cstdint> - #include <cstdio> - #include <cstdlib> + #include <cinttypes> + #include <climits> + #include <cstdint> + #include <cstdio> + #include <cstdlib> extern "C" { -#else - #include <inttypes.h> - #include <limits.h> - #include <stdint.h> - #include <stdio.h> - #include <stdlib.h> +#else + #include <inttypes.h> + #include <limits.h> + #include <stdint.h> + #include <stdio.h> + #include <stdlib.h> #endif -#if (defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)) && \ - defined(__GNUC__) && __GNUC__ >= 4 && !defined(__INTEL_COMPILER) - #define MPD_PRAGMA(x) _Pragma(x) - #define MPD_HIDE_SYMBOLS_START "GCC visibility push(hidden)" - #define MPD_HIDE_SYMBOLS_END "GCC visibility pop" -#else - #define MPD_PRAGMA(x) - #define MPD_HIDE_SYMBOLS_START - #define MPD_HIDE_SYMBOLS_END +#if (defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)) && \ + defined(__GNUC__) && __GNUC__ >= 4 && !defined(__INTEL_COMPILER) + #define MPD_PRAGMA(x) _Pragma(x) + #define MPD_HIDE_SYMBOLS_START "GCC visibility push(hidden)" + #define MPD_HIDE_SYMBOLS_END "GCC visibility pop" +#else + #define MPD_PRAGMA(x) + #define MPD_HIDE_SYMBOLS_START + #define MPD_HIDE_SYMBOLS_END #endif -#if defined(_MSC_VER) +#if defined(_MSC_VER) #include "vccompat.h" #define EXTINLINE extern inline #else @@ -89,10 +89,10 @@ MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) /******************************************************************************/ #define MPD_MAJOR_VERSION 2 -#define MPD_MINOR_VERSION 5 -#define MPD_MICRO_VERSION 0 +#define MPD_MINOR_VERSION 5 +#define MPD_MICRO_VERSION 0 -#define MPD_VERSION "2.5.0" +#define MPD_VERSION "2.5.0" #define MPD_VERSION_HEX ((MPD_MAJOR_VERSION << 24) | \ (MPD_MINOR_VERSION << 16) | \ @@ -121,9 +121,9 @@ const char *mpd_version(void); #elif defined(__x86_64__) #define CONFIG_64 #define ASM - #elif defined(__arm64__) - #define CONFIG_64 - #define ANSI + #elif defined(__arm64__) + #define CONFIG_64 + #define ANSI #else #error "unknown architecture for universal build." #endif @@ -412,7 +412,7 @@ void mpd_print(const mpd_t *dec); /* assignment from a string */ void mpd_qset_string(mpd_t *dec, const char *s, const mpd_context_t *ctx, uint32_t *status); -void mpd_qset_string_exact(mpd_t *dec, const char *s, uint32_t *status); +void mpd_qset_string_exact(mpd_t *dec, const char *s, uint32_t *status); /* set to NaN with error flags */ void mpd_seterror(mpd_t *result, uint32_t flags, uint32_t *status); @@ -430,8 +430,8 @@ void mpd_qset_u32(mpd_t *result, uint32_t a, const mpd_context_t *ctx, uint32_t #ifndef LEGACY_COMPILER void mpd_qset_i64(mpd_t *result, int64_t a, const mpd_context_t *ctx, uint32_t *status); void mpd_qset_u64(mpd_t *result, uint64_t a, const mpd_context_t *ctx, uint32_t *status); -void mpd_qset_i64_exact(mpd_t *result, int64_t a, uint32_t *status); -void mpd_qset_u64_exact(mpd_t *result, uint64_t a, uint32_t *status); +void mpd_qset_i64_exact(mpd_t *result, int64_t a, uint32_t *status); +void mpd_qset_u64_exact(mpd_t *result, uint64_t a, uint32_t *status); #endif /* quietly assign a C integer type to an mpd_t with a static coefficient */ @@ -459,8 +459,8 @@ 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); -int mpd_qcopy(mpd_t *result, const mpd_t *a, uint32_t *status); -int mpd_qcopy_cxx(mpd_t *result, const mpd_t *a); +int mpd_qcopy(mpd_t *result, const mpd_t *a, uint32_t *status); +int mpd_qcopy_cxx(mpd_t *result, const mpd_t *a); mpd_t *mpd_qncopy(const mpd_t *a); int mpd_qcopy_abs(mpd_t *result, const mpd_t *a, uint32_t *status); int mpd_qcopy_negate(mpd_t *result, const mpd_t *a, uint32_t *status); @@ -714,7 +714,7 @@ EXTINLINE mpd_uint_t mpd_lsd(mpd_uint_t word); EXTINLINE mpd_ssize_t mpd_digits_to_size(mpd_ssize_t digits); /* number of digits in the exponent, undefined for MPD_SSIZE_MIN */ EXTINLINE int mpd_exp_digits(mpd_ssize_t exp); -EXTINLINE int mpd_iscanonical(const mpd_t *dec); +EXTINLINE int mpd_iscanonical(const mpd_t *dec); EXTINLINE int mpd_isfinite(const mpd_t *dec); EXTINLINE int mpd_isinfinite(const mpd_t *dec); EXTINLINE int mpd_isinteger(const mpd_t *dec); @@ -830,4 +830,4 @@ MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ #endif -#endif /* LIBMPDEC_MPDECIMAL_H_ */ +#endif /* LIBMPDEC_MPDECIMAL_H_ */ diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/numbertheory.c b/contrib/tools/python3/src/Modules/_decimal/libmpdec/numbertheory.c index b476b8682c..210e0deb37 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/numbertheory.c +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/numbertheory.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,12 +27,12 @@ #include "mpdecimal.h" - -#include <assert.h> + +#include <assert.h> #include <stdlib.h> - + #include "bits.h" -#include "numbertheory.h" +#include "numbertheory.h" #include "umodarith.h" diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/numbertheory.h b/contrib/tools/python3/src/Modules/_decimal/libmpdec/numbertheory.h index 20db08b080..47b7753b83 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/numbertheory.h +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/numbertheory.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,11 +26,11 @@ */ -#ifndef LIBMPDEC_NUMBERTHEORY_H_ -#define LIBMPDEC_NUMBERTHEORY_H_ +#ifndef LIBMPDEC_NUMBERTHEORY_H_ +#define LIBMPDEC_NUMBERTHEORY_H_ -#include "mpdecimal.h" +#include "mpdecimal.h" #include "constants.h" @@ -73,4 +73,4 @@ std_setmodulus(int modnum, mpd_uint_t *umod) MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif /* LIBMPDEC_NUMBERTHEORY_H_ */ +#endif /* LIBMPDEC_NUMBERTHEORY_H_ */ diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/sixstep.c b/contrib/tools/python3/src/Modules/_decimal/libmpdec/sixstep.c index 8e643603ac..a4d1dbed78 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/sixstep.c +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/sixstep.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,15 +27,15 @@ #include "mpdecimal.h" - -#include <assert.h> + +#include <assert.h> #include <stdio.h> - + #include "bits.h" -#include "constants.h" +#include "constants.h" #include "difradix2.h" #include "numbertheory.h" -#include "sixstep.h" +#include "sixstep.h" #include "transpose.h" #include "umodarith.h" diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/sixstep.h b/contrib/tools/python3/src/Modules/_decimal/libmpdec/sixstep.h index 6af6243a14..89b4a33afc 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/sixstep.h +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/sixstep.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,8 +26,8 @@ */ -#ifndef LIBMPDEC_SIXSTEP_H_ -#define LIBMPDEC_SIXSTEP_H_ +#ifndef LIBMPDEC_SIXSTEP_H_ +#define LIBMPDEC_SIXSTEP_H_ #include "mpdecimal.h" @@ -44,4 +44,4 @@ int inv_six_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum); MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif /* LIBMPDEC_SIXSTEP_H_ */ +#endif /* LIBMPDEC_SIXSTEP_H_ */ diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/transpose.c b/contrib/tools/python3/src/Modules/_decimal/libmpdec/transpose.c index 4604335622..56321b5f39 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/transpose.c +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/transpose.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,16 +27,16 @@ #include "mpdecimal.h" - -#include <assert.h> -#include <limits.h> + +#include <assert.h> +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> - + #include "bits.h" #include "constants.h" -#include "transpose.h" +#include "transpose.h" #include "typearith.h" diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/transpose.h b/contrib/tools/python3/src/Modules/_decimal/libmpdec/transpose.h index ec6da2b7c5..e91c18d743 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/transpose.h +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/transpose.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,8 +26,8 @@ */ -#ifndef LIBMPDEC_TRANSPOSE_H_ -#define LIBMPDEC_TRANSPOSE_H_ +#ifndef LIBMPDEC_TRANSPOSE_H_ +#define LIBMPDEC_TRANSPOSE_H_ #include "mpdecimal.h" @@ -58,4 +58,4 @@ static inline void pointerswap(mpd_uint_t **a, mpd_uint_t **b) MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ -#endif /* LIBMPDEC_TRANSPOSE_H_ */ +#endif /* LIBMPDEC_TRANSPOSE_H_ */ diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/typearith.h b/contrib/tools/python3/src/Modules/_decimal/libmpdec/typearith.h index 886c527296..47961788d7 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/typearith.h +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/typearith.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,15 +26,15 @@ */ -#ifndef LIBMPDEC_TYPEARITH_H_ -#define LIBMPDEC_TYPEARITH_H_ +#ifndef LIBMPDEC_TYPEARITH_H_ +#define LIBMPDEC_TYPEARITH_H_ #include "mpdecimal.h" -#include <assert.h> +#include <assert.h> + - /*****************************************************************************/ /* Low level native arithmetic on basic types */ /*****************************************************************************/ @@ -665,4 +665,4 @@ mulmod_size_t(mpd_size_t a, mpd_size_t b, mpd_size_t m) } -#endif /* LIBMPDEC_TYPEARITH_H_ */ +#endif /* LIBMPDEC_TYPEARITH_H_ */ diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/umodarith.h b/contrib/tools/python3/src/Modules/_decimal/libmpdec/umodarith.h index 62633ae395..d7dbbbe6a7 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/umodarith.h +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/umodarith.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,12 +26,12 @@ */ -#ifndef LIBMPDEC_UMODARITH_H_ -#define LIBMPDEC_UMODARITH_H_ +#ifndef LIBMPDEC_UMODARITH_H_ +#define LIBMPDEC_UMODARITH_H_ -#include "mpdecimal.h" - +#include "mpdecimal.h" + #include "constants.h" #include "typearith.h" @@ -645,4 +645,4 @@ ppro_powmod(mpd_uint_t base, mpd_uint_t exp, double *dmod, uint32_t *dinvmod) #endif /* CONFIG_32 */ -#endif /* LIBMPDEC_UMODARITH_H_ */ +#endif /* LIBMPDEC_UMODARITH_H_ */ diff --git a/contrib/tools/python3/src/Modules/_decimal/libmpdec/vccompat.h b/contrib/tools/python3/src/Modules/_decimal/libmpdec/vccompat.h index 8e349a7cf0..e2e1c42cc0 100644 --- a/contrib/tools/python3/src/Modules/_decimal/libmpdec/vccompat.h +++ b/contrib/tools/python3/src/Modules/_decimal/libmpdec/vccompat.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. + * Copyright (c) 2008-2020 Stefan Krah. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,16 +26,16 @@ */ -#ifndef LIBMPDEC_VCCOMPAT_H_ -#define LIBMPDEC_VCCOMPAT_H_ +#ifndef LIBMPDEC_VCCOMPAT_H_ +#define LIBMPDEC_VCCOMPAT_H_ -/* Visual C fixes: no snprintf ... */ +/* Visual C fixes: no snprintf ... */ #ifdef _MSC_VER - #ifndef __cplusplus - #undef inline - #define inline __inline - #endif + #ifndef __cplusplus + #undef inline + #define inline __inline + #endif #undef random #define random rand #undef srandom @@ -53,4 +53,4 @@ #endif -#endif /* LIBMPDEC_VCCOMPAT_H_ */ +#endif /* LIBMPDEC_VCCOMPAT_H_ */ |