Commit Graph

237 Commits

Author SHA1 Message Date
Victor Stinner 0c4a828cad Run Argument Clinic: METH_VARARGS=>METH_FASTCALL
Issue #29286. Run Argument Clinic to get the new faster METH_FASTCALL calling
convention for functions using "boring" positional arguments.

Manually fix _elementtree: _elementtree_XMLParser_doctype() must remain
consistent with the clinic code.
2017-01-17 02:21:47 +01:00
Serhiy Storchaka 47bdc40352 Merge from 3.6. 2016-12-21 12:36:29 +02:00
Serhiy Storchaka 690e81f63f Merge from 3.5. 2016-12-21 12:35:11 +02:00
Serhiy Storchaka 18f018ca12 Issue #28871: Fixed a crash when deallocate deep ElementTree. 2016-12-21 12:32:56 +02:00
Serhiy Storchaka 5ab81d787f Issue #28959: Added private macro PyDict_GET_SIZE for retrieving the size of dict. 2016-12-16 16:18:57 +02:00
Victor Stinner 5abaa2b139 Use PyObject_CallFunctionObjArgs()
Issue #28915: Replace PyObject_CallFunction() with
PyObject_CallFunctionObjArgs() when the format string was only made of "O"
formats, PyObject* arguments.

PyObject_CallFunctionObjArgs() avoids the creation of a temporary tuple and
doesn't have to parse a format string.
2016-12-09 16:22:32 +01:00
Victor Stinner f561634c82 Use _PyObject_CallMethodIdObjArgs() in _elementtree
Issue #28915: Replace _PyObject_CallMethodId() with
_PyObject_CallMethodIdObjArgs() when the format string was only made of "O"
formats, PyObject* arguments.

_PyObject_CallMethodIdObjArgs() avoids the creation of a temporary tuple and
doesn't have to parse a format string.
2016-12-09 15:26:00 +01:00
Victor Stinner 7bfb42d5b7 Issue #28858: Remove _PyObject_CallArg1() macro
Replace
   _PyObject_CallArg1(func, arg)
with
   PyObject_CallFunctionObjArgs(func, arg, NULL)

Using the _PyObject_CallArg1() macro increases the usage of the C stack, which
was unexpected and unwanted. PyObject_CallFunctionObjArgs() doesn't have this
issue.
2016-12-05 17:04:32 +01:00
Victor Stinner de4ae3d486 Backed out changeset b9c9691c72c5
Issue #28858: The change b9c9691c72c5 introduced a regression. It seems like
_PyObject_CallArg1() uses more stack memory than
PyObject_CallFunctionObjArgs().
2016-12-04 22:59:09 +01:00
Victor Stinner 4778eab1f2 Replace PyObject_CallFunction() with fastcall
Replace
    PyObject_CallFunction(func, "O", arg)
and
    PyObject_CallFunction(func, "O", arg, NULL)
with
    _PyObject_CallArg1(func, arg)

Replace
    PyObject_CallFunction(func, NULL)
with
    _PyObject_CallNoArg(func)

_PyObject_CallNoArg() and _PyObject_CallArg1() are simpler and don't allocate
memory on the C stack.
2016-12-01 14:51:04 +01:00
Victor Stinner 27580c1fb5 Replace PyObject_CallFunctionObjArgs() with fastcall
* PyObject_CallFunctionObjArgs(func, NULL) => _PyObject_CallNoArg(func)
* PyObject_CallFunctionObjArgs(func, arg, NULL) => _PyObject_CallArg1(func, arg)

PyObject_CallFunctionObjArgs() allocates 40 bytes on the C stack and requires
extra work to "parse" C arguments to build a C array of PyObject*.

_PyObject_CallNoArg() and _PyObject_CallArg1() are simpler and don't allocate
memory on the C stack.

This change is part of the fastcall project. The change on listsort() is
related to the issue #23507.
2016-12-01 14:43:22 +01:00
Serhiy Storchaka 85b0f5beb1 Added the const qualifier to char* variables that refer to readonly internal
UTF-8 represenatation of Unicode objects.
2016-11-20 10:16:47 +02:00
Serhiy Storchaka 3b73ea1278 Issue #28701: Replace PyUnicode_CompareWithASCIIString with _PyUnicode_EqualToASCIIString.
The latter function is more readable, faster and doesn't raise exceptions.
2016-11-16 10:19:20 +02:00
Serhiy Storchaka f4934ea77d Issue #28701: Replace PyUnicode_CompareWithASCIIString with _PyUnicode_EqualToASCIIString.
The latter function is more readable, faster and doesn't raise exceptions.
2016-11-16 10:17:58 +02:00
Victor Stinner 84d8baadbe Fix xml.etree.ElementTree.Element.getiterator()
Issue #28314: Fix function declaration (C flags) for the getiterator() method
of xml.etree.ElementTree.Element.
2016-09-29 22:12:35 +02:00
Benjamin Peterson 2f8bfef158 replace PY_SIZE_MAX with SIZE_MAX 2016-09-07 09:26:18 -07:00
Benjamin Peterson ca47063998 replace Py_(u)intptr_t with the c99 standard types 2016-09-06 13:47:26 -07:00
Victor Stinner 3466bde1cc Avoid calling functions with an empty string as format string
Directly pass NULL rather than an empty string.
2016-09-05 18:16:01 -07:00
Victor Stinner 559bb6a713 Rename _PyObject_FastCall() to _PyObject_FastCallDict()
Issue #27809:

* Rename _PyObject_FastCall() function to _PyObject_FastCallDict()
* Add _PyObject_FastCall(), _PyObject_CallNoArg() and _PyObject_CallArg1()
  macros calling _PyObject_FastCallDict()
2016-08-22 22:48:54 +02:00
Victor Stinner 7fbac45287 _elementtree: deepcopy() now uses fast call
Issue #27128.
2016-08-20 01:34:44 +02:00
Serhiy Storchaka f0ee5ccd19 Issue #25455: Fixed a crash in repr of ElementTree.Element with recursive tag. 2016-06-12 09:47:20 +03:00
Serhiy Storchaka 9062c261a4 Issue #25455: Fixed a crash in repr of ElementTree.Element with recursive tag. 2016-06-12 09:43:55 +03:00
Serhiy Storchaka f01e408c16 Issue #26200: Added Py_SETREF and replaced Py_XSETREF with Py_SETREF
in places where Py_DECREF was used.
2016-04-10 18:12:01 +03:00
Serhiy Storchaka 57a01d3a0e Issue #26200: Added Py_SETREF and replaced Py_XSETREF with Py_SETREF
in places where Py_DECREF was used.
2016-04-10 18:05:40 +03:00
Serhiy Storchaka ec39756960 Issue #22570: Renamed Py_SETREF to Py_XSETREF. 2016-04-06 09:50:03 +03:00
Serhiy Storchaka 48842714b9 Issue #22570: Renamed Py_SETREF to Py_XSETREF. 2016-04-06 09:45:48 +03:00
Serhiy Storchaka 576f132b98 Issue #20440: Cleaning up the code by using Py_SETREF. 2016-01-05 21:27:54 +02:00
Serhiy Storchaka 1ed017ae92 Issue #20440: Cleaning up the code by using Py_SETREF and Py_CLEAR.
Old code is correct, but with Py_SETREF and Py_CLEAR it can be cleaner.
This patch doesn't fix bugs and hence there is no need to backport it.
2015-12-27 15:51:32 +02:00
Serhiy Storchaka 726fc139a5 Issue #20440: More use of Py_SETREF.
This patch is manually crafted and contains changes that couldn't be handled
automatically.
2015-12-27 15:44:33 +02:00
Serhiy Storchaka 191321d11b Issue #20440: More use of Py_SETREF.
This patch is manually crafted and contains changes that couldn't be handled
automatically.
2015-12-27 15:41:34 +02:00
Serhiy Storchaka ea8c43152f Issue #24103: Fixed possible use after free in ElementTree.XMLPullParser. 2015-12-24 11:53:16 +02:00
Serhiy Storchaka bc4ded9537 Issue #24103: Fixed possible use after free in ElementTree.XMLPullParser. 2015-12-24 11:51:57 +02:00
Serhiy Storchaka 060ed718ce Issue #25869: Optimized deepcopying ElementTree; it is now 20 times faster. 2015-12-21 12:57:27 +02:00
Serhiy Storchaka 22adf2ac02 Issue #25873: Optimized iterating ElementTree.
Iterating elements Element.iter() is now 40% faster,
iterating text Element.itertext() is now up to 2.5 times faster.
2015-12-21 12:43:54 +02:00
Serhiy Storchaka 47a9d59d51 Issue #25902: Fixed various refcount issues in ElementTree iteration. 2015-12-21 11:11:12 +02:00
Serhiy Storchaka 66c08d90f6 Issue #25902: Fixed various refcount issues in ElementTree iteration. 2015-12-21 11:09:48 +02:00
Serhiy Storchaka a9406e77fa Issue #25421: __sizeof__ methods of builtin types now use dynamic basic size.
This allows sys.getsize() to work correctly with their subclasses with
__slots__ defined.
2015-12-19 20:07:11 +02:00
Serhiy Storchaka 5c4064e8bd Issue #25421: __sizeof__ methods of builtin types now use dynamic basic size.
This allows sys.getsize() to work correctly with their subclasses with
__slots__ defined.
2015-12-19 20:05:25 +02:00
Serhiy Storchaka 36ff997988 Issue #25638: Optimized ElementTree parsing; it is now 10% faster. 2015-12-10 09:51:53 +02:00
Serhiy Storchaka 956244bee1 Fixed possible leaks in ElementTree parser. 2015-12-09 19:45:07 +02:00
Serhiy Storchaka a29eb08fb9 Fixed possible leaks in ElementTree parser. 2015-12-09 19:44:30 +02:00
Serhiy Storchaka 9fcbdf480e Fixed possible leak in ElementTree.Element.iter(). 2015-12-09 11:27:34 +02:00
Serhiy Storchaka d6a69d8ccb Fixed possible leak in ElementTree.Element.iter(). 2015-12-09 11:27:07 +02:00
Serhiy Storchaka 9ec5e25f26 Issue #25638: Optimized ElementTree.iterparse(); it is now 2x faster.
ElementTree.XMLParser._setevents now accepts any objects with the append
method, not just a list.
2015-12-07 02:31:11 +02:00
Serhiy Storchaka f2fdfe1f88 Issue25814: Propagate all errors from custom XML parser handlers
in ElementTree.iterparse().
2015-12-06 23:55:05 +02:00
Serhiy Storchaka 7ff276fd2e Issue25814: Propagate all errors from custom XML parser handlers
in ElementTree.iterparse().
2015-12-06 23:54:28 +02:00
Serhiy Storchaka 7efaf95934 Issue25814: Propagate all errors from custom XML parser handlers
in ElementTree.iterparse().
2015-12-06 23:51:44 +02:00
Serhiy Storchaka 097a664f57 Issue #19687: Fixed possible integer overflows in ElementTree.
Based on patch by Christian Heimes.
2015-11-25 20:12:37 +02:00
Serhiy Storchaka dde0815c35 Issue #7990: dir() on ElementTree.Element now lists properties: "tag",
"text", "tail" and "attrib".  Original patch by Santoso Wijaya.
2015-11-25 15:28:13 +02:00
Serhiy Storchaka 3987fefd6f Issue #25691: Fixed crash on deleting ElementTree.Element attributes. 2015-11-23 08:47:26 +02:00
Serhiy Storchaka b6aa5375d5 Issue #25691: Fixed crash on deleting ElementTree.Element attributes. 2015-11-23 08:42:25 +02:00
Serhiy Storchaka 36e4f760f6 Issue #19687: Fixed memory leak on failed Element slice assignment.
Added new tests for Element slice assignments.
2015-11-22 12:30:28 +02:00
Serhiy Storchaka 04d759b1e4 Issue #19687: Fixed memory leak on failed Element slice assignment.
Added new tests for Element slice assignments.
2015-11-22 12:18:38 +02:00
Serhiy Storchaka 4a01cab898 Issue #19176: Fixed doctype() related bugs in C implementation of ElementTree.
A deprecation warning no longer issued by XMLParser subclass with default
doctype() method.  Direct call of doctype() now issues a warning.  Parser's
doctype() now is not called if target's doctype() is called.  Based on patch
by Martin Panter.
2015-06-29 23:08:52 +03:00
Serhiy Storchaka 05744ac6e0 Issue #19176: Fixed doctype() related bugs in C implementation of ElementTree.
A deprecation warning no longer issued by XMLParser subclass with default
doctype() method.  Direct call of doctype() now issues a warning.  Parser's
doctype() now is not called if target's doctype() is called.  Based on patch
by Martin Panter.
2015-06-29 22:35:58 +03:00
Serhiy Storchaka a2c145c2f3 Issue #24091: Fixed various crashes in corner cases in C implementation of
ElementTree.
2015-05-18 18:33:31 +03:00
Serhiy Storchaka 5bf3120e24 Issue #24091: Fixed various crashes in corner cases in C implementation of
ElementTree.
2015-05-18 18:29:33 +03:00
Larry Hastings dbfdc380df Issue #24001: Argument Clinic converters now use accept={type}
instead of types={'type'} to specify the types the converter accepts.
2015-05-04 06:59:46 -07:00
Serhiy Storchaka cb98556373 Issue #20159. Converted the _elementtree module to Argument Clinic. 2015-05-04 15:32:48 +03:00
Serhiy Storchaka 26861b0b29 Issue #23450: Fixed possible integer overflows. 2015-02-16 20:52:17 +02:00
Victor Stinner 706768c687 Issue #22156: Fix some "comparison between signed and unsigned integers"
compiler warnings in the Modules/ subdirectory.
2014-08-16 01:03:39 +02:00
Eli Bendersky 8148164353 Issue #19815: Fix segfault when parsing empty namespace declaration.
Based on patches by Christian Heimes and Vajrasky Kok
2013-11-28 06:35:40 -08:00
Eli Bendersky 4b79518f83 Fix indentation from previous commit 2013-11-28 06:33:21 -08:00
Eli Bendersky 5dd40e555b Issue #19815: Fix segfault when parsing empty namespace declaration.
Based on patches by Christian Heimes and Vajrasky Kok
2013-11-28 06:31:58 -08:00
Eli Bendersky 163d7f02a1 Cosmetic fixes 2013-11-24 06:55:04 -08:00
Victor Stinner 59799a8399 Don't use deprecated function PyUnicode_GET_SIZE()
Replace it with PyUnicode_GET_LENGTH() or PyUnicode_AsUnicodeAndSize()
2013-11-13 14:17:30 +01:00
Antoine Pitrou 4d397008cd Issue #19356: Avoid using a C variabled named "_self", it's a reserved word in some C compilers. 2013-10-23 19:21:55 +02:00
Antoine Pitrou 09fcb72048 Issue #19356: Avoid using a C variabled named "_self", it's a reserved word in some C compilers. 2013-10-23 19:20:21 +02:00
doko@ubuntu.com 9937155a1c - followup for issue #18997, make _clear_joined_ptr static. 2013-09-18 12:13:18 +02:00
doko@ubuntu.com 0648bf795c - followup for issue #18997, make _clear_joined_ptr static. 2013-09-18 12:12:28 +02:00
Eli Bendersky 12f18289c0 Merge for Issue #18997: Issue #18997: fix ElementTree crash with using pickle and __getstate__. 2013-09-13 06:27:52 -07:00
Eli Bendersky dd3661e782 Issue #18997: fix ElementTree crash with using pickle and __getstate__.
Based on report and initial patch from Germán M. Bravo
2013-09-13 06:24:25 -07:00
Eli Bendersky 6eb50b1f5b Use consistent style for else if / else 2013-08-24 15:17:08 -07:00
Eli Bendersky 532d03e547 Issue #15651: PEP 3121 refactoring for _elementtree
Patch by Antoine Pitrou (based on Robin Schreiber's original patch)
2013-08-10 08:00:39 -07:00
Christian Heimes 2ef710e40f Add missing check of PyDict_Update()'s return value in _elementtree.c
CID 719637
2013-07-20 15:12:19 +02:00
Christian Heimes 7ed4294d7f Add missing check of PyDict_Update()'s return value in _elementtree.c
CID 719637
2013-07-20 15:12:09 +02:00
Ronald Oussoren ced1226cce (3.3->default): #18480: Add missing PyType_Ready call to _elementtree extension 2013-07-19 11:14:05 +02:00
Ronald Oussoren 138d080a28 #18480: Add missing PyType_Ready call to _elementtree extension 2013-07-19 11:11:25 +02:00
Victor Stinner 3fd8cbd5e4 Issue #18408: Fix _elementtree.c, don't call Python function from an expat
handler if a Python exception is set
2013-07-18 22:46:14 +02:00
Victor Stinner d917dcbe5e Issue #18408: Fix constructors of _elementtree.c
* Use Py_DECREF() instead of PyObject_GC_Del() to release correctly all
  resources
* Raise MemoryError on memory allocation failure
2013-07-12 02:05:17 +02:00
Victor Stinner 81aac734e1 Issue #18408: Fix create_extra() of _elementtree.c, raise MemoryError on memory
allocation failure
2013-07-12 02:03:34 +02:00
Victor Stinner 71c8b7ec04 Issue #18408: Different fixes in _elementtree.c to handle correctly MemoryError
* create_new_element() initializes all attributes before handling errors,
   to fix a crash in the destructor
* create_new_element() calls PyObject_GC_Del() on error, instead of
  PyObject_Del(), because the object was created by PyObject_GC_New()
* subelement() now handles create_new_element() failure
* element_getattro() now handles element_get_text() failure
* makeuniversal() now handles PyBytes_FromStringAndSize() failure
2013-07-11 23:08:39 +02:00
Victor Stinner 4d46343340 Cleanup _elementtree.c 2013-07-11 23:05:03 +02:00
Victor Stinner 5f0af23f5e Issue #18408: _elementtree.c now handles create_extra() failure 2013-07-11 23:01:36 +02:00
Eli Bendersky 6dc32b34dd Issue #13612: handle unknown encodings without a buffer overflow.
This affects pyexpat and _elementtree. PyExpat_CAPI now exposes a new
function - DefaultUnknownEncodingHandler.

Based on a patch by Serhiy Storchaka.
2013-05-25 05:25:48 -07:00
Serhiy Storchaka 66d53fa9ad Issue #16986: ElementTree now correctly parses a string input not only when
an internal XML encoding is UTF-8 or US-ASCII.
2013-05-22 17:07:51 +03:00
Eli Bendersky 6a55dc3b4a Issue #17989: fix typo in error message 2013-05-19 16:59:59 -07:00
Eli Bendersky 08231a9c6a Issue #17901: fix TreeBuilder construction for an explicit element_factory=None
Based on report and patch by Aaron Oakley.
2013-05-18 15:47:16 -07:00
Eli Bendersky ef9683b73f Issue #17989: element_setattro returned incorrect error value.
This caused an exception to be raised later than expected.
2013-05-18 07:52:34 -07:00
Eli Bendersky 7b3022f24f Issue #13612: handle unknown encodings without a buffer overflow.
This affects pyexpat and _elementtree. PyExpat_CAPI now exposes a new
function - DefaultUnknownEncodingHandler.

Based on a patch by Serhiy Storchaka.
2013-05-25 05:27:10 -07:00
Serhiy Storchaka 447b6e3c6e Issue #16986: ElementTree now correctly parses a string input not only when
an internal XML encoding is UTF-8 or US-ASCII.
2013-05-22 17:21:06 +03:00
Eli Bendersky a369923cab Get rid of ugly code duplication for ElementTree.parse when the accelerator
is imported. Instead, ElementTree.parse can look for a special internal method
defined by the accelerator.
2013-05-19 18:47:23 -07:00
Eli Bendersky 3a36756ba1 Issue #17989: fix typo in error message 2013-05-19 17:00:28 -07:00
Eli Bendersky 3a4fbd8241 _elementtree.XMLParser._setevents should support any sequence, not just tuples
Also clean up some code around this
2013-05-19 09:01:49 -07:00
Eli Bendersky 20c1cdd64a Issue #17901: fix TreeBuilder construction for an explicit element_factory=None
Based on report and patch by Aaron Oakley.
2013-05-18 15:47:58 -07:00
Eli Bendersky 1a8c3e247a Issue #17989: element_setattro returned incorrect error value.
This caused an exception to be raised later than expected.
2013-05-18 07:53:47 -07:00
Eli Bendersky 45f3d2fff0 Revert c9674421d78e, leaving an additional comment 2013-04-24 05:34:07 -07:00
Eli Bendersky 1859fe80c4 Simplify the code of get_attrib_from_keywords somewhat. 2013-04-22 05:52:16 -07:00
Eli Bendersky ed8b86d323 Issue #17736: fix misleading comment in _elementtree.c
Patch by Jonas Wagner
2013-04-22 05:29:09 -07:00
Eli Bendersky d4cb4b7451 Issue #17736: fix misleading comment in _elementtree.c
Patch by Jonas Wagner
2013-04-22 05:25:25 -07:00