classification
Title: SystemError when formatting int subclass
Type: crash Stage: resolved
Components: Versions: Python 3.4, Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: barry, eli.bendersky, eric.smith, ethan.furman, haypo, ncoghlan, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2013-08-19 14:10 by serhiy.storchaka, last changed 2013-08-31 19:49 by python-dev. This issue is now closed.

Files
File name Uploaded Description Edit
issue18780.stoneleaf.01.patch ethan.furman, 2013-08-28 02:12 review
Messages (8)
msg195631 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-08-19 14:10
>>> class I(int):
...     def __str__(self):
...         return 'spam'
... 
>>> '%i' % (I(42),)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: Objects/unicodeobject.c:13595: bad argument to internal function

This issue is related to issue18738 and will be fixed when use PyNumber_ToBase() for any int subclass (not only for bool).
msg195634 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2013-08-19 14:36
formatlong() should copy the string if Py_REFCNT(str) != 1.
msg195778 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-08-21 12:03
I think we should just use PyNumber_ToBase() for any int and int subclass. The calling __str__() for special case looks weird.
msg195813 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2013-08-21 18:17
I'll get my patch separated and over here when I get back home (on a business trip at the moment).
msg196343 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2013-08-28 02:12
Okay, simple fix, patch and tests attached.
msg196528 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2013-08-30 12:44
lgtm
msg196652 - (view) Author: Roundup Robot (python-dev) Date: 2013-08-31 17:19
New changeset 33727fbb4668 by Ethan Furman in branch 'default':
Close #18780: %-formatting now prints value for int subclasses with %d, %i, and %u codes.
http://hg.python.org/cpython/rev/33727fbb4668
msg196668 - (view) Author: Roundup Robot (python-dev) Date: 2013-08-31 19:49
New changeset 833246d42825 by Ethan Furman in branch 'default':
Issue #18780: code cleanup.
http://hg.python.org/cpython/rev/833246d42825
History
Date User Action Args
2013-08-31 19:49:06python-devsetmessages: + msg196668
2013-08-31 17:19:16python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg196652

resolution: fixed
stage: patch review -> resolved
2013-08-30 12:44:37eli.benderskysetmessages: + msg196528
2013-08-28 02:13:00ethan.furmansetfiles: + issue18780.stoneleaf.01.patch

nosy: + ncoghlan
messages: + msg196343

keywords: + patch
stage: patch review
2013-08-21 18:17:34ethan.furmansetmessages: + msg195813
2013-08-21 13:51:30serhiy.storchakasetnosy: + barry, eric.smith, eli.bendersky, ethan.furman
2013-08-21 12:03:07serhiy.storchakasetmessages: + msg195778
2013-08-19 14:36:16hayposetmessages: + msg195634
2013-08-19 14:10:34serhiy.storchakacreate