]> granicus.if.org Git - php/commitdiff
- Brought ext/bcmath to the new millennium
authorfoobar <sniper@php.net>
Tue, 9 Dec 2003 23:59:33 +0000 (23:59 +0000)
committerfoobar <sniper@php.net>
Tue, 9 Dec 2003 23:59:33 +0000 (23:59 +0000)
# consistency..

Zend/zend_operators.c
Zend/zend_operators.h
ext/bcmath/bcmath.c
ext/bcmath/config.m4
ext/bcmath/libbcmath/src/bcmath.h
ext/bcmath/libbcmath/src/init.c
ext/bcmath/php_bcmath.h
main/config.nw.h
main/config.w32.h
main/internal_functions_nw.c
main/internal_functions_win32.c

index 8a6f78e6456b9df029f29889f732f1198a850cc5..b58eb7eb29cd56807c7c87471a0194b33fbd83c4 100644 (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;
                        
index db0f9560569a38220546c162171d96305e6566f9..7127b1c47a923fedb40362bed34652a0a1336bd4 100644 (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;
                                
index d5435a468c7c1ea68c52ba4986b168e95e90dff5..90e73b838d9fec86cb12300e460aeb1cd30cc20d 100644 (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);
+
+       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 */
@@ -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;
 }
index 0e008e736d175b72e0668fd81bee124d6ed77a65..d5e13e83ef61f4f97d52739af665c8f527c89198 100644 (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
index 1c26a3d93dd9a62788ecc3c2e7a23365e9725b22..ce68f0da4e8ca1dd0378797515b873423e2d8496 100644 (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
index d540a88060c033979369530b426565f483c270c6..cd45b9fbc1862537012a375fb6eb442aac51ba0b 100644 (file)
 /* 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;
 }
 
index 799c4b2942b9ccc0cf9975f92f100dbba92afc07..e478c4f1f7f19c06ed40fdf7708b4c2d1f47bb95 100644 (file)
 #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
index c92760908256cf11c81b7dae83adf5c356f48717..924d4572f6c8b8ed97c134be6cb0fb1e3c58e404 100644 (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
index 5ca103213c4df402f06f84fc1e4e9cf7c29829f4..fcaa7218aa0c923bc428d4d2b0bb99a8bcd0d494 100644 (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
index de14dba7655143e479e079b35651915f70387ba1..9cc324a4f6371247c2f3cd55800df72d8256967b 100644 (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,
index 39e9efc1794108791c9fa1a2f4c8587e56244f31..8799ff9e6f2cc6e580e3e7db88c38c947a71720f 100644 (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
  */
 zend_module_entry *php_builtin_extensions[] = {
        phpext_standard_ptr
-#if WITH_BCMATH
+#if HAVE_BCMATH
        ,phpext_bcmath_ptr
 #endif
 #if HAVE_CALENDAR