Skip to content

Conversation

jorgsowa
Copy link
Contributor

@jorgsowa jorgsowa commented Jul 8, 2023

This PR improves the performance of the BC extension computations for the decimal numbers with trailing zeros. Specifically we get Memory limit error while we want to raise zero with many trailing zeros to large exponent. Example: https://onlinephp.io/c/dcd86
Also it may improve other special cases of the math operations with number zero, like multiplying with number zero.

Changes made:

  • while we transform the number from string to bc_num we strip of the trailing zeros lower the scale.

@Girgias
Copy link
Member

Girgias commented Jul 24, 2023

Can you rebase this now that the refactoring PR has landed

@jorgsowa jorgsowa force-pushed the bcmath-fix-performance-for-numbers-with-trailing-zeros branch from 94cfed7 to d63ba2f Compare July 25, 2023 22:05
@jorgsowa jorgsowa requested a review from Girgias as a code owner July 25, 2023 22:05
@Girgias
Copy link
Member

Girgias commented Jul 26, 2023

There still seems to be a conflict, I think you forgot to pull the lastest changes from master

petk and others added 19 commits July 26, 2023 09:58
The typo in HAVE_PTHREAD_ATTR_GET_STACK (might be due to pthread_attr_get_np being different from Linux's pthread_getattr_np) led to this code path never get called on FreeBSD.
x8 being already reserved, we can only pull x18 to x27.
The normal xmlSetProp() function parses the name to find the namespace.
But we don't care about the namespace in this case.
These checks will always be false because we're dealing with elements
here. DOMElement always are of type XML_ELEMENT_NODE, so they don't need
to be checked.
dom_get_doc_props_read_only() already does a NULL check.
* 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
- publicId could crash PHP if none was provided
- notationName never worked

The fields of this classs were untested. This new test file changes that.

Closes phpGH-11779.
Previously, when replacing the node with itself (or contained within
itself), the node disappeared.

Closes phpGH-11770.
Fixes oss-fuzz #60741
Closes phpGH-11780
@jorgsowa
Copy link
Contributor Author

I messed up with rebasing. Sorry. Will create new PR.

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.

8 participants