This commit is contained in:
CismonX 2019-12-09 12:27:30 +08:00
parent 8dafe932a8
commit c74a1b90aa
3 changed files with 12 additions and 22 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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;