# consistency..
#include "zend_fast_cache.h"
#include "zend_API.h"
-#if 0&&WITH_BCMATH
+#if 0&&HAVE_BCMATH
#include "ext/bcmath/number.h"
#endif
case IS_DOUBLE:
case IS_LONG:
break;
-#if 0 && WITH_BCMATH
+#if 0 && HAVE_BCMATH
case FLAG_IS_BC:
op->type = IS_DOUBLE; /* may have lost significant digits */
break;
if ((ret1=is_numeric_string(s1->value.str.val, s1->value.str.len, &lval1, &dval1, 0)) &&
(ret2=is_numeric_string(s2->value.str.val, s2->value.str.len, &lval2, &dval2, 0))) {
-#if 0&&WITH_BCMATH
+#if 0&&HAVE_BCMATH
if ((ret1==FLAG_IS_BC) || (ret2==FLAG_IS_BC)) {
bc_num first, second;
#endif
-#if 0&&WITH_BCMATH
+#if 0&&HAVE_BCMATH
#include "ext/bcmath/libbcmath/src/bcmath.h"
#endif
if (dval) {
*dval = local_dval;
}
-#if 0&&WITH_BCMATH
+#if 0&&HAVE_BCMATH
if (length>16) {
register char *ptr=str, *end=str+length;
#include "php.h"
-#if WITH_BCMATH
+#if HAVE_BCMATH
+#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_bcmath.h"
#include "libbcmath/src/bcmath.h"
STANDARD_MODULE_HEADER,
"bcmath",
bcmath_functions,
-#if ZTS
- PHP_MODULE_STARTUP_N(bcmath),
-#else
+ PHP_MINIT(bcmath),
+ PHP_MSHUTDOWN(bcmath),
NULL,
-#endif
NULL,
- PHP_RINIT(bcmath),
- PHP_RSHUTDOWN(bcmath),
PHP_MINFO(bcmath),
NO_VERSION_YET,
STANDARD_MODULE_PROPERTIES
ZEND_GET_MODULE(bcmath)
#endif
-#ifndef THREAD_SAFE
-static long bc_precision;
-#endif
+/* {{{ PHP_INI */
+PHP_INI_BEGIN()
+ STD_PHP_INI_ENTRY("bcmath.scale", "0", PHP_INI_ALL, OnUpdateLong, bc_precision, zend_bcmath_globals, bcmath_globals)
+PHP_INI_END()
+/* }}} */
-#if ZTS
-PHP_MODULE_STARTUP_D(bcmath)
+/* {{{ php_bcmath_init_globals
+ */
+static void php_bcmath_init_globals(zend_bcmath_globals *bcmath_globals)
{
- zend_bcmath_globals *bcmath_globals;
-
- ts_allocate_id(&bcmath_globals_id, sizeof(zend_bcmath_globals), NULL, NULL);
- bcmath_globals = ts_resource(bcmath_globals_id);
- return SUCCESS;
+ bcmath_globals->bc_precision = 0;
}
-#endif
+/* }}} */
-PHP_RSHUTDOWN_FUNCTION(bcmath)
+/* {{{ PHP_MINIT_FUNCTION
+ */
+PHP_MINIT_FUNCTION(bcmath)
{
- bc_free_num(&BCG(_zero_));
- bc_free_num(&BCG(_one_));
- bc_free_num(&BCG(_two_));
+ ZEND_INIT_MODULE_GLOBALS(bcmath, php_bcmath_init_globals, NULL);
+
+ REGISTER_INI_ENTRIES();
+
+ bc_init_numbers(TSRMLS_C);
return SUCCESS;
}
+/* }}} */
-
-PHP_RINIT_FUNCTION(bcmath)
+/* {{{ PHP_MSHUTDOWN_FUNCTION
+ */
+PHP_MSHUTDOWN_FUNCTION(bcmath)
{
- if (cfg_get_long("bcmath.scale", &bc_precision) == FAILURE) {
- bc_precision = 0;
- }
+ _bc_free_num_ex(&BCG(_zero_), 1);
+ _bc_free_num_ex(&BCG(_one_), 1);
+ _bc_free_num_ex(&BCG(_two_), 1);
- if (bc_precision < 0) {
- bc_precision = 0;
- }
-
- bc_init_numbers(TSRMLS_C);
-
return SUCCESS;
}
-
-
+/* }}} */
+
+/* {{{ PHP_MINFO_FUNCTION
+ */
PHP_MINFO_FUNCTION(bcmath)
{
php_info_print_table_start();
php_info_print_table_row(2, "BCMath support", "enabled");
php_info_print_table_end();
}
+/* }}} */
/* {{{ php_str2num
Convert to bc_num detecting scale */
{
zval **left, **right, **scale_param;
bc_num first, second, result;
- int scale = bc_precision;
+ int scale = BCG(bc_precision);
switch (ZEND_NUM_ARGS()) {
case 2:
{
zval **left, **right, **scale_param;
bc_num first, second, result;
- int scale = bc_precision;
+ int scale = BCG(bc_precision);
switch (ZEND_NUM_ARGS()) {
case 2:
{
zval **left, **right, **scale_param;
bc_num first, second, result;
- int scale = bc_precision;
+ int scale = BCG(bc_precision);
switch (ZEND_NUM_ARGS()) {
case 2:
{
zval **left, **right, **scale_param;
bc_num first, second, result;
- int scale = bc_precision;
+ int scale = BCG(bc_precision);
switch (ZEND_NUM_ARGS()) {
case 2:
char *left, *right, *modulous;
int left_len, right_len, modulous_len;
bc_num first, second, mod, result;
- int scale = bc_precision;
+ int scale = BCG(bc_precision);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss|l", &left, &left_len, &right, &right_len, &modulous, &modulous_len, &scale) == FAILURE) {
WRONG_PARAM_COUNT;
{
zval **left, **right, **scale_param;
bc_num first, second, result;
- int scale = bc_precision;
+ int scale = BCG(bc_precision);
switch (ZEND_NUM_ARGS()) {
case 2:
{
zval **left, **scale_param;
bc_num result;
- int scale = bc_precision;
+ int scale = BCG(bc_precision);
switch (ZEND_NUM_ARGS()) {
case 1:
{
zval **left, **right, **scale_param;
bc_num first, second;
- int scale = bc_precision;
+ int scale = BCG(bc_precision);
switch (ZEND_NUM_ARGS()) {
case 2:
}
convert_to_long_ex(new_scale);
- bc_precision = (Z_LVAL_PP(new_scale) < 0) ? 0 : Z_LVAL_PP(new_scale);
+ BCG(bc_precision) = (Z_LVAL_PP(new_scale) < 0) ? 0 : Z_LVAL_PP(new_scale);
RETURN_TRUE;
}
[ --enable-bcmath Enable bc style precision math functions.])
if test "$PHP_BCMATH" != "no"; then
- AC_DEFINE(WITH_BCMATH, 1, [Whether you have bcmath])
PHP_NEW_EXTENSION(bcmath, bcmath.c \
libbcmath/src/add.c libbcmath/src/div.c libbcmath/src/init.c libbcmath/src/neg.c libbcmath/src/outofmem.c libbcmath/src/raisemod.c libbcmath/src/rt.c libbcmath/src/sub.c \
libbcmath/src/compare.c libbcmath/src/divmod.c libbcmath/src/int2num.c libbcmath/src/num2long.c libbcmath/src/output.c libbcmath/src/recmul.c \
libbcmath/src/rmzero.c libbcmath/src/str2num.c,
$ext_shared,,-I@ext_srcdir@/libbcmath/src)
PHP_ADD_BUILD_DIR($ext_builddir/libbcmath/src)
+ AC_DEFINE(HAVE_BCMATH, 1, [Whether you have bcmath])
fi
_PROTOTYPE(void bc_init_numbers, (TSRMLS_D));
-_PROTOTYPE(bc_num bc_new_num, (int length, int scale));
+_PROTOTYPE(bc_num _bc_new_num_ex, (int length, int scale, int persistent));
-_PROTOTYPE(void bc_free_num, (bc_num *num));
+_PROTOTYPE(void _bc_free_num_ex, (bc_num *num, int persistent));
_PROTOTYPE(bc_num bc_copy_num, (bc_num num));
_PROTOTYPE(void bc_rt_warn, (char *mesg ,...));
_PROTOTYPE(void bc_rt_error, (char *mesg ,...));
_PROTOTYPE(void bc_out_of_memory, (void));
+
+#define bc_new_num(length, scale) _bc_new_num_ex((length), (scale), 0)
+#define bc_free_num(num) _bc_free_num_ex((num), 0)
+
#endif
/* new_num allocates a number and sets fields to known values. */
bc_num
-bc_new_num (length, scale)
- int length, scale;
+_bc_new_num_ex (length, scale, persistent)
+ int length, scale, persistent;
{
bc_num temp;
- /* PHP Change: malloc() -> emalloc(), removed free_list code */
- temp = (bc_num) emalloc (sizeof(bc_struct)+length+scale);
+ /* PHP Change: malloc() -> pemalloc(), removed free_list code */
+ temp = (bc_num) pemalloc (sizeof(bc_struct)+length+scale, persistent);
#if 0
if (_bc_Free_list != NULL) {
temp = _bc_Free_list;
_bc_Free_list = temp->n_next;
} else {
- temp = (bc_num) emalloc (sizeof(bc_struct));
+ temp = (bc_num) pemalloc (sizeof(bc_struct), persistent);
if (temp == NULL) bc_out_of_memory ();
}
#endif
temp->n_len = length;
temp->n_scale = scale;
temp->n_refs = 1;
- /* PHP Change: malloc() -> emalloc() */
- temp->n_ptr = (char *) emalloc (length+scale);
+ /* PHP Change: malloc() -> pemalloc() */
+ temp->n_ptr = (char *) pemalloc (length+scale, persistent);
if (temp->n_ptr == NULL) bc_out_of_memory();
temp->n_value = temp->n_ptr;
memset (temp->n_ptr, 0, length+scale);
frees the storage if reference count is zero. */
void
-bc_free_num (num)
+_bc_free_num_ex (num, persistent)
bc_num *num;
+ int persistent;
{
if (*num == NULL) return;
(*num)->n_refs--;
if ((*num)->n_refs == 0) {
if ((*num)->n_ptr)
- /* PHP Change: free() -> efree(), removed free_list code */
- efree ((*num)->n_ptr);
- efree(*num);
+ /* PHP Change: free() -> pefree(), removed free_list code */
+ pefree ((*num)->n_ptr, persistent);
+ pefree(*num, persistent);
#if 0
(*num)->n_next = _bc_Free_list;
_bc_Free_list = *num;
void
bc_init_numbers (TSRMLS_D)
{
- BCG(_zero_) = bc_new_num (1,0);
- BCG(_one_) = bc_new_num (1,0);
+ BCG(_zero_) = _bc_new_num_ex (1,0,1);
+ BCG(_one_) = _bc_new_num_ex (1,0,1);
BCG(_one_)->n_value[0] = 1;
- BCG(_two_) = bc_new_num (1,0);
+ BCG(_two_) = _bc_new_num_ex (1,0,1);
BCG(_two_)->n_value[0] = 2;
}
#ifndef PHP_BCMATH_H
#define PHP_BCMATH_H
-#if WITH_BCMATH
+#if HAVE_BCMATH
#include "libbcmath/src/bcmath.h"
-ZEND_BEGIN_MODULE_GLOBALS(bcmath)
- bc_num _zero_;
- bc_num _one_;
- bc_num _two_;
-ZEND_END_MODULE_GLOBALS(bcmath)
-
-#if ZTS
-# define BCG(v) TSRMG(bcmath_globals_id, zend_bcmath_globals *, v)
-extern int bcmath_globals_id;
-#else
-# define BCG(v) (bcmath_globals.v)
-extern zend_bcmath_globals bcmath_globals;
-#endif
-
-#define BC
-
extern zend_module_entry bcmath_module_entry;
#define phpext_bcmath_ptr &bcmath_module_entry
-#if ZTS
PHP_MINIT_FUNCTION(bcmath);
-#endif
-PHP_RINIT_FUNCTION(bcmath);
-PHP_RSHUTDOWN_FUNCTION(bcmath);
+PHP_MSHUTDOWN_FUNCTION(bcmath);
PHP_MINFO_FUNCTION(bcmath);
PHP_FUNCTION(bcadd);
PHP_FUNCTION(bcscale);
PHP_FUNCTION(bcpowmod);
+ZEND_BEGIN_MODULE_GLOBALS(bcmath)
+ bc_num _zero_;
+ bc_num _one_;
+ bc_num _two_;
+ long bc_precision;
+ZEND_END_MODULE_GLOBALS(bcmath)
+
+#if ZTS
+#define BCG(v) TSRMG(bcmath_globals_id, zend_bcmath_globals *, v)
+#else
+#define BCG(v) (bcmath_globals.v)
+#endif
+
+ZEND_EXTERN_MODULE_GLOBALS(bcmath)
+
#else
#define phpext_bcmath_ptr NULL
#define HAVE_GETPROTOBYNUMBER 1
/* set to enable bcmath */
-#define WITH_BCMATH 1
+#define HAVE_BCMATH 1
/* set to enable mysql */
#define HAVE_MYSQL 1
#define PHP_SYSCONFDIR "c:\\php5"
/* Enable / Disable BCMATH extension (default: enabled) */
-#define WITH_BCMATH 1
+#define HAVE_BCMATH 1
/* Enable / Disable crypt() function (default: enabled) */
#define HAVE_CRYPT 1
*/
zend_module_entry *php_builtin_extensions[] = {
phpext_standard_ptr,
-#if WITH_BCMATH
+#if HAVE_BCMATH
phpext_bcmath_ptr,
#endif
phpext_calendar_ptr,
#include "ext/standard/php_lcg.h"
#include "ext/standard/php_array.h"
#include "ext/standard/php_assert.h"
-#if WITH_BCMATH
+#if HAVE_BCMATH
#include "ext/bcmath/php_bcmath.h"
#endif
#if HAVE_CALENDAR
*/
zend_module_entry *php_builtin_extensions[] = {
phpext_standard_ptr
-#if WITH_BCMATH
+#if HAVE_BCMATH
,phpext_bcmath_ptr
#endif
#if HAVE_CALENDAR