- Brought ext/bcmath to the new millennium

# consistency..
This commit is contained in:
foobar 2003-12-09 23:59:33 +00:00
parent 398ab9756a
commit a08c1e4dce
11 changed files with 93 additions and 93 deletions

View file

@ -29,7 +29,7 @@
#include "zend_fast_cache.h" #include "zend_fast_cache.h"
#include "zend_API.h" #include "zend_API.h"
#if 0&&WITH_BCMATH #if 0&&HAVE_BCMATH
#include "ext/bcmath/number.h" #include "ext/bcmath/number.h"
#endif #endif
@ -117,7 +117,7 @@ ZEND_API void convert_scalar_to_number(zval *op TSRMLS_DC)
case IS_DOUBLE: case IS_DOUBLE:
case IS_LONG: case IS_LONG:
break; break;
#if 0 && WITH_BCMATH #if 0 && HAVE_BCMATH
case FLAG_IS_BC: case FLAG_IS_BC:
op->type = IS_DOUBLE; /* may have lost significant digits */ op->type = IS_DOUBLE; /* may have lost significant digits */
break; break;
@ -1752,7 +1752,7 @@ ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2)
if ((ret1=is_numeric_string(s1->value.str.val, s1->value.str.len, &lval1, &dval1, 0)) && 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))) { (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)) { if ((ret1==FLAG_IS_BC) || (ret2==FLAG_IS_BC)) {
bc_num first, second; bc_num first, second;

View file

@ -30,7 +30,7 @@
#endif #endif
#if 0&&WITH_BCMATH #if 0&&HAVE_BCMATH
#include "ext/bcmath/libbcmath/src/bcmath.h" #include "ext/bcmath/libbcmath/src/bcmath.h"
#endif #endif
@ -106,7 +106,7 @@ static inline zend_bool is_numeric_string(char *str, int length, long *lval, dou
if (dval) { if (dval) {
*dval = local_dval; *dval = local_dval;
} }
#if 0&&WITH_BCMATH #if 0&&HAVE_BCMATH
if (length>16) { if (length>16) {
register char *ptr=str, *end=str+length; register char *ptr=str, *end=str+length;

View file

@ -24,8 +24,9 @@
#include "php.h" #include "php.h"
#if WITH_BCMATH #if HAVE_BCMATH
#include "php_ini.h"
#include "ext/standard/info.h" #include "ext/standard/info.h"
#include "php_bcmath.h" #include "php_bcmath.h"
#include "libbcmath/src/bcmath.h" #include "libbcmath/src/bcmath.h"
@ -50,14 +51,10 @@ zend_module_entry bcmath_module_entry = {
STANDARD_MODULE_HEADER, STANDARD_MODULE_HEADER,
"bcmath", "bcmath",
bcmath_functions, bcmath_functions,
#if ZTS PHP_MINIT(bcmath),
PHP_MODULE_STARTUP_N(bcmath), PHP_MSHUTDOWN(bcmath),
#else
NULL, NULL,
#endif
NULL, NULL,
PHP_RINIT(bcmath),
PHP_RSHUTDOWN(bcmath),
PHP_MINFO(bcmath), PHP_MINFO(bcmath),
NO_VERSION_YET, NO_VERSION_YET,
STANDARD_MODULE_PROPERTIES STANDARD_MODULE_PROPERTIES
@ -67,53 +64,55 @@ zend_module_entry bcmath_module_entry = {
ZEND_GET_MODULE(bcmath) ZEND_GET_MODULE(bcmath)
#endif #endif
#ifndef THREAD_SAFE /* {{{ PHP_INI */
static long bc_precision; PHP_INI_BEGIN()
#endif STD_PHP_INI_ENTRY("bcmath.scale", "0", PHP_INI_ALL, OnUpdateLong, bc_precision, zend_bcmath_globals, bcmath_globals)
PHP_INI_END()
/* }}} */
#if ZTS /* {{{ php_bcmath_init_globals
PHP_MODULE_STARTUP_D(bcmath) */
static void php_bcmath_init_globals(zend_bcmath_globals *bcmath_globals)
{ {
zend_bcmath_globals *bcmath_globals; bcmath_globals->bc_precision = 0;
ts_allocate_id(&bcmath_globals_id, sizeof(zend_bcmath_globals), NULL, NULL);
bcmath_globals = ts_resource(bcmath_globals_id);
return SUCCESS;
} }
#endif /* }}} */
PHP_RSHUTDOWN_FUNCTION(bcmath) /* {{{ PHP_MINIT_FUNCTION
*/
PHP_MINIT_FUNCTION(bcmath)
{ {
bc_free_num(&BCG(_zero_)); ZEND_INIT_MODULE_GLOBALS(bcmath, php_bcmath_init_globals, NULL);
bc_free_num(&BCG(_one_));
bc_free_num(&BCG(_two_));
return SUCCESS; REGISTER_INI_ENTRIES();
}
PHP_RINIT_FUNCTION(bcmath)
{
if (cfg_get_long("bcmath.scale", &bc_precision) == FAILURE) {
bc_precision = 0;
}
if (bc_precision < 0) {
bc_precision = 0;
}
bc_init_numbers(TSRMLS_C); bc_init_numbers(TSRMLS_C);
return SUCCESS; return SUCCESS;
} }
/* }}} */
/* {{{ PHP_MSHUTDOWN_FUNCTION
*/
PHP_MSHUTDOWN_FUNCTION(bcmath)
{
_bc_free_num_ex(&BCG(_zero_), 1);
_bc_free_num_ex(&BCG(_one_), 1);
_bc_free_num_ex(&BCG(_two_), 1);
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION
*/
PHP_MINFO_FUNCTION(bcmath) PHP_MINFO_FUNCTION(bcmath)
{ {
php_info_print_table_start(); php_info_print_table_start();
php_info_print_table_row(2, "BCMath support", "enabled"); php_info_print_table_row(2, "BCMath support", "enabled");
php_info_print_table_end(); php_info_print_table_end();
} }
/* }}} */
/* {{{ php_str2num /* {{{ php_str2num
Convert to bc_num detecting scale */ Convert to bc_num detecting scale */
@ -136,7 +135,7 @@ PHP_FUNCTION(bcadd)
{ {
zval **left, **right, **scale_param; zval **left, **right, **scale_param;
bc_num first, second, result; bc_num first, second, result;
int scale = bc_precision; int scale = BCG(bc_precision);
switch (ZEND_NUM_ARGS()) { switch (ZEND_NUM_ARGS()) {
case 2: case 2:
@ -182,7 +181,7 @@ PHP_FUNCTION(bcsub)
{ {
zval **left, **right, **scale_param; zval **left, **right, **scale_param;
bc_num first, second, result; bc_num first, second, result;
int scale = bc_precision; int scale = BCG(bc_precision);
switch (ZEND_NUM_ARGS()) { switch (ZEND_NUM_ARGS()) {
case 2: case 2:
@ -228,7 +227,7 @@ PHP_FUNCTION(bcmul)
{ {
zval **left, **right, **scale_param; zval **left, **right, **scale_param;
bc_num first, second, result; bc_num first, second, result;
int scale = bc_precision; int scale = BCG(bc_precision);
switch (ZEND_NUM_ARGS()) { switch (ZEND_NUM_ARGS()) {
case 2: case 2:
@ -274,7 +273,7 @@ PHP_FUNCTION(bcdiv)
{ {
zval **left, **right, **scale_param; zval **left, **right, **scale_param;
bc_num first, second, result; bc_num first, second, result;
int scale = bc_precision; int scale = BCG(bc_precision);
switch (ZEND_NUM_ARGS()) { switch (ZEND_NUM_ARGS()) {
case 2: case 2:
@ -368,7 +367,7 @@ PHP_FUNCTION(bcpowmod)
char *left, *right, *modulous; char *left, *right, *modulous;
int left_len, right_len, modulous_len; int left_len, right_len, modulous_len;
bc_num first, second, mod, result; 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) { 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; WRONG_PARAM_COUNT;
@ -402,7 +401,7 @@ PHP_FUNCTION(bcpow)
{ {
zval **left, **right, **scale_param; zval **left, **right, **scale_param;
bc_num first, second, result; bc_num first, second, result;
int scale = bc_precision; int scale = BCG(bc_precision);
switch (ZEND_NUM_ARGS()) { switch (ZEND_NUM_ARGS()) {
case 2: case 2:
@ -448,7 +447,7 @@ PHP_FUNCTION(bcsqrt)
{ {
zval **left, **scale_param; zval **left, **scale_param;
bc_num result; bc_num result;
int scale = bc_precision; int scale = BCG(bc_precision);
switch (ZEND_NUM_ARGS()) { switch (ZEND_NUM_ARGS()) {
case 1: case 1:
@ -491,7 +490,7 @@ PHP_FUNCTION(bccomp)
{ {
zval **left, **right, **scale_param; zval **left, **right, **scale_param;
bc_num first, second; bc_num first, second;
int scale = bc_precision; int scale = BCG(bc_precision);
switch (ZEND_NUM_ARGS()) { switch (ZEND_NUM_ARGS()) {
case 2: case 2:
@ -538,7 +537,7 @@ PHP_FUNCTION(bcscale)
} }
convert_to_long_ex(new_scale); 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; RETURN_TRUE;
} }

View file

@ -6,7 +6,6 @@ PHP_ARG_ENABLE(bcmath, whether to enable bc style precision math functions,
[ --enable-bcmath Enable bc style precision math functions.]) [ --enable-bcmath Enable bc style precision math functions.])
if test "$PHP_BCMATH" != "no"; then if test "$PHP_BCMATH" != "no"; then
AC_DEFINE(WITH_BCMATH, 1, [Whether you have bcmath])
PHP_NEW_EXTENSION(bcmath, bcmath.c \ 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/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/compare.c libbcmath/src/divmod.c libbcmath/src/int2num.c libbcmath/src/num2long.c libbcmath/src/output.c libbcmath/src/recmul.c \
@ -14,4 +13,5 @@ libbcmath/src/sqrt.c libbcmath/src/zero.c libbcmath/src/debug.c libbcmath/src/do
libbcmath/src/rmzero.c libbcmath/src/str2num.c, libbcmath/src/rmzero.c libbcmath/src/str2num.c,
$ext_shared,,-I@ext_srcdir@/libbcmath/src) $ext_shared,,-I@ext_srcdir@/libbcmath/src)
PHP_ADD_BUILD_DIR($ext_builddir/libbcmath/src) PHP_ADD_BUILD_DIR($ext_builddir/libbcmath/src)
AC_DEFINE(HAVE_BCMATH, 1, [Whether you have bcmath])
fi fi

View file

@ -101,9 +101,9 @@ typedef struct bc_struct
_PROTOTYPE(void bc_init_numbers, (TSRMLS_D)); _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(bc_num bc_copy_num, (bc_num num));
@ -155,4 +155,8 @@ _PROTOTYPE(void bc_out_num, (bc_num num, int o_base, void (* out_char)(int),
_PROTOTYPE(void bc_rt_warn, (char *mesg ,...)); _PROTOTYPE(void bc_rt_warn, (char *mesg ,...));
_PROTOTYPE(void bc_rt_error, (char *mesg ,...)); _PROTOTYPE(void bc_rt_error, (char *mesg ,...));
_PROTOTYPE(void bc_out_of_memory, (void)); _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 #endif

View file

@ -45,19 +45,19 @@
/* new_num allocates a number and sets fields to known values. */ /* new_num allocates a number and sets fields to known values. */
bc_num bc_num
bc_new_num (length, scale) _bc_new_num_ex (length, scale, persistent)
int length, scale; int length, scale, persistent;
{ {
bc_num temp; bc_num temp;
/* PHP Change: malloc() -> emalloc(), removed free_list code */ /* PHP Change: malloc() -> pemalloc(), removed free_list code */
temp = (bc_num) emalloc (sizeof(bc_struct)+length+scale); temp = (bc_num) pemalloc (sizeof(bc_struct)+length+scale, persistent);
#if 0 #if 0
if (_bc_Free_list != NULL) { if (_bc_Free_list != NULL) {
temp = _bc_Free_list; temp = _bc_Free_list;
_bc_Free_list = temp->n_next; _bc_Free_list = temp->n_next;
} else { } else {
temp = (bc_num) emalloc (sizeof(bc_struct)); temp = (bc_num) pemalloc (sizeof(bc_struct), persistent);
if (temp == NULL) bc_out_of_memory (); if (temp == NULL) bc_out_of_memory ();
} }
#endif #endif
@ -65,8 +65,8 @@ bc_new_num (length, scale)
temp->n_len = length; temp->n_len = length;
temp->n_scale = scale; temp->n_scale = scale;
temp->n_refs = 1; temp->n_refs = 1;
/* PHP Change: malloc() -> emalloc() */ /* PHP Change: malloc() -> pemalloc() */
temp->n_ptr = (char *) emalloc (length+scale); temp->n_ptr = (char *) pemalloc (length+scale, persistent);
if (temp->n_ptr == NULL) bc_out_of_memory(); if (temp->n_ptr == NULL) bc_out_of_memory();
temp->n_value = temp->n_ptr; temp->n_value = temp->n_ptr;
memset (temp->n_ptr, 0, length+scale); memset (temp->n_ptr, 0, length+scale);
@ -78,16 +78,17 @@ bc_new_num (length, scale)
frees the storage if reference count is zero. */ frees the storage if reference count is zero. */
void void
bc_free_num (num) _bc_free_num_ex (num, persistent)
bc_num *num; bc_num *num;
int persistent;
{ {
if (*num == NULL) return; if (*num == NULL) return;
(*num)->n_refs--; (*num)->n_refs--;
if ((*num)->n_refs == 0) { if ((*num)->n_refs == 0) {
if ((*num)->n_ptr) if ((*num)->n_ptr)
/* PHP Change: free() -> efree(), removed free_list code */ /* PHP Change: free() -> pefree(), removed free_list code */
efree ((*num)->n_ptr); pefree ((*num)->n_ptr, persistent);
efree(*num); pefree(*num, persistent);
#if 0 #if 0
(*num)->n_next = _bc_Free_list; (*num)->n_next = _bc_Free_list;
_bc_Free_list = *num; _bc_Free_list = *num;
@ -102,10 +103,10 @@ bc_free_num (num)
void void
bc_init_numbers (TSRMLS_D) bc_init_numbers (TSRMLS_D)
{ {
BCG(_zero_) = bc_new_num (1,0); BCG(_zero_) = _bc_new_num_ex (1,0,1);
BCG(_one_) = bc_new_num (1,0); BCG(_one_) = _bc_new_num_ex (1,0,1);
BCG(_one_)->n_value[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; BCG(_two_)->n_value[0] = 2;
} }

View file

@ -21,34 +21,15 @@
#ifndef PHP_BCMATH_H #ifndef PHP_BCMATH_H
#define PHP_BCMATH_H #define PHP_BCMATH_H
#if WITH_BCMATH #if HAVE_BCMATH
#include "libbcmath/src/bcmath.h" #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; extern zend_module_entry bcmath_module_entry;
#define phpext_bcmath_ptr &bcmath_module_entry #define phpext_bcmath_ptr &bcmath_module_entry
#if ZTS
PHP_MINIT_FUNCTION(bcmath); PHP_MINIT_FUNCTION(bcmath);
#endif PHP_MSHUTDOWN_FUNCTION(bcmath);
PHP_RINIT_FUNCTION(bcmath);
PHP_RSHUTDOWN_FUNCTION(bcmath);
PHP_MINFO_FUNCTION(bcmath); PHP_MINFO_FUNCTION(bcmath);
PHP_FUNCTION(bcadd); PHP_FUNCTION(bcadd);
@ -62,6 +43,21 @@ PHP_FUNCTION(bccomp);
PHP_FUNCTION(bcscale); PHP_FUNCTION(bcscale);
PHP_FUNCTION(bcpowmod); 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 #else
#define phpext_bcmath_ptr NULL #define phpext_bcmath_ptr NULL

View file

@ -33,7 +33,7 @@
#define HAVE_GETPROTOBYNUMBER 1 #define HAVE_GETPROTOBYNUMBER 1
/* set to enable bcmath */ /* set to enable bcmath */
#define WITH_BCMATH 1 #define HAVE_BCMATH 1
/* set to enable mysql */ /* set to enable mysql */
#define HAVE_MYSQL 1 #define HAVE_MYSQL 1

View file

@ -20,7 +20,7 @@
#define PHP_SYSCONFDIR "c:\\php5" #define PHP_SYSCONFDIR "c:\\php5"
/* Enable / Disable BCMATH extension (default: enabled) */ /* Enable / Disable BCMATH extension (default: enabled) */
#define WITH_BCMATH 1 #define HAVE_BCMATH 1
/* Enable / Disable crypt() function (default: enabled) */ /* Enable / Disable crypt() function (default: enabled) */
#define HAVE_CRYPT 1 #define HAVE_CRYPT 1

View file

@ -65,7 +65,7 @@
*/ */
zend_module_entry *php_builtin_extensions[] = { zend_module_entry *php_builtin_extensions[] = {
phpext_standard_ptr, phpext_standard_ptr,
#if WITH_BCMATH #if HAVE_BCMATH
phpext_bcmath_ptr, phpext_bcmath_ptr,
#endif #endif
phpext_calendar_ptr, phpext_calendar_ptr,

View file

@ -49,7 +49,7 @@
#include "ext/standard/php_lcg.h" #include "ext/standard/php_lcg.h"
#include "ext/standard/php_array.h" #include "ext/standard/php_array.h"
#include "ext/standard/php_assert.h" #include "ext/standard/php_assert.h"
#if WITH_BCMATH #if HAVE_BCMATH
#include "ext/bcmath/php_bcmath.h" #include "ext/bcmath/php_bcmath.h"
#endif #endif
#if HAVE_CALENDAR #if HAVE_CALENDAR
@ -105,7 +105,7 @@
*/ */
zend_module_entry *php_builtin_extensions[] = { zend_module_entry *php_builtin_extensions[] = {
phpext_standard_ptr phpext_standard_ptr
#if WITH_BCMATH #if HAVE_BCMATH
,phpext_bcmath_ptr ,phpext_bcmath_ptr
#endif #endif
#if HAVE_CALENDAR #if HAVE_CALENDAR