Issue 8014: Setting a T_INT attribute raises internal error (original) (raw)
Created on 2010-02-24 17:18 by doerwalter, last changed 2022-04-11 14:56 by admin. This issue is now closed.
Messages (10)
Author: Walter Dörwald (doerwalter) *
Date: 2010-02-24 17:18
In the current py3k branch setting an attribute of an object with PyMemberDefs raises an internal error:
$ ./python.exe Python 3.2a0 (py3k:78419M, Feb 24 2010, 17:56:06) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information.
x = UnicodeEncodeError('ascii', 'gurk', 0, 4, 'broken') [37539 refs] x.start = None Traceback (most recent call last): File "", line 1, in SystemError: Objects/longobject.c:439: bad argument to internal function
In Python 2.6.4 (and in the current trunk version) this raises a proper TypeError:
$ python Python 2.6.4 (r264:75706, Oct 27 2009, 15🔞04) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information.
x = UnicodeEncodeError('ascii', u'gurk', 0, 4, 'broken') x.start = None Traceback (most recent call last): File "", line 1, in TypeError: an integer is required
Author: Benjamin Peterson (benjamin.peterson) *
Date: 2010-02-24 21:10
It seems that T_INT uses PyLong_AsLong to get a integer, and 2.x uses PyInt_AsLong. PyInt_AsLong tries to convert the number to an integer, but PyLong_AsLong just throws up if the type is not correct. Mark, thoughts?
Author: Mark Dickinson (mark.dickinson) *
Date: 2010-02-24 21:46
Might it be T_PYSSIZET rather than T_INT? In which case it's PyLong_AsSsize_t that's at fault: it should raise TypeError for non-integers. What's slightly less clear is whether PyLong_AsSsize_t should also try to call int to convert to int, as PyLong_AsLong does; I'd say not---the PyLong_AsLong behaviour isn't particularly desirable in my view, and is mostly there for historical reasons.
Author: Mark Dickinson (mark.dickinson) *
Date: 2010-02-24 21:57
Here's a patch that raises TypeError if either PyLongAs_Size_t or PyLong_As_Ssize_t gets called with a valid non-integer PyObject *.
I'm not sure where the most appropriate place for a test is.
Author: Benjamin Peterson (benjamin.peterson) *
Date: 2010-02-25 00:05
2010/2/24 Mark Dickinson <report@bugs.python.org>:
Mark Dickinson <dickinsm@gmail.com> added the comment:
Here's a patch that raises TypeError if either PyLongAs_Size_t or PyLong_As_Ssize_t gets called with a valid non-integer PyObject *.
I'm not sure where the most appropriate place for a test is.
There's test_structmembers.py I think.
Author: Mark Dickinson (mark.dickinson) *
Date: 2010-03-13 10:41
Thanks, Benjamin! test_structmembers.py looks perfect.
Author: Mark Dickinson (mark.dickinson) *
Date: 2010-03-13 10:46
Tests for this issue, currently failing on T_INT/T_UINT (internal error), T_LONG/T_ULONG (fails to raise TypeError), T_PYSSIZET (internal error). The older patch only fixes the T_PYSSIZET failures; I'm working on a fix for the others.
Author: Mark Dickinson (mark.dickinson) *
Date: 2010-03-13 11:43
Internal errors for T_UINT and T_PYSSIZET fixed in r78918. The fix needs to be backported to the release31-maint branch, but I don't think it's urgent enough to try getting it in between 3.1.2 rc1 and 3.1.2 final.
There's still a problem with testing repeated attribute setting for T_UINT and T_ULONG; for some reason, the first attempt to set a T_UINT attribute to something invalid correctly produces TypeError, but an immediately following second attempt doesn't raise TypeError---this can be seen by uncommenting the T_UINT and T_ULONG bits in test_bad_assignments. Am investigating.
Author: Mark Dickinson (mark.dickinson) *
Date: 2010-03-13 13:25
Fixed reason for failing tests (there was a bad error check in structmembers.c that compared a return value with (unsigned int)-1 instead of (unsigned long)-1), and re-enabled those tests, in r78920.
Leaving open for the backport to 3.1.
Author: Mark Dickinson (mark.dickinson) *
Date: 2010-04-06 15:45
Backported to 3.1 in r79838.
History
Date
User
Action
Args
2022-04-11 14:56:58
admin
set
github: 52262
2010-04-06 15:45:55
mark.dickinson
set
status: open -> closed
resolution: fixed
messages: +
2010-03-13 13:25:10
mark.dickinson
set
messages: +
versions: - Python 3.2
2010-03-13 11:43:56
mark.dickinson
set
messages: +
2010-03-13 10:46:10
mark.dickinson
set
files: + issue8014_tests.patch
messages: +
2010-03-13 10:41:00
mark.dickinson
set
messages: +
2010-02-25 16:15:03
eric.smith
set
nosy: + eric.smith
2010-02-25 00:05:19
benjamin.peterson
set
messages: +
2010-02-24 21:58:39
mark.dickinson
set
versions: + Python 3.1
2010-02-24 21:57:54
mark.dickinson
set
files: + issue8014.patch
priority: normal
messages: +
assignee: mark.dickinson
keywords: + patch
stage: test needed
2010-02-24 21:46:41
mark.dickinson
set
messages: +
2010-02-24 21:10:40
benjamin.peterson
set
nosy: + mark.dickinson, benjamin.peterson
messages: +
2010-02-24 17🔞20
doerwalter
create