summaryrefslogtreecommitdiffstats
path: root/Objects/abstract.c
Commit message (Collapse)AuthorAgeFilesLines
* closes bpo-34504: Remove the useless NULL check in PySequence_Check(). (GH-8935)Alexey Izbyshev2018-08-251-1/+1
| | | Reported by Svace static analyzer.
* bpo-32500: Fix error messages for sequence and mapping C API. (GH-7846)Serhiy Storchaka2018-07-231-0/+20
| | | | | Fix error messages for PySequence_Size(), PySequence_GetItem(), PySequence_SetItem() and PySequence_DelItem() called with a mapping and PyMapping_Size() called with a sequence.
* bpo-33738: Address review comments in GH #7477 (GH-7585)Christian Tismer2018-06-101-0/+2
|
* bpo-33738: Fix macros which contradict PEP 384 (GH-7477)Christian Tismer2018-06-091-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | During development of the limited API support for PySide, we saw an error in a macro that accessed a type field. This patch fixes the 7 errors in the Python headers. Macros which were not written as capitals were implemented as function. To do the necessary analysis again, a script was included that parses all headers and looks for "->tp_" in serctions which can be reached with active limited API. It is easily possible to call this script as a test. Error listing: ../../Include/objimpl.h:243 #define PyObject_IS_GC(o) (PyType_IS_GC(Py_TYPE(o)) && \ (Py_TYPE(o)->tp_is_gc == NULL || Py_TYPE(o)->tp_is_gc(o))) Action: commented only ../../Include/objimpl.h:362 #define PyType_SUPPORTS_WEAKREFS(t) ((t)->tp_weaklistoffset > 0) Action: commented only ../../Include/objimpl.h:364 #define PyObject_GET_WEAKREFS_LISTPTR(o) \ ((PyObject **) (((char *) (o)) + Py_TYPE(o)->tp_weaklistoffset)) Action: commented only ../../Include/pyerrors.h:143 #define PyExceptionClass_Name(x) \ ((char *)(((PyTypeObject*)(x))->tp_name)) Action: implemented function ../../Include/abstract.h:593 #define PyIter_Check(obj) \ ((obj)->ob_type->tp_iternext != NULL && \ (obj)->ob_type->tp_iternext != &_PyObject_NextNotImplemented) Action: implemented function ../../Include/abstract.h:713 #define PyIndex_Check(obj) \ ((obj)->ob_type->tp_as_number != NULL && \ (obj)->ob_type->tp_as_number->nb_index != NULL) Action: implemented function ../../Include/abstract.h:924 #define PySequence_ITEM(o, i)\ ( Py_TYPE(o)->tp_as_sequence->sq_item(o, i) ) Action: commented only
* bpo-32571: Avoid raising unneeded AttributeError and silencing it in C code ↵Serhiy Storchaka2018-01-251-33/+17
| | | | | (GH-5222) Add two new private APIs: _PyObject_LookupAttr() and _PyObject_LookupAttrId()
* bpo-32226: Make __class_getitem__ an automatic class method. (#5098)Serhiy Storchaka2018-01-041-2/+2
|
* bpo-32226: Implementation of PEP 560 (core components) (#4732)Ivan Levkivskyi2017-12-141-0/+15
| | | | | This part of the PEP implementation adds support for __mro_entries__ and __class_getitem__ by updating __build_class__ and PyObject_GetItem.
* bpo-28280: Make PyMapping_Keys(), PyMapping_Values() and PyMapping_Items() ↵Oren Milman2017-10-081-27/+49
| | | | always return a list (#3840)
* bpo-31338 (#3374)Barry Warsaw2017-09-151-1/+1
| | | | | | | * Add Py_UNREACHABLE() as an alias to abort(). * Use Py_UNREACHABLE() instead of assert(0) * Convert more unreachable code to use Py_UNREACHABLE() * Document Py_UNREACHABLE() and a few other macros.
* bpo-30860: Consolidate stateful runtime globals. (#3397)Eric Snow2017-09-081-0/+1
| | | | | | | * group the (stateful) runtime globals into various topical structs * consolidate the topical structs under a single top-level _PyRuntimeState struct * add a check-c-globals.py script that helps identify runtime globals Other globals are excluded (see globals.txt and check-c-globals.py).
* bpo-30721: Add missing '?' to new error message (GH-3131)Sanyam Khurana2017-08-181-1/+1
|
* bpo-30721: Show correct syntax hint in Py3 when using Py2 redirection syntax ↵Sanyam Khurana2017-08-181-0/+15
| | | | (#2345)
* bpo-30730: Prevent environment variables injection in subprocess on Windows. ↵Serhiy Storchaka2017-06-231-2/+2
| | | | | | (#2325) Prevent passing other invalid environment variables and command arguments.
* bpo-29838: Add asserts for checking results of sq_length and mq_length ↵Serhiy Storchaka2017-04-161-9/+23
| | | | | | slots. (#700) Negative result should be returned only when an error is set.
* bpo-29548: Fix some inefficient call API usage (GH-97)INADA Naoki2017-02-161-1/+1
|
* bpo-29524: Add Objects/call.c file (#12)Victor Stinner2017-02-121-725/+0
| | | | | | | | | * Move all functions to call objects in a new Objects/call.c file. * Rename fast_function() to _PyFunction_FastCallKeywords(). * Copy null_error() from Objects/abstract.c * Inline type_error() in call.c to not have to copy it, it was only called once. * Export _PyEval_EvalCodeWithName() since it is now called from call.c.
* Backed out changeset f23fa1f7b68fVictor Stinner2017-02-101-0/+725
| | | | | Sorry, I didn't want to push this change before the review :-( I was pushing a change into the 2.7 branch.
* Issue #29465: Add Objects/call.c fileVictor Stinner2017-02-101-725/+0
| | | | | | | | | | * Move all functions to call objects in a new Objects/call.c file. * Rename fast_function() to _PyFunction_FastCallKeywords(). * Copy null_error() from Objects/abstract.c * Inline type_error() in call.c to not have to copy it, it was only called once. * Export _PyEval_EvalCodeWithName() since it is now called from call.c.
* Issue #29507: Fix _PyObject_CallFunctionVa()Victor Stinner2017-02-091-2/+4
| | | | is_size_t test was reversed. Bug spotted by INADA Naoki.
* Optimize slots: avoid temporary PyMethodObjectVictor Stinner2017-02-091-0/+35
| | | | | | | | | | | | | | | | | | Issue #29507: Optimize slots calling Python methods. For Python methods, get the unbound Python function and prepend arguments with self, rather than calling the descriptor which creates a temporary PyMethodObject. Add a new _PyObject_FastCall_Prepend() function used to call the unbound Python method with self. It avoids the creation of a temporary tuple to pass positional arguments. Avoiding temporary PyMethodObject and avoiding temporary tuple makes Python slots up to 1.46x faster. Microbenchmark on a __getitem__() method implemented in Python: Median +- std dev: 121 ns +- 5 ns -> 82.8 ns +- 1.0 ns: 1.46x faster (-31%) Co-Authored-by: INADA Naoki <songofacandy@gmail.com>
* Fix refleaks if Py_EnterRecursiveCall() failsVictor Stinner2017-02-081-1/+4
| | | | Issue #29306: Destroy argstuple and kwdict if Py_EnterRecursiveCall() fails.
* Issue #29306: Fix usage of Py_EnterRecursiveCall()Victor Stinner2017-02-081-48/+54
| | | | | | | * *PyCFunction_*Call*() functions now call Py_EnterRecursiveCall(). * PyObject_Call() now calls directly _PyFunction_FastCallDict() and PyCFunction_Call() to avoid calling Py_EnterRecursiveCall() twice per function call
* Issue #29360: _PyStack_AsDict() doesn't check kwnamesVictor Stinner2017-01-241-2/+1
| | | | | Remove two assertions which can fail on legit code. Keyword arguments are checked later with better tests and raise a regular (TypeError) exception.
* _PyStack_AsDict() now checks kwnames != NULLVictor Stinner2017-01-181-1/+3
| | | | Issue #29259.
* Rephrase !PyErr_Occurred() comment: may=>canVictor Stinner2017-01-181-2/+2
| | | | Issue #29259.
* _PyObject_FastCallKeywords() now checks !PyErr_Occurred()Victor Stinner2017-01-181-0/+5
| | | | | Issue #29259. All other functions calling functions start with the similar assertion.
* _PyObject_FastCallKeywords() now checks the resultVictor Stinner2017-01-181-0/+2
| | | | Issue ##27830, Issue #29259.
* Remove unused func parameter of _PyStack_UnpackDict()Victor Stinner2017-01-181-1/+1
| | | | Issue #29259.
* _PyStack_UnpackDict() now returns -1 on errorVictor Stinner2017-01-171-7/+9
| | | | | Issue #29286. Change _PyStack_UnpackDict() prototype to be able to notify of failure when args is NULL.
* Rename _PyArg_ParseStack to _PyArg_ParseStackAndKeywordsVictor Stinner2017-01-171-1/+1
| | | | Issue #29286.
* Add _PyStack_AsTupleSlice() helperVictor Stinner2017-01-161-0/+23
|
* Disable _PyStack_AsTuple() inliningVictor Stinner2017-01-111-1/+3
| | | | | | | | | | | | | | | Issue #29234: Inlining _PyStack_AsTuple() into callers increases their stack consumption, Disable inlining to optimize the stack consumption. Add _Py_NO_INLINE: use __attribute__((noinline)) of GCC and Clang. It reduces the stack consumption, bytes per call, before => after: test_python_call: 1040 => 976 (-64 B) test_python_getitem: 976 => 912 (-64 B) test_python_iterator: 1120 => 1056 (-64 B) => total: 3136 => 2944 (- 192 B)
* call_method() now uses _PyObject_FastCall()Victor Stinner2017-01-101-5/+5
| | | | | | | | | | | | | | | | | | | Issue #29233: Replace the inefficient _PyObject_VaCallFunctionObjArgs() with _PyObject_FastCall() in call_method() and call_maybe(). Only a few functions call call_method() and call it with a fixed number of arguments. Avoid the complex and expensive _PyObject_VaCallFunctionObjArgs() function, replace it with an array allocated on the stack with the exact number of argumlents. It reduces the stack consumption, bytes per call, before => after: test_python_call: 1168 => 1152 (-16 B) test_python_getitem: 1344 => 1008 (-336 B) test_python_iterator: 1568 => 1232 (-336 B) Remove the _PyObject_VaCallFunctionObjArgs() function which became useless. Rename it to object_vacall() and make it private.
* Issue #28959: Added private macro PyDict_GET_SIZE for retrieving the size of ↵Serhiy Storchaka2016-12-161-2/+1
| | | | dict.
* Use _PyDict_NewPresized() in _PyStack_AsDict()Victor Stinner2016-12-151-1/+1
| | | | Issue #27810.
* Add _PY_FASTCALL_SMALL_STACK constantVictor Stinner2016-12-151-3/+3
| | | | | | | | | Issue #28870: Add a new _PY_FASTCALL_SMALL_STACK constant, size of "small stacks" allocated on the C stack to pass positional arguments to _PyObject_FastCall(). _PyObject_Call_Prepend() now uses a small stack of 5 arguments (40 bytes) instead of 8 (64 bytes), since it is modified to use _PY_FASTCALL_SMALL_STACK.
* Fix _PyObject_CallFunctionVa(), use the small stackVictor Stinner2016-12-151-2/+1
| | | | | Issue #28915. Oops, I disabled the small stack to test both code paths. It's now fixed.
* Issue #28820: Merge typo fixes from 3.6Martin Panter2016-12-101-1/+1
|\
| * Fix typos in comment and documentationMartin Panter2016-12-101-1/+1
| |
* | Remove useless variable initializationVictor Stinner2016-12-091-9/+6
| | | | | | | | Don't initialize variables which are not used before they are assigned.
* | Use PyObject_CallFunctionObjArgs()Victor Stinner2016-12-091-1/+1
| | | | | | | | | | | | | | | | | | 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.
* | Add _PyObject_VaCallFunctionObjArgs() private functionVictor Stinner2016-12-081-5/+5
| | | | | | | | | | Issue #28915: Similar to _PyObject_CallFunctionObjArgs() but use va_list to pass arguments.
* | _PyObject_CallFunctionVa() uses fast callVictor Stinner2016-12-081-9/+25
| | | | | | | | | | | | | | | | Issue #28915: Use _Py_VaBuildStack() to build a C array of PyObject* and then use _PyObject_FastCall(). The function has a special case if the stack only contains one parameter and the parameter is a tuple: "unpack" the tuple of arguments in this case.
* | Add _PyObject_CallFunctionVa() helperVictor Stinner2016-12-081-54/+29
| | | | | | | | | | | | | | | | | | Issue #28915: Add _PyObject_CallFunctionVa() helper to factorize code of functions: * PyObject_CallFunction() * _PyObject_CallFunction_SizeT() * callmethod()
* | Add _PyObject_FastCallVa() helperVictor Stinner2016-12-081-71/+37
| | | | | | | | | | | | | | | | | | | | | | Issue #28915: Add _PyObject_FastCallVa() helper to factorize code of functions: * PyObject_CallFunctionObjArgs() * PyObject_CallMethodObjArgs() * _PyObject_CallMethodIdObjArgs() Inline objargs_mkstack() into _PyObject_FastCallVa(), remove objargs_mkstack().
* | _PyObject_FastCallKeywords() now calls directly tp_callVictor Stinner2016-12-061-15/+45
| | | | | | | | | | _PyObject_FastCallKeywords() doesn't call _PyObject_FastCallDict() anymore: call directly tp_call.
* | Fix typo in a comment of abstract.cVictor Stinner2016-12-061-1/+1
| |
* | Use _PyObject_CallNoArg()Victor Stinner2016-12-061-1/+1
| | | | | | | | | | | | | | Replace: PyObject_CallFunctionObjArgs(callable, NULL) with: _PyObject_CallNoArg(callable)
* | Uniformize argument names of "call" functionsVictor Stinner2016-12-061-70/+78
| | | | | | | | | | | | | | | | | | | | | | | | Issue #28838: Rename parameters of the "calls" functions of the Python C API. * Rename 'callable_object' and 'func' to 'callable': any Python callable object is accepted, not only Python functions * Rename 'method' and 'nameid' to 'name' (method name) * Rename 'o' to 'obj' * Move, fix and update documentation of PyObject_CallXXX() functions in abstract.h * Update also the documentaton of the C API (update parameter names)
* | Issue #28858: Remove _PyObject_CallArg1() macroVictor Stinner2016-12-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | 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.