Commit Graph

161 Commits

Author SHA1 Message Date
Serhiy Storchaka 762bf40438 bpo-29852: Argument Clinic Py_ssize_t converter now supports None (#716)
if pass `accept={int, NoneType}`.
2017-03-30 09:15:31 +03:00
Victor Stinner 0f7b0b397e bpo-29735: Optimize partial_call(): avoid tuple (#516)
* Add _PyObject_HasFastCall()
* partial_call() now avoids temporary tuple to pass positional
  arguments if the callable supports the FASTCALL calling convention
  for positional arguments.
* Fix also a performance regression in partial_call() if the callable
  doesn't support FASTCALL.
2017-03-14 21:37:20 +01:00
Victor Stinner 516b98161a Optimize slots: avoid temporary PyMethodObject
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>
2017-02-09 22:53:47 +01:00
Victor Stinner c3858bd7c6 Issue #29360: _PyStack_AsDict() doesn't check kwnames
Remove two assertions which can fail on legit code. Keyword arguments are
checked later with better tests and raise a regular (TypeError) exception.
2017-01-24 15:05:30 +01:00
Victor Stinner 35ecebe165 Remove unused func parameter of _PyStack_UnpackDict()
Issue #29259.
2017-01-18 10:31:46 +01:00
Victor Stinner 998c20962c _PyStack_UnpackDict() now returns -1 on error
Issue #29286. Change _PyStack_UnpackDict() prototype to be able to notify of
failure when args is NULL.
2017-01-17 01:57:29 +01:00
Victor Stinner 3e1fad6913 Rename _PyArg_ParseStack to _PyArg_ParseStackAndKeywords
Issue #29286.
2017-01-17 01:29:01 +01:00
Victor Stinner 69de71b255 Add _PyStack_AsTupleSlice() helper 2017-01-16 23:50:53 +01:00
Victor Stinner 434723f94c call_method() now uses _PyObject_FastCall()
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.
2017-01-11 00:07:40 +01:00
Serhiy Storchaka a171a03bd2 Issue #29058: All stable API extensions added after Python 3.2 are now
available only when Py_LIMITED_API is set to the PY_VERSION_HEX value of
the minimum Python version supporting this API.
2016-12-27 15:04:59 +02:00
Serhiy Storchaka 34d0ac8027 Issue #29058: All stable API extensions added after Python 3.2 are now
available only when Py_LIMITED_API is set to the PY_VERSION_HEX value of
the minimum Python version supporting this API.
2016-12-27 14:57:39 +02:00
Victor Stinner b6522d0f77 abstract.h: remove long outdated comment
Issue #28838: The documentation is of the Python C API is more complete and
more up to date than this old comment.

Removal suggested by Antoine Pitrou.
2016-12-19 13:12:08 +01:00
Victor Stinner bc08ab4598 Add _PY_FASTCALL_SMALL_STACK constant
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.
2016-12-15 12:40:53 +01:00
Victor Stinner 5bef7cd7f4 Issue #28838: Cleanup abstract.h
Rewrite all comments to use the same style than other Python header files:
comment functions *before* their declaration, no newline between the comment
and the declaration.

Reformat some comments, add newlines, to make them easier to read.

Quote argument like 'arg' to mention an argument in a comment.
2016-12-15 09:14:25 +01:00
Victor Stinner 7f39c0ccfc Add _PyObject_VaCallFunctionObjArgs() private function
Issue #28915: Similar to _PyObject_CallFunctionObjArgs() but use va_list to
pass arguments.
2016-12-09 00:40:33 +01:00
Victor Stinner 2a358f862b Issue #28838: Fix weird indentation of abstract.h
Remove most indentation to move code at the left.
2016-12-06 16:55:39 +01:00
Victor Stinner 2d0eb65f45 Uniformize argument names of "call" functions
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)
2016-12-06 16:27:24 +01:00
Serhiy Storchaka 89072047b8 Fixed misplaced comment. 2016-12-06 13:46:17 +02:00
Serhiy Storchaka b0f75c520e Fixed misplaced comment. 2016-12-06 13:45:44 +02:00
Serhiy Storchaka e503126074 Fixed misplaced comment. 2016-12-06 13:43:46 +02: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
Benjamin Peterson 7cf9e13f25 fix _PyObject_CallArg1 compiler warnings (closes #28855) 2016-12-01 22:01:32 -08:00
Victor Stinner 8be1c39eb3 Backed out changeset 7efddbf1aa70 2016-11-30 12:10:54 +01:00
Victor Stinner ebea9988e0 Uniformize argument names of "call" functions
* Callable object: callable, o, callable_object => func
* Object for method calls: o => obj
* Method name: name or nameid => method

Cleanup also the C code:

* Don't initialize variables to NULL if they are not used before their first
  assignement
* Add braces for readability
2016-11-29 18:47:56 +01:00
Serhiy Storchaka 460bd0d284 Issue #19569: Compiler warnings are now emitted if use most of deprecated
functions.
2016-11-20 12:16:46 +02:00
Serhiy Storchaka 4781b59185 Issues #25909, #28211: Restored correct documentation of PyMapping_Items,
PyMapping_Keys and PyMapping_Values.  Based on patch by Xiang Zhang.
2016-09-26 20:53:27 +03:00
Serhiy Storchaka 1d480bea9c Issues #25909, #28211: Restored correct documentation of PyMapping_Items,
PyMapping_Keys and PyMapping_Values.  Based on patch by Xiang Zhang.
2016-09-26 20:52:41 +03:00
Victor Stinner 57f91ac95a Document kwnames in _PyObject_FastCallKeywords() and _PyStack_AsDict()
Issue #27213.
2016-09-12 13:37:07 +02:00
Victor Stinner b8d768b019 Revert change f860b7a775c5
Revert change "Issue #27213: Reintroduce checks in _PyStack_AsDict()", pushed
by mistake.
2016-09-12 13:30:02 +02:00
Victor Stinner b1e169bf4b ssue #27213: Reintroduce checks in _PyStack_AsDict() 2016-09-12 12:55:28 +02:00
Serhiy Storchaka b72810583e Issue #27213: Fixed different issues with reworked CALL_FUNCTION* opcodes.
* BUILD_TUPLE_UNPACK and BUILD_MAP_UNPACK_WITH_CALL no longer generated with
  single tuple or dict.
* Restored more informative error messages for incorrect var-positional and
  var-keyword arguments.
* Removed code duplications in _PyEval_EvalCodeWithName().
* Removed redundant runtime checks and parameters in _PyStack_AsDict().
* Added a workaround and enabled previously disabled test in test_traceback.
* Removed dead code from the dis module.
2016-09-12 00:52:40 +03:00
Serhiy Storchaka 9fab79bcb5 Issue #26900: Excluded underscored names and other private API from limited API. 2016-09-11 11:03:14 +03:00
Victor Stinner a9efb2f56e Add METH_FASTCALL calling convention
Issue #27810: Add a new calling convention for C functions:

    PyObject* func(PyObject *self, PyObject **args,
                   Py_ssize_t nargs, PyObject *kwnames);

Where args is a C array of positional arguments followed by values of keyword
arguments. nargs is the number of positional arguments, kwnames are keys of
keyword arguments. kwnames can be NULL.
2016-09-09 17:40:22 -07:00
Victor Stinner ae8b69c410 Issue #27810: Add _PyCFunction_FastCallKeywords()
Use _PyCFunction_FastCallKeywords() in ceval.c: it allows to remove a lot of
code from ceval.c which was only used to call C functions.
2016-09-09 14:07:44 -07:00
Victor Stinner d873572095 Add _PyObject_FastCallKeywords()
Issue #27830: Add _PyObject_FastCallKeywords(): avoid the creation of a
temporary dictionary for keyword arguments.

Other changes:

* Cleanup call_function() and fast_function() (ex: rename nk to nkwargs)
* Remove now useless do_call(), replaced with _PyObject_FastCallKeywords()
2016-09-09 12:36:44 -07:00
Martin Panter 0be894b2f6 Issue #27895: Spelling fixes (Contributed by Ville Skyttä). 2016-09-07 12:03:06 +00:00
Raymond Hettinger 15f44ab043 Issue #27895: Spelling fixes (Contributed by Ville Skyttä). 2016-08-30 10:47:49 -07:00
Victor Stinner e90bdb19f2 Issue #27830: Revert, remove _PyFunction_FastCallKeywords() 2016-08-25 23:26:50 +02:00
Victor Stinner 3f1057a4b6 method_call() and slot_tp_new() now uses fast call
Issue #27841: Add _PyObject_Call_Prepend() helper function to prepend an
argument to existing arguments to call a function. This helper uses fast calls.

Modify method_call() and slot_tp_new() to use _PyObject_Call_Prepend().
2016-08-25 01:04:14 +02:00
Victor Stinner 577e1f8cb4 Add _PyObject_FastCallKeywords()
Issue #27830: Similar to _PyObject_FastCallDict(), but keyword arguments are
also passed in the same C array than positional arguments, rather than being
passed as a Python dict.
2016-08-25 00:29:32 +02:00
Victor Stinner 74319ae219 Use Py_ssize_t type for number of arguments
Issue #27848: use Py_ssize_t rather than C int for the number of function
positional and keyword arguments.
2016-08-25 00:04:09 +02: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 8a31c82093 Fix PyObject_Call() parameter names
Issue #27128: arg=>args, kw=>kwargs.

Same change for PyEval_CallObjectWithKeywords().
2016-08-19 17:12:23 +02:00
Victor Stinner 9be7e7b52f Add _PyObject_FastCall()
Issue #27128: Add _PyObject_FastCall(), a new calling convention avoiding a
temporary tuple to pass positional parameters in most cases, but create a
temporary tuple if needed (ex: for the tp_call slot).

The API is prepared to support keyword parameters, but the full implementation
will come later (_PyFunction_FastCall() doesn't support keyword parameters
yet).

Add also:

* _PyStack_AsTuple() helper function: convert a "stack" of parameters to
  a tuple.
* _PyCFunction_FastCall(): fast call implementation for C functions
* _PyFunction_FastCall(): fast call implementation for Python functions
2016-08-19 16:11:43 +02:00
Senthil Kumaran 1538b3d3df issue25909 - Correct the documentation of PyMapping_Items, PyMapping_Keys and
PyMapping_Values in Include/abstract.h and Doc/c-api/mapping.rst.

Patch contributed by Sonali Gupta.
2016-01-21 09:37:28 -08:00
Martin Panter 45be8d67be Issue #25701: Document C API functions that both set and delete objects
Also document that the separate functions that delete objects are preferred;
using PyObject_SetAttr(), _SetAttrString(), and PySequence_SetItem() to
delete is deprecated.
2015-12-08 00:03:20 +00:00
Martin Panter 2eb819f7a8 Issue #25523: Merge "a" to "an" fixes from 3.4 into 3.5 2015-11-02 04:04:57 +00:00
Martin Panter 7462b64911 Issue #25523: Correct "a" article to "an" article
This changes the main documentation, doc strings, source code comments, and a
couple error messages in the test suite. In some cases the word was removed
or edited some other way to fix the grammar.
2015-11-02 03:37:02 +00:00
Victor Stinner efde146b0c Issue #23571: _Py_CheckFunctionResult() now gives the name of the function
which returned an invalid result (result+error or no result without error) in
the exception message.

Add also unit test to check that the exception contains the name of the
function.

Special case: the final _PyEval_EvalFrameEx() check doesn't mention the
function since it didn't execute a single function but a whole frame.
2015-03-21 15:04:43 +01:00
Victor Stinner 4a7cc88472 Issue #23571: PyObject_Call(), PyCFunction_Call() and call_function() now
raise a SystemError if a function returns a result and raises an exception.
The SystemError is chained to the previous exception.

Refactor also PyObject_Call() and PyCFunction_Call() to make them more readable.

Remove some checks which became useless (duplicate checks).

Change reviewed by Serhiy Storchaka.
2015-03-06 23:35:27 +01:00