Skip to content

Optional support for ieee contexts in the decimal module doesn't work #122081

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

Closed
skirpichev opened this issue Jul 21, 2024 · 8 comments
Closed

Optional support for ieee contexts in the decimal module doesn't work #122081

skirpichev opened this issue Jul 21, 2024 · 8 comments
Labels
extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@skirpichev
Copy link
Contributor

skirpichev commented Jul 21, 2024

Crash report

What happened?

Reproducer:

$ ./configure CFLAGS=-DEXTRA_FUNCTIONALITY -q && make -s
configure: WARNING: no system libmpdecimal found; falling back to bundled libmpdecimal (deprecated and scheduled for removal in Python 3.15)
In function ‘word_to_string’,
    inlined from ‘coeff_to_string’ at ./Modules/_decimal/libmpdec/io.c:411:13,
    inlined from ‘_mpd_to_string’ at ./Modules/_decimal/libmpdec/io.c:612:18:
./Modules/_decimal/libmpdec/io.c:349:40: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
  349 |         if (s == dot) *s++ = '.'; *s++ = '0' + (char)(x / d); x %= d
      |                                   ~~~~~^~~~~~~~~~~~~~~~~~~~~
./Modules/_decimal/libmpdec/io.c:360:14: note: in expansion of macro ‘EXTRACT_DIGIT’
  360 |     case 15: EXTRACT_DIGIT(s, x, 100000000000000ULL, dot);
      |              ^~~~~~~~~~~~~
[... and similar warnings from issue #108562, hardly relevant]
Checked 112 modules (34 built-in, 77 shared, 1 n/a on linux-x86_64, 0 disabled, 0 missing, 0 failed on import)
$ ./python 
Python 3.14.0a0 (heads/main:cecaceea31, Jul 19 2024, 05:34:00) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from decimal import *
>>> IEEEContext(11)
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    IEEEContext(11)
    ~~~~~~~~~~~^^^^
ValueError: argument must be a multiple of 32, with a maximum of 512
>>> IEEEContext(1024)
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    IEEEContext(1024)
    ~~~~~~~~~~~^^^^^^
ValueError: argument must be a multiple of 32, with a maximum of 512
>>> IEEEContext(512)  # oops
Segmentation fault

There are tests (decorated by @requires_extra_functionality) for this, but it seems nobody (including build bots) run this a long time. These tests are broken too (crash).

I'll provide a patch.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

Python 3.14.0a0 (heads/fix-decimal-extra:c8d2630995, Jul 21 2024, 10:20:04) [GCC 12.2.0]

Linked PRs

@skirpichev skirpichev added the type-crash A hard crash of the interpreter, possibly with a core dump label Jul 21, 2024
skirpichev added a commit to skirpichev/cpython that referenced this issue Jul 21, 2024
Now

$ ./configure CFLAGS=-DEXTRA_FUNCTIONALITY -q && make -s && \
     ./python -m test test_decimal

- PASS
@skirpichev
Copy link
Contributor Author

PR is ready for review: #122082

@skirpichev skirpichev changed the title Optional support for ieee context in the decimal module doesn't work Optional support for ieee contexts in the decimal module doesn't work Jul 21, 2024
@skirpichev
Copy link
Contributor Author

Gentle ping (per devguide).

@picnixz picnixz added the extension-modules C modules in the Modules dir label Aug 18, 2024
@picnixz
Copy link
Member

picnixz commented Aug 18, 2024

@skirpichev As a mathematician, I'm always interested in your PRs so feel free to ping me / request a review in general!

@skirpichev
Copy link
Contributor Author

Thanks, @picnixz! When it does make sense for you, feel free to ask me for review.

kumaraditya303 added a commit that referenced this issue Aug 19, 2024
* gh-122081: fixed crash in decimal.IEEEContext()

Now

$ ./configure CFLAGS=-DEXTRA_FUNCTIONALITY -q && make -s && \
     ./python -m test test_decimal

- PASS

* Apply suggestions from code review

Co-authored-by: Bénédikt Tran <[email protected]>

* Update Misc/NEWS.d/next/Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst

* Apply suggestions from code review

---------

Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Kumar Aditya <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 19, 2024
* pythongh-122081: fixed crash in decimal.IEEEContext()

Now

$ ./configure CFLAGS=-DEXTRA_FUNCTIONALITY -q && make -s && \
     ./python -m test test_decimal

- PASS

* Apply suggestions from code review

Co-authored-by: Bénédikt Tran <[email protected]>

* Update Misc/NEWS.d/next/Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst

* Apply suggestions from code review

---------

(cherry picked from commit b9e10d1)

Co-authored-by: Sergey B Kirpichev <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Kumar Aditya <[email protected]>
kumaraditya303 added a commit that referenced this issue Aug 19, 2024
…123136)

gh-122081: fixed crash in decimal.IEEEContext() (GH-122082)

* gh-122081: fixed crash in decimal.IEEEContext()

Now

$ ./configure CFLAGS=-DEXTRA_FUNCTIONALITY -q && make -s && \
     ./python -m test test_decimal

- PASS

* Apply suggestions from code review



* Update Misc/NEWS.d/next/Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst

* Apply suggestions from code review

---------

(cherry picked from commit b9e10d1)

Co-authored-by: Sergey B Kirpichev <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Kumar Aditya <[email protected]>
@picnixz
Copy link
Member

picnixz commented Aug 19, 2024

Closing since completed in #122082 and backported in #123136.

@picnixz picnixz closed this as completed Aug 19, 2024
@picnixz
Copy link
Member

picnixz commented Aug 19, 2024

Re-opening because the 3.12 backport is actually missing.

@skirpichev @kumaraditya303 Either of you should do the 3.12 backport manually since it failed.

@picnixz picnixz reopened this Aug 19, 2024
@skirpichev
Copy link
Contributor Author

I'm working on this. Probably, that backport isn't required.

@skirpichev
Copy link
Contributor Author

skirpichev commented Aug 19, 2024

Yeah, it works without the patch. @picnixz, you can remove label.

jeremyhylton pushed a commit to jeremyhylton/cpython that referenced this issue Aug 19, 2024
* pythongh-122081: fixed crash in decimal.IEEEContext()

Now

$ ./configure CFLAGS=-DEXTRA_FUNCTIONALITY -q && make -s && \
     ./python -m test test_decimal

- PASS

* Apply suggestions from code review

Co-authored-by: Bénédikt Tran <[email protected]>

* Update Misc/NEWS.d/next/Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst

* Apply suggestions from code review

---------

Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Kumar Aditya <[email protected]>
blhsing pushed a commit to blhsing/cpython that referenced this issue Aug 22, 2024
* pythongh-122081: fixed crash in decimal.IEEEContext()

Now

$ ./configure CFLAGS=-DEXTRA_FUNCTIONALITY -q && make -s && \
     ./python -m test test_decimal

- PASS

* Apply suggestions from code review

Co-authored-by: Bénédikt Tran <[email protected]>

* Update Misc/NEWS.d/next/Library/2024-07-21-10-45-24.gh-issue-122081.dNrYMq.rst

* Apply suggestions from code review

---------

Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Kumar Aditya <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump
Projects
None yet
Development

No branches or pull requests

2 participants