Skip to content

Commit

Permalink
For #12
Browse files Browse the repository at this point in the history
  libmpdec assumes that contexts are truly global symbols, they **must**
  be stored as such
  this commit moves the globals outside of the control of zend, and initializes
  them once per process, as the library requires
  • Loading branch information
krakjoe committed Feb 8, 2019
1 parent d9b1862 commit 0bc1cb0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
21 changes: 13 additions & 8 deletions php_decimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ zend_class_entry *php_decimal_ce;
*/
zend_object_handlers php_decimal_handlers;

/*
* Truly global context
*/
mpd_context_t php_decimal_ctx;


/******************************************************************************/
/* ERRORS AND DEBUGGING */
Expand Down Expand Up @@ -252,7 +257,7 @@ static void php_decimal_mpd_traphandler(mpd_context_t *ctx)
*/
static zend_always_inline mpd_context_t *php_decimal_context()
{
return &DECIMAL_G(ctx);
return &php_decimal_ctx;
}

/**
Expand Down Expand Up @@ -2592,6 +2597,13 @@ PHP_MINIT_FUNCTION(decimal)
/* */
mpd_traphandler = php_decimal_mpd_traphandler;

/* Initialize the shared context */
mpd_init(php_decimal_context(), PHP_DECIMAL_DEFAULT_PRECISION);

/* Set default rounding */
mpd_qsettraps(php_decimal_context(), PHP_DECIMAL_TRAPS);
mpd_qsetround(php_decimal_context(), PHP_DECIMAL_DEFAULT_ROUNDING);

return SUCCESS;
}

Expand All @@ -2612,13 +2624,6 @@ PHP_RINIT_FUNCTION(decimal)
ZEND_TSRMLS_CACHE_UPDATE();
#endif

/* Initialize the shared context */
mpd_init(php_decimal_context(), PHP_DECIMAL_DEFAULT_PRECISION);

/* Set default rounding */
mpd_qsettraps(php_decimal_context(), PHP_DECIMAL_TRAPS);
mpd_qsetround(php_decimal_context(), PHP_DECIMAL_DEFAULT_ROUNDING);

return SUCCESS;
}

Expand Down
1 change: 0 additions & 1 deletion php_decimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ ZEND_RSHUTDOWN_FUNCTION(decimal);
ZEND_MINFO_FUNCTION(decimal);

ZEND_BEGIN_MODULE_GLOBALS(decimal)
mpd_context_t ctx;
mpd_t *pi;

This comment has been minimized.

Copy link
@rtheunissen

rtheunissen Feb 8, 2019

Contributor

Hah this isn't even used... will remove..

ZEND_END_MODULE_GLOBALS(decimal)

Expand Down

0 comments on commit 0bc1cb0

Please sign in to comment.