Fix bugs.

This commit is contained in:
CismonX 2019-04-19 20:08:43 +08:00
parent 16853df7d4
commit 84717bb121
2 changed files with 24 additions and 20 deletions

View File

@ -48,7 +48,7 @@
#define PHP_ARMA_COMPLEX_OPERATOR_ASSIGN(type, func) \
if (instanceof_function(ce, complex<type>::ce)) { \
auto v = complex<type>::operators::func(zv1, zv2, zv1); \
if (EX(opline)->result_type != IS_UNUSED) { \
if (rv) { \
ZVAL_COPY(rv, zv1); \
} \
return v; \
@ -220,12 +220,13 @@ 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

@ -54,26 +54,29 @@ namespace php_arma
const zend_op *opline = EX(opline);
zend_free_op free_op1 = nullptr;
zend_free_op free_op2 = nullptr;
zval *op1 = get_zval_ptr_undef(opline->op1_type, &opline->op1, &free_op1, execute_data);
zval *op2 = get_zval_ptr_undef(opline->op2_type, &opline->op2, &free_op2, execute_data);
auto op1 = get_zval_ptr_undef(opline->op1_type, &opline->op1, &free_op1, execute_data);
auto op2 = get_zval_ptr_undef(opline->op2_type, &opline->op2, &free_op2, execute_data);
zend_class_entry *ce = nullptr;
if (op1) {
if (EXPECTED(op1)) {
ZVAL_DEREF(op1);
if (Z_TYPE_P(op1) == IS_OBJECT) {
ce = Z_OBJCE_P(op1);
}
}
if (op2) {
ZVAL_DEREF(op2);
}
if ((op1 && Z_TYPE_P(op1) != IS_OBJECT) && (op2 && Z_TYPE_P(op2) != IS_OBJECT)) {
return ZEND_USER_OPCODE_DISPATCH;
}
if (UNEXPECTED(opcode_is_greater(opline))) {
std::swap(op1, op2);
std::swap(free_op1, free_op2);
if (ce == nullptr) {
if (Z_TYPE_P(op2) == IS_OBJECT) {
ce = Z_OBJCE_P(op2);
} else {
return ZEND_USER_OPCODE_DISPATCH;
}
}
}
auto ce = Z_TYPE_P(op1) == IS_OBJECT ? Z_OBJCE_P(op1) : Z_OBJCE_P(op2);
if (!handler(op1, op2, EX_VAR(opline->result.var), ce)) {
zval *result = opline->result_type == IS_UNUSED ? nullptr : EX_VAR(opline->result.var);
if (ce == nullptr || !handler(op1, op2, result, ce)) {
return ZEND_USER_OPCODE_DISPATCH;
}
@ -100,7 +103,7 @@ namespace php_arma
int add_assign_handler(zend_execute_data *execute_data)
{
return op_handler(execute_data, [execute_data] (auto zv1, auto zv2, auto rv, auto ce) {
return op_handler(execute_data, [] (auto zv1, auto zv2, auto rv, auto ce) {
PHP_ARMA_OPERATOR_BEGIN(complex_ce)
PHP_ARMA_COMPLEX_OPERATOR_ASSIGN(double, add)
PHP_ARMA_OPERATOR_END();
@ -122,7 +125,7 @@ namespace php_arma
int sub_assign_handler(zend_execute_data *execute_data)
{
return op_handler(execute_data, [execute_data] (auto zv1, auto zv2, auto rv, auto ce) {
return op_handler(execute_data, [] (auto zv1, auto zv2, auto rv, auto ce) {
PHP_ARMA_OPERATOR_BEGIN(complex_ce)
PHP_ARMA_COMPLEX_OPERATOR_ASSIGN(double, sub)
PHP_ARMA_OPERATOR_END();
@ -144,7 +147,7 @@ namespace php_arma
int mul_assign_handler(zend_execute_data *execute_data)
{
return op_handler(execute_data, [execute_data] (auto zv1, auto zv2, auto rv, auto ce) {
return op_handler(execute_data, [] (auto zv1, auto zv2, auto rv, auto ce) {
PHP_ARMA_OPERATOR_BEGIN(complex_ce)
PHP_ARMA_COMPLEX_OPERATOR_ASSIGN(double, mul)
PHP_ARMA_OPERATOR_END();
@ -166,7 +169,7 @@ namespace php_arma
int div_assign_handler(zend_execute_data *execute_data)
{
return op_handler(execute_data, [execute_data] (auto zv1, auto zv2, auto rv, auto ce) {
return op_handler(execute_data, [] (auto zv1, auto zv2, auto rv, auto ce) {
PHP_ARMA_OPERATOR_BEGIN(complex_ce)
PHP_ARMA_COMPLEX_OPERATOR_ASSIGN(double, div)
PHP_ARMA_OPERATOR_END();
@ -188,7 +191,7 @@ namespace php_arma
int pow_assign_handler(zend_execute_data *execute_data)
{
return op_handler(execute_data, [execute_data] (auto zv1, auto zv2, auto rv, auto ce) {
return op_handler(execute_data, [] (auto zv1, auto zv2, auto rv, auto ce) {
PHP_ARMA_OPERATOR_BEGIN(complex_ce)
PHP_ARMA_COMPLEX_OPERATOR_ASSIGN(double, pow)
PHP_ARMA_OPERATOR_END();