From 660d7a2291e955fc65168d58fd59d605d8199501 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Thu, 16 Dec 2021 13:11:33 +0100 Subject: [PATCH] make decContext a module global --- ion.c | 5 +++-- ion_private.h | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ion.c b/ion.c index 6bf02f5..ab7f80b 100644 --- a/ion.c +++ b/ion.c @@ -1498,8 +1498,7 @@ PHP_RSHUTDOWN_FUNCTION(ion) PHP_MINIT_FUNCTION(ion) { - // globals - php_ion_decimal_ctx_init_max(&g_dec_ctx, DEC_ROUND_HALF_EVEN); + // true globals php_ion_decimal_from_zend_long(&g_ion_dec_zend_max, &g_dec_ctx, ZEND_LONG_MAX); php_ion_decimal_from_zend_long(&g_ion_dec_zend_min, &g_dec_ctx, ZEND_LONG_MIN); @@ -1578,6 +1577,8 @@ PHP_MINFO_FUNCTION(ion) PHP_GINIT_FUNCTION(ion) { memset(ion_globals, 0, sizeof(*ion_globals)); + + php_ion_decimal_ctx_init_max(&ion_globals->decimal_ctx, DEC_ROUND_HALF_EVEN); } PHP_GSHUTDOWN_FUNCTION(ion) { diff --git a/ion_private.h b/ion_private.h index c233333..888a493 100644 --- a/ion_private.h +++ b/ion_private.h @@ -57,6 +57,8 @@ typedef struct php_ion_unserializer { ZEND_BEGIN_MODULE_GLOBALS(ion) + decContext decimal_ctx; + php_ion_serializer serializer; php_ion_unserializer unserializer; @@ -499,12 +501,12 @@ static inline bool php_ion_decimal_fits_zend_long(php_ion_decimal *obj) } result = 1; - ion_decimal_compare(&obj->dec, &g_ion_dec_zend_max, &g_dec_ctx, &result); + ion_decimal_compare(&obj->dec, &g_ion_dec_zend_max, &php_ion_globals.decimal_ctx, &result); if (result == 1) { return false; } result = -1; - ion_decimal_compare(&obj->dec, &g_ion_dec_zend_min, &g_dec_ctx, &result); + ion_decimal_compare(&obj->dec, &g_ion_dec_zend_min, &php_ion_globals.decimal_ctx, &result); if (result == -1) { return false; } @@ -545,7 +547,7 @@ typedef php_date_obj php_ion_timestamp; static inline zend_long php_usec_from_ion(const decQuad *frac, decContext *ctx) { if (!ctx) { - ctx = &g_dec_ctx; + ctx = &php_ion_globals.decimal_ctx; } decQuad microsecs, result; decQuadMultiply(&result, decQuadFromInt32(µsecs, 1000000), frac, ctx); @@ -555,7 +557,7 @@ static inline zend_long php_usec_from_ion(const decQuad *frac, decContext *ctx) static inline decQuad *ion_ts_frac_from_usec(decQuad *frac, zend_long usec, decContext *ctx) { if (!ctx) { - ctx = &g_dec_ctx; + ctx = &php_ion_globals.decimal_ctx; } decQuad microsecs, us; return decQuadDivide(frac, decQuadFromInt32(&us, usec), decQuadFromInt32(µsecs, 1000000), ctx); -- 2.30.2