- 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_API.h"
#if 0&&WITH_BCMATH
#if 0&&HAVE_BCMATH
#include "ext/bcmath/number.h"
#endif
@ -117,7 +117,7 @@ ZEND_API void convert_scalar_to_number(zval *op TSRMLS_DC)
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;
@ -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)) &&
(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;

View file

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

View file

@ -24,8 +24,9 @@
#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"
@ -50,14 +51,10 @@ zend_module_entry bcmath_module_entry = {
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
@ -67,53 +64,55 @@ zend_module_entry bcmath_module_entry = {
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);
return SUCCESS;
}
PHP_RINIT_FUNCTION(bcmath)
{
if (cfg_get_long("bcmath.scale", &bc_precision) == FAILURE) {
bc_precision = 0;
}
if (bc_precision < 0) {
bc_precision = 0;
}
REGISTER_INI_ENTRIES();
bc_init_numbers(TSRMLS_C);
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_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 */
@ -136,7 +135,7 @@ PHP_FUNCTION(bcadd)
{
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:
@ -182,7 +181,7 @@ PHP_FUNCTION(bcsub)
{
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:
@ -228,7 +227,7 @@ PHP_FUNCTION(bcmul)
{
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:
@ -274,7 +273,7 @@ PHP_FUNCTION(bcdiv)
{
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:
@ -368,7 +367,7 @@ PHP_FUNCTION(bcpowmod)
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;
@ -402,7 +401,7 @@ PHP_FUNCTION(bcpow)
{
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:
@ -448,7 +447,7 @@ PHP_FUNCTION(bcsqrt)
{
zval **left, **scale_param;
bc_num result;
int scale = bc_precision;
int scale = BCG(bc_precision);
switch (ZEND_NUM_ARGS()) {
case 1:
@ -491,7 +490,7 @@ PHP_FUNCTION(bccomp)
{
zval **left, **right, **scale_param;
bc_num first, second;
int scale = bc_precision;
int scale = BCG(bc_precision);
switch (ZEND_NUM_ARGS()) {
case 2:
@ -538,7 +537,7 @@ PHP_FUNCTION(bcscale)
}
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;
}

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.])
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 \
@ -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,
$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

View file

@ -101,9 +101,9 @@ typedef struct bc_struct
_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));
@ -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_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

View file

@ -45,19 +45,19 @@
/* 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
@ -65,8 +65,8 @@ bc_new_num (length, scale)
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);
@ -78,16 +78,17 @@ bc_new_num (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;
@ -102,10 +103,10 @@ bc_free_num (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;
}

View file

@ -21,34 +21,15 @@
#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);
@ -62,6 +43,21 @@ PHP_FUNCTION(bccomp);
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

View file

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

View file

@ -20,7 +20,7 @@
#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

View file

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

View file

@ -49,7 +49,7 @@
#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
@ -105,7 +105,7 @@
*/
zend_module_entry *php_builtin_extensions[] = {
phpext_standard_ptr
#if WITH_BCMATH
#if HAVE_BCMATH
,phpext_bcmath_ptr
#endif
#if HAVE_CALENDAR