summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_struct.py
Commit message (Collapse)AuthorAgeFilesLines
* bpo-35714: Reject null characters in struct format strings (GH-16928)Zackery Spytz2020-05-251-0/+8
| | | | struct.error is now raised if there is a null character in a struct format string.
* bpo-38076 Clear the interpreter state only after clearing module globals ↵Eddie Elizondo2020-02-041-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (GH-18039) Currently, during runtime destruction, `_PyImport_Cleanup` is clearing the interpreter state before clearing out the modules themselves. This leads to a segfault on modules that rely on the module state to clear themselves up. For example, let's take the small snippet added in the issue by @DinoV : ``` import _struct class C: def __init__(self): self.pack = _struct.pack def __del__(self): self.pack('I', -42) _struct.x = C() ``` The module `_struct` uses the module state to run `pack`. Therefore, the module state has to be alive until after the module has been cleared out to successfully run `C.__del__`. This happens at line 606, when `_PyImport_Cleanup` calls `_PyModule_Clear`. In fact, the loop that calls `_PyModule_Clear` has in its comments: > Now, if there are any modules left alive, clear their globals to minimize potential leaks. All C extension modules actually end up here, since they are kept alive in the interpreter state. That means that we can't clear the module state (which is used by C Extensions) before we run that loop. Moving `_PyInterpreterState_ClearModules` until after it, fixes the segfault in the code snippet. Finally, this updates a test in `io` to correctly assert the error that it now throws (since it now finds the io module state). The test that uses this is: `test_create_at_shutdown_without_encoding`. Given this test is now working is a proof that the module state now stays alive even when `__del__` is called at module destruction time. Thus, I didn't add a new tests for this. https://bugs.python.org/issue38076
* bpo-38076: Make struct module PEP-384 compatible (#15805)Dino Viehland2019-09-101-0/+4
| | | | | | | | | | * PEP-384 _struct * More PEP-384 fixes for _struct Summary: Add a couple of more fixes for `_struct` that were previously missed such as removing `tp_*` accessors and using `PyBytesWriter` instead of calling `PyBytes_FromStringAndSize` with `NULL`. Also added a test to confirm that `iter_unpack` type is still uninstantiable. * 📜🤖 Added by blurb_it.
* bpo-30249: Improve struct.unpack_from() error messages (GH-6059)Xiang Zhang2018-03-101-4/+30
|
* Fix bytes warnings in test_struct (added in bpo-29802). (#4068)Serhiy Storchaka2017-10-211-2/+2
|
* bpo-21071: struct.Struct.format type is now str (#845)Victor Stinner2017-06-231-0/+8
|
* bpo-30245: Fix possible overflow when organize struct.pack_into error ↵Johan Liu2017-06-021-0/+10
| | | | message (#1682)
* bpo-29802: Fix reference counting in module-level struct functions (#1213)Serhiy Storchaka2017-04-201-0/+10
| | | | when pass arguments of wrong type.
* bpo-29649: Improve struct.pack_into() boundary error messages (#424)Andrew Nester2017-04-041-0/+20
|
* Rename struct.unpack() 2nd parameter to "buffer"Victor Stinner2017-02-021-3/+3
| | | | | | | | | | Issue #29300: Rename struct.unpack() second parameter from "inputstr" to "buffer", and use the Py_buffer type. Fix also unit tests on struct.unpack() which passed a Unicode string instead of a bytes string as struct.unpack() second parameter. The purpose of test_trailing_counter() is to test invalid format strings, not to test the buffer parameter.
* Issue #29300: Convert _struct module to Argument ClinicVictor Stinner2017-02-021-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | * The struct module now requires contiguous buffers. * Convert most functions and methods of the _struct module to Argument Clinic * Use "Py_buffer" type for the "buffer" argument. Argument Clinic is responsible to create and release the Py_buffer object. * Use "PyStructObject *" type for self to avoid explicit conversions. * Add an unit test on the _struct.Struct.unpack_from() method to test passing arguments as keywords. * Rephrase docstrings. * Rename "fmt" argument to "format" in docstrings and the documentation. As a side effect, functions and methods which used METH_VARARGS calling convention like struct.pack() now use the METH_FASTCALL calling convention which avoids the creation of temporary tuple to pass positional arguments and so is faster. For example, struct.pack("i", 1) becomes 1.56x faster (-36%):: $ ./python -m perf timeit \ -s 'import struct; pack=struct.pack' 'pack("i", 1)' \ --compare-to=../default-ref/python Median +- std dev: 119 ns +- 1 ns -> 76.8 ns +- 0.4 ns: 1.56x faster (-36%) Significant (t=295.91) Patch co-written with Serhiy Storchaka.
* require a long long data type (closes #27961)Benjamin Peterson2016-09-061-18/+3
|
* Issue #11734: Add support for IEEE 754 half-precision floats to the struct ↵Mark Dickinson2016-09-031-2/+105
| | | | module. Original patch by Eli Stevens.
* Issue #21741: Update 147 test modules to use test discovery.Zachary Ware2015-04-131-4/+1
| | | | | | | I have compared output between pre- and post-patch runs of these tests to make sure there's nothing missing and nothing broken, on both Windows and Linux. The only differences I found were actually tests that were previously *not* run.
* Issue #18783: Removed existing mentions of Python long type in docstrings,Serhiy Storchaka2013-08-271-1/+1
|\ | | | | | | error messages and comments.
| * Issue #18783: Removed existing mentions of Python long type in docstrings,Serhiy Storchaka2013-08-271-1/+1
| | | | | | | | error messages and comments.
* | Issue #14596: The struct.Struct() objects now use more compact implementation.Serhiy Storchaka2013-05-171-7/+2
| |
* | Issue #17804: New function ``struct.iter_unpack`` allows for streaming ↵Antoine Pitrou2013-04-261-1/+73
| | | | | | | | struct unpacking.
* | Replace IOError with OSError (#16715)Andrew Svetlov2012-12-251-3/+3
|/
* Issue #15467: Merge 3.2Martin v. Löwis2012-07-291-30/+10
|\
| * Issue #15467: Move helpers for __sizeof__ tests into test_support.Martin v. Löwis2012-07-291-29/+10
| | | | | | | | Patch by Serhiy Storchaka.
* | Issue #15402: Simplify Struct.__sizeof__ and make tests more precise.Meador Inge2012-07-291-10/+41
|\ \ | |/
| * Issue #15402: Simplify Struct.__sizeof__ and make tests more precise.Meador Inge2012-07-291-10/+41
| |
* | MERGE: Better test for Issue #15402: Add a __sizeof__ method to struct.StructJesus Cea2012-07-231-4/+4
|\ \ | |/
| * Better test for Issue #15402: Add a __sizeof__ method to struct.StructJesus Cea2012-07-231-4/+4
| |
* | Issue #15402: Add a __sizeof__ method to struct.Struct.Meador Inge2012-07-231-0/+10
|\ \ | |/ | | | | Initial patch by Serhiy Storchaka.
| * Issue #15402: Add a __sizeof__ method to struct.Struct.Meador Inge2012-07-231-0/+10
| | | | | | | | Initial patch by Serhiy Storchaka.
* | Issue #3163: The struct module gets new format characters 'n' and 'N'Antoine Pitrou2011-10-061-25/+41
|/ | | | supporting C integer types `ssize_t` and `size_t`, respectively.
* #11565: Merge with 3.1.Ezio Melotti2011-03-161-1/+1
|\
| * #11565: Fix several typos. Patch by Piotr Kasprzyk.Ezio Melotti2011-03-161-1/+1
| |
| * Merged revisions 82637 via svnmerge fromBenjamin Peterson2010-07-071-4/+8
| | | | | | | | | | | | | | | | | | | | svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r82637 | benjamin.peterson | 2010-07-07 17:45:06 -0500 (Wed, 07 Jul 2010) | 1 line ValueError in this case is also acceptable ........
| * Merged revisions 82628,82630 via svnmerge fromBenjamin Peterson2010-07-071-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r82628 | benjamin.peterson | 2010-07-07 13:44:05 -0500 (Wed, 07 Jul 2010) | 1 line this needn't be in the loop ........ r82630 | benjamin.peterson | 2010-07-07 13:54:59 -0500 (Wed, 07 Jul 2010) | 1 line don't ignore exceptions from PyObject_IsTrue ........
| * Merged revisions 81897-81898,81902 via svnmerge fromMark Dickinson2010-06-111-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r81897 | mark.dickinson | 2010-06-11 17:56:34 +0100 (Fri, 11 Jun 2010) | 1 line Avoid possible undefined behaviour from signed overflow. ........ r81898 | mark.dickinson | 2010-06-11 20:05:08 +0100 (Fri, 11 Jun 2010) | 1 line Fix an incorrect return type. ........ r81902 | mark.dickinson | 2010-06-11 20:50:30 +0100 (Fri, 11 Jun 2010) | 1 line Fix more undefined-behaviour inducing overflow checks in struct module. ........
| * Merged revisions 78692 via svnmerge fromMark Dickinson2010-03-051-6/+2
| | | | | | | | | | | | | | | | | | | | svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r78692 | mark.dickinson | 2010-03-05 14:44:08 +0000 (Fri, 05 Mar 2010) | 1 line Remove unused imports & clean up sys imports in test_struct. ........
| * Merged revisions 73715 via svnmerge fromGeorg Brandl2009-08-131-2/+2
| | | | | | | | | | | | | | | | | | | | svn+ssh://svn.python.org/python/branches/py3k ........ r73715 | benjamin.peterson | 2009-07-01 01:06:06 +0200 (Mi, 01 Jul 2009) | 1 line convert old fail* assertions to assert* ........
* | Issue #10783: struct.pack() doesn't encode implicitly unicode to UTF-8Victor Stinner2010-12-281-57/+46
| | | | | | | | | | | | | | * Replace "bytes" by "bytes object" in struct error messages * Document the API change in What's new in Python 3.2 * Fix test_wave * Remove also ugly implicit conversions in test_struct
* | Issue #8990: array.fromstring() and array.tostring() get renamed toAntoine Pitrou2010-09-011-4/+4
| | | | | | | | | | | | frombytes() and tobytes(), respectively, to avoid confusion. Furthermore, array.frombytes(), array.extend() as well as the array.array() constructor now accept bytearray objects. Patch by Thomas Jollans.
* | Add test for memory leak reported in issue 9422.Mark Dickinson2010-08-011-1/+6
| |
* | Issue #4770: Restrict binascii module to accept only bytes (as specified).Florent Xicluna2010-07-271-0/+1
| | | | | | | | And fix the email package to encode to ASCII instead of ``raw-unicode-escape`` before ASCII-to-binary decoding.
* | Yield more information on failure in test_struct boolean test.Mark Dickinson2010-07-121-2/+7
| |
* | ValueError is eventually what we want to move to, I supposeBenjamin Peterson2010-07-101-2/+2
| |
* | wrapBenjamin Peterson2010-07-091-1/+2
| |
* | allow more exceptionsBenjamin Peterson2010-07-091-3/+3
| |
* | OverflowError is fineBenjamin Peterson2010-07-091-1/+2
| |
* | ValueError in this case is also acceptableBenjamin Peterson2010-07-071-4/+8
| |
* | don't ignore exceptions from PyObject_IsTrueBenjamin Peterson2010-07-071-0/+6
| |
* | this needn't be in the loopBenjamin Peterson2010-07-071-2/+2
| |
* | Fix more undefined-behaviour inducing overflow checks in struct module.Mark Dickinson2010-06-111-0/+2
| |
* | Avoid possible undefined behaviour from signed overflow.Mark Dickinson2010-06-111-0/+5
| |
* | Issue #3129: Trailing digits in format string are no longer ignored.Alexander Belopolsky2010-06-111-1/+27
| |