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

bpo-45548: Remove _math.c workarounds for pre-C99 libm #29179

Merged
merged 4 commits into from Oct 25, 2021

Conversation

tiran
Copy link
Member

@tiran tiran commented Oct 22, 2021

The :mod:math and :mod:cmath implementation now require a C99 compatible
libm and no longer ship with workarounds for missing acosh, asinh,
expm1, and log1p functions.

The changeset also removes _math.c and moves the last remaining
workaround into _math.h. This simplifies static builds with
Modules/Setup and resolves symbol conflicts.

Co-authored-by: Mark Dickinson mdickinson@enthought.com
Co-authored-by: Brett Cannon brett@python.org
Signed-off-by: Christian Heimes christian@python.org

https://bugs.python.org/issue45548

Automerge-Triggered-By: GH:tiran

@brettcannon
Copy link
Member

I created an alternative approach but just inlining into _math.h: #29181 .

@mdickinson
Copy link
Member

I don't see it as a major problem. The functions are small.

Agreed. Looks fine to me. I somewhat prefer @brettcannon's approach (it feels odd to be including a .c file), but either seems fine, and it looks as though #29181 is having some issues with the Windows build.

@mdickinson
Copy link
Member

A bit off-topic (and probably fodder for a separate PR), but it looks as though we ought to be able to get rid of most of the functionality in _math.c: if we can assume C99, then we can assume the existence of asinh, atanh, etc.

@mdickinson
Copy link
Member

we ought to be able to get rid of most of the functionality in _math.c

Looking more closely, I think we can assume that all of HAVE_ACOSH, HAVE_ASINH, HAVE_ATANH, HAVE_EXPM1 and HAVE_LOG1P are defined. That would make almost all of _math.c redundant, with the sole exception of the extra zero-handling in _Py_log1p. But again, that can be fixed in a separate PR.

The :mod:`math` and :mod:`cmath` implementation now require a C99 compatible
``libm`` and no longer ship with workarounds for missing acosh, asinh,
expm1, and log1p functions.

The changeset also removes ``_math.c`` and moves the last remaining
workaround into ``_math.h``. This simplifies static builds with
``Modules/Setup`` and resolves symbol conflicts.

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
Co-authored-by: Brett Cannon <brett@python.org>
Signed-off-by: Christian Heimes <christian@python.org>
@tiran tiran changed the title bpo-45548: Directly include _math.c bpo-45548: Remove _math.c workarounds for pre-C99 libm Oct 24, 2021
@tiran tiran marked this pull request as ready for review October 24, 2021 20:00
@tiran tiran requested a review from a team as a code owner October 24, 2021 20:00
@tiran
Copy link
Member Author

tiran commented Oct 24, 2021

@mdickinson I implemented your suggestion, moved the log1p workaround into _math.h and deleted _math.c.

(Sorry for the squashed commit. I made an error while rewriting the commit message)

Copy link
Member

@mdickinson mdickinson left a comment

Choose a reason for hiding this comment

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

Mostly LGTM; two nitpicks and one question.

Modules/mathmodule.c Outdated Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants