Skip to content

ext/gmp: Minor refactorings #15346

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Aug 11, 2024

No description provided.

ext/gmp/gmp.c Outdated
bool failed = true;
zend_long shift = zval_try_get_long(op2, &failed);
if (failed) {
//char operator_sigil[2];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left-over comment?

ext/gmp/gmp.c Outdated
zend_long shift = zval_try_get_long(op2, &failed);
if (failed) {
//char operator_sigil[2];
char *operator_sigil;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be const

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I initially tried to do some stuff with the fixed width char array to be const but my IDE was complaining.

operator_sigil = ">>";
}

zend_type_error("Unsupported operand types: GMP %s %s", operator_sigil, zend_zval_value_name(op2));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zval_try_get_long can already throw. This will be chained, but is that desirable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reasons that I don't understand it was not actually throwing an exception, might be doing something dumb

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I double-checked, and it does not throw an exception (contrary to the non try version)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you start from an object then the function could fail with an exception. Similarly, passing a double will cause a conversion to a long which can warn and thus can also trigger an exception. So exceptions seem possible to me. I guess it's fine though to chain it with the extra exception you're throwing here. Wdyt ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a test case for this:

<?php

set_error_handler(function () {
    throw new Error('whoops');
});

$gmp = new GMP("5");
$gmp << 3.14;

Outputs this for me with this PR:

Fatal error: Uncaught Error: whoops in /run/media/niels/MoreData/php-src/x.php:4
Stack trace:
#0 /run/media/niels/MoreData/php-src/x.php(8): {closure:/run/media/niels/MoreData/php-src/x.php:3}(8192, 'Implicit conver...', '/run/media/niel...', 8)
#1 {main}

Next TypeError: Unsupported operand types: GMP << float in /run/media/niels/MoreData/php-src/x.php:8
Stack trace:
#0 {main}
  thrown in /run/media/niels/MoreData/php-src/x.php on line 8

maybe that's fine though.

@Girgias
Copy link
Member Author

Girgias commented Aug 12, 2024

I merged the first 3 commits and rebased.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants