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: PyArg_ParseTuple problem with 'L' format
Type: Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: loewis, mdehoon, theller
Priority: normal Keywords: patch

Created on 2003-04-17 16:03 by theller, last changed 2022-04-10 16:08 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
getargs.patch theller, 2003-04-17 16:03 patch to getargs.c
Messages (5)
msg43392 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2003-04-17 16:03
PyArg_ParseTuple(tup, "B", &value) will raise 'Bad
Argument to internal function' if the object is not a
Python integer or long.
I believe the patch fixes the problem, but it is untested.

This problem probably exists since 2.2.
msg43393 - (view) Author: Michiel de Hoon (mdehoon) * Date: 2005-01-19 04:04
Logged In: YES 
user_id=488897

I can replicate this bug with the "L" format but not with
"B". Is the 'B' in PyArg_ParseTuple(tup, "B",
&value)  a typo?
msg43394 - (view) Author: Michiel de Hoon (mdehoon) * Date: 2005-01-20 05:15
Logged In: YES 
user_id=488897

The PyLong_AsLongLong function (in Objects/longobject.c)
also contains a call to PyLong_Check and PyInt_Check, so I
would think that there is no need for another call to a
PyLong_Check and a PyInt_Check.
Instead, I would suggest to replace the
PyErr_BadInternalCall() (which raises the 'Bad Argument to
internal function') in PyLong_AsLongLong by

PyErr_SetString(PyExc_TypeError, "an integer is required").

This would also make it consistent with PyInt_AsLong in
Objects/intobject.c.
msg43395 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2005-03-03 09:27
Logged In: YES 
user_id=21627

I agree that the proposed double-type check is redundant.
OTOH, relying on the exception in the _As* function loses
information which argument specifically cannot be converted.
As a solution, I now clear the exception before invoking
converterr.

Fixed in
test_capi.py 1.8.2.1
NEWS 1.1193.2.24
getargs.c 2.102.2.1
test_capi.py 1.9
NEWS 1.1252
getargs.c 2.103
msg43396 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2005-03-03 12:29
Logged In: YES 
user_id=21627

Turns out that this approach breaks cases where
PyLong_AsLongLong returns OverflowErrors; it also turns out
that test_getargs2 is the place where the getargs tests are
implemented. So I reverted the previous patch, implemented
nb_int conversion for longs, and committed this as

test_capi.py 1.8.2.2
test_getargs2.py 1.5.12.1
longobject.c 1.165.2.1
getargs.c 2.102.2.2
test_capi.py 1.10
test_getargs2.py 1.6
longobject.c 1.166
getargs.c 2.104

History
Date User Action Args
2022-04-10 16:08:11adminsetgithub: 38318
2003-04-17 16:03:41thellercreate