Merge pull request #2 from CismonX/bugfix/php-7.4-operator-segfault
bugfix for possible segfault in PHP 7.4
This commit is contained in:
commit
0134e6427d
|
@ -25,11 +25,11 @@ install:
|
|||
- sudo apt-get install -qq libsuperlu-dev libhdf5-dev
|
||||
- pushd armadillo-${ARMA_VERSION} && cmake . && make && sudo make install && popd
|
||||
|
||||
before_script:
|
||||
- phpenv config-rm xdebug.ini
|
||||
|
||||
script:
|
||||
- phpize
|
||||
- ./configure --enable-arma-operators --enable-arma-pch
|
||||
- make -j$(nproc)
|
||||
- make test
|
||||
|
||||
after_failure:
|
||||
- cat tests/*.out
|
||||
|
|
|
@ -15,34 +15,26 @@
|
|||
|
||||
#if PHP_VERSION_ID < 70300
|
||||
// Before PHP 7.3, `-$a` is compile to `MUL -1, $a, ~` instead of `MUL $a, -1, ~`.
|
||||
#define CONVERT_NEG_1_TO_COMPLEX(zv, type) \
|
||||
else if (Z_TYPE_P(zv) == IS_LONG && Z_LVAL_P(zv) == -1) { \
|
||||
zval_set_scalar(&tmp, std::complex<type>(-1)); \
|
||||
zv1 = &tmp; \
|
||||
#define CONVERT_NEG_1_TO_COMPLEX \
|
||||
else if (Z_TYPE_P(zv1) == IS_LONG && Z_LVAL_P(zv1) == -1) { \
|
||||
std::swap(zv1, zv2); \
|
||||
}
|
||||
#else
|
||||
#define CONVERT_NEG_1_TO_COMPLEX(zv, type)
|
||||
#define CONVERT_NEG_1_TO_COMPLEX
|
||||
#endif
|
||||
|
||||
// For non-assignment operators, first operand can be of type double.
|
||||
#define PHP_ARMA_COMPLEX_OPERATOR_EX(type, func) \
|
||||
if (instanceof_function(ce, complex<type>::ce)) { \
|
||||
zval tmp; \
|
||||
ZVAL_UNDEF(&tmp); \
|
||||
if (zval_is_scalar<type>(zv1)) { \
|
||||
auto real = zval_get_scalar<type>(zv1); \
|
||||
zval_set_scalar(&tmp, std::complex<type>(real)); \
|
||||
zv1 = &tmp; \
|
||||
std::swap(zv1, zv2); \
|
||||
} \
|
||||
CONVERT_NEG_1_TO_COMPLEX(zv1, type) \
|
||||
CONVERT_NEG_1_TO_COMPLEX \
|
||||
else if (UNEXPECTED(Z_TYPE_P(zv1) != IS_OBJECT)) { \
|
||||
return false; \
|
||||
} \
|
||||
auto v = complex<type>::operators::func(zv1, zv2, rv); \
|
||||
if (Z_TYPE(tmp) != IS_UNDEF) { \
|
||||
zval_ptr_dtor_nogc(&tmp); \
|
||||
} \
|
||||
return v; \
|
||||
ZVAL_UNDEF(rv); \
|
||||
return complex<type>::operators::func(zv1, zv2, rv); \
|
||||
}
|
||||
|
||||
#define PHP_ARMA_COMPLEX_OPERATOR(func) \
|
||||
|
@ -227,13 +219,11 @@ namespace php_arma
|
|||
zval_set_scalar(retval, v1 * zval_get_scalar<T>(zv2));
|
||||
return true;
|
||||
}
|
||||
#if PHP_VERSION_ID >= 70300
|
||||
if (Z_TYPE_P(zv2) == IS_LONG && Z_LVAL_P(zv2) == -1) {
|
||||
// Negation operator is compiled as multiplication to -1.
|
||||
neg(zv1, retval);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace php_arma
|
|||
|
||||
template <typename F>
|
||||
zend_always_inline
|
||||
int op_handler(zend_execute_data *execute_data, F handler)
|
||||
int op_handler(zend_execute_data *execute_data, F&& handler)
|
||||
{
|
||||
const zend_op *opline = EX(opline);
|
||||
zend_free_op free_op1 = nullptr;
|
||||
|
|
Reference in New Issue
Block a user