[ python-Bugs-1545696 ] structmember T_LONG won't accept a python long
SourceForge.net
noreply at sourceforge.net
Fri Aug 25 02:52:26 CEST 2006
Bugs item #1545696, was opened at 2006-08-23 22:07
Message generated for change (Comment added) made by nnorwitz
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1545696&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Submitted By: Roger Upole (rupole)
Assigned to: Nobody/Anonymous (nobody)
Summary: structmember T_LONG won't accept a python long
Initial Comment:
An attribute defined as T_LONG throws a vague error
when set to a python long, even when the value is
within the range of a LONG.
TypeError: bad argument type for built-in operation
----------------------------------------------------------------------
>Comment By: Neal Norwitz (nnorwitz)
Date: 2006-08-24 17:52
Message:
Logged In: YES
user_id=33168
Ugh. This code is lax in checking/conversion. Do you think
you could provide a patch?
All of the int cases should call PyInt_AsLong() if this call
fails (returns -1), then that should be returned from
PyMember_SetOne. If it succeeds, there should be a range
check that ensures the value is valid. If that fails a
warning should be produced. We need to issue a warning
rather than an error for backwards compatability (at least
for 2.6).
The float/double cases can be simplified some by calling
PyFloat_AsDouble and doing similar checks as in the int cases.
----------------------------------------------------------------------
Comment By: Roger Upole (rupole)
Date: 2006-08-24 12:56
Message:
Logged In: YES
user_id=771074
The DEVMODE object from pywintypes has attributes defined
as T_LONG via the structmember API.
>>> import pywintypes
>>> dm=pywintypes.DEVMODEType()
>>> dm.Position_x=3
>>> dm.Position_x
3
>>> dm.Position_x=long(3)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: bad argument type for built-in operation
>>>
Here's the relevant code from structmember.c
that throws the error:
case T_LONG:
if (!PyInt_Check(v)) {
PyErr_BadArgument();
return -1;
}
*(long*)addr = PyInt_AsLong(v);
break;
----------------------------------------------------------------------
Comment By: Neal Norwitz (nnorwitz)
Date: 2006-08-24 11:30
Message:
Logged In: YES
user_id=33168
Can you provide example code that demonstrates what you mean?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1545696&group_id=5470
More information about the Python-bugs-list
mailing list