summaryrefslogtreecommitdiffstats
path: root/Modules/_struct.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-104276: Make `_struct.unpack_iterator` type use type flag instead of ↵chgnrdv2023-05-091-7/+1
| | | | custom constructor (#104277)
* gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205)Eric Snow2023-05-051-0/+1
| | | Here we are doing no more than adding the value for Py_mod_multiple_interpreters and using it for stdlib modules. We will start checking for it in gh-104206 (once PyInterpreterState.ceval.own_gil is added in gh-104204).
* gh-98248: Normalizing the error messages in function struct.pack (GH-98252)Felix Ye2022-12-041-57/+130
| | | | Provide consistent and informative error messages in function struct.pack when its integral arguments are not in range.
* gh-99845: Use size_t type in __sizeof__() methods (#99846)Victor Stinner2022-11-301-6/+4
| | | | | | | | The implementation of __sizeof__() methods using _PyObject_SIZE() now use an unsigned type (size_t) to compute the size, rather than a signed type (Py_ssize_t). Cast explicitly signed (Py_ssize_t) values to unsigned type (Py_ssize_t).
* gh-99537: Use Py_SETREF(var, NULL) in C code (#99687)Victor Stinner2022-11-231-2/+1
| | | Replace "Py_DECREF(var); var = NULL;" with "Py_SETREF(var, NULL);".
* gh-99300: Use Py_NewRef() in Modules/ directory (#99468)Victor Stinner2022-11-141-4/+2
| | | | Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in test C files of the Modules/ directory.
* GH-78724: Initialize struct.Struct in __new__ (GH-94532)Kumar Aditya2022-09-251-33/+26
| | | | Closes https://github.com/python/cpython/issues/75960 Closes https://github.com/python/cpython/issues/78724
* gh-96735: Fix undefined behaviour in struct unpacking functions (#96739)Mark Dickinson2022-09-251-26/+70
| | | | | | | | | | This PR fixes undefined behaviour in the struct module unpacking support functions `bu_longlong`, `lu_longlong`, `bu_int` and `lu_int`; thanks to @kumaraditya303 for finding these. The fix is to accumulate the bytes in an unsigned integer type instead of a signed integer type, then to convert to the appropriate signed type. In cases where the width matches, that conversion will typically be compiled away to a no-op. (Evidence from Godbolt: https://godbolt.org/z/5zvxodj64 .) To make the conversions efficient, I've specialised the relevant functions for their output size: for `bu_longlong` and `lu_longlong`, this only entails checking that the output size is indeed `8`. But `bu_int` and `lu_int` were used for format sizes `2` and `4` - I've split those into two separate functions each. No tests, because all of the affected cases are already exercised by the test suite.
* GH-94254: Make _struct module types immutable (#94269)Kumar Aditya2022-06-261-2/+4
|
* gh-94207: Fix struct module leak (GH-94239)Mark Dickinson2022-06-251-2/+20
| | | | | | | | | | | | Make _struct.Struct a GC type This fixes a memory leak in the _struct module, where as soon as a Struct object is stored in the cache, there's a cycle from the _struct module to the cache to Struct objects to the Struct type back to the module. If _struct.Struct is not gc-tracked, that cycle is never collected. This PR makes _struct.Struct GC-tracked, and adds a regression test.
* gh-91320: Use _PyCFunction_CAST() (#92251)Victor Stinner2022-05-031-4/+4
| | | | | | | | | | Replace "(PyCFunction)(void(*)(void))func" cast with _PyCFunction_CAST(func). Change generated by the command: sed -i -e \ 's!(PyCFunction)(void(\*)(void)) *\([A-Za-z0-9_]\+\)!_PyCFunction_CAST(\1)!g' \ $(find -name "*.c")
* bpo-46906: Add PyFloat_Pack8() to the C API (GH-31657)Victor Stinner2022-03-111-11/+8
| | | | | | | | | | | | | | | | | | | | | | Add new functions to pack and unpack C double (serialize and deserialize): * PyFloat_Pack2(), PyFloat_Pack4(), PyFloat_Pack8() * PyFloat_Unpack2(), PyFloat_Unpack4(), PyFloat_Unpack8() Document these functions and add unit tests. Rename private functions and move them from the internal C API to the public C API: * _PyFloat_Pack2() => PyFloat_Pack2() * _PyFloat_Pack4() => PyFloat_Pack4() * _PyFloat_Pack8() => PyFloat_Pack8() * _PyFloat_Unpack2() => PyFloat_Unpack2() * _PyFloat_Unpack4() => PyFloat_Unpack4() * _PyFloat_Unpack8() => PyFloat_Unpack8() Replace the "unsigned char*" type with "char*" which is more common and easy to use.
* bpo-46613: Add PyType_GetModuleByDef to the public API (GH-31081)Petr Viktorin2022-02-111-1/+1
| | | | | * Make PyType_GetModuleByDef public (remove underscore) Co-authored-by: Victor Stinner <vstinner@python.org>
* bpo-46670: Remove unused macros in the Modules directory (GH-31194)Victor Stinner2022-02-071-2/+0
| | | | | * bpo-46670: Remove unused macros in the Modules directory * Add again LINKAT_DIR_FD_CONVERTER: generated by Argument Clinic
* bpo-43974: Move Py_BUILD_CORE_MODULE into module code (GH-29157)Christian Heimes2021-10-221-0/+4
| | | | | | | | | | | | | | setup.py no longer defines Py_BUILD_CORE_MODULE. Instead every module defines the macro before #include "Python.h" unless Py_BUILD_CORE_BUILTIN is already defined. Py_BUILD_CORE_BUILTIN is defined for every module that is built by Modules/Setup. The PR also simplifies Modules/Setup. Makefile and makesetup already define Py_BUILD_CORE_BUILTIN and include Modules/internal for us. Signed-off-by: Christian Heimes <christian@python.org>
* bpo-35134: Add Include/cpython/floatobject.h (GH-28957)Victor Stinner2021-10-141-0/+1
| | | | | Split Include/floatobject.h into sub-files: add Include/cpython/floatobject.h and Include/internal/pycore_floatobject.h.
* bpo-45407: Remove outdated XXX comment from Struct___init___impl (GH-28805)Jeong YunWon2021-10-081-1/+0
|
* bpo-45034: Fix how upper limit is formatted for `struct.pack("H", ...)` ↵Nikita Sobolev2021-09-071-6/+6
| | | | | | (GH-28178) Co-authored-by: Mark Dickinson <dickinsm@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-40137: Add pycore_moduleobject.h internal header (GH-25507)Victor Stinner2021-04-211-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add pycore_moduleobject.h internal header file with static inline functions to access module members: * _PyModule_GetDict() * _PyModule_GetDef() * _PyModule_GetState() These functions don't check at runtime if their argument has a valid type and can be inlined even if Python is not built with LTO. _PyType_GetModuleByDef() uses _PyModule_GetDef(). Replace PyModule_GetState() with _PyModule_GetState() in the extension modules, considered as performance sensitive: * _abc * _functools * _operator * _pickle * _queue * _random * _sre * _struct * _thread * _winapi * array * posix The following extensions are now built with the Py_BUILD_CORE_MODULE macro defined, to be able to use the internal pycore_moduleobject.h header: _abc, array, _operator, _queue, _sre, _struct.
* Use Py_NewRef in Modules/_struct.c (GH-23981)Pablo Galindo2020-12-281-2/+1
|
* bpo-42519: Replace PyMem_MALLOC() with PyMem_Malloc() (GH-23586)Victor Stinner2020-12-011-3/+3
| | | | | | | | | | | No longer use deprecated aliases to functions: * Replace PyMem_MALLOC() with PyMem_Malloc() * Replace PyMem_REALLOC() with PyMem_Realloc() * Replace PyMem_FREE() with PyMem_Free() * Replace PyMem_Del() with PyMem_Free() * Replace PyMem_DEL() with PyMem_Free() Modify also the PyMem_DEL() macro to use directly PyMem_Free().
* bpo-1635741: Fix _struct for build bot error (GH-23402)Dong-hee Na2020-11-191-1/+1
| | | Automerge-Triggered-By: GH:tiran
* bpo-1635741: Port _struct to multiphase initialization (GH-23398)Christian Heimes2020-11-191-233/+265
| | | Signed-off-by: Christian Heimes <christian@python.org>
* bpo-40792: Make the result of PyNumber_Index() always having exact type int. ↵Serhiy Storchaka2020-05-281-1/+1
| | | | | | | | | | | | (GH-20443) Previously, the result could have been an instance of a subclass of int. Also revert bpo-26202 and make attributes start, stop and step of the range object having exact type int. Add private function _PyNumber_Index() which preserves the old behavior of PyNumber_Index() for performance to use it in the conversion functions like PyLong_AsLong().
* bpo-40217: Ensure Py_VISIT(Py_TYPE(self)) is always called for ↵Pablo Galindo2020-05-271-0/+1
| | | | | | | | | PyType_FromSpec types (reverts GH-19414) (GH-20264) Heap types now always visit the type in tp_traverse. See added docs for details. This reverts commit 0169d3003be3d072751dd14a5c84748ab63a249f. Automerge-Triggered-By: @encukou
* bpo-35714: Reject null characters in struct format strings (GH-16928)Zackery Spytz2020-05-251-0/+5
| | | | struct.error is now raised if there is a null character in a struct format string.
* bpo-40268: Remove unused structmember.h includes (GH-19530)Victor Stinner2020-04-151-1/+1
| | | | | | If only offsetof() is needed: include stddef.h instead. When structmember.h is used, add a comment explaining that PyMemberDef is used.
* bpo-39943: Add the const qualifier to pointers on non-mutable PyBytes data. ↵Serhiy Storchaka2020-04-121-2/+2
| | | | (GH-19472)
* bpo-39689: Do not use native packing for format "?" with standard size ↵Stefan Krah2020-03-241-0/+3
| | | | (GH-18969)
* bpo-39968: Convert extension modules' macros of get_module_state() to inline ↵Hai Shi2020-03-161-11/+23
| | | | functions (GH-19017)
* bpo-39573: Clean up modules and headers to use Py_IS_TYPE() function (GH-18521)Dong-hee Na2020-02-171-1/+1
|
* bpo-39245: Switch to public API for Vectorcall (GH-18460)Petr Viktorin2020-02-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The bulk of this patch was generated automatically with: for name in \ PyObject_Vectorcall \ Py_TPFLAGS_HAVE_VECTORCALL \ PyObject_VectorcallMethod \ PyVectorcall_Function \ PyObject_CallOneArg \ PyObject_CallMethodNoArgs \ PyObject_CallMethodOneArg \ ; do echo $name git grep -lwz _$name | xargs -0 sed -i "s/\b_$name\b/$name/g" done old=_PyObject_FastCallDict new=PyObject_VectorcallDict git grep -lwz $old | xargs -0 sed -i "s/\b$old\b/$new/g" and then cleaned up: - Revert changes to in docs & news - Revert changes to backcompat defines in headers - Nudge misaligned comments
* bpo-38140: Make dict and weakref offsets opaque for C heap types (#16076)Eddie Elizondo2019-09-191-1/+1
| | | | | | * Make dict and weakref offsets opaque for C heap types * Add news
* bpo-37752: Delete redundant Py_CHARMASK in normalizestring() (GH-15095)Jordon Xu2019-09-101-2/+2
|
* bpo-38076: Make struct module PEP-384 compatible (#15805)Dino Viehland2019-09-101-147/+172
| | | | | | | | | | * 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.
* Fix typos in comments, docs and test names (#15018)Min ho Kim2019-07-301-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | * Fix typos in comments, docs and test names * Update test_pyparse.py account for change in string length * Apply suggestion: splitable -> splittable Co-Authored-By: Terry Jan Reedy <tjreedy@udel.edu> * Apply suggestion: splitable -> splittable Co-Authored-By: Terry Jan Reedy <tjreedy@udel.edu> * Apply suggestion: Dealloccte -> Deallocate Co-Authored-By: Terry Jan Reedy <tjreedy@udel.edu> * Update posixmodule checksum. * Reverse idlelib changes.
* bpo-37483: add _PyObject_CallOneArg() function (#14558)Jeroen Demeyer2019-07-041-1/+1
|
* bpo-36974: tp_print -> tp_vectorcall_offset and tp_reserved -> tp_as_async ↵Jeroen Demeyer2019-05-311-4/+4
| | | | | | | | | (GH-13464) Automatically replace tp_print -> tp_vectorcall_offset tp_compare -> tp_as_async tp_reserved -> tp_as_async
* bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem(). (GH-11112)Serhiy Storchaka2019-02-251-1/+4
|
* bpo-23867: Argument Clinic: inline parsing code for a single positional ↵Serhiy Storchaka2018-12-251-6/+6
| | | | parameter. (GH-9689)
* bpo-33012: Fix invalid function cast warnings with gcc 8. (GH-6749)Serhiy Storchaka2018-11-271-4/+4
| | | | | | Fix invalid function cast warnings with gcc 8 for method conventions different from METH_NOARGS, METH_O and METH_VARARGS excluding Argument Clinic generated code.
* bpo-33012: Fix invalid function cast warnings with gcc 8 for METH_NOARGS. ↵Siddhesh Poyarekar2018-04-291-1/+1
| | | | | | | | | (GH-6030) METH_NOARGS functions need only a single argument but they are cast into a PyCFunction, which takes two arguments. This triggers an invalid function cast warning in gcc8 due to the argument mismatch. Fix this by adding a dummy unused argument.
* bpo-30249: Improve struct.unpack_from() error messages (GH-6059)Xiang Zhang2018-03-101-6/+29
|
* bpo-32240: Add the const qualifier to declarations of PyObject* array ↵Serhiy Storchaka2017-12-151-5/+5
| | | | arguments. (#4746)
* bpo-30246: fix several error messages which only mention bytes in struct (#1421)Xiang Zhang2017-09-141-4/+5
|
* bpo-31095: fix potential crash during GC (GH-2974)INADA Naoki2017-08-241-0/+2
|
* bpo-29464: Rename METH_FASTCALL to METH_FASTCALL|METH_KEYWORDS and make (#1955)Serhiy Storchaka2017-07-031-20/+6
| | | | | the bare METH_FASTCALL be used for functions with positional-only parameters.
* bpo-21071: struct.Struct.format type is now str (#845)Victor Stinner2017-06-231-2/+2
|
* bpo-20627: Fix error message when keyword arguments are used (#2115)Sylvain2017-06-151-6/+14
|
* bpo-30245: Fix possible overflow when organize struct.pack_into error ↵Johan Liu2017-06-021-2/+5
| | | | message (#1682)