classification
Title: Undetected error in _struct.pack_into
Type: Stage:
Components: Extension Modules Versions: Python 3.0, Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ajaksu2, amaury.forgeotdarc, georg.brandl
Priority: Keywords: patch

Created on 2008-08-27 04:29 by ajaksu2, last changed 2008-08-27 09:26 by amaury.forgeotdarc.

Files
File name Uploaded Description Edit Remove
s26.diff georg.brandl, 2008-08-27 08:47
s30.diff georg.brandl, 2008-08-27 08:47
Messages
msg72005 (view) Author: Daniel Diniz (ajaksu2) Date: 2008-08-27 04:29
The following code leads to XXX Undetected errors in debug builds of
trunk and 3.0:

import _struct
_struct.pack_into(b"8", bytearray(1), None)

Besides that, there's something fishy happening in non-debug builds: 

2.6:
>>> _struct.pack_into(b"8", bytearray(1), None);
>>> _struct.pack_into(b"8", bytearray(1), None);
>>> import sys
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: an integer is required

3.0:
>>> _struct.pack_into(b"8", bytearray(1), None)
>>> _struct.pack_into(b"8", bytearray(1), None)
SystemError: Objects/longobject.c:433: bad argument to internal function


Found with Fusil.
msg72014 (view) Author: Georg Brandl (georg.brandl) Date: 2008-08-27 08:44
The problem is that, unlike PyInt_AsSsize_t, PyLong_AsSsize_t expects
its argument to already be a long object and else raises the SystemError.

It should probably behave like PyInt_AsSsize_t and raise the TypeError
since in 3.0 it's used in many places where PyInt_AsSsize_t was used.
msg72015 (view) Author: Georg Brandl (georg.brandl) Date: 2008-08-27 08:47
The attached patches at least correct the XXX undetected error.
msg72016 (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) Date: 2008-08-27 09:26
Isn't PyNumber_AsSsize_t designed for this purpose?
History
Date User Action Args
2008-08-27 09:26:28amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg72016
2008-08-27 08:47:36georg.brandlsetfiles: + s30.diff
2008-08-27 08:47:30georg.brandlsetfiles: + s26.diff
keywords: + patch
messages: + msg72015
2008-08-27 08:44:42georg.brandlsetnosy: + georg.brandl
messages: + msg72014
2008-08-27 04:29:50ajaksu2create