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: PyLong_AsLong doesn't check tp_as_number
Type: Stage:
Components: None Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: loewis Nosy List: loewis, rupole
Priority: normal Keywords:

Created on 2007-01-08 20:06 by rupole, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg30952 - (view) Author: Roger Upole (rupole) Date: 2007-01-08 20:06
Both PyInt_AsLong and PyLong_AsLongLong check if an object's type has PyNumberMethods defined.  However, PyLong_AsLong does not, causing conversion to fail for
objects which can legitimately be converted to a long.
 
msg30953 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2007-01-11 23:20
I fail to see the problem. If you want to convert arbitrary objects to long, use PyInt_AsLong.
msg30954 - (view) Author: Roger Upole (rupole) Date: 2007-01-12 02:11
The problem is that the conversion fails when it should succeed.
The place I ran into this was in PyLong_AsVoidPtr, which I can't change.
Are you saying that PyLong_AsLong is deprecated, and should never be used ?
msg30955 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2007-01-12 07:46
No, I'm saying that PyLong_AsVoidPtr is guaranteed to convert ints and longs, nothing else. Likewise, PyLong_AsVoidPtr is only supported for int and long objects (read the documentation). It's not deprecated -  but it should only be used for the cases which it is documented to support.

If, for some reason, you want to convert an object that is not an int or long into a void*, by converting it to an int first, you need to invoke the number methods first yourself.

Closing this report as invalid.
History
Date User Action Args
2022-04-11 14:56:22adminsetgithub: 44430
2007-01-08 20:06:02rupolecreate