summaryrefslogtreecommitdiffstats
path: root/Modules/_elementtree.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-140061: Use `_PyObject_IsUniquelyReferenced()` to check if objects are ↵Sergey Miryanov2025-10-151-3/+4
| | | | | | | | | uniquely referenced (gh-140062) The previous `Py_REFCNT(x) == 1` checks can have data races in the free threaded build. `_PyObject_IsUniquelyReferenced(x)` is a more conservative check that is safe in the free threaded build and is identical to `Py_REFCNT(x) == 1` in the default GIL-enabled build.
* gh-139210: Fix use-after-free in xml.etree.ElementTree.iterparse() (GH-139211)Ken Jin2025-09-301-1/+1
|
* gh-135607: remove null checking of weakref list in dealloc of extension ↵Xuanteng Huang2025-06-301-2/+2
| | | | | | modules and objects (#135614) Co-authored-by: Kumar Aditya <kumaraditya@python.org> Co-authored-by: Victor Stinner <vstinner@python.org>
* gh-133009: fix UAF in `xml.etree.ElementTree.Element.__deepcopy__` (#133010)Bénédikt Tran2025-05-101-7/+34
|
* GH-124715: Move trashcan mechanism into `Py_Dealloc` (GH-132280)Mark Shannon2025-04-301-2/+0
|
* gh-132097: fix runtime UB when calling expat handlers (#132265)Bénédikt Tran2025-04-121-38/+45
|
* gh-131938: Update exception message for `Element.remove()` when an element ↵Bénédikt Tran2025-04-041-1/+2
| | | | | | is not found (#131972) The exception message for `xml.etree.ElementTree.Element.remove` when an element is not found has been updated from "list.remove(x): x not in list" to "Element.remove(x): element not found".
* gh-126033: fix UAF in `xml.etree.ElementTree.Element.remove` when concurrent ↵Bénédikt Tran2025-03-311-26/+32
| | | | mutations happen (#126124)
* gh-126037: fix UAF in `xml.etree.ElementTree.Element.find*` when concurrent ↵Bénédikt Tran2025-03-311-36/+28
| | | | | | | mutations happen (#127964) We fix a use-after-free in the `find`, `findtext` and `findall` methods of `xml.etree.ElementTree.Element` objects that can be triggered when the tag to find implements an `__eq__` method that mutates the element being queried.
* gh-111178: Change Argument Clinic signature for METH_O (#130682)Victor Stinner2025-03-111-10/+12
| | | Use "PyObject*" for METH_O functions to fix an undefined behavior.
* gh-128911: Add PyImport_ImportModuleAttr() function (#128912)Victor Stinner2025-01-301-3/+2
| | | | | | | | | | | Add PyImport_ImportModuleAttr() and PyImport_ImportModuleAttrString() functions. * Add unit tests. * Replace _PyImport_GetModuleAttr() with PyImport_ImportModuleAttr(). * Replace _PyImport_GetModuleAttrString() with PyImport_ImportModuleAttrString(). * Remove "pycore_import.h" includes, no longer needed.
* gh-111178: fix UBSan failures in `_elementtree.c` (#127982)Bénédikt Tran2024-12-161-53/+80
|
* gh-115754: Use Py_GetConstant(Py_CONSTANT_EMPTY_STR) (#125194)Victor Stinner2024-10-091-2/+2
| | | | | Replace PyUnicode_New(0, 0), PyUnicode_FromString("") and PyUnicode_FromStringAndSize("", 0) with Py_GetConstant(Py_CONSTANT_EMPTY_STR).
* gh-123213: Fixed xml.etree.ElementTree.Element.extend and assignment to no ↵Bar Harel2024-08-231-10/+2
| | | | longer hide exceptions (GH-123214)
* gh-119577: Adjust DeprecationWarning when testing element truth values in ↵Jacob Walls2024-06-071-1/+1
| | | | | ElementTree (GH-119762) Adjust DeprecationWarning when testing element truth values in ElementTree, we're planning to go with the more natural True return rather than a disruptive harder to code around exception raise, and are deferring the behavior change for a few more releases.
* gh-116322: Add Py_mod_gil module slot (#116882)Brett Simmers2024-05-031-0/+1
| | | | | | | | | | | | | | This PR adds the ability to enable the GIL if it was disabled at interpreter startup, and modifies the multi-phase module initialization path to enable the GIL when loading a module, unless that module's spec includes a slot indicating it can run safely without the GIL. PEP 703 called the constant for the slot `Py_mod_gil_not_used`; I went with `Py_MOD_GIL_NOT_USED` for consistency with gh-104148. A warning will be issued up to once per interpreter for the first GIL-using module that is loaded. If `-v` is given, a shorter message will be printed to stderr every time a GIL-using module is loaded (including the first one that issues a warning).
* gh-116437: Use new C API PyDict_Pop() to simplify the code (GH-116438)Serhiy Storchaka2024-03-071-11/+5
|
* gh-115398: Expose Expat >=2.6.0 reparse deferral API (CVE-2023-52425) ↵Sebastian Pipping2024-02-291-0/+35
| | | | | | | | | | | | | | | | | | | | | (GH-115623) Allow controlling Expat >=2.6.0 reparse deferral (CVE-2023-52425) by adding five new methods: - `xml.etree.ElementTree.XMLParser.flush` - `xml.etree.ElementTree.XMLPullParser.flush` - `xml.parsers.expat.xmlparser.GetReparseDeferralEnabled` - `xml.parsers.expat.xmlparser.SetReparseDeferralEnabled` - `xml.sax.expatreader.ExpatParser.flush` Based on the "flush" idea from https://github.com/python/cpython/pull/115138#issuecomment-1932444270 . ### Notes - Please treat as a security fix related to CVE-2023-52425. Includes code suggested-by: Snild Dolkow <snild@sony.com> and by core dev Serhiy Storchaka.
* gh-114569: Use PyMem_* APIs for most non-PyObject uses (#114574)Erlend E. Aasland2024-01-261-10/+13
| | | Fix usage in Modules, Objects, and Parser subdirectories.
* gh-103092: Make `_elementtree` module importable in sub-interpreters (#113434)Kirill Podoprigora2023-12-281-3/+1
| | | Enable imports of _elementtree module in sub-interpreters
* gh-111784: Fix two segfaults in the elementtree module (GH-113405)Kirill Podoprigora2023-12-241-2/+14
| | | | | | | | | | First fix resolve situation when pyexpat module (which contains expat_CAPI capsule) deallocates before _elementtree, so we need to hold a strong reference to pyexpat module to. Second fix resolve situation when module state is deallocated before deallocation of XMLParser instances, which uses module state to clear some stuff.
* gh-108511: Add C API functions which do not silently ignore errors (GH-109025)Serhiy Storchaka2023-09-171-2/+1
| | | | | | | | | Add the following functions: * PyObject_HasAttrWithError() * PyObject_HasAttrStringWithError() * PyMapping_HasKeyWithError() * PyMapping_HasKeyStringWithError()
* gh-106869: Use new PyMemberDef constant names (#106871)Victor Stinner2023-07-251-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Remove '#include "structmember.h"'. * If needed, add <stddef.h> to get offsetof() function. * Update Parser/asdl_c.py to regenerate Python/Python-ast.c. * Replace: * T_SHORT => Py_T_SHORT * T_INT => Py_T_INT * T_LONG => Py_T_LONG * T_FLOAT => Py_T_FLOAT * T_DOUBLE => Py_T_DOUBLE * T_STRING => Py_T_STRING * T_OBJECT => _Py_T_OBJECT * T_CHAR => Py_T_CHAR * T_BYTE => Py_T_BYTE * T_UBYTE => Py_T_UBYTE * T_USHORT => Py_T_USHORT * T_UINT => Py_T_UINT * T_ULONG => Py_T_ULONG * T_STRING_INPLACE => Py_T_STRING_INPLACE * T_BOOL => Py_T_BOOL * T_OBJECT_EX => Py_T_OBJECT_EX * T_LONGLONG => Py_T_LONGLONG * T_ULONGLONG => Py_T_ULONGLONG * T_PYSSIZET => Py_T_PYSSIZET * T_NONE => _Py_T_NONE * READONLY => Py_READONLY * PY_AUDIT_READ => Py_AUDIT_READ * READ_RESTRICTED => Py_AUDIT_READ * PY_WRITE_RESTRICTED => _Py_WRITE_RESTRICTED * RESTRICTED => (READ_RESTRICTED | _Py_WRITE_RESTRICTED)
* gh-106320: Move private _PyHash API to the internal C API (#107026)Victor Stinner2023-07-221-0/+1
| | | | | * No longer export most private _PyHash symbols, only export the ones which are needed by shared extensions. * Modules/_xxtestfuzz/fuzzer.c now uses the internal C API.
* gh-106521: Remove _PyObject_LookupAttr() function (GH-106642)Serhiy Storchaka2023-07-121-1/+1
|
* gh-106320: Remove private _PyImport C API functions (#106383)Victor Stinner2023-07-031-0/+5
| | | | | | * Remove private _PyImport C API functions: move them to the internal C API (pycore_import.h). * No longer export most of these private functions. * _testcapi avoids private _PyImport_GetModuleAttrString().
* gh-104922: remove PY_SSIZE_T_CLEAN (#106315)Inada Naoki2023-07-021-2/+0
|
* gh-106023: Update code using _PyObject_FastCall() (#106257)Victor Stinner2023-06-301-14/+8
| | | Replace _PyObject_FastCall() calls with PyObject_Vectorcall().
* gh-105375: Improve error handling in _elementtree (#105591)Erlend E. Aasland2023-06-091-3/+7
| | | Fix bugs where exceptions could end up being overwritten.
* gh-92536: Remove PyUnicode_READY() calls (#105210)Victor Stinner2023-06-011-2/+0
| | | | Since Python 3.12, PyUnicode_READY() does nothing and always returns 0.
* GH-103092: isolate `_elementtree` (#104561)Kumar Aditya2023-05-161-43/+42
|
* gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205)Eric Snow2023-05-051-0/+3
| | | 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-92123: Adapt _elementtree to multi-phase init (PEP 489) (#101285)Erlend E. Aasland2023-01-241-82/+117
|
* GH-92123: Pass _elementtree state as parameter (#101189)Erlend E. Aasland2023-01-241-57/+73
|
* GH-92123: Store _elementtree state in type contexts (#101190)Erlend E. Aasland2023-01-231-17/+21
| | | | - add state pointer to TreeBuilderObject - add state pointer to XMLParserObject
* gh-83122: Deprecate testing element truth values in `ElementTree` (#31149)Jacob Walls2023-01-231-0/+18
| | | | | | | When testing element truth values, emit a DeprecationWarning in all implementations. This had emitted a FutureWarning in the rarely used python-only implementation since ~2.7 and has always been documented as a behavior not to rely on. Matching an element in a tree search but having it test False can be unexpected. Raising the warning enables making the choice to finally raise an exception for this ambiguous behavior in the future.
* GH-92123: Move _elementtree heap types to module state (#101187)Erlend E. Aasland2023-01-211-57/+91
|
* gh-92123: Convert `_elementtree` types to heap types (#99221)Erlend E. Aasland2023-01-201-229/+157
|
* GH-90699: Clear interned strings in `_elementtree` (#101185)Erlend E. Aasland2023-01-201-0/+10
|
* gh-99845: Use size_t type in __sizeof__() methods (#99846)Victor Stinner2022-11-301-6/+7
| | | | | | | | 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: Replace Py_INCREF() with Py_NewRef() in _elementtree.c (#99696)Victor Stinner2022-11-221-69/+36
| | | | | | | * Replace Py_INCREF() and Py_XINCREF() using a cast with Py_NewRef() and Py_XNewRef() in Modules/_elementtree.c. * Make reference counting more explicit: don't steal implicitly a reference on PyList_SET_ITEM(), use Py_NewRef() instead. * Replace PyModule_AddObject() with PyModule_AddObjectRef().
* gh-99537: Use Py_SETREF() function in C code (#99656)Victor Stinner2022-11-221-4/+2
| | | | | | | | | | | | | | | Fix potential race condition in code patterns: * Replace "Py_DECREF(var); var = new;" with "Py_SETREF(var, new);" * Replace "Py_XDECREF(var); var = new;" with "Py_XSETREF(var, new);" * Replace "Py_CLEAR(var); var = new;" with "Py_XSETREF(var, new);" Other changes: * Replace "old = var; var = new; Py_DECREF(var)" with "Py_SETREF(var, new);" * Replace "old = var; var = new; Py_XDECREF(var)" with "Py_XSETREF(var, new);" * And remove the "old" variable.
* gh-99300: Replace Py_INCREF() with Py_NewRef() (#99513)Victor Stinner2022-11-161-8/+4
| | | | Replace Py_INCREF() and Py_XINCREF() using a cast with Py_NewRef() and Py_XNewRef().
* gh-99300: Use Py_NewRef() in Modules/_elementtree.c (#99438)Victor Stinner2022-11-131-82/+37
| | | | Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in Modules/_elementtree.c.
* GH-90699: Remove `_Py_IDENTIFIER` usage from `_elementtree` module (GH-99012)Kumar Aditya2022-11-021-25/+59
|
* gh-93741: Add private C API _PyImport_GetModuleAttrString() (GH-93742)Serhiy Storchaka2022-06-141-6/+2
| | | | | | It combines PyImport_ImportModule() and PyObject_GetAttrString() and saves 4-6 lines of code on every use. Add also _PyImport_GetModuleAttr() which takes Python strings as arguments.
* gh-89653: Use int type for Unicode kind (#92704)Victor Stinner2022-05-131-1/+1
| | | | Use the same type that PyUnicode_FromKindAndData() kind parameter type (public C API): int.
* gh-91320: Use _PyCFunction_CAST() (#92251)Victor Stinner2022-05-031-1/+1
| | | | | | | | | | 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")
* Remove an old, elementtree-specific leak detector (GH-31811)Oleg Iarygin2022-03-111-13/+0
|