FAQ
stas Mon Apr 25 06:22:00 2005 EDT

Modified files: (Branch: PHP_4_3)
/php-src/ext/gmp gmp.c
Log:
Remove broken fix - second operand of GMP operation certainly can be 0 in general case


http://cvs.php.net/diff.php/php-src/ext/gmp/gmp.c?r1=1.29.4.13&r2=1.29.4.14&ty=u
Index: php-src/ext/gmp/gmp.c
diff -u php-src/ext/gmp/gmp.c:1.29.4.13 php-src/ext/gmp/gmp.c:1.29.4.14
--- php-src/ext/gmp/gmp.c:1.29.4.13 Mon Apr 4 12:30:42 2005
+++ php-src/ext/gmp/gmp.c Mon Apr 25 06:21:58 2005
@@ -309,10 +309,6 @@
FETCH_GMP_ZVAL(gmpnum_b, b_arg);
}

- if (!Z_LVAL_PP(b_arg)) {
- RETURN_FALSE;
- }
-
INIT_GMP_NUM(gmpnum_result);
if(use_ui && gmp_ui_op) {
if(allow_ui_return) {
@@ -352,10 +348,6 @@
FETCH_GMP_ZVAL(gmpnum_b, b_arg);
}

- if (!Z_LVAL_PP(b_arg)) {
- RETURN_FALSE;
- }
-
INIT_GMP_NUM(gmpnum_result1);
INIT_GMP_NUM(gmpnum_result2);

Search Discussions

  • Jani Taskinen at Apr 25, 2005 at 10:28 am
    This was propably some bug report..? Can you please add
    a test case for this and the NEWS entry?

    --Jani

    On Mon, 25 Apr 2005, Stanislav Malyshev wrote:

    stas Mon Apr 25 06:22:00 2005 EDT

    Modified files: (Branch: PHP_4_3)
    /php-src/ext/gmp gmp.c
    Log:
    Remove broken fix - second operand of GMP operation certainly can be 0 in general case


    http://cvs.php.net/diff.php/php-src/ext/gmp/gmp.c?r1=1.29.4.13&r2=1.29.4.14&ty=u
    Index: php-src/ext/gmp/gmp.c
    diff -u php-src/ext/gmp/gmp.c:1.29.4.13 php-src/ext/gmp/gmp.c:1.29.4.14
    --- php-src/ext/gmp/gmp.c:1.29.4.13 Mon Apr 4 12:30:42 2005
    +++ php-src/ext/gmp/gmp.c Mon Apr 25 06:21:58 2005
    @@ -309,10 +309,6 @@
    FETCH_GMP_ZVAL(gmpnum_b, b_arg);
    }

    - if (!Z_LVAL_PP(b_arg)) {
    - RETURN_FALSE;
    - }
    -
    INIT_GMP_NUM(gmpnum_result);
    if(use_ui && gmp_ui_op) {
    if(allow_ui_return) {
    @@ -352,10 +348,6 @@
    FETCH_GMP_ZVAL(gmpnum_b, b_arg);
    }

    - if (!Z_LVAL_PP(b_arg)) {
    - RETURN_FALSE;
    - }
    -
    INIT_GMP_NUM(gmpnum_result1);
    INIT_GMP_NUM(gmpnum_result2);

    --
    Donate @ http://pecl.php.net/wishlist.php/sniper
  • Stanislav Malyshev at Apr 25, 2005 at 10:34 am
    JT>> This was propably some bug report..? Can you please add
    JT>> a test case for this and the NEWS entry?

    I'm not finished with it yet - this broken fix attempted to fix a real
    problem, just did it in a wrong way, breaking all the other ops. This is
    following #32773, I'll add the NEWS entry as soon as I'm done with it.

    --
    Stanislav Malyshev, Zend Products Engineer
    stas@zend.com http://www.zend.com/ +972-3-6139665 ext.115
  • Jani Taskinen at Apr 25, 2005 at 11:05 am

    On Mon, 25 Apr 2005, Stanislav Malyshev wrote:

    JT>> This was propably some bug report..? Can you please add
    JT>> a test case for this and the NEWS entry?

    I'm not finished with it yet - this broken fix attempted to fix a real
    problem, just did it in a wrong way, breaking all the other ops. This is
    following #32773, I'll add the NEWS entry as soon as I'm done with it.
    Ah, cool.

    --Jani
  • Stanislav Malyshev at Apr 25, 2005 at 12:03 pm
    stas Mon Apr 25 08:03:29 2005 EDT

    Modified files: (Branch: PHP_4_3)
    /php-src/ext/gmp gmp.c
    Log:
    Fix #32773 and made right fix for GMP FPEs


    http://cvs.php.net/diff.php/php-src/ext/gmp/gmp.c?r1=1.29.4.14&r2=1.29.4.15&ty=u
    Index: php-src/ext/gmp/gmp.c
    diff -u php-src/ext/gmp/gmp.c:1.29.4.14 php-src/ext/gmp/gmp.c:1.29.4.15
    --- php-src/ext/gmp/gmp.c:1.29.4.14 Mon Apr 25 06:21:58 2005
    +++ php-src/ext/gmp/gmp.c Mon Apr 25 08:03:27 2005
    @@ -280,8 +280,8 @@
    typedef unsigned long (*gmp_binary_ui_op2_t)(mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long);
    /* }}} */

    -#define gmp_zval_binary_ui_op(r, a, b, o, u) gmp_zval_binary_ui_op_ex(r, a, b, o, u, 0 TSRMLS_CC)
    -#define gmp_zval_binary_ui_op2(r, a, b, o, u) gmp_zval_binary_ui_op2_ex(r, a, b, o, u, 0 TSRMLS_CC)
    +#define gmp_zval_binary_ui_op(r, a, b, o, u) gmp_zval_binary_ui_op_ex(r, a, b, o, u, 0, 0 TSRMLS_CC)
    +#define gmp_zval_binary_ui_op2(r, a, b, o, u) gmp_zval_binary_ui_op2_ex(r, a, b, o, u, 0, 0 TSRMLS_CC)

    #define gmp_binary_ui_op(op, uop) _gmp_binary_ui_op(INTERNAL_FUNCTION_PARAM_PASSTHRU, op, uop)
    #define gmp_binary_op(op) _gmp_binary_ui_op(INTERNAL_FUNCTION_PARAM_PASSTHRU, op, NULL)
    @@ -292,11 +292,13 @@
    #define gmp_unary_opl(op) _gmp_unary_opl(INTERNAL_FUNCTION_PARAM_PASSTHRU, op)
    #define gmp_unary_ui_op(op) _gmp_unary_ui_op(INTERNAL_FUNCTION_PARAM_PASSTHRU, op)

    +typedef int (*gmp_validate_params_t)(mpz_ptr);
    +
    /* {{{ gmp_zval_binary_ui_op_ex
    Execute GMP binary operation.
    May return GMP resource or long if operation allows this
    */
    -static inline void gmp_zval_binary_ui_op_ex(zval *return_value, zval **a_arg, zval **b_arg, gmp_binary_op_t gmp_op, gmp_binary_ui_op_t gmp_ui_op, int allow_ui_return TSRMLS_DC)
    +static inline void gmp_zval_binary_ui_op_ex(zval *return_value, zval **a_arg, zval **b_arg, gmp_binary_op_t gmp_op, gmp_binary_ui_op_t gmp_ui_op, int allow_ui_return, int check_b_zero TSRMLS_DC)
    {
    mpz_t *gmpnum_a, *gmpnum_b, *gmpnum_result;
    unsigned long long_result=0;
    @@ -309,6 +311,20 @@
    FETCH_GMP_ZVAL(gmpnum_b, b_arg);
    }

    + if(check_b_zero) {
    + int b_is_zero = 0;
    + if(use_ui) {
    + b_is_zero = (Z_LVAL_PP(b_arg) == 0);
    + } else {
    + b_is_zero = !mpz_cmp_ui(*gmpnum_b, 0);
    + }
    +
    + if(b_is_zero) {
    + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Zero operand not allowed");
    + RETURN_FALSE;
    + }
    + }
    +
    INIT_GMP_NUM(gmpnum_result);
    if(use_ui && gmp_ui_op) {
    if(allow_ui_return) {
    @@ -333,7 +349,7 @@
    Execute GMP binary operation which returns 2 values.
    May return GMP resources or longs if operation allows this.
    */
    -static inline void gmp_zval_binary_ui_op2_ex(zval *return_value, zval **a_arg, zval **b_arg, gmp_binary_op2_t gmp_op, gmp_binary_ui_op2_t gmp_ui_op, int allow_ui_return TSRMLS_DC)
    +static inline void gmp_zval_binary_ui_op2_ex(zval *return_value, zval **a_arg, zval **b_arg, gmp_binary_op2_t gmp_op, gmp_binary_ui_op2_t gmp_ui_op, int allow_ui_return, int check_b_zero TSRMLS_DC)
    {
    mpz_t *gmpnum_a, *gmpnum_b, *gmpnum_result1, *gmpnum_result2;
    zval r;
    @@ -348,6 +364,20 @@
    FETCH_GMP_ZVAL(gmpnum_b, b_arg);
    }

    + if(check_b_zero) {
    + int b_is_zero = 0;
    + if(use_ui) {
    + b_is_zero = (Z_LVAL_PP(b_arg) == 0);
    + } else {
    + b_is_zero = !mpz_cmp_ui(*gmpnum_b, 0);
    + }
    +
    + if(b_is_zero) {
    + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Zero operand not allowed");
    + RETURN_FALSE;
    + }
    + }
    +
    INIT_GMP_NUM(gmpnum_result1);
    INIT_GMP_NUM(gmpnum_result2);

    @@ -634,13 +664,13 @@

    switch(round) {
    case GMP_ROUND_ZERO:
    - gmp_zval_binary_ui_op2(return_value, a_arg, b_arg, mpz_tdiv_qr, (gmp_binary_ui_op2_t)mpz_tdiv_qr_ui);
    + gmp_zval_binary_ui_op2_ex(return_value, a_arg, b_arg, mpz_tdiv_qr, (gmp_binary_ui_op2_t)mpz_tdiv_qr_ui, 0, 1 TSRMLS_CC);
    break;
    case GMP_ROUND_PLUSINF:
    - gmp_zval_binary_ui_op2(return_value, a_arg, b_arg, mpz_cdiv_qr, (gmp_binary_ui_op2_t)mpz_cdiv_qr_ui);
    + gmp_zval_binary_ui_op2_ex(return_value, a_arg, b_arg, mpz_cdiv_qr, (gmp_binary_ui_op2_t)mpz_cdiv_qr_ui, 0, 1 TSRMLS_CC);
    break;
    case GMP_ROUND_MINUSINF:
    - gmp_zval_binary_ui_op2(return_value, a_arg, b_arg, mpz_fdiv_qr, (gmp_binary_ui_op2_t)mpz_fdiv_qr_ui);
    + gmp_zval_binary_ui_op2_ex(return_value, a_arg, b_arg, mpz_fdiv_qr, (gmp_binary_ui_op2_t)mpz_fdiv_qr_ui, 0, 1 TSRMLS_CC);
    break;
    }

    @@ -669,15 +699,17 @@
    break;
    }

    +
    +
    switch(round) {
    case GMP_ROUND_ZERO:
    - gmp_zval_binary_ui_op_ex(return_value, a_arg, b_arg, mpz_tdiv_r, (gmp_binary_ui_op_t)mpz_tdiv_r_ui, 1 TSRMLS_CC);
    + gmp_zval_binary_ui_op_ex(return_value, a_arg, b_arg, mpz_tdiv_r, (gmp_binary_ui_op_t)mpz_tdiv_r_ui, 1, 1 TSRMLS_CC);
    break;
    case GMP_ROUND_PLUSINF:
    - gmp_zval_binary_ui_op_ex(return_value, a_arg, b_arg, mpz_cdiv_r, (gmp_binary_ui_op_t)mpz_cdiv_r_ui, 1 TSRMLS_CC);
    + gmp_zval_binary_ui_op_ex(return_value, a_arg, b_arg, mpz_cdiv_r, (gmp_binary_ui_op_t)mpz_cdiv_r_ui, 1, 1 TSRMLS_CC);
    break;
    case GMP_ROUND_MINUSINF:
    - gmp_zval_binary_ui_op_ex(return_value, a_arg, b_arg, mpz_fdiv_r, (gmp_binary_ui_op_t)mpz_fdiv_r_ui, 1 TSRMLS_CC);
    + gmp_zval_binary_ui_op_ex(return_value, a_arg, b_arg, mpz_fdiv_r, (gmp_binary_ui_op_t)mpz_fdiv_r_ui, 1, 1 TSRMLS_CC);
    break;
    }
    }
    @@ -707,13 +739,13 @@

    switch(round) {
    case GMP_ROUND_ZERO:
    - gmp_zval_binary_ui_op(return_value, a_arg, b_arg, mpz_tdiv_q, (gmp_binary_ui_op_t)mpz_tdiv_q_ui);
    + gmp_zval_binary_ui_op_ex(return_value, a_arg, b_arg, mpz_tdiv_q, (gmp_binary_ui_op_t)mpz_tdiv_q_ui, 0, 1 TSRMLS_CC);
    break;
    case GMP_ROUND_PLUSINF:
    - gmp_zval_binary_ui_op(return_value, a_arg, b_arg, mpz_cdiv_q, (gmp_binary_ui_op_t)mpz_cdiv_q_ui);
    + gmp_zval_binary_ui_op_ex(return_value, a_arg, b_arg, mpz_cdiv_q, (gmp_binary_ui_op_t)mpz_cdiv_q_ui, 0, 1 TSRMLS_CC);
    break;
    case GMP_ROUND_MINUSINF:
    - gmp_zval_binary_ui_op(return_value, a_arg, b_arg, mpz_fdiv_q, (gmp_binary_ui_op_t)mpz_fdiv_q_ui);
    + gmp_zval_binary_ui_op_ex(return_value, a_arg, b_arg, mpz_fdiv_q, (gmp_binary_ui_op_t)mpz_fdiv_q_ui, 0, 1 TSRMLS_CC);
    break;
    }

    @@ -730,7 +762,7 @@
    WRONG_PARAM_COUNT;
    }

    - gmp_zval_binary_ui_op_ex(return_value, a_arg, b_arg, mpz_mod, (gmp_binary_ui_op_t)mpz_mod_ui, 1 TSRMLS_CC);
    + gmp_zval_binary_ui_op_ex(return_value, a_arg, b_arg, mpz_mod, (gmp_binary_ui_op_t)mpz_mod_ui, 1, 1 TSRMLS_CC);
    }
    /* }}} */

    @@ -976,7 +1008,7 @@
    WRONG_PARAM_COUNT;
    }

    - gmp_zval_binary_ui_op_ex(return_value, a_arg, b_arg, mpz_gcd, (gmp_binary_ui_op_t)mpz_gcd_ui, 1 TSRMLS_CC);
    + gmp_zval_binary_ui_op_ex(return_value, a_arg, b_arg, mpz_gcd, (gmp_binary_ui_op_t)mpz_gcd_ui, 1, 0 TSRMLS_CC);
    }
    /* }}} */
  • Stanislav Malyshev at Apr 25, 2005 at 12:04 pm
    stas Mon Apr 25 08:04:35 2005 EDT

    Modified files: (Branch: PHP_4_3)
    /php-src/ext/gmp gmp.c
    Log:
    rm unneeded


    http://cvs.php.net/diff.php/php-src/ext/gmp/gmp.c?r1=1.29.4.15&r2=1.29.4.16&ty=u
    Index: php-src/ext/gmp/gmp.c
    diff -u php-src/ext/gmp/gmp.c:1.29.4.15 php-src/ext/gmp/gmp.c:1.29.4.16
    --- php-src/ext/gmp/gmp.c:1.29.4.15 Mon Apr 25 08:03:27 2005
    +++ php-src/ext/gmp/gmp.c Mon Apr 25 08:04:35 2005
    @@ -292,8 +292,6 @@
    #define gmp_unary_opl(op) _gmp_unary_opl(INTERNAL_FUNCTION_PARAM_PASSTHRU, op)
    #define gmp_unary_ui_op(op) _gmp_unary_ui_op(INTERNAL_FUNCTION_PARAM_PASSTHRU, op)

    -typedef int (*gmp_validate_params_t)(mpz_ptr);
    -
    /* {{{ gmp_zval_binary_ui_op_ex
    Execute GMP binary operation.
    May return GMP resource or long if operation allows this

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-cvs @
categoriesphp
postedApr 25, '05 at 10:22a
activeApr 25, '05 at 12:04p
posts6
users3
websitephp.net

People

Translate

site design / logo © 2019 Grokbase