Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for PHP 8.2 crashes #41

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading