-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Refactor BCMath bundledlib and extension #10774
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
Conversation
4ff57ba
to
63f191b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Girgias. I saw your PR fixing formatting in this extension and would be awesome to merge it.
Although I'm not very convinced of using size_t
. I would leave int
, however I'm not still very experienced in PHP internal structure and don't know benefits of this type.
63f191b
to
44fe404
Compare
ext/bcmath/libbcmath/src/compare.c
Outdated
/* They are equal up to the last part of the equal part of the fraction. */ | ||
if (n1->n_scale != n2->n_scale) { | ||
if (n1->n_scale > n2->n_scale) { | ||
for (count = n1->n_scale-n2->n_scale; count>0; count--) { | ||
if (*n1ptr++ != 0) { | ||
/* Magnitude of n1 > n2. */ | ||
if (!use_sign || n1->n_sign == PLUS) { | ||
return (1); | ||
} else { | ||
return (-1); | ||
} | ||
} | ||
} | ||
} | ||
} else { | ||
for (count = n2->n_scale-n1->n_scale; count>0; count--) { | ||
if (*n2ptr++ != 0) { | ||
/* Magnitude of n1 < n2. */ | ||
if (!use_sign || n1->n_sign == PLUS) { | ||
return (-1); | ||
} else { | ||
return (1); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Girgias! I analyzed your PR and found the cause of the failing tests. Problem is with if/else conditions here. You changed scope of top level if
in those lines. Top level if
doesn't have else
statement.
If you need help with this PR I offer it, because I would like to have this extension tidied up. 🙌🏾
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you that was very helpful :)
Was busy with trying to get stuff done for feature freeze, so if the rebase, fix + force push has everything working on CI I'll merge this. :)
44fe404
to
7e149b5
Compare
And add braces to block statements, as the current code was pretty much unreadable with how inconsistent it was.
This seperates the concerns of throwing exceptions back into the PHP_FUNCTION instead of being the responsability of the library
This seperates the concerns of throwing exceptions back into the PHP_FUNCTION instead of being the responsability of the library
Return false on division by 0 attempt instead of -1 and true on success instead of 0
Return false on division by 0 attempt instead of -1 and true on success instead of 0
7e149b5
to
01fa580
Compare
* ext/bcmath: coding style: use indentation And add braces to block statements, as the current code was pretty much unreadable with how inconsistent it was. * ext/bcmath: Remove some useless header inclusions * ext/bcmath: Use standard C99 bool type instead of char * ext/bcmath: Include specific headers instead of config.h * Restructure definitions to reduce header inclusions * Use size_t as a more appropriate type * Remove unused variable full_scale * Refactor bc_raisemod() to get rid of Zend dependencies This separates the concerns of throwing exceptions back into the PHP_FUNCTION instead of being the responsibility of the library * Refactor bc_raise() to get rid of Zend dependencies This separates the concerns of throwing exceptions back into the PHP_FUNCTION instead of being the responsibility of the library * Refactor bc_divmod() and bc_modulo() to return bool Return false on division by 0 attempt instead of -1 and true on success instead of 0 * Refactor bc_divide() to return bool Return false on division by 0 attempt instead of -1 and true on success instead of 0
We've already been injecting ourselves into the library, so may as well have it in a reasonable state.
The first commit is about CS and fixing the very inconsistent indentation to make it readable for a human.
The rest of the changes shouldn't be very controversial as they clarify intent, the only one I am somewhat unsure of is the change from
int
tosize_t
for thescale
arguments, as I couldn't do it forbc_divide()
without hitting either a ASAN error or a complete change in behaviour, similar story with_bc_simp_mul()
where changing then2len
type from int tosize_t
causes issues.