Commit Graph

121 Commits

Author SHA1 Message Date
Eric Snow 2ebc5ce42a bpo-30860: Consolidate stateful runtime globals. (#3397)
* 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).
2017-09-07 23:51:28 -06:00
Victor Stinner c22bfaae83 bpo-29524: Add Objects/call.c file (#12)
* 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.
2017-02-12 19:27:05 +01:00
Victor Stinner d2306cec4d Backed out changeset f23fa1f7b68f
Sorry, I didn't want to push this change before the review :-( I was pushing a
change into the 2.7 branch.
2017-02-10 14:19:36 +01:00
Victor Stinner 766af559ad Issue #29465: Add Objects/call.c file
* 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.
2017-02-10 13:32:29 +01:00
Victor Stinner 12c5838dae Fix PyCFunction_Call() performance issue
Issue #29259, #29465: PyCFunction_Call() doesn't create anymore a redundant
tuple to pass positional arguments for METH_VARARGS.

Add a new cfunction_call() subfunction.
2017-02-09 02:01:37 +01:00
Victor Stinner 7399a05965 Issue #29306: Fix usage of Py_EnterRecursiveCall()
* *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
2017-02-08 12:06:00 +01:00
INADA Naoki 5566bbb8d5 Issue #29263: LOAD_METHOD support for C methods
Calling builtin method is at most 10% faster.
2017-02-03 07:43:03 +09:00
Victor Stinner 0a2e46835d Cleanup _PyMethodDef_RawFastCallDict()
Issue #29259: use a different case for METH_VARARGS and
METH_VARARGS|METH_KEYWORDS to avoid testing again flags to decide if keywords
should be checked or not.
2017-01-18 14:16:57 +01:00
Victor Stinner a8cb515a29 Rephrase !PyErr_Occurred() comment: may=>can
Issue #29259.
2017-01-18 14:12:51 +01:00
Victor Stinner c89ef828cf PyCFunction_Call() now calls _PyCFunction_FastCallDict()
Issue #29259. We had 3 versions of similar code:

* PyCFunction_Call()
* _PyCFunction_FastCallDict()
* _PyCFunction_FastCallKeywords()

PyCFunction_Call() now calls _PyCFunction_FastCallDict() to factorize the code.
2017-01-18 14:04:37 +01:00
Victor Stinner 250e4b0063 Fix _PyMethodDef_RawFastCallDict() argument parsing
Issue #29259:

* Move also the !PyErr_Occurred() assertion to the top, similar to
  other functions.
* Fix also comment/error messages: the function was renamed to
  _PyMethodDef_RawFastCallDict()
2017-01-18 14:01:12 +01:00
Victor Stinner c52572319c Optimize methoddescr_call(): avoid temporary PyCFunction
Issue #29259, #29263. methoddescr_call() creates a PyCFunction object, call it
and the destroy it. Add a new _PyMethodDef_RawFastCallDict() method to avoid
the temporary PyCFunction object.
2017-01-18 10:38:09 +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 7fc252adfb Optimize _PyCFunction_FastCallKeywords()
Issue #29259: Write fast path in _PyCFunction_FastCallKeywords() for
METH_FASTCALL, avoid the creation of a temporary dictionary for keyword
arguments.

Cleanup also _PyCFunction_FastCallDict():

* Don't dereference func before checking that it's not NULL
* Move code to raise the "no keyword argument" exception into a new
  no_keyword_error label.

Update python-gdb.py for the change.
2017-01-16 17:18:53 +01: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 476bd5ea97 Fix warning in _PyCFunction_FastCallKeywords()
Issue #28105.
2016-09-12 15:33:26 -04: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
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 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 b900939186 _PyFunction_FastCallDict() supports keyword args
Issue #27809:

* Rename _PyFunction_FastCall() to _PyFunction_FastCallDict()
* Rename _PyCFunction_FastCall() to _PyCFunction_FastCallDict()
*  _PyFunction_FastCallDict() now supports keyword arguments
2016-08-22 23:15:44 +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
Martin Panter ec1aa5c2a1 More typos in 3.5 documentation and comments 2015-10-07 11:03:53 +00:00
Andrew Svetlov 48050cbbe7 Merge 3.4 2015-04-27 17:49:16 +03:00
Andrew Svetlov 9df36c9456 Issue #21354: PyCFunction_New function is exposed by python DLL again. 2015-04-27 17:48:50 +03: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
Antoine Pitrou b349e4c929 Issue #22116: C functions and methods (of the 'builtin_function_or_method' type) can now be weakref'ed. Patch by Wei Wu. 2014-08-06 19:31:40 -04:00
Larry Hastings 2623c8c23c Issue #20530: Argument Clinic's signature format has been revised again.
The new syntax is highly human readable while still preventing false
positives.  The syntax also extends Python syntax to denote "self" and
positional-only parameters, allowing inspect.Signature objects to be
totally accurate for all supported builtins in Python 3.4.
2014-02-08 22:15:29 -08:00
Larry Hastings 581ee3618c Issue #20326: Argument Clinic now uses a simple, unique signature to
annotate text signatures in docstrings, resulting in fewer false
positives.  "self" parameters are also explicitly marked, allowing
inspect.Signature() to authoritatively detect (and skip) said parameters.

Issue #20326: Argument Clinic now generates separate checksums for the
input and output sections of the block, allowing external tools to verify
that the input has not changed (and thus the output is not out-of-date).
2014-01-28 05:00:08 -08:00
Larry Hastings 5c66189e88 Issue #20189: Four additional builtin types (PyTypeObject,
PyMethodDescr_Type, _PyMethodWrapper_Type, and PyWrapperDescr_Type)
have been modified to provide introspection information for builtins.
Also: many additional Lib, test suite, and Argument Clinic fixes.
2014-01-24 06:17:25 -08:00
Christian Heimes d3afe781b1 Silence expression result unused warnings with clang.
The PyObject_INIT() macros returns obj:

../cpython/Objects/methodobject.c:32:23: warning: expression result unused [-Wunused-value]
        PyObject_INIT(op, &PyCFunction_Type);
                      ^~
../cpython/Include/objimpl.h:139:69: note: expanded from macro 'PyObject_INIT'
    ( Py_TYPE(op) = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )
                                                                    ^
1 warning generated.
2013-12-04 09:27:47 +01:00
Alexandre Vassalotti 4c05d3bc56 Make built-in methods picklable through the reduce protocol. 2013-11-24 02:41:05 -08:00
Larry Hastings 44e2eaab54 Issue #19674: inspect.signature() now produces a correct signature
for some builtins.
2013-11-23 15:37:55 -08:00
Victor Stinner 9035ad932b Issue #18408: In debug mode, PyCFunction_Call() now checks if an exception was
raised if the result is NULL to help to find bugs in C mode (get the error
earlier than the SystemError in ceval.c).
2013-07-11 23:44:46 +02:00
Antoine Pitrou dc040f099d Fix supernumerary 's' in sys._debugmallocstats() output. 2013-04-11 21:02:20 +02:00
Antoine Pitrou 36b045f4db Fix supernumerary 's' in sys._debugmallocstats() output. 2013-04-11 21:01:40 +02:00
Antoine Pitrou a2678f3eb6 Fix the advertised size of PyCFunctionObjects in sys._debugmallocstats(). 2012-12-30 22:46:56 +01:00
Antoine Pitrou 0811f98e10 Fix the advertised size of PyCFunctionObjects in sys._debugmallocstats(). 2012-12-30 22:46:04 +01:00
Andrew Svetlov 4de2924dab Fix compilation error for #15422 2012-12-26 23:08:54 +02:00
Andrew Svetlov 3ba3a3ee56 Issue #15422: get rid of PyCFunction_New macro 2012-12-25 13:32:35 +02:00
David Malcolm 49526f48fc Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues 2012-06-22 14:55:41 -04:00
Antoine Pitrou 5b62942074 Issue #13577: Built-in methods and functions now have a __qualname__.
Patch by sbt.
2011-12-23 12:40:16 +01:00
Brian Curtin dfc80e3d97 Replace Py_NotImplemented returns with the macro form Py_RETURN_NOTIMPLEMENTED.
The macro was introduced in #12724.
2011-08-10 20:28:54 -05:00
Benjamin Peterson 8f67d0893f make hashes always the size of pointers; introduce Py_hash_t #9778 2010-10-17 20:54:53 +00:00
Antoine Pitrou f95a1b3c53 Recorded merge of revisions 81029 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r81029 | antoine.pitrou | 2010-05-09 16:46:46 +0200 (dim., 09 mai 2010) | 3 lines

  Untabify C files. Will watch buildbots.
........
2010-05-09 15:52:27 +00:00