This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Setting a T_INT attribute raises internal error
Type: behavior Stage: test needed
Components: Versions: Python 3.1
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: benjamin.peterson, doerwalter, eric.smith, mark.dickinson
Priority: normal Keywords: patch

Created on 2010-02-24 17:18 by doerwalter, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue8014.patch mark.dickinson, 2010-02-24 21:57
issue8014_tests.patch mark.dickinson, 2010-03-13 10:46
Messages (10)
msg100051 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) 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 "<stdin>", line 1, in <module>
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:18: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 "<stdin>", line 1, in <module>
TypeError: an integer is required
msg100069 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) 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?
msg100071 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) 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.
msg100072 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) 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.
msg100078 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) 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.
msg101000 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-03-13 10:41
Thanks, Benjamin!  test_structmembers.py looks perfect.
msg101001 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) 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.
msg101002 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) 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.
msg101003 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) 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.
msg102470 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-04-06 15:45
Backported to 3.1 in r79838.
History
Date User Action Args
2022-04-11 14:56:58adminsetgithub: 52262
2010-04-06 15:45:55mark.dickinsonsetstatus: open -> closed
resolution: fixed
messages: + msg102470
2010-03-13 13:25:10mark.dickinsonsetmessages: + msg101003
versions: - Python 3.2
2010-03-13 11:43:56mark.dickinsonsetmessages: + msg101002
2010-03-13 10:46:10mark.dickinsonsetfiles: + issue8014_tests.patch

messages: + msg101001
2010-03-13 10:41:00mark.dickinsonsetmessages: + msg101000
2010-02-25 16:15:03eric.smithsetnosy: + eric.smith
2010-02-25 00:05:19benjamin.petersonsetmessages: + msg100078
2010-02-24 21:58:39mark.dickinsonsetversions: + Python 3.1
2010-02-24 21:57:54mark.dickinsonsetfiles: + issue8014.patch
priority: normal
messages: + msg100072

assignee: mark.dickinson
keywords: + patch
stage: test needed
2010-02-24 21:46:41mark.dickinsonsetmessages: + msg100071
2010-02-24 21:10:40benjamin.petersonsetnosy: + mark.dickinson, benjamin.peterson
messages: + msg100069
2010-02-24 17:18:20doerwaltercreate