@@ -163,28 +163,8 @@ typedef struct {
163
163
char repr [16384 ];
164
164
} Dragon4_Scratch ;
165
165
166
- static NPY_TLS int _bigint_static_in_use = 0 ;
167
166
static NPY_TLS Dragon4_Scratch _bigint_static ;
168
167
169
- static Dragon4_Scratch *
170
- get_dragon4_bigint_scratch (void ) {
171
- if (_bigint_static_in_use ) {
172
- PyErr_SetString (PyExc_RuntimeError ,
173
- "numpy float printing code is not re-entrant. "
174
- "Ping the devs to fix it." );
175
- return NULL ;
176
- }
177
- _bigint_static_in_use = 1 ;
178
-
179
- /* in this dummy implementation we only return the static allocation */
180
- return & _bigint_static ;
181
- }
182
-
183
- static void
184
- free_dragon4_bigint_scratch (Dragon4_Scratch * mem ){
185
- _bigint_static_in_use = 0 ;
186
- }
187
-
188
168
/* Copy integer */
189
169
static void
190
170
BigInt_Copy (BigInt * dst , const BigInt * src )
@@ -2209,11 +2189,11 @@ Format_floatbits(char *buffer, npy_uint32 bufferSize, BigInt *mantissa,
2209
2189
*/
2210
2190
static npy_uint32
2211
2191
Dragon4_PrintFloat_IEEE_binary16 (
2212
- Dragon4_Scratch * scratch , npy_half * value , Dragon4_Options * opt )
2192
+ npy_half * value , Dragon4_Options * opt )
2213
2193
{
2214
- char * buffer = scratch -> repr ;
2215
- const npy_uint32 bufferSize = sizeof (scratch -> repr );
2216
- BigInt * bigints = scratch -> bigints ;
2194
+ char * buffer = _bigint_static . repr ;
2195
+ const npy_uint32 bufferSize = sizeof (_bigint_static . repr );
2196
+ BigInt * bigints = _bigint_static . bigints ;
2217
2197
2218
2198
npy_uint16 val = * value ;
2219
2199
npy_uint32 floatExponent , floatMantissa , floatSign ;
@@ -2296,12 +2276,12 @@ Dragon4_PrintFloat_IEEE_binary16(
2296
2276
*/
2297
2277
static npy_uint32
2298
2278
Dragon4_PrintFloat_IEEE_binary32 (
2299
- Dragon4_Scratch * scratch , npy_float32 * value ,
2279
+ npy_float32 * value ,
2300
2280
Dragon4_Options * opt )
2301
2281
{
2302
- char * buffer = scratch -> repr ;
2303
- const npy_uint32 bufferSize = sizeof (scratch -> repr );
2304
- BigInt * bigints = scratch -> bigints ;
2282
+ char * buffer = _bigint_static . repr ;
2283
+ const npy_uint32 bufferSize = sizeof (_bigint_static . repr );
2284
+ BigInt * bigints = _bigint_static . bigints ;
2305
2285
2306
2286
union
2307
2287
{
@@ -2389,11 +2369,11 @@ Dragon4_PrintFloat_IEEE_binary32(
2389
2369
*/
2390
2370
static npy_uint32
2391
2371
Dragon4_PrintFloat_IEEE_binary64 (
2392
- Dragon4_Scratch * scratch , npy_float64 * value , Dragon4_Options * opt )
2372
+ npy_float64 * value , Dragon4_Options * opt )
2393
2373
{
2394
- char * buffer = scratch -> repr ;
2395
- const npy_uint32 bufferSize = sizeof (scratch -> repr );
2396
- BigInt * bigints = scratch -> bigints ;
2374
+ char * buffer = _bigint_static . repr ;
2375
+ const npy_uint32 bufferSize = sizeof (_bigint_static . repr );
2376
+ BigInt * bigints = _bigint_static . bigints ;
2397
2377
2398
2378
union
2399
2379
{
@@ -2504,11 +2484,11 @@ typedef struct FloatVal128 {
2504
2484
*/
2505
2485
static npy_uint32
2506
2486
Dragon4_PrintFloat_Intel_extended (
2507
- Dragon4_Scratch * scratch , FloatVal128 value , Dragon4_Options * opt )
2487
+ FloatVal128 value , Dragon4_Options * opt )
2508
2488
{
2509
- char * buffer = scratch -> repr ;
2510
- const npy_uint32 bufferSize = sizeof (scratch -> repr );
2511
- BigInt * bigints = scratch -> bigints ;
2489
+ char * buffer = _bigint_static . repr ;
2490
+ const npy_uint32 bufferSize = sizeof (_bigint_static . repr );
2491
+ BigInt * bigints = _bigint_static . bigints ;
2512
2492
2513
2493
npy_uint32 floatExponent , floatSign ;
2514
2494
npy_uint64 floatMantissa ;
@@ -2602,7 +2582,7 @@ Dragon4_PrintFloat_Intel_extended(
2602
2582
*/
2603
2583
static npy_uint32
2604
2584
Dragon4_PrintFloat_Intel_extended80 (
2605
- Dragon4_Scratch * scratch , npy_float80 * value , Dragon4_Options * opt )
2585
+ npy_float80 * value , Dragon4_Options * opt )
2606
2586
{
2607
2587
FloatVal128 val128 ;
2608
2588
union {
@@ -2618,15 +2598,15 @@ Dragon4_PrintFloat_Intel_extended80(
2618
2598
val128 .lo = buf80 .integer .a ;
2619
2599
val128 .hi = buf80 .integer .b ;
2620
2600
2621
- return Dragon4_PrintFloat_Intel_extended (scratch , val128 , opt );
2601
+ return Dragon4_PrintFloat_Intel_extended (val128 , opt );
2622
2602
}
2623
2603
#endif /* HAVE_LDOUBLE_INTEL_EXTENDED_10_BYTES_LE */
2624
2604
2625
2605
#ifdef HAVE_LDOUBLE_INTEL_EXTENDED_12_BYTES_LE
2626
2606
/* Intel's 80-bit IEEE extended precision format, 96-bit storage */
2627
2607
static npy_uint32
2628
2608
Dragon4_PrintFloat_Intel_extended96 (
2629
- Dragon4_Scratch * scratch , npy_float96 * value , Dragon4_Options * opt )
2609
+ npy_float96 * value , Dragon4_Options * opt )
2630
2610
{
2631
2611
FloatVal128 val128 ;
2632
2612
union {
@@ -2642,15 +2622,15 @@ Dragon4_PrintFloat_Intel_extended96(
2642
2622
val128 .lo = buf96 .integer .a ;
2643
2623
val128 .hi = buf96 .integer .b ;
2644
2624
2645
- return Dragon4_PrintFloat_Intel_extended (scratch , val128 , opt );
2625
+ return Dragon4_PrintFloat_Intel_extended (val128 , opt );
2646
2626
}
2647
2627
#endif /* HAVE_LDOUBLE_INTEL_EXTENDED_12_BYTES_LE */
2648
2628
2649
2629
#ifdef HAVE_LDOUBLE_MOTOROLA_EXTENDED_12_BYTES_BE
2650
2630
/* Motorola Big-endian equivalent of the Intel-extended 96 fp format */
2651
2631
static npy_uint32
2652
2632
Dragon4_PrintFloat_Motorola_extended96 (
2653
- Dragon4_Scratch * scratch , npy_float96 * value , Dragon4_Options * opt )
2633
+ npy_float96 * value , Dragon4_Options * opt )
2654
2634
{
2655
2635
FloatVal128 val128 ;
2656
2636
union {
@@ -2667,7 +2647,7 @@ Dragon4_PrintFloat_Motorola_extended96(
2667
2647
val128 .hi = buf96 .integer .a >> 16 ;
2668
2648
/* once again we assume the int has same endianness as the float */
2669
2649
2670
- return Dragon4_PrintFloat_Intel_extended (scratch , val128 , opt );
2650
+ return Dragon4_PrintFloat_Intel_extended (val128 , opt );
2671
2651
}
2672
2652
#endif /* HAVE_LDOUBLE_MOTOROLA_EXTENDED_12_BYTES_BE */
2673
2653
@@ -2687,7 +2667,7 @@ typedef union FloatUnion128
2687
2667
/* Intel's 80-bit IEEE extended precision format, 128-bit storage */
2688
2668
static npy_uint32
2689
2669
Dragon4_PrintFloat_Intel_extended128 (
2690
- Dragon4_Scratch * scratch , npy_float128 * value , Dragon4_Options * opt )
2670
+ npy_float128 * value , Dragon4_Options * opt )
2691
2671
{
2692
2672
FloatVal128 val128 ;
2693
2673
FloatUnion128 buf128 ;
@@ -2697,7 +2677,7 @@ Dragon4_PrintFloat_Intel_extended128(
2697
2677
val128 .lo = buf128 .integer .a ;
2698
2678
val128 .hi = buf128 .integer .b ;
2699
2679
2700
- return Dragon4_PrintFloat_Intel_extended (scratch , val128 , opt );
2680
+ return Dragon4_PrintFloat_Intel_extended (val128 , opt );
2701
2681
}
2702
2682
#endif /* HAVE_LDOUBLE_INTEL_EXTENDED_16_BYTES_LE */
2703
2683
@@ -2716,11 +2696,11 @@ Dragon4_PrintFloat_Intel_extended128(
2716
2696
*/
2717
2697
static npy_uint32
2718
2698
Dragon4_PrintFloat_IEEE_binary128 (
2719
- Dragon4_Scratch * scratch , FloatVal128 val128 , Dragon4_Options * opt )
2699
+ FloatVal128 val128 , Dragon4_Options * opt )
2720
2700
{
2721
- char * buffer = scratch -> repr ;
2722
- const npy_uint32 bufferSize = sizeof (scratch -> repr );
2723
- BigInt * bigints = scratch -> bigints ;
2701
+ char * buffer = _bigint_static . repr ;
2702
+ const npy_uint32 bufferSize = sizeof (_bigint_static . repr );
2703
+ BigInt * bigints = _bigint_static . bigints ;
2724
2704
2725
2705
npy_uint32 floatExponent , floatSign ;
2726
2706
@@ -2801,7 +2781,7 @@ Dragon4_PrintFloat_IEEE_binary128(
2801
2781
#if defined(HAVE_LDOUBLE_IEEE_QUAD_LE )
2802
2782
static npy_uint32
2803
2783
Dragon4_PrintFloat_IEEE_binary128_le (
2804
- Dragon4_Scratch * scratch , npy_float128 * value , Dragon4_Options * opt )
2784
+ npy_float128 * value , Dragon4_Options * opt )
2805
2785
{
2806
2786
FloatVal128 val128 ;
2807
2787
FloatUnion128 buf128 ;
@@ -2810,7 +2790,7 @@ Dragon4_PrintFloat_IEEE_binary128_le(
2810
2790
val128 .lo = buf128 .integer .a ;
2811
2791
val128 .hi = buf128 .integer .b ;
2812
2792
2813
- return Dragon4_PrintFloat_IEEE_binary128 (scratch , val128 , opt );
2793
+ return Dragon4_PrintFloat_IEEE_binary128 (val128 , opt );
2814
2794
}
2815
2795
#endif /* HAVE_LDOUBLE_IEEE_QUAD_LE */
2816
2796
@@ -2821,7 +2801,7 @@ Dragon4_PrintFloat_IEEE_binary128_le(
2821
2801
*/
2822
2802
static npy_uint32
2823
2803
Dragon4_PrintFloat_IEEE_binary128_be (
2824
- Dragon4_Scratch * scratch , npy_float128 * value , Dragon4_Options * opt )
2804
+ npy_float128 * value , Dragon4_Options * opt )
2825
2805
{
2826
2806
FloatVal128 val128 ;
2827
2807
FloatUnion128 buf128 ;
@@ -2830,7 +2810,7 @@ Dragon4_PrintFloat_IEEE_binary128_be(
2830
2810
val128 .lo = buf128 .integer .b ;
2831
2811
val128 .hi = buf128 .integer .a ;
2832
2812
2833
- return Dragon4_PrintFloat_IEEE_binary128 (scratch , val128 , opt );
2813
+ return Dragon4_PrintFloat_IEEE_binary128 (val128 , opt );
2834
2814
}
2835
2815
#endif /* HAVE_LDOUBLE_IEEE_QUAD_BE */
2836
2816
@@ -2876,11 +2856,11 @@ Dragon4_PrintFloat_IEEE_binary128_be(
2876
2856
*/
2877
2857
static npy_uint32
2878
2858
Dragon4_PrintFloat_IBM_double_double (
2879
- Dragon4_Scratch * scratch , npy_float128 * value , Dragon4_Options * opt )
2859
+ npy_float128 * value , Dragon4_Options * opt )
2880
2860
{
2881
- char * buffer = scratch -> repr ;
2882
- const npy_uint32 bufferSize = sizeof (scratch -> repr );
2883
- BigInt * bigints = scratch -> bigints ;
2861
+ char * buffer = _bigint_static . repr ;
2862
+ const npy_uint32 bufferSize = sizeof (_bigint_static . repr );
2863
+ BigInt * bigints = _bigint_static . bigints ;
2884
2864
2885
2865
FloatVal128 val128 ;
2886
2866
FloatUnion128 buf128 ;
@@ -3067,16 +3047,10 @@ PyObject *\
3067
3047
Dragon4_Positional_##Type##_opt(npy_type *val, Dragon4_Options *opt)\
3068
3048
{\
3069
3049
PyObject *ret;\
3070
- Dragon4_Scratch *scratch = get_dragon4_bigint_scratch();\
3071
- if (scratch == NULL) {\
3072
- return NULL;\
3073
- }\
3074
- if (Dragon4_PrintFloat_##format(scratch, val, opt) < 0) {\
3075
- free_dragon4_bigint_scratch(scratch);\
3050
+ if (Dragon4_PrintFloat_##format(val, opt) < 0) {\
3076
3051
return NULL;\
3077
3052
}\
3078
- ret = PyUnicode_FromString(scratch->repr);\
3079
- free_dragon4_bigint_scratch(scratch);\
3053
+ ret = PyUnicode_FromString(_bigint_static.repr);\
3080
3054
return ret;\
3081
3055
}\
3082
3056
\
@@ -3105,16 +3079,10 @@ PyObject *\
3105
3079
Dragon4_Scientific_##Type##_opt(npy_type *val, Dragon4_Options *opt)\
3106
3080
{\
3107
3081
PyObject *ret;\
3108
- Dragon4_Scratch *scratch = get_dragon4_bigint_scratch();\
3109
- if (scratch == NULL) {\
3110
- return NULL;\
3111
- }\
3112
- if (Dragon4_PrintFloat_##format(scratch, val, opt) < 0) {\
3113
- free_dragon4_bigint_scratch(scratch);\
3082
+ if (Dragon4_PrintFloat_##format(val, opt) < 0) { \
3114
3083
return NULL;\
3115
3084
}\
3116
- ret = PyUnicode_FromString(scratch->repr);\
3117
- free_dragon4_bigint_scratch(scratch);\
3085
+ ret = PyUnicode_FromString(_bigint_static.repr);\
3118
3086
return ret;\
3119
3087
}\
3120
3088
PyObject *\
0 commit comments