Skip to content

Commit

Permalink
Fixes for PHP 8.2 crashes (#41)
Browse files Browse the repository at this point in the history
* Updates

* Test updates
  • Loading branch information
27pchrisl authored Sep 20, 2023
1 parent 52e1391 commit e06ebc8
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 176 deletions.
54 changes: 12 additions & 42 deletions ext/include/arithmetic.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ void tensor_multiply(zval * return_value, zval * a, zval * b)
zend_array * aa = Z_ARR_P(a);
zend_array * ab = Z_ARR_P(b);

Bucket * ba = aa->arData;
Bucket * bb = ab->arData;

unsigned int n = zend_array_count(aa);

array_init_size(&c, n);

for (i = 0; i < n; ++i) {
product = zephir_get_doubleval(&ba[i].val) * zephir_get_doubleval(&bb[i].val);
product = zephir_get_doubleval(zend_hash_index_find(aa, i)) * zephir_get_doubleval(zend_hash_index_find(ab, i));

add_next_index_double(&c, product);
}
Expand All @@ -39,15 +36,12 @@ void tensor_divide(zval * return_value, zval * a, zval * b)
zend_array * aa = Z_ARR_P(a);
zend_array * ab = Z_ARR_P(b);

Bucket * ba = aa->arData;
Bucket * bb = ab->arData;

unsigned int n = zend_array_count(aa);

array_init_size(&c, n);

for (i = 0; i < n; ++i) {
quotient = zephir_get_doubleval(&ba[i].val) / zephir_get_doubleval(&bb[i].val);
quotient = zephir_get_doubleval(zend_hash_index_find(aa, i)) / zephir_get_doubleval(zend_hash_index_find(ab, i));

add_next_index_double(&c, quotient);
}
Expand All @@ -64,15 +58,12 @@ void tensor_add(zval * return_value, zval * a, zval * b)
zend_array * aa = Z_ARR_P(a);
zend_array * ab = Z_ARR_P(b);

Bucket * ba = aa->arData;
Bucket * bb = ab->arData;

unsigned int n = zend_array_count(aa);

array_init_size(&c, n);

for (i = 0; i < n; ++i) {
sum = zephir_get_doubleval(&ba[i].val) + zephir_get_doubleval(&bb[i].val);
sum = zephir_get_doubleval(zend_hash_index_find(aa, i)) + zephir_get_doubleval(zend_hash_index_find(ab, i));

add_next_index_double(&c, sum);
}
Expand All @@ -89,15 +80,12 @@ void tensor_subtract(zval * return_value, zval * a, zval * b)
zend_array * aa = Z_ARR_P(a);
zend_array * ab = Z_ARR_P(b);

Bucket * ba = aa->arData;
Bucket * bb = ab->arData;

unsigned int n = zend_array_count(aa);

array_init_size(&c, n);

for (i = 0; i < n; ++i) {
difference = zephir_get_doubleval(&ba[i].val) - zephir_get_doubleval(&bb[i].val);
difference = zephir_get_doubleval(zend_hash_index_find(aa, i)) - zephir_get_doubleval(zend_hash_index_find(ab, i));

add_next_index_double(&c, difference);
}
Expand All @@ -114,15 +102,12 @@ void tensor_pow(zval * return_value, zval * a, zval * b)
zend_array * aa = Z_ARR_P(a);
zend_array * ab = Z_ARR_P(b);

Bucket * ba = aa->arData;
Bucket * bb = ab->arData;

unsigned int n = zend_array_count(aa);

array_init_size(&c, n);

for (i = 0; i < n; ++i) {
power = pow(zephir_get_doubleval(&ba[i].val), zephir_get_doubleval(&bb[i].val));
power = pow(zephir_get_doubleval(zend_hash_index_find(aa, i)), zephir_get_doubleval(zend_hash_index_find(ab, i)));

add_next_index_double(&c, power);
}
Expand All @@ -139,15 +124,12 @@ void tensor_mod(zval * return_value, zval * a, zval * b)
zend_array * aa = Z_ARR_P(a);
zend_array * ab = Z_ARR_P(b);

Bucket * ba = aa->arData;
Bucket * bb = ab->arData;

unsigned int n = zend_array_count(aa);

array_init_size(&c, n);

for (i = 0; i < n; ++i) {
mod_function(&modulus, &ba[i].val, &bb[i].val);
mod_function(&modulus, zend_hash_index_find(aa, i), zend_hash_index_find(ab, i));

add_next_index_zval(&c, &modulus);
}
Expand All @@ -163,16 +145,14 @@ void tensor_multiply_scalar(zval * return_value, zval * a, zval * b)

zend_array * aa = Z_ARR_P(a);

Bucket * ba = aa->arData;

double ab = zephir_get_doubleval(b);

unsigned int n = zend_array_count(aa);

array_init_size(&c, n);

for (i = 0; i < n; ++i) {
product = zephir_get_doubleval(&ba[i].val) * ab;
product = zephir_get_doubleval(zend_hash_index_find(aa, i)) * ab;

add_next_index_double(&c, product);
}
Expand All @@ -188,16 +168,14 @@ void tensor_divide_scalar(zval * return_value, zval * a, zval * b)

zend_array * aa = Z_ARR_P(a);

Bucket * ba = aa->arData;

double ab = zephir_get_doubleval(b);

unsigned int n = zend_array_count(aa);

array_init_size(&c, n);

for (i = 0; i < n; ++i) {
quotient = zephir_get_doubleval(&ba[i].val) / ab;
quotient = zephir_get_doubleval(zend_hash_index_find(aa, i)) / ab;

add_next_index_double(&c, quotient);
}
Expand All @@ -213,16 +191,14 @@ void tensor_add_scalar(zval * return_value, zval * a, zval * b)

zend_array * aa = Z_ARR_P(a);

Bucket * ba = aa->arData;

double ab = zephir_get_doubleval(b);

unsigned int n = zend_array_count(aa);

array_init_size(&c, n);

for (i = 0; i < n; ++i) {
sum = zephir_get_doubleval(&ba[i].val) + ab;
sum = zephir_get_doubleval(zend_hash_index_find(aa, i)) + ab;

add_next_index_double(&c, sum);
}
Expand All @@ -238,16 +214,14 @@ void tensor_subtract_scalar(zval * return_value, zval * a, zval * b)

zend_array * aa = Z_ARR_P(a);

Bucket * ba = aa->arData;

double ab = zephir_get_doubleval(b);

unsigned int n = zend_array_count(aa);

array_init_size(&c, n);

for (i = 0; i < n; ++i) {
difference = zephir_get_doubleval(&ba[i].val) - ab;
difference = zephir_get_doubleval(zend_hash_index_find(aa, i)) - ab;

add_next_index_double(&c, difference);
}
Expand All @@ -263,16 +237,14 @@ void tensor_pow_scalar(zval * return_value, zval * a, zval * b)

zend_array * aa = Z_ARR_P(a);

Bucket * ba = aa->arData;

double ab = zephir_get_doubleval(b);

unsigned int n = zend_array_count(aa);

array_init_size(&c, n);

for (i = 0; i < n; ++i) {
power = pow(zephir_get_doubleval(&ba[i].val), ab);
power = pow(zephir_get_doubleval(zend_hash_index_find(aa, i)), ab);

add_next_index_double(&c, power);
}
Expand All @@ -288,14 +260,12 @@ void tensor_mod_scalar(zval * return_value, zval * a, zval * b)

zend_array * aa = Z_ARR_P(a);

Bucket * ba = aa->arData;

unsigned int n = zend_array_count(aa);

array_init_size(&c, n);

for (i = 0; i < n; ++i) {
mod_function(&modulus, &ba[i].val, b);
mod_function(&modulus, zend_hash_index_find(aa, i), b);

add_next_index_zval(&c, &modulus);
}
Expand Down
Loading

0 comments on commit e06ebc8

Please sign in to comment.