Commit Graph

5454 Commits

Author SHA1 Message Date
Victor Stinner 57f91ac95a Document kwnames in _PyObject_FastCallKeywords() and _PyStack_AsDict()
Issue #27213.
2016-09-12 13:37:07 +02:00
Victor Stinner eece2229e2 Issue #27213: Fix reference leaks 2016-09-12 11:16:37 +02:00
Eric V. Smith 09835dcdbb Make an f-string error message more exact and consistent. 2016-09-11 18:58:20 -04: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
Guido van Rossum 015d874626 Issue #28076: Variable annotations should be mangled for private names.
By Ivan Levkivskyi.
2016-09-11 09:45:24 -07:00
Serhiy Storchaka a1e9ab34a9 Fixed refactoring bug in dd046963bd42 (issue27129). 2016-09-11 15:19:12 +03:00
Serhiy Storchaka ab8740058a Issue #27129: Replaced wordcode related magic constants with macros. 2016-09-11 13:48:15 +03:00
Nick Coghlan 944368e1cc Issue #23722: Initialize __class__ from type.__new__()
The __class__ cell used by zero-argument super() is now initialized
from type.__new__ rather than __build_class__, so class methods
relying on that will now work correctly when called from metaclass
methods during class creation.

Patch by Martin Teichmann.
2016-09-11 14:45:49 +10:00
Benjamin Peterson 4eef505064 Backed out changeset 3934e070c9db 2016-09-10 17:04:36 -07:00
Victor Stinner 54de2b1edd Fix check_force_ascii()
Issue #27938: Normalize aliases of the ASCII encoding, because
_Py_normalize_encoding() now correctly normalize encoding names.
2016-09-09 23:11:52 -07:00
Łukasz Langa fef7e94fa1 Don't run garbage collection on interpreter exit if it was explicitly disabled
by the user.
2016-09-09 21:47:46 -07:00
Victor Stinner c7454ff5fc Issue #27810: Fix getargs.c compilation on Windows 2016-09-09 20:56:52 -07:00
Benjamin Peterson 819a46f33a fix export of size_t parse stack function 2016-09-09 20:45:06 -07:00
Victor Stinner 37e4ef7b17 Issue #27810: Rerun Argument Clinic on all modules 2016-09-09 20:00:13 -07:00
Victor Stinner f0ccbbbc57 Emit METH_FASTCALL code in Argument Clinic
Issue #27810:

* Modify vgetargskeywordsfast() to work on a C array of PyObject* rather than
  working on a tuple directly.
* Add _PyArg_ParseStack()
* Argument Clinic now emits code using the new METH_FASTCALL calling convention
2016-09-09 17:40:38 -07: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
Benjamin Peterson eb0dfa9251 make invalid_comma_and_underscore a real prototype 2016-09-09 20:14:05 -07:00
Eric V. Smith 89e1b1aae0 Issue 27080: PEP 515: add '_' formatting option. 2016-09-09 23:06:47 -04:00
Benjamin Peterson f5781958af add dtrace inline stubs 2016-09-09 19:48:47 -07:00
Benjamin Peterson 4ba5c88a3f just start with an int rather than casting 2016-09-09 19:31:12 -07:00
Eric V. Smith 451d0e38fc Issue 27948: Allow backslashes in the literal string portion of f-strings, but not in the expressions. Also, require expressions to begin and end with literal curly braces. 2016-09-09 21:56:20 -04:00
Łukasz Langa a785c87d6e DTrace support: function calls, GC activity, line execution
Tested on macOS 10.11 dtrace, Ubuntu 16.04 SystemTap, and libbcc.

Largely based by an initial patch by Jesús Cea Avión, with some
influence from Dave Malcolm's SystemTap patch and Nikhil Benesch's
unification patch.

Things deliberately left out for simplicity:
- ustack helpers, I have no way of testing them at this point since
they are Solaris-specific
- PyFrameObject * in function__entry/function__return, this is
SystemTap-specific
- SPARC support
- dynamic tracing
- sys module dtrace facility introspection

All of those might be added later.
2016-09-09 17:37:37 -07:00
Benjamin Peterson 75f94a7dff remove more READ_TIMESTAMP 2016-09-09 15:03:18 -07:00
Benjamin Peterson 1cfe1d1f53 remove READ_TIMESTAMP macro 2016-09-09 15:02:11 -07:00
Benjamin Peterson 4fd64b9a6a remove ceval timestamp support 2016-09-09 14:57:58 -07:00
Brett Cannon a721abac29 Issue #26331: Implement the parsing part of PEP 515.
Thanks to Georg Brandl for the patch.
2016-09-09 14:57:09 -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
Eric Snow 50fd89806f Issue #24320: Drop an old setuptools-induced hack. 2016-09-09 13:30:54 -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
Victor Stinner f9b760f48a Rework CALL_FUNCTION* opcodes
Issue #27213: Rework CALL_FUNCTION* opcodes to produce shorter and more
efficient bytecode:

* CALL_FUNCTION now only accepts position arguments
* CALL_FUNCTION_KW accepts position arguments and keyword arguments, but keys
  of keyword arguments are packed into a constant tuple.
* CALL_FUNCTION_EX is the most generic, it expects a tuple and a dict for
  positional and keyword arguments.

CALL_FUNCTION_VAR and CALL_FUNCTION_VAR_KW opcodes have been removed.

2 tests of test_traceback are currently broken: skip test, the issue #28050 was
created to track the issue.

Patch by Demur Rumed, design by Serhiy Storchaka, reviewed by Serhiy Storchaka
and Victor Stinner.
2016-09-09 10:17:08 -07:00
Yury Selivanov 52c4e7cc84 Issue #28008: Implement PEP 530 -- asynchronous comprehensions. 2016-09-09 10:36:01 -07:00
Guido van Rossum 6cff8744a0 Issue #27999: Make "global after use" a SyntaxError, and ditto for nonlocal.
Patch by Ivan Levkivskyi.
2016-09-09 09:36:26 -07:00
Yury Selivanov 87672d777a Issue #28003: Fix a compiler warning 2016-09-09 00:05:42 -07:00
Yury Selivanov 50c584f50b ceval: tighten the code of STORE_ANNOTATION 2016-09-08 23:38:21 -07:00
Yury Selivanov eb6364557f Issue #28003: Implement PEP 525 -- Asynchronous Generators. 2016-09-08 22:01:51 -07:00
Yury Selivanov f8cb8a16a3 Issue #27985: Implement PEP 526 -- Syntax for Variable Annotations.
Patch by Ivan Levkivskyi.
2016-09-08 20:50:03 -07:00
Christian Heimes a78b627e2b Fix potential NULL pointer dereference in _imp_create_builtin
PyModule_GetDef() can return NULL. Let's check the return value properly
like in the other five cases.

CID 1299590
2016-09-09 00:25:03 +02:00
Eric Snow 4f29e75289 Issue #24254: Drop cls.__definition_order__. 2016-09-08 15:11:11 -07:00
Christian Heimes 45af0c83da Fix potential NULL pointer dereference in update_symbols()
symtable_analyze() calls analyze_block() with bound=NULL. Theoretically
that NULL can be passed down to update_symbols(). update_symbols() may
deference NULL and pass it to PySet_Contains()
2016-09-09 00:22:28 +02:00
Raymond Hettinger 4c483ad52b Merge 2016-09-08 14:45:40 -07:00
Raymond Hettinger 262b6793e0 Issue #26020: Fix evaluation order for set literals 2016-09-08 14:40:36 -07:00
Martin Panter 0be894b2f6 Issue #27895: Spelling fixes (Contributed by Ville Skyttä). 2016-09-07 12:03:06 +00:00
Senthil Kumaran 32d374215a [backport to 3.5] - issue26896 - Disambiguate uses of "importer" with "finder". 2016-09-07 00:52:20 -07:00
Raymond Hettinger f0f1c239e4 Issue 27936: Fix inconsistent round() behavior between float and int 2016-09-03 01:55:11 -07:00
Raymond Hettinger f0afe77c52 Issue #27909: Fix INCREF for possible NULL value 2016-08-31 08:44:11 -07:00
Steve Dower 3929499914 Issue #1602: Windows console doesn't input or print Unicode (PEP 528)
Closes #17602: Adds a readline implementation for the Windows console
2016-08-30 21:22:36 -07:00
Steve Dower 940f33a50f Issue #23524: Finish removing _PyVerify_fd from sources 2016-09-08 11:21:54 -07:00
Eric Snow f3fd06a2e4 Issue #28026: Raise ImportError when exec_module() exists but create_module() is missing. 2016-09-08 11:12:31 -07:00
Steve Dower cc16be85c0 Issue #27781: Change file system encoding on Windows to UTF-8 (PEP 529) 2016-09-08 10:35:16 -07:00
Brett Cannon 035a100382 Issue #26667: Add path-like object support to importlib.util. 2016-09-07 18:39:18 -07:00
Brett Cannon 52794db825 Issue #27911: Remove some unnecessary error checks in import.c.
Thanks to Xiang Zhang for the patch.
2016-09-07 17:00:43 -07:00
Eric Snow 46f97b85a8 Issue #15767: Use ModuleNotFoundError. 2016-09-07 16:56:15 -07:00
Brett Cannon 5c4de2863b Add the co_extra field and accompanying APIs to code objects.
This completes PEP 523.
2016-09-07 11:16:41 -07:00
Benjamin Peterson 2f8bfef158 replace PY_SIZE_MAX with SIZE_MAX 2016-09-07 09:26:18 -07:00
Victor Stinner e66987e626 os.urandom() now blocks on Linux
Issue #27776: The os.urandom() function does now block on Linux 3.17 and newer
until the system urandom entropy pool is initialized to increase the security.

This change is part of the PEP 524.
2016-09-06 16:33:52 -07:00
Brett Cannon eaecc692df Issue #27974: Remove importlib._bootstrap._ManageReload.
Class was dead code. Thanks to Xiang Zhang for the patch.
2016-09-06 16:20:46 -07:00
Benjamin Peterson ca47063998 replace Py_(u)intptr_t with the c99 standard types 2016-09-06 13:47:26 -07:00
Benjamin Peterson 9b3d77052f replace Python aliases for standard integer types with the standard integer types (#17884) 2016-09-06 13:24:00 -07:00
Benjamin Peterson 5d75f441ef dtoa.c: remove code for platforms with 64-bit integers (#17884) 2016-09-06 12:44:21 -07:00
Serhiy Storchaka ea525a2d1a Issue #27078: Added BUILD_STRING opcode. Optimized f-strings evaluation. 2016-09-06 22:07:53 +03:00
Benjamin Peterson 4fe55106d1 require standard int types to be defined (#17884) 2016-09-06 11:58:01 -07:00
Benjamin Peterson af580dff4a replace PY_LONG_LONG with long long 2016-09-06 10:46:49 -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 ad8c83ad6b Avoid inefficient way to call functions without argument
Don't pass "()" format to PyObject_CallXXX() to call a function without
argument: pass NULL as the format string instead. It avoids to have to parse a
string to produce 0 argument.
2016-09-05 17:53:15 -07:00
Benjamin Peterson ed4aa83ff7 require a long long data type (closes #27961) 2016-09-05 17:44:18 -07:00
Brett Cannon 3cebf93872 Implement the frame evaluation API aspect of PEP 523. 2016-09-05 15:33:46 -07:00
Larry Hastings 10108a7b9a Issue #27355: Removed support for Windows CE. It was never finished,
and Windows CE is no longer a relevant platform for Python.
2016-09-05 15:11:23 -07:00
Eric Snow 92a6c170e6 Issue #24254: Preserve class attribute definition order. 2016-09-05 14:50:11 -07:00
Eric V. Smith 6a4efce7a5 Closes issue 27921: Disallow backslashes anywhere in f-strings. This is a temporary restriction. In 3.6 beta 2, the plan is to again allow backslashes in the string parts of f-strings, but disallow them in the expression parts. 2016-09-03 09:18:34 -04:00
Raymond Hettinger 3b09cd64e0 Merge 2016-09-03 01:55:39 -07:00
Raymond Hettinger 74942c9252 Merge 2016-08-31 08:44:26 -07:00
Raymond Hettinger 15f44ab043 Issue #27895: Spelling fixes (Contributed by Ville Skyttä). 2016-08-30 10:47:49 -07:00
Serhiy Storchaka 1f9326196e Issue #27818: Speed up parsing width and precision in format() strings for
numbers.  Patch by Stefan Behnel.
2016-08-29 15:57:26 +03:00
Raymond Hettinger f74c33ad5c Merge 2016-08-25 21:12:16 -07:00
Raymond Hettinger 7ea386e56e Issue 19504: Change "customise" to "customize" American spelling. 2016-08-25 21:11:50 -07:00
Victor Stinner e90bdb19f2 Issue #27830: Revert, remove _PyFunction_FastCallKeywords() 2016-08-25 23:26:50 +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 cdb5cee980 Issue #27809: map_next() uses fast call
Use a small stack allocated in the C stack for up to 5 iterator functions,
otherwise allocates a stack on the heap memory.
2016-08-24 01:45:13 +02:00
Victor Stinner f0cba67d0b Backed out changeset 70f88b097f60 (map_next) 2016-08-24 00:54:47 +02:00
Victor Stinner a9ba1ab21b Issue #27809: map_next() uses fast call
Use a small stack allocated in the C stack for up to 5 iterator functions,
otherwise allocates a stack on the heap memory.
2016-08-23 17:56:06 +02:00
Victor Stinner d1c2a8e2b5 Issue #27809: builtin___build_class__() uses fast call 2016-08-23 01:34:35 +02:00
Victor Stinner 6e2333dfdf PyEval_CallObjectWithKeywords() doesn't inc/decref
Issue #27809: PyEval_CallObjectWithKeywords() doesn't increment temporary the
reference counter of the args tuple (positional arguments). The caller already
holds a strong reference to it.
2016-08-23 00:25:01 +02:00
Victor Stinner f45a56150b Issue #27809: PyErr_SetImportError() uses fast call 2016-08-23 00:04:41 +02:00
Victor Stinner 3a84097291 Add _PyErr_CreateException()
Issue #27809: Helper function optimized to create an exception: use fastcall
whenever possible.
2016-08-22 23:59:08 +02:00
Victor Stinner 463b86a881 Issue #27809: Use _PyObject_FastCallDict()
Modify:

* init_subclass()
* builtin___build_class__()

Fix also a bug in init_subclass(): check for super() failure.
2016-08-22 23:33:13 +02:00
Victor Stinner 155ea65e5c PyEval_CallObjectWithKeywords() uses fast call with kwargs
Issue #27809. _PyObject_FastCallDict() now supports keyword arguments, and so
the args==NULL fast-path can also be used when kwargs is not NULL.
2016-08-22 23:26:00 +02:00
Victor Stinner 2990fa11bc Issue #27809: Use _PyObject_FastCallDict()
Modify:

* builtin_sorted()
* classmethoddescr_call()
* methoddescr_call()
* wrapperdescr_call()
2016-08-22 23:21:55 +02:00
Victor Stinner 6fea7f7ffc Issue #27809: Cleanup _PyEval_EvalCodeWithName()
* Rename nm to name
* PEP 7: add { ... } to if/else blocks
2016-08-22 23:17:30 +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 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
Berker Peksag c98afb7a26 Issue #27587: Merge from 3.5 2016-08-22 18:07:02 +03:00
Berker Peksag 4b7b565c58 Issue #27587: Move null pointer check earlier in _PyState_AddModule()
This was found by PVS-Studio:

V595 The 'def' pointer was utilized before it was verified
against nullptr. Check lines: 286, 292. pystate.c 286

Initial patch by Christian Heimes.
2016-08-22 18:05:56 +03:00
Victor Stinner 2eedc119c2 Optimize call to Python function without argument
Issue #27128. When a Python function is called with no arguments, but all
parameters have a default value: use default values as arguments for the fast
path.
2016-08-22 12:29:42 +02:00
Victor Stinner a88b2f4e5e Fix reference leak in tb_printinternal()
Issue #26823.
2016-08-20 03:05:13 +02:00
Victor Stinner c3ccaae6f3 sys_pyfile_write_unicode() now uses fast call
Issue #27128.
2016-08-20 01:24:22 +02:00
Victor Stinner 78da82bf3e call_trampoline() now uses fast call
Issue #27128.
2016-08-20 01:22:57 +02:00
Victor Stinner 71cb64acc2 PyErr_PrintEx() now uses fast call
Issue #27128.
2016-08-20 00:57:43 +02:00
Victor Stinner df142fdc4b import_name() now uses fast call
Issue #27128: import_name() now calls _PyObject_FastCall() to avoid the
creation of a temporary tuple.
2016-08-20 00:44:42 +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 3f745bf1d9 PyEval_CallObjectWithKeywords() uses fast call
Issue #27128: Modify PyEval_CallObjectWithKeywords() to use
_PyObject_FastCall() when args==NULL and kw==NULL. It avoids the creation of a
temporary empty tuple for positional arguments.
2016-08-19 16:42:42 +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
Victor Stinner 0a6996d87d Merge 3.5 (fix raise) 2016-08-18 18:14:15 +02:00
Victor Stinner eec9331b20 Fix SystemError in "raise" statement
Issue #27558: Fix a SystemError in the implementation of "raise" statement.
In a brand new thread, raise a RuntimeError since there is no active
exception to reraise.

Patch written by Xiang Zhang.
2016-08-18 18:13:10 +02:00
Ned Deily dc35cda2de Issue #27594: Prevent assertion error when running test_ast with coverage
enabled: ensure code object has a valid first line number.
Patch suggested by Ivan Levkivskyi.
2016-08-17 17:18:33 -04:00
Victor Stinner 17061a99b0 Use Py_ssize_t in _PyEval_EvalCodeWithName()
Issue #27128, #18295: replace int type with Py_ssize_t for index variables used
for positional arguments. It should help to avoid integer overflow and help to
emit better machine code for "i++" (no trap needed for overflow).

Make also the total_args variable constant.
2016-08-16 23:39:42 +02:00
Victor Stinner c70200165c Issue #27128: Cleanup _PyEval_EvalCodeWithName()
* Add comments
* Add empty lines for readability
* PEP 7 style for if block
* Remove useless assert(globals != NULL); (globals is tested a few lines
  before)
2016-08-16 23:40:29 +02:00
Victor Stinner 3ee933f1c3 Issue #27776: dev_urandom(raise=0) now closes the file descriptor on error 2016-08-16 18:27:44 +02:00
Victor Stinner 6974cf2c27 Issue #27776: Cleanup random.c
Merge dev_urandom_python() and dev_urandom_noraise() functions to reduce code
duplication.
2016-08-16 18:46:38 +02:00
Victor Stinner cecdd9634b Issue #27776: _PyRandom_Init() doesn't call PyErr_CheckSignals() anymore
Modify py_getrandom() to not call PyErr_CheckSignals() if raise is zero.
_PyRandom_Init() is called very early in the Python initialization, so it's
safer to not call PyErr_CheckSignals().
2016-08-16 15:19:09 +02:00
Victor Stinner 4bad3b622e Issue #27776: Cleanup random.c
* Add pyurandom() helper function to factorize the code
* don't call Py_FatalError() in helper functions, but only in _PyRandom_Init()
  if pyurandom() failed, to uniformize the code
2016-08-16 15:23:58 +02:00
Nick Coghlan d00342347e Issue #26823: Abbreviate recursive tracebacks
Large sections of repeated lines in tracebacks are now abbreviated as
"[Previous line repeated {count} more times]" by both the traceback
module and the builtin traceback rendering.

Patch by Emanuel Barry.
2016-08-15 13:11:34 +10:00
Serhiy Storchaka 9171a8b4ce Issue #27574: Decreased an overhead of parsing keyword arguments in functions
implemented with using Argument Clinic.
2016-08-14 10:52:18 +03:00
Raymond Hettinger 08eef3ff49 Re-linewrap comments 2016-08-07 20:20:33 -07:00
Martin Panter 02b75abf73 Merge spelling and grammar fixes from 3.5 2016-08-05 01:51:39 +00:00
Martin Panter 69332c1a64 Fix spelling and grammar in documentation and code comments 2016-08-04 13:07:31 +00:00
Serhiy Storchaka 133138a284 Issue #22557: Now importing already imported modules is up to 2.5 times faster. 2016-08-02 22:51:21 +03:00
Martin Panter d2f87472fe Issue #17596: MINGW: add wincrypt.h in Python/random.c
Based on patch by Roumen Petrov.
2016-07-29 04:00:44 +00:00
Martin Panter 36261d7446 Issue #16191: Merge comment fixes from 3.5 2016-07-18 08:25:01 +00:00
Martin Panter 95f53c13ce Issue #16191: Fix up references to renamed variables 2016-07-18 08:23:26 +00:00
Serhiy Storchaka caaf53e748 Issue #27419: Added temporary workaround for subinterpreters. 2016-07-17 14:16:04 +03:00
Serhiy Storchaka 80ab069f1b Issue #27419: Added temporary workaround for subinterpreters. 2016-07-17 14:15:28 +03:00
Serhiy Storchaka 7905f99a27 Issue #27419: Standard __import__() no longer look up "__import__" in globals
or builtins for importing submodules or "from import".  Fixed a crash if
raise a warning about unabling to resolve package from __spec__ or
__package__.
2016-07-17 12:51:34 +03:00
Serhiy Storchaka b3b65e618c Issue #27419: Standard __import__() no longer look up "__import__" in globals
or builtins for importing submodules or "from import".  Fixed handling an
error of non-string package name.
2016-07-17 12:47:17 +03:00
Brett Cannon b2f8a801c2 Check in update for importlib_external.h 2016-07-16 10:46:10 -07:00
Brett Cannon 7ca63cb7cc Fix regressions introduced by fixes for issue #27083. 2016-07-16 10:44:13 -07:00
Brett Cannon b3e73b30ff Merge for #27083 2016-07-15 11:55:21 -07:00
Benjamin Peterson ce7b27d169 merge 3.5 (#27514) 2016-07-14 22:02:09 -07:00
Benjamin Peterson e09ed5419b make too many nested blocks be a SyntaxError instead of a SystemError (closes #27514)
Patch by Ammar Askar.
2016-07-14 22:00:03 -07:00
Brett Cannon 2247e5c48c Update frozen importlib code 2016-07-08 16:44:54 -07:00
Brett Cannon fdcdd9ed80 Issue #26896: Disambiguate uses of "importer" with "finder".
Thanks to Oren Milman for the patch.
2016-07-08 11:00:00 -07:00
Serhiy Storchaka 2954f83999 - Issue #27332: Fixed the type of the first argument of module-level functions
generated by Argument Clinic.  Patch by Petr Viktorin.
2016-07-07 18:20:03 +03:00
Serhiy Storchaka 1a2b24f02d Issue #27332: Fixed the type of the first argument of module-level functions
generated by Argument Clinic.  Patch by Petr Viktorin.
2016-07-07 17:35:15 +03:00
Serhiy Storchaka 7e160ce356 Issue #23034: The output of a special Python build with defined COUNT_ALLOCS,
SHOW_ALLOC_COUNT or SHOW_TRACK_COUNT macros is now off by  default.  It can
be re-enabled using the "-X showalloccount" option.  It now outputs to stderr
instead of stdout.
2016-07-03 21:03:53 +03:00
Serhiy Storchaka fbd1523525 Issue #27352: Correct the validation of the ImportFrom AST node and simplify
the implementation of the IMPORT_NAME opcode.
2016-06-27 21:39:12 +03:00
Serhiy Storchaka da9c513414 Issue #27255: Added more predictions in ceval.c. 2016-06-27 18:58:57 +03:00
Serhiy Storchaka cfdfbb4d3c Issue #27342: Replaced some Py_XDECREFs with Py_DECREFs.
Patch by Xiang Zhang.
2016-06-18 09:44:03 +03:00
Victor Stinner d7292b5e9f Issue #27336: Fix compilation on Windows
Replace "#if WITH_THREAD" with "#ifdef WITH_THREAD".
2016-06-17 12:29:00 +02:00
Berker Peksag 531396c764 Issue #27336: Fix compilation failures --without-threads 2016-06-17 13:25:01 +03:00
Victor Stinner a63073a807 Merge 3.5 2016-06-17 00:01:30 +02:00
Victor Stinner ec721f3305 py_getrandom(): use long type for the syscall() result
Issue #27278. It should fix a conversion warning.

In practice, the Linux kernel doesn't return more than 32 MB per call to the
getrandom() syscall.
2016-06-16 23:53:47 +02:00
Serhiy Storchaka 607f8a5e28 Issue #27301: Fixed incorrect return codes for errors in compile.c. 2016-06-15 20:07:53 +03:00
Serhiy Storchaka 694de3bff7 Issue #27301: Fixed incorrect return codes for errors in compile.c. 2016-06-15 20:06:07 +03:00
Victor Stinner d017176209 Merge 3.5 2016-06-14 16:36:00 +02:00
Victor Stinner c72828ba33 cleanup random.c
Casting Py_ssize_t to Py_ssize_t is useless.
2016-06-14 16:35:49 +02:00
Victor Stinner 370f5136d4 Merge 3.5 (os.urandom, issue #27278) 2016-06-14 16:33:17 +02:00
Victor Stinner b98a36e8f3 Fix os.urandom() using getrandom() on Linux
Issue #27278: Fix os.urandom() implementation using getrandom() on Linux.
Truncate size to INT_MAX and loop until we collected enough random bytes,
instead of casting a directly Py_ssize_t to int.
2016-06-14 16:31:35 +02:00
doko@ubuntu.com 5553231b91 - Issue #23968: Rename the platform directory from plat-$(MACHDEP) to
plat-$(PLATFORM_TRIPLET).
  Rename the config directory (LIBPL) from config-$(LDVERSION) to
  config-$(LDVERSION)-$(PLATFORM_TRIPLET).
  Install the platform specifc _sysconfigdata module into the platform
  directory and rename it to include the ABIFLAGS.
2016-06-14 08:55:19 +02:00
Serhiy Storchaka 64204de04c Issue #27095: Simplified MAKE_FUNCTION and removed MAKE_CLOSURE opcodes.
Patch by Demur Rumed.
2016-06-12 17:36:24 +03:00
Serhiy Storchaka 5697c4b641 Comment fixes extracted from patch by Demur Rumed. 2016-06-12 17:02:10 +03:00
Serhiy Storchaka cf2ad55511 Issue #27286: Fixed compiling BUILD_MAP_UNPACK_WITH_CALL opcode. Calling
function with generalized unpacking (PEP 448) and conflicting keyword names
could cause undefined behavior.
2016-06-12 09:35:13 +03:00
Serhiy Storchaka 3c317e76a2 Issue #27286: Fixed compiling BUILD_MAP_UNPACK_WITH_CALL opcode. Calling
function with generalized unpacking (PEP 448) and conflicting keyword names
could cause undefined behavior.
2016-06-12 09:22:01 +03:00
Serhiy Storchaka 6a7506a77f Issue #27140: Added BUILD_CONST_KEY_MAP opcode. 2016-06-12 00:39:41 +03:00
Serhiy Storchaka f41b82fb19 Issue #26282: PyArg_ParseTupleAndKeywords() and Argument Clinic now support
positional-only and keyword parameters in the same function.
2016-06-09 16:30:29 +03:00
Martin Panter 596357de23 Merge comment fix from 3.5 2016-06-10 08:38:56 +00:00
Martin Panter 39b1025356 Fix typo and move comment to appropriate condition 2016-06-10 08:07:11 +00:00
Yury Selivanov 711d25db48 Merge 3.5 (issue #27243) 2016-06-09 15:13:16 -04:00
Yury Selivanov a6f6edbda8 Issue #27243: Fix __aiter__ protocol 2016-06-09 15:08:31 -04:00
Serhiy Storchaka 5dee6551e2 Issue #26305: Argument Clinic now uses braces in C code as required by PEP 7. 2016-06-09 16:16:06 +03:00
Victor Stinner cfb1961f61 py_getrandom(): use char* instead of void* for the destination
Fix a "gcc -pedantic" warning on "buffer += n" because buffer type is void*.
2016-06-08 10:16:50 +02:00
Victor Stinner 9ff9cbd600 Merge 3.5 (os.urandom) 2016-06-07 11:25:43 +02:00
Victor Stinner dddf4849ec os.urandom() doesn't block on Linux anymore
Issue #26839: On Linux, os.urandom() now calls getrandom() with GRND_NONBLOCK
to fall back on reading /dev/urandom if the urandom entropy pool is not
initialized yet. Patch written by Colm Buckley.
2016-06-07 11:21:42 +02:00
Martin Panter 19409197e2 Merge typo fixes from 3.5 2016-06-04 05:26:40 +00:00
Martin Panter 3ee6270262 Fix typos in code comment and documentation 2016-06-04 04:57:19 +00:00
Serhiy Storchaka 76c4161b92 Issue #27138: Regenerate Python/importlib_external.h. 2016-05-28 14:48:19 +03:00
Serhiy Storchaka c7385f31d3 Issue #27138: Regenerate Python/importlib_external.h. 2016-05-28 14:46:13 +03:00
Martin Panter 3e04d5b306 Issue #27076: Merge spelling from 3.5 2016-05-26 06:03:19 +00:00
Martin Panter 46f50726a0 Issue #27076: Doc, comment and tests spelling fixes
Most fixes to Doc/ and Lib/ directories by Ville Skyttä.
2016-05-26 05:35:26 +00:00
Serhiy Storchaka 74f2fe6489 Fixed the use of _Py_IS_ALIGNED (issue #27097). 2016-05-25 20:35:44 +03:00
Serhiy Storchaka f60bf5f7d6 Issue #27097: Python interpreter is now about 7% faster due to optimized
instruction decoding.  Based on patch by Demur Rumed.
2016-05-25 20:02:01 +03:00
Serhiy Storchaka b0f80b0312 Issue #26647: Python interpreter now uses 16-bit wordcode instead of bytecode.
Patch by Demur Rumed.
2016-05-24 09:15:14 +03:00
Serhiy Storchaka 2a95219bc4 Issue #26168: Fixed possible refleaks in failing Py_BuildValue() with the "N"
format unit.
2016-05-20 22:31:50 +03:00
Serhiy Storchaka 13e602ea0f Issue #26168: Fixed possible refleaks in failing Py_BuildValue() with the "N"
format unit.
2016-05-20 22:31:14 +03:00
Victor Stinner 744c34e2ea Cleanup import.c
* Replace PyUnicode_RPartition() with PyUnicode_FindChar() and
  PyUnicode_Substring() to avoid the creation of a temporary tuple.
* Use PyUnicode_FromFormat() to build a string and avoid the single_dot ('.')
  singleton

Thanks Serhiy Storchaka for your review.
2016-05-20 11:36:13 +02:00
Victor Stinner 4a3443be43 Merge 3.5 (issue #27057) 2016-05-19 16:48:06 +02:00
Victor Stinner 3116cc44af Fix os.set_inheritable() on Android
Issue #27057: Fix os.set_inheritable() on Android, ioctl() is blocked by
SELinux and fails with EACCESS. The function now falls back to fcntl().

Patch written by Michał Bednarski.
2016-05-19 16:46:18 +02:00
Berker Peksag 094c9c921c Issue #23275: Allow () = iterable assignment syntax
Documentation updates by Martin Panter.
2016-05-18 08:44:29 +03:00
Benjamin Peterson ed64d6b4a5 regen importlib bytecode 2016-05-16 22:54:05 -07:00
Benjamin Peterson 5b2b3aae2a merge 3.5 (#26991) 2016-05-16 22:53:44 -07:00
Benjamin Peterson ad887cf7d1 fix possible refleak in MAKE_FUNCTION (closes #26991)
Patch by Xiang Zhang.
2016-05-16 22:52:40 -07:00
Serhiy Storchaka 4b23494ded Issue #27039: Fixed bytearray.remove() for values greater than 127.
Based on patch by Joe Jevnik.
2016-05-16 22:24:03 +03:00
Serhiy Storchaka ce41287e99 Issue #18531: Single var-keyword argument of dict subtype was passed
unscathed to the C-defined function.  Now it is converted to exact dict.
2016-05-08 23:36:44 +03:00
Martin Panter 1ce738e08f Merge typo fixes from 3.5 2016-05-08 14:02:35 +00:00
Martin Panter 4c35964b76 Corrections for a/an in code comments and documentation 2016-05-08 13:53:41 +00:00
Serhiy Storchaka 24182a3aaa Restored parameter name "self" since gdb needs exact specific parameter names. 2016-05-05 16:21:35 +03:00
Serhiy Storchaka c2f7d87897 Issue #26932: Fixed support of RTLD_* constants defined as enum values,
not via macros (in particular on Android).  Patch by Chi Hsuan Yen.
2016-05-04 09:44:44 +03:00
Serhiy Storchaka 7a9579c0ce Got rid of redundand "self" parameter declarations.
Argument Clinic is now able to infer all needed information.
2016-05-02 13:45:20 +03:00
Serhiy Storchaka 2e310b4c38 Regenerate Argument Clinic code for issue #26874. 2016-05-01 20:34:00 +03:00
Serhiy Storchaka df071730bb Regenerate Argument Clinic code for issue #26874. 2016-05-01 20:33:24 +03:00
Berker Peksag aa9d369707 Issue #23960: Cleanup args and kwargs on error in PyErr_SetImportError
Patch by Ofer Schwarz.
2016-05-01 09:06:57 +03:00
Berker Peksag ec766d3c15 Issue #23960: Cleanup args and kwargs on error in PyErr_SetImportError
Patch by Ofer Schwarz.
2016-05-01 09:06:36 +03:00
Zachary Ware 5031a67821 Closes #26874: Merge with 3.5 2016-04-28 14:40:08 -05:00
Zachary Ware 7f227d9087 Issue #26874: Simplify the divmod docstring 2016-04-28 14:39:50 -05:00
Zachary Ware 54559b6511 Closes #26874: Merge with 3.5 2016-04-28 14:25:32 -05:00
Zachary Ware 4d4160af6a Issue #26874: Fix divmod docstring 2016-04-28 14:24:55 -05:00
Stefan Krah 144da4ec85 Issue #22747: Workaround for systems without langinfo.h. 2016-04-26 01:56:50 +02:00
Stefan Krah 1845d144bc Issue #17905: Do not guard locale include with HAVE_LANGINFO_H. 2016-04-25 21:38:53 +02:00
Serhiy Storchaka 79d6e8de9e Issue #26802: Optimized calling a function with *args only positional arguments.
Patch by Joe Jevnik.
2016-04-19 23:37:17 +03:00
Victor Stinner a858bbde03 Avoid fcntl() if possible in set_inheritable()
Issue #26770: set_inheritable() avoids calling fcntl() twice if the FD_CLOEXEC
is already set/cleared. This change only impacts platforms using the fcntl()
implementation of set_inheritable() (not Linux nor Windows).
2016-04-17 16:51:52 +02:00
Serhiy Storchaka b6a9c9761c Issue #26778: Fixed "a/an/and" typos in code comment, documentation and error
messages.
2016-04-17 09:39:28 +03:00
Serhiy Storchaka 6a7b3a77b4 Issue #26778: Fixed "a/an/and" typos in code comment and documentation. 2016-04-17 08:32:47 +03:00
Martin Panter cda80940ed Issue #15984: Merge PyUnicode doc from 3.5 2016-04-15 02:27:11 +00:00
Martin Panter 6245cb3c01 Correct “an” → “a” with “Unicode”, “user”, “UTF”, etc
This affects documentation, code comments, and a debugging messages.
2016-04-15 02:14:19 +00:00
Serhiy Storchaka 23c5cbbdde fs_unicode_converter is no longer used. 2016-04-14 12:36:11 +03:00
Serhiy Storchaka 21a663ea28 Issue #26057: Got rid of nonneeded use of PyUnicode_FromObject(). 2016-04-13 15:37:23 +03:00
Victor Stinner 7258176c68 Merge 3.5 (os.urandom) 2016-04-12 22:38:22 +02:00
Victor Stinner 9d24271d86 Fix os.urandom() on Solaris 11.3
Issue #26735: Fix os.urandom() on Solaris 11.3 and newer when reading more than
1,024 bytes: call getrandom() multiple times with a limit of 1024 bytes per
call.
2016-04-12 22:28:49 +02: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 403002723f Issue #25339: PYTHONIOENCODING now has priority over locale in setting the
error handler for stdin and stdout.
2016-04-10 14:35:21 +03:00
Serhiy Storchaka fc43511867 Issue #25339: PYTHONIOENCODING now has priority over locale in setting the
error handler for stdin and stdout.
2016-04-10 14:34:13 +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
Raymond Hettinger 942302371c Minor code cleanup for PyArg_UnpackTuple. 2016-03-26 03:02:48 -07:00
Victor Stinner ca9dbc7d88 makeopcodetargets.py: we need to import Lib/opcode.py
Issue #20021: use importlib.machinery to import Lib/opcode.py and not an opcode
module coming from somewhere else. makeopcodetargets.py is part of the Python
build process and it is run by an external Python program, not the built Python
program.

Patch written by Serhiy Storchaka.
2016-03-26 01:04:37 +01:00
Victor Stinner a9a852c2b1 Modernize Python/makeopcodetargets.py
* Simply use "import opcode" to import the opcode module instead of tricks
  using the imp module
* Use context manager for the output file
* Move code into a new main() function
* Replace assert with a regular if to check the number of arguments
* Import modules at top level
2016-03-25 11:54:47 +01:00
Victor Stinner 4f17426437 Fix bug in __import__ during Python shutdown
Issue #26637: The importlib module now emits an ImportError rather than a
TypeError if __import__() is tried during the Python shutdown process but
sys.path is already cleared (set to None).
2016-03-25 00:40:59 +01:00
Victor Stinner 023654fa68 get_warnings_attr(): Fix coverity warning
Don't check if the dict key exists before getting the key. Instead get the key
and handle error.
2016-03-23 17:48:22 +01:00
Victor Stinner 1c3069aed6 Rework _Py_DumpASCII() to make Coverity happy 2016-03-23 16:10:07 +01:00
Victor Stinner 976bb4099c compiler.c: fix compiler warnings on Windows 2016-03-23 11:36:19 +01:00
Victor Stinner bd31b7c483 Issue #23848: Expose _Py_DumpHexadecimal()
This function will be reused by faulthandler.
2016-03-23 10:32:26 +01:00
Victor Stinner 5dacbd4c42 Cleanup hashtable.h
Issue #26588:

* Pass the hash table rather than the key size to hash and compare functions
* _Py_HASHTABLE_READ_KEY() and _Py_HASHTABLE_ENTRY_READ_KEY() macros now expect
  the hash table as the first parameter, rather than the key size
* tracemalloc_get_traces_fill(): use _Py_HASHTABLE_ENTRY_READ_DATA() rather
  than pointer dereference
* Remove the _Py_HASHTABLE_ENTRY_WRITE_PKEY() macro
* Move "PKEY" and "PDATA" macros inside hashtable.c
2016-03-23 09:52:13 +01:00
Victor Stinner e8c6b2fd1b Issue #26588:
* _Py_HASHTABLE_ENTRY_DATA: change type from "char *" to "const void *"
* Add _Py_HASHTABLE_ENTRY_WRITE_PKEY() macro
* Rename _Py_HASHTABLE_ENTRY_WRITE_DATA() macro to
  _Py_HASHTABLE_ENTRY_WRITE_PDATA()
* Add _Py_HASHTABLE_ENTRY_WRITE_DATA() macro
2016-03-23 09:25:01 +01:00
Victor Stinner e98445a4de _warnings.warn_explicit(): try to import warnings
Issue #26592: _warnings.warn_explicit() now tries to import the warnings module
(Python implementation) if the source parameter is set to be able to log the
traceback where the source was allocated.
2016-03-23 00:54:48 +01:00
Victor Stinner e19558af1b Add a source parameter to warnings.warn()
Issue #26604:

* Add a new optional source parameter to _warnings.warn() and warnings.warn()
* Modify asyncore, asyncio and _pyio modules to set the source parameter when
  logging a ResourceWarning warning
2016-03-23 00:28:08 +01:00
Victor Stinner 285cf0a601 hashtable.h now supports keys of any size
Issue #26588: hashtable.h now supports keys of any size, not only
sizeof(void*). It allows to support key larger than sizeof(void*), but also to
use less memory for key smaller than sizeof(void*).
2016-03-21 22:00:58 +01:00
Victor Stinner 322bc12c31 Ooops, revert changeset ea9efa06c137
Change pushed by mistake, the patch is still under review :-/

"""
_tracemalloc: add domain to trace keys

* hashtable.h: key has now a variable size
* _tracemalloc uses (pointer: void*, domain: unsigned int) as key for traces
"""
2016-03-21 14:36:39 +01:00
Victor Stinner 51b846c47a _tracemalloc: add domain to trace keys
* hashtable.h: key has now a variable size
* _tracemalloc uses (pointer: void*, domain: unsigned int) as key for traces
2016-03-18 21:52:22 +01:00
Victor Stinner 914cde89d4 On ResourceWarning, log traceback where the object was allocated
Issue #26567:

* Add a new function PyErr_ResourceWarning() function to pass the destroyed
  object
* Add a source attribute to warnings.WarningMessage
* Add warnings._showwarnmsg() which uses tracemalloc to get the traceback where
  source object was allocated.
2016-03-19 01:03:51 +01:00
Victor Stinner 1231a4615f Add _showwarnmsg() and _formatwarnmsg() to warnings
Issue #26568: add new  _showwarnmsg() and _formatwarnmsg() functions to the
warnings module.

The C function warn_explicit() now calls warnings._showwarnmsg() with a
warnings.WarningMessage as parameter, instead of calling warnings.showwarning()
with multiple parameters.

_showwarnmsg() calls warnings.showwarning() if warnings.showwarning() was
replaced. Same for _formatwarnmsg(): call warnings.formatwarning() if it was
replaced.
2016-03-19 00:47:17 +01:00
Victor Stinner 2025d7839b Py_FatalError: disable faulthandler earlier
Issue #26563: Py_FatalError: disable faulthandler before trying to flush
sys.stdout and sys.stderr.
2016-03-16 23:19:15 +01:00
Victor Stinner 861d9abfcf faulthandler now works in non-Python threads
Issue #26563:

* Add _PyGILState_GetInterpreterStateUnsafe() function: the single
  PyInterpreterState used by this process' GILState implementation.
* Enhance _Py_DumpTracebackThreads() to retrieve the interpreter state from
  autoInterpreterState in last resort. The function now accepts NULL for interp
  and current_tstate parameters.
* test_faulthandler: fix a ResourceWarning when test is interrupted by CTRL+c
2016-03-16 22:45:24 +01:00
Victor Stinner 013024ef67 Fix compilation error of traceback.c on Windows
Issue #26564.
2016-03-16 09:43:14 +01:00
Victor Stinner 82f04e2dfd regrtest: Fix module.__path__
Issue #26538: libregrtest: Fix setup_tests() to keep module.__path__ type
(_NamespacePath), don't convert to a list.

Add _NamespacePath.__setitem__() method to importlib._bootstrap_external.
2016-03-15 23:08:44 +01:00
Victor Stinner 89e7cdcb9c Enhance and rewrite traceback dump C functions
Issue #26564:

* Expose _Py_DumpASCII() and _Py_DumpDecimal() in traceback.h
* Change the type of the second _Py_DumpASCII() parameter from int to unsigned
  long
* Rewrite _Py_DumpDecimal() and dump_hexadecimal() to write directly characters
  in the expected order, avoid the need of reversing the string.
* dump_hexadecimal() limits width to the size of the buffer
* _Py_DumpASCII() does nothing if the object is not a Unicode string
* dump_frame() wrtites "???" as the line number if the line number is negative
2016-03-15 21:49:37 +01:00
Victor Stinner 8a1be61849 Add more checks on the GIL
Issue #10915, #15751, #26558:

* PyGILState_Check() now returns 1 (success) before the creation of the GIL and
  after the destruction of the GIL. It allows to use the function early in
  Python initialization and late in Python finalization.
* Add a flag to disable PyGILState_Check(). Disable PyGILState_Check() when
  Py_NewInterpreter() is called
* Add assert(PyGILState_Check()) to: _Py_dup(), _Py_fstat(), _Py_read()
  and _Py_write()
2016-03-14 22:07:55 +01:00
Victor Stinner 791da1cc26 Fix Py_FatalError() if called without the GIL
Issue #26558: If Py_FatalError() is called without the GIL, don't try to print
the current exception, nor try to flush stdout and stderr: only dump the
traceback of Python threads.
2016-03-14 16:53:12 +01:00
Victor Stinner 34be807ca4 Add PYTHONMALLOC env var
Issue #26516:

* Add PYTHONMALLOC environment variable to set the Python memory
  allocators and/or install debug hooks.
* PyMem_SetupDebugHooks() can now also be used on Python compiled in release
  mode.
* The PYTHONMALLOCSTATS environment variable can now also be used on Python
  compiled in release mode. It now has no effect if set to an empty string.
* In debug mode, debug hooks are now also installed on Python memory allocators
  when Python is configured without pymalloc.
2016-03-14 12:04:26 +01:00
Yury Selivanov d2dc15b26b Merge 3.5 (issue #25888) 2016-03-02 11:31:06 -05:00
Yury Selivanov c724bae51c coroutines: Error when awaiting on coroutine that's being awaited
Issue #25888
2016-03-02 11:30:46 -05:00
Victor Stinner 2ad474ba5e Update assertion in compiler_addop_i()
In practice, bytecode instruction arguments are unsigned. Update the assertion
to make it more explicit that argument must be greater or equal than 0.

Rewrite also the comment.
2016-03-01 23:34:47 +01:00
Martin Panter 8cacc63002 Issue #22836: Merge exception reporting from 3.5 2016-02-28 03:29:51 +00:00
Martin Panter 3263f6874a Issue #22836: Keep exception reports sensible despite errors 2016-02-28 03:16:11 +00:00
Victor Stinner fc6f2efd13 compile.c: inline compiler_use_new_block()
* Inline compiler_use_new_block() function into its only callee,
  compiler_enter_scope()
* Remove unused NEW_BLOCK() macro
2016-02-27 02:19:22 +01:00
Benjamin Peterson 9d66d4af06 remove unused c_encoding struct member 2016-02-25 23:25:14 -08:00
Benjamin Peterson 768921cf33 rewrite parsestr() so it's comprehensible; remove dead code 2016-02-25 23:13:53 -08:00
Benjamin Peterson 202803a0c0 c_encoding can never be NULL, which allows some code simplification 2016-02-25 22:34:45 -08:00
Brett Cannon 0911c0d271 Merge for issue #26367 2016-02-20 12:59:36 -08:00
Brett Cannon 4f38cb41fe Issue #26367: Have importlib.__init__() raise RuntimeError when
'level' is specified but no __package__.

This brings the function inline with builtins.__import__(). Thanks to
Manuel Jacob for the patch.
2016-02-20 12:52:06 -08:00
Serhiy Storchaka 885bdc4946 Issue #25985: sys.version_info is now used instead of sys.version
to format short Python version.
2016-02-11 13:10:36 +02:00
Serhiy Storchaka a9725f86a9 Issue #26312: SystemError is now raised in all programming bugs with using
PyArg_ParseTupleAndKeywords().  RuntimeError did raised before in some
programming bugs.
2016-02-11 12:41:40 +02:00
Serhiy Storchaka 5b613dd810 Issue #25698: Prevent possible replacing imported module with the empty one
if the stack is too deep.
2016-02-10 10:31:43 +02:00
Serhiy Storchaka 48a583b1d8 Issue #25698: Prevent possible replacing imported module with the empty one
if the stack is too deep.
2016-02-10 10:31:20 +02:00
Victor Stinner 15a3095d64 compiler: don't emit SyntaxWarning on const stmt
Issue #26204: the compiler doesn't emit SyntaxWarning warnings anymore when
constant statements are ignored.
2016-02-08 22:45:06 +01:00
Victor Stinner a2724095cd compiler now ignores constant statements
The compile ignores constant statements and emit a SyntaxWarning warning.

Don't emit the warning for string statement because triple quoted string is a
common syntax for multiline comments.

Don't emit the warning on ellipis neither: 'def f(): ...' is a legit syntax for
abstract functions.

Changes:

* test_ast: ignore SyntaxWarning when compiling test statements. Modify
  test_load_const() to use assignment expressions rather than constant
  expression.
* test_code: add more kinds of constant statements, ignore SyntaxWarning when
  testing that the compiler removes constant statements.
* test_grammar: ignore SyntaxWarning on the statement "1"
2016-02-08 18:17:58 +01:00
Serhiy Storchaka 4cd63ef67a Issue #26198: ValueError is now raised instead of TypeError on buffer
overflow in parsing "es#" and "et#" format units.  SystemError is now raised
instead of TypeError on programmical error in parsing format string.
2016-02-08 01:22:47 +02:00
Serhiy Storchaka 3e17c788a8 Issue #26198: Fixed error messages for some argument parsing errors. 2016-02-08 01:20:21 +02:00
Serhiy Storchaka c4b813d05d Issue #26198: Fixed error messages for some argument parsing errors.
Fixed the documented about buffer overflow error for "es#" and "et#" format
units.
2016-02-08 01:06:11 +02:00
Eric V. Smith eb588a1d10 Switch to more idiomatic C code. 2016-02-05 18:26:20 -05:00
Eric V. Smith 135d5f49f6 Fix issue 26287: While handling FORMAT_VALUE opcode, the top of stack was being corrupted if an error occurred in PyObject_Format(). 2016-02-05 18:23:08 -05:00
Martin Panter cca32995b3 Issue #4806: Merge * unpacking fix from 3.5 2016-01-31 06:33:16 +00:00
Martin Panter b5944220ab Issue #4806: Avoid masking original TypeError in call with * unpacking
Based on patch by Hagen Fürstenau and Daniel Urban.
2016-01-31 06:30:56 +00:00
Victor Stinner be59d1489b Issue #26146: enhance ast.Constant error message
Mention the name of the invalid type in error message of AST validation for
constants.

Suggestion made by Joseph Jevnik on a review.
2016-01-27 00:39:12 +01:00
Victor Stinner 25219f596a Issue #26146: remove useless code
obj2ast_constant() code is baesd on obj2ast_object() which has a special case
for Py_None. But in practice, we don't need to have a special case for
constants.

Issue noticed by Joseph Jevnik on a review.
2016-01-27 00:37:59 +01:00
Victor Stinner 726f6902ce Fix a refleak in validate_constant()
Issue #26146.
2016-01-27 00:11:47 +01:00
Victor Stinner f2c1aa1661 Add ast.Constant
Issue #26146: Add a new kind of AST node: ast.Constant. It can be used by
external AST optimizers, but the compiler does not emit directly such node.

An optimizer can replace the following AST nodes with ast.Constant:

* ast.NameConstant: None, False, True
* ast.Num: int, float, complex
* ast.Str: str
* ast.Bytes: bytes
* ast.Tuple if items are constants too: tuple
* frozenset

Update code to accept ast.Constant instead of ast.Num and/or ast.Str:

* compiler
* docstrings
* ast.literal_eval()
* Tools/parser/unparse.py
2016-01-26 00:40:57 +01:00
Victor Stinner 1aa78938b0 Issue #26146: marshal.loads() now uses the empty frozenset singleton 2016-01-23 14:15:48 +01:00
Brett Cannon 9fa812668f Issue #18018: Raise an ImportError if a relative import is attempted
with no known parent package.

Previously SystemError was raised if the parent package didn't exist
(e.g., __package__ was set to '').
Thanks to Florent Xicluna and Yongzhi Pan for reporting the issue.
2016-01-22 16:39:02 -08:00
Brett Cannon 849113af6b Issue #25791: Warn when __package__ != __spec__.parent.
In a previous change, __spec__.parent was prioritized over
__package__. That is a backwards-compatibility break, but we do
eventually want __spec__ to be the ground truth for module details. So
this change reverts the change in semantics and instead raises an
ImportWarning when __package__ != __spec__.parent to give people time
to adjust to using spec objects.
2016-01-22 15:25:50 -08:00
Victor Stinner b02ef715a3 Use Py_uintptr_t for atomic pointers
Issue #26161: Use Py_uintptr_t instead of void* for atomic pointers in
pyatomic.h. Use atomic_uintptr_t when <stdatomic.h> is used.

Using void* causes compilation warnings depending on which implementation of
atomic types is used.
2016-01-22 14:09:55 +01:00
Victor Stinner 3cdd5fb970 code_richcompare() now uses the constants types
Issue #25843: When compiling code, don't merge constants if they are equal but
have a different types. For example, "f1, f2 = lambda: 1, lambda: 1.0" is now
correctly compiled to two different functions: f1() returns 1 (int) and f2()
returns 1.0 (int), even if 1 and 1.0 are equal.

Add a new _PyCode_ConstantKey() private function.
2016-01-22 12:33:12 +01:00
Victor Stinner efb2413ce8 code_richcompare() now uses the constants types
Issue #25843: When compiling code, don't merge constants if they are equal but
have a different types. For example, "f1, f2 = lambda: 1, lambda: 1.0" is now
correctly compiled to two different functions: f1() returns 1 (int) and f2()
returns 1.0 (int), even if 1 and 1.0 are equal.

Add a new _PyCode_ConstantKey() private function.
2016-01-22 12:33:12 +01:00
Victor Stinner f3914eb16d co_lnotab supports negative line number delta
Issue #26107: The format of the co_lnotab attribute of code objects changes to
support negative line number delta.

Changes:

* assemble_lnotab(): if line number delta is less than -128 or greater than
  127, emit multiple (offset_delta, lineno_delta) in co_lnotab
* update functions decoding co_lnotab to use signed 8-bit integers

  - dis.findlinestarts()
  - PyCode_Addr2Line()
  - _PyCode_CheckLineNumber()
  - frame_setlineno()

* update lnotab_notes.txt
* increase importlib MAGIC_NUMBER to 3361
* document the change in What's New in Python 3.6
* cleanup also PyCode_Optimize() to use better variable names
2016-01-20 12:16:21 +01:00
Victor Stinner b56837a033 Merge 3.5
Issue #26154: Add a new private _PyThreadState_UncheckedGet() function.
2016-01-20 11:19:46 +01:00
Victor Stinner bfd316e750 Add _PyThreadState_UncheckedGet()
Issue #26154: Add a new private _PyThreadState_UncheckedGet() function which
gets the current thread state, but don't call Py_FatalError() if it is NULL.

Python 3.5.1 removed the _PyThreadState_Current symbol from the Python C API to
no more expose complex and private atomic types. Atomic types depends on the
compiler or can even depend on compiler options. The new function
_PyThreadState_UncheckedGet() allows to get the variable value without having
to care of the exact implementation of atomic types.

Changes:

* Replace direct usage of the _PyThreadState_Current variable with a call to
  _PyThreadState_UncheckedGet().
* In pystate.c, replace direct usage of the _PyThreadState_Current variable
  with the PyThreadState_GET() macro for readability.
* Document also PyThreadState_Get() in pystate.h
2016-01-20 11:12:38 +01:00
Georg Brandl 4b5b06203e Fix indentation of continuation lines. 2016-01-18 08:00:15 +01:00
Georg Brandl 5c60ea3fa1 Fix two instances of wrong indentation. 2016-01-18 07:53:59 +01:00
Brett Cannon 63b8505281 Issue #25791: Raise an ImportWarning when __spec__ or __package__ are
not defined for a relative import.

This is the start of work to try and clean up import semantics to rely
more on a module's spec than on the myriad attributes that get set on
a module. Thanks to Rose Ames for the patch.
2016-01-15 13:33:03 -08:00
Serhiy Storchaka 576f132b98 Issue #20440: Cleaning up the code by using Py_SETREF. 2016-01-05 21:27:54 +02:00
Benjamin Peterson 71db903563 merge 3.5 2016-01-01 10:25:22 -06:00
Benjamin Peterson 4c70293755 merge 3.4 2016-01-01 10:25:12 -06:00
Benjamin Peterson e8c2a957c8 merge 3.3 2016-01-01 10:24:21 -06:00
Benjamin Peterson 75e3630c60 2016 will be another year of writing copyrighted code 2016-01-01 10:23:45 -06:00
Benjamin Peterson 5aab44b301 merge 3.5 (#25973) 2015-12-29 10:08:51 -06:00
Benjamin Peterson 3cc8f4b969 make recording and reporting errors and nonlocal and global directives more robust (closes #25973) 2015-12-29 10:08:34 -06:00
Brett Cannon eae3079041 Issue #25802: Deprecate load_module() on importlib.machinery.SourceFileLoader and SourcelessFileLoader.
They were the only remaining implementations of load_module() not
documented as deprecated.
2015-12-28 17:55:27 -08: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 bdb908ea54 Issue #20440: Applied yet one patch for using Py_SETREF.
The patch is automatically generated, it replaces the code that uses Py_CLEAR.
2015-12-27 12:38:28 +02:00
Serhiy Storchaka 4a1e70fc31 Issue #20440: Applied yet one patch for using Py_SETREF.
The patch is automatically generated, it replaces the code that uses Py_CLEAR.
2015-12-27 12:36:18 +02:00
Serhiy Storchaka ef1585eb9a Issue #25923: Added more const qualifiers to signatures of static and private functions. 2015-12-25 20:01:53 +02:00
Serhiy Storchaka 2d06e84455 Issue #25923: Added the const qualifier to static constant arrays. 2015-12-25 19:53:18 +02:00
Serhiy Storchaka f006940351 Issue #20440: Massive replacing unsafe attribute setting code with special
macro Py_SETREF.
2015-12-24 10:39:57 +02:00
Serhiy Storchaka 5a57ade58e Issue #20440: Massive replacing unsafe attribute setting code with special
macro Py_SETREF.
2015-12-24 10:35:59 +02:00
Serhiy Storchaka 3fd4a735d8 Issue #25899: Converted non-ASCII characters in docstrings and manpage
to ASCII replacements.  Removed UTF-8 BOM from Misc/NEWS.
Original patch by Chris Angelico.
2015-12-18 13:10:37 +02:00
Serhiy Storchaka 225821c653 Issue #25899: Converted non-ASCII characters in docstrings and manpage
to ASCII replacements.  Original patch by Chris Angelico.
2015-12-18 13:05:04 +02:00
Martin Panter afaf3544aa Merge typo fixes from 3.5 2015-12-17 10:20:21 +00:00
Martin Panter 6f9b010242 Fix a couple of typos in code comments 2015-12-17 10:18:28 +00:00
Martin Panter b4ce1fc31b Issue #5319: New Py_FinalizeEx() API to exit with status 120 on failure 2015-11-30 03:18:29 +00:00
Victor Stinner b4efc963d6 Issue #25557: Refactor _PyDict_LoadGlobal()
Don't fallback to PyDict_GetItemWithError() if the hash is unknown: compute the
hash instead. Add also comments to explain the optimization a little bit.
2015-11-20 09:24:02 +01:00