Commit Graph

5469 Commits

Author SHA1 Message Date
Serhiy Storchaka d4edfc9abf bpo-29935: Fixed error messages in the index() method of tuple, list and deque (#887)
when pass indices of wrong type.
2017-03-30 18:29:23 +03:00
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
Serhiy Storchaka ba85d69a3e bpo-29878: Add global instances of int for 0 and 1. (#852) 2017-03-30 09:09:41 +03:00
Serhiy Storchaka aefa7ebf0f bpo-6532: Make the thread id an unsigned integer. (#781)
* bpo-6532: Make the thread id an unsigned integer.

From C API side the type of results of PyThread_start_new_thread() and
PyThread_get_thread_ident(), the id parameter of
PyThreadState_SetAsyncExc(), and the thread_id field of PyThreadState
changed from "long" to "unsigned long".

* Restore a check in thread_get_ident().
2017-03-23 14:48:39 +01:00
Daniel Birnstiel d7fa6b259e bpo-29859: Fix error messages from return codes for pthread_* calls (GH-741) 2017-03-21 22:06:06 +09:00
Serhiy Storchaka fff9a31a91 bpo-29865: Use PyXXX_GET_SIZE macros rather than Py_SIZE for concrete types. (#748) 2017-03-21 08:53:25 +02:00
Xiang Zhang 4830f581af bpo-29849: fix a memory leak in import_from (GH-712) 2017-03-21 11:13:42 +08:00
Serhiy Storchaka 80ec8364f1 bpo-29748: Added the slice index converter in Argument Clinic. (#549) 2017-03-19 19:37:40 +02:00
Serhiy Storchaka c2cf128571 bpo-8256: Fixed possible failing or crashing input() (#517)
if attributes "encoding" or "errors" of sys.stdin or sys.stdout
are not set or are not strings.
2017-03-12 13:50:36 +02:00
Serhiy Storchaka 202fda55c2 bpo-24037: Add Argument Clinic converter `bool(accept={int})`. (#485) 2017-03-12 10:10:47 +02:00
Serhiy Storchaka 0767ad40bf bpo-20185: Convert the marshal module to Argument Clinic. (#541)
Based on patch by Vajrasky Kok.
2017-03-12 09:20:15 +02:00
Serhiy Storchaka c611a5b1d4 bpo-29746: Update marshal docs to Python 3. (#547) 2017-03-12 08:53:22 +02:00
Xiang Zhang 0710d75425 bpo-29770: remove outdated PYO related info (GH-590) 2017-03-11 13:02:52 +08:00
Victor Stinner 0f6d73343d bpo-29619: Convert st_ino using unsigned integer (#557)
bpo-29619: os.stat() and os.DirEntry.inodeo() now convert inode
(st_ino) using unsigned integers.
2017-03-09 17:34:28 +01:00
Serhiy Storchaka 370fd202f1 Use Py_RETURN_FALSE/Py_RETURN_TRUE rather than PyBool_FromLong(0)/PyBool_FromLong(1). (#567) 2017-03-08 20:47:48 +02:00
INADA Naoki 93fac8dd35 bpo-29676: fix lsprof can't profile C method call. (GH523)
When LOAD_METHOD is used for calling C mehtod, PyMethodDescrObject
was passed to profilefunc from 5566bbb.
But lsprof traces only PyCFunctionObject. Additionally, there can be
some third party extension which assumes passed arg is
PyCFunctionObject without calling PyCFunction_Check().

So make PyCFunctionObject from PyMethodDescrObject when
tstate->c_profilefunc is set.
2017-03-07 14:24:37 +09:00
Ned Deily 5c4b0d063a bpo-27593: Get SCM build info from git instead of hg. (#446)
sys.version and the platform module python_build(),
python_branch(), and python_revision() functions now use
git information rather than hg when building from a repo.

Based on original patches by Brett Cannon and Steve Dower.
2017-03-04 00:19:55 -05:00
Yury Selivanov 398ff91ac0 bpo-28893: Set __cause__ for errors in async iteration protocol (#407) 2017-03-02 22:20:00 -05:00
Matthias Bussonnier 160edb4357 bpo-29655: Fixed possible reference leaks in `import *`. (#301)
Patch by Matthias Bussonnier.
2017-02-26 07:58:05 +02:00
INADA Naoki 4c78c527d2 bpo-29622: Make AST constructor to accept less than enough number of positional arguments (GH-249)
bpo-29463 added optional "docstring" field to 4 AST types.
While it is optional, it breaks backward compatibility because AST constructor
requires number of positional argument is same to number of fields.

AST types accepts empty arguments, and incomplete keyword arguments.
But it's not big problem because field can be filled after creation, and checked when compiling.
So stop requiring complete set of fields for positional arguments too.
2017-02-24 02:48:17 +09:00
Martijn Pieters d7e64337ef bpo-28598: Support __rmod__ for RHS subclasses of str in % string formatting operations (#51)
When you use `'%s' % SubClassOfStr()`, where `SubClassOfStr.__rmod__` exists, the reverse operation is ignored as normally such string formatting operations use the `PyUnicode_Format()` fast path. This patch tests for subclasses of `str` first and picks the slow path in that case.

Patch by Martijn Pieters.
2017-02-23 15:38:04 +02:00
INADA Naoki cb41b2766d bpo-29463: Add docstring field to some AST nodes. (#46)
* bpo-29463: Add docstring field to some AST nodes.

ClassDef, ModuleDef, FunctionDef, and AsyncFunctionDef has docstring
field for now.  It was first statement of there body.

* fix document.  thanks travis!

* doc fixes
2017-02-22 16:31:59 +01:00
Matthias Bussonnier 1bc156430b bpo-29546: Improve from-import error message with location (#103)
bpo-29546: Improve from-import error message with location
2017-02-22 10:06:50 -05:00
Matthieu Dartiailh 3a9ac827c7 bpo-29607: Fix stack_effect computation for CALL_FUNCTION_EX (#202) 2017-02-21 15:25:22 +02:00
Yen Chi Hsuan 72e81d00ee bpo-29556: Remove unused #include <langinfo.h> (#98)
bltinmodule.c: Added in b744ba1 and no longer necessary since d64e8a7
posixmodule.c: Added in d1cd4d4 and no longer necessary since efb00c0
pythonrun.c:   Added in 73d538b and no longer necessary since d600951
sysmodule.c:   Added in 5467d4c and no longer necessary since a2c17c5
2017-02-16 00:34:30 +01:00
Matthias Bussonnier bc4bed4405 bpo-29546: Set 'path' on ImportError for ``from ... import ...`` (GH-91) 2017-02-14 16:05:25 -08: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
Serhiy Storchaka 68a001dd59 Issue #29460: _PyArg_NoKeywords(), _PyArg_NoStackKeywords() and
_PyArg_NoPositional() now are macros.
2017-02-06 10:41:46 +02:00
Serhiy Storchaka 685c203e84 Removed redundant Argument Clinic directives. 2017-02-04 11:53:22 +02: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 fdbc397f4d Issue #29286: Rename private PyArg_UnpackStack_impl() to unpack_stack()
Rename also "l" argument to "nargs".
2017-02-01 17:42:18 +01:00
Victor Stinner 122fb562d4 Document that _PyFunction_FastCallDict() must copy kwargs
Issue #29318: Caller and callee functions must not share the dictionary:
kwargs must be copied.
2017-02-01 17:04:52 +01:00
INADA Naoki fc489082c8 Issue #29369: Use Py_IDENTIFIER in Python-ast.c 2017-01-25 22:33:43 +09:00
Serhiy Storchaka 9fa4a120f0 Issue #26729: Fixed __text_signature__ for sorted().
Patch by Erik Welch.
2017-01-23 12:30:59 +02:00
Serhiy Storchaka ad9422559f Issue #26729: Fixed __text_signature__ for sorted().
Patch by Erik Welch.
2017-01-23 12:30:35 +02:00
Serhiy Storchaka 3a1042567c Issue #26729: Fixed __text_signature__ for sorted().
Patch by Erik Welch.
2017-01-23 12:29:47 +02:00
Serhiy Storchaka 228b12edcc Issue #28999: Use Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE wherever
possible.  Patch is writen with Coccinelle.
2017-01-23 09:47:21 +02:00
Serhiy Storchaka 7cf8bebb07 Issue #29331: Simplified argument parsing in sorted() and list.sort(). 2017-01-21 23:05:00 +02:00
Serhiy Storchaka 299dc239fe Issue #29327: Fixed a crash when pass the iterable keyword argument to sorted(). 2017-01-20 08:35:18 +02:00
Serhiy Storchaka 398ef5c08f Issue #29327: Fixed a crash when pass the iterable keyword argument to sorted(). 2017-01-20 08:33:06 +02:00
INADA Naoki bd584f169f Issue #29296: convert print() to METH_FASTCALL
* Replace PyArg_ParseTupleAndKeywords() with _PyArg_ParseStackAndKeywords()
  which is more efficient to parse keywords, since it decodes only keywords
  (char*) from UTF-8 once, instead of decoding at each call.
* METH_FASTCALL avoids the creation of a temporary tuple to pass positional
  arguments.

Patch written by INADA Naoki, pushed by Victor Stinner.
2017-01-19 12:50:34 +01:00
Victor Stinner a8cb515a29 Rephrase !PyErr_Occurred() comment: may=>can
Issue #29259.
2017-01-18 14:12:51 +01:00
Victor Stinner 5a60ecaa7a sorted() uses METH_FASTCALL 2017-01-17 15:17:49 +01:00
Victor Stinner fda6d0acf0 next() uses FASTCALL 2017-01-17 04:09:14 +01:00
Victor Stinner 84b388bb80 getattr() uses METH_FASTCALL 2017-01-17 03:52:27 +01:00
Serhiy Storchaka 1741441649 Issue #29029: Speed up processing positional arguments in
PyArg_ParseTupleAndKeywords(), _PyArg_ParseTupleAndKeywordsFast() and like.
2017-01-17 10:07:25 +02:00
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
Victor Stinner fe54dd8a08 Add _PyArg_UnpackStack() function helper
Issue #29286.
2017-01-17 02:33:55 +01:00
Victor Stinner 259f0e4437 Run Argument Clinic: METH_VARARGS=>METH_FASTCALL
Issue #29286. Run Argument Clinic to get the new faster METH_FASTCALL calling
convention for functions using only positional arguments.
2017-01-17 01:35:17 +01:00
Victor Stinner 29d39cc8f5 Add _PyArg_NoStackKeywords() helper function
Issue #29286. Similar to _PyArg_NoKeywords(), but expects a tuple of keyword
names, instead of a dict.
2017-01-17 01:40:01 +01:00
Victor Stinner 6518a93cb1 Add _PyArg_ParseStack() helper function
Issue #29286. Function similar to PyArg_ParseTuple(), but uses a C array of
PyObject* to pass arguments. Don't support the compatibility mode.
2017-01-17 01:29:49 +01:00
Victor Stinner 3e1fad6913 Rename _PyArg_ParseStack to _PyArg_ParseStackAndKeywords
Issue #29286.
2017-01-17 01:29:01 +01:00
Victor Stinner c0083fc47d Rename keywords to kwargs in getargs.c
Issue #29029. Patch written by Serhiy Storchaka.
2017-01-17 00:37:42 +01:00
Victor Stinner 80ab22fa2c Cleanup getargs.c
Factorize argument checks in:

* vgetargskeywordsfast()
* vgetargskeywordsfast_impl()
2017-01-16 23:16:47 +01:00
Victor Stinner 773dc6dd06 __build_class__() builtin uses METH_FASTCALL 2017-01-16 23:46:26 +01:00
INADA Naoki 015bce64b3 Issue #26110: Add document for LOAD_METHOD and CALL_METHOD opcode.
Changed stack layout bit for "easy to explain."
2017-01-16 17:23:30 +09:00
Victor Stinner 231d1f3439 _PyEval_EvalCodeWithName(): remove redundant check
Replace the runtime check with an assertion (just in case).
2017-01-11 02:12:06 +01:00
Victor Stinner 415c5107be Inline call_function()
Issue #29227: Inline call_function() into _PyEval_EvalFrameDefault() using
Py_LOCAL_INLINE to reduce the stack consumption.

It reduces the stack consumption, bytes per call, before => after:

test_python_call: 1152 => 1040 (-112 B)
test_python_getitem: 1008 => 976 (-32 B)
test_python_iterator: 1232 => 1120 (-112 B)

=> total: 3392 => 3136 (- 256 B)
2017-01-11 00:54:57 +01:00
Victor Stinner 035ba5da3e Issue #29157: Prefer getrandom() over getentropy()
Copy and then adapt Python/random.c from default branch. Difference between 3.5
and default branches:

* Python 3.5 only uses getrandom() in non-blocking mode: flags=GRND_NONBLOCK
* If getrandom() fails with EAGAIN: py_getrandom() immediately fails and
  remembers that getrandom() doesn't work.
* Python 3.5 has no _PyOS_URandomNonblock() function: _PyOS_URandom()
  works in non-blocking mode on Python 3.5
2017-01-09 11:18:53 +01:00
Victor Stinner ff558f5aba Issue #29157: Prefer getrandom() over getentropy()
* dev_urandom() now calls py_getentropy(). Prepare the fallback to support
  getentropy() failure and falls back on reading from /dev/urandom.
* Simplify dev_urandom(). pyurandom() is now responsible to call getentropy()
  or getrandom(). Enhance also dev_urandom() and pyurandom() documentation.
* getrandom() is now preferred over getentropy(). The glibc 2.24 now implements
  getentropy() on Linux using the getrandom() syscall.  But getentropy()
  doesn't support non-blocking mode. Since getrandom() is tried first, it's not
  more needed to explicitly exclude getentropy() on Solaris. Replace:
  "if defined(HAVE_GETENTROPY) && !defined(sun)"
  with "if defined(HAVE_GETENTROPY)"
* Enhance py_getrandom() documentation. py_getentropy() now supports ENOSYS,
  EPERM & EINTR
2017-01-07 00:07:45 +01:00
Victor Stinner b27df6faa5 Issue #29157: enhance py_getrandom() documentation 2017-01-06 11:39:15 +01:00
Victor Stinner de2f1ea124 py_getentropy() now supports ENOSYS, EPERM & EINTR
Issue #29157.
2017-01-06 11:33:18 +01:00
Victor Stinner 2f7964393d Issue #29157: getrandom() is now preferred over getentropy()
The glibc now implements getentropy() on Linux using the getrandom() syscall.
But getentropy() doesn't support non-blocking mode.

Since getrandom() is tried first, it's not more needed to explicitly exclude
getentropy() on Solaris. Replace:

    if defined(HAVE_GETENTROPY) && !defined(sun)

with

    if defined(HAVE_GETENTROPY)
2017-01-06 11:26:01 +01:00
Victor Stinner a49a2078e8 Issue #29157: Simplify dev_urandom()
pyurandom() is now responsible to call getentropy() or getrandom().

Enhance also dev_urandom() and pyurandom() documentation.
2017-01-06 11:17:52 +01:00
Victor Stinner dcdb60e4b3 Issue #29157: dev_urandom() now calls py_getentropy()
Prepare the fallback to support getentropy() failure and falls back on reading
from /dev/urandom.
2017-01-06 11:16:20 +01:00
Victor Stinner 865a0f621f Optimize _PyFunction_FastCallDict() when kwargs is {}
Issue #28839: Optimize _PyFunction_FastCallDict() when kwargs is an empty
dictionary, avoid the creation of an useless empty tuple.
2017-01-03 02:01:42 +01:00
Benjamin Peterson 646bf754e3 merge 3.6 (#29057) 2017-01-01 22:30:35 -06:00
Benjamin Peterson 46322587ec merge 3.5 (#29057) 2017-01-01 22:30:26 -06:00
Benjamin Peterson 493ac1bbe0 only include sys/random.h if it seems like it might have something useful (#29057) 2017-01-01 22:29:36 -06:00
Benjamin Peterson 6784be1d00 merge 3.6 2017-01-01 22:08:51 -06:00
Benjamin Peterson 5848e72ee1 merge 3.5 2017-01-01 22:08:44 -06:00
Benjamin Peterson 4365833d11 merge 3.4 2017-01-01 22:08:33 -06:00
Benjamin Peterson b6e2142b0c merge 3.3 2017-01-01 22:07:37 -06:00
Benjamin Peterson e527dd34bc ring in 2017 for Python 2017-01-01 22:04:13 -06:00
INADA Naoki 9c15776fac Issue #29049: Remove unnecessary Py_DECREF 2016-12-26 18:52:46 +09:00
INADA Naoki 6a3cedf8dd Issue #29049: Fix refleak introduced by f5eb0c4f5d37. 2016-12-26 18:01:46 +09:00
INADA Naoki 5a625d0aa6 Issue #29049: Call _PyObject_GC_TRACK() lazily when calling Python function.
Calling function is up to 5% faster.
2016-12-24 20:19:08 +09:00
Benjamin Peterson 38f225dd48 merge 3.6 (#28932) 2016-12-19 23:55:24 -08:00
Benjamin Peterson b0eb986eb2 merge 3.5 (#28932) 2016-12-19 23:54:57 -08:00
Benjamin Peterson fb2ae15c67 add a specific configure check for sys/random.h (closes #28932) 2016-12-19 23:54:25 -08:00
Martin Panter b46edf35f3 Issue #25677: Merge SyntaxError caret positioning from 3.6 2016-12-19 06:46:12 +00:00
Martin Panter 619555d77b Issue #25677: Merge SyntaxError caret positioning from 3.5 2016-12-19 06:46:01 +00:00
Serhiy Storchaka 5bb8b9134b Issue #18896: Python function can now have more than 255 parameters.
collections.namedtuple() now supports tuples with more than 255 elements.
2016-12-16 19:19:02 +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
Xavier de Gaye 31eaf49ed9 Merge 3.6. 2016-12-15 21:01:52 +01:00
Xavier de Gaye 76febd0792 Issue #26919: On Android, operating system data is now always encoded/decoded
to/from UTF-8, instead of the locale encoding to avoid inconsistencies with
os.fsencode() and os.fsdecode() which are already using UTF-8.
2016-12-15 20:59:58 +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
Yury Selivanov f2392133eb Issue #26110: Add LOAD_METHOD/CALL_METHOD opcodes.
Special thanks to INADA Naoki for pushing the patch through
the last mile, Serhiy Storchaka for reviewing the code, and to
Victor Stinner for suggesting the idea (originally implemented
in the PyPy project).
2016-12-13 19:03:51 -05:00
Steve Dower 21e033466b Issue #28896: Disable WindowsRegistryFinder by default. 2016-12-12 11:19:03 -08:00
Steve Dower 10beb3cfef Issue #28896: Disable WindowsRegistryFinder by default. 2016-12-12 11:17:59 -08:00
Serhiy Storchaka 0f6373c34f Issue #28739: f-string expressions no longer accepted as docstrings and
by ast.literal_eval() even if they do not include subexpressions.
2016-12-11 19:39:36 +02:00
Serhiy Storchaka 4cc30ae313 Issue #28739: f-string expressions no longer accepted as docstrings and
by ast.literal_eval() even if they do not include subexpressions.
2016-12-11 19:37:19 +02:00
Serhiy Storchaka 26817a8490 Issue #28512: Fixed setting the offset attribute of SyntaxError by
PyErr_SyntaxLocationEx() and PyErr_SyntaxLocationObject().
2016-12-11 14:44:21 +02:00
Serhiy Storchaka 8114f21668 Issue #28512: Fixed setting the offset attribute of SyntaxError by
PyErr_SyntaxLocationEx() and PyErr_SyntaxLocationObject().
2016-12-11 14:43:18 +02:00
Serhiy Storchaka 8b58339eb2 Issue #28512: Fixed setting the offset attribute of SyntaxError by
PyErr_SyntaxLocationEx() and PyErr_SyntaxLocationObject().
2016-12-11 14:39:01 +02:00
Martin Panter ca3263c50c Issue #25677: Correct syntax error caret for indented blocks.
Based on patch by Michael Layzell.
2016-12-11 00:18:36 +00:00
Victor Stinner 59a73276e9 Backed out changeset 99c34e47348b
The change broke test_gdb.
2016-12-09 18:51:13 +01:00
Victor Stinner 22f18750a5 Issue #20185: Convert _warnings.warn() to Argument Clinic
Fix warn_explicit(): interpret source=None as source=NULL.
2016-12-09 18:08:18 +01:00