Commit Graph

5702 Commits

Author SHA1 Message Date
Benjamin Peterson 9b3d77052f replace Python aliases for standard integer types with the standard integer types (#17884) 2016-09-06 13:24:00 -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 d953f8e10b remove some silly defined() tests 2016-09-06 10:51:19 -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
Victor Stinner 942889aae2 Issue #27938: Add a fast-path for us-ascii encoding
Other changes:

* Rewrite _Py_normalize_encoding() as a C implementation of
  encodings.normalize_encoding(). For example, " utf-8 " is now normalized to
  "utf_8". So the fast path is now used for more name variants of the same
  encoding.
* Avoid strcpy() when encoding is NULL: call directly the UTF-8 codec
2016-09-05 15:40:10 -07:00
Eric Snow 92a6c170e6 Issue #24254: Preserve class attribute definition order. 2016-09-05 14:50:11 -07:00
Benjamin Peterson 55f445282d remove memory indirections in dict_traverse (closes #27956) 2016-09-05 12:12:59 -07:00
Victor Stinner 2250c4cb81 Issue #27830: Remove unused _PyStack_AsDict()
I forgot to remove this function, I made a mistake in my revert.
2016-09-05 11:43:18 -07:00
Benjamin Peterson 7b24b27302 merge 3.5 (#27812) 2016-09-05 10:40:34 -07:00
Benjamin Peterson bdddb11b0e clear out f_gen during generator finalization (closes #27812)
Patch from Armin Rigo.
2016-09-05 10:39:57 -07:00
Benjamin Peterson 98020812e6 merge 3.5 (closes #27811) 2016-09-05 10:16:31 -07:00
Benjamin Peterson 2f40ed4b94 do not allow _PyGen_Finalize to fail (closes #27811)
Patch from Armin Rigo.
2016-09-05 10:14:54 -07:00
Mark Dickinson 7c4e409d07 Issue #11734: Add support for IEEE 754 half-precision floats to the struct module. Original patch by Eli Stevens. 2016-09-03 17:21:29 +01:00
Victor Stinner 1a05d6c04d PEP 7 style for if/else in C
Add also a newline for readability in normalize_encoding().
2016-09-02 12:12:23 +02:00
Raymond Hettinger 15f44ab043 Issue #27895: Spelling fixes (Contributed by Ville Skyttä). 2016-08-30 10:47:49 -07:00
Mark Dickinson 82a95277b8 Issue #27870: A left shift of zero by a large integer no longer attempts to allocate large amounts of memory. 2016-08-29 19:27:06 +01:00
Mark Dickinson 4e1de16f88 Issue #25402: in int-to-decimal-string conversion, reduce intermediate storage requirements and relax restriction on converting large integers. Patch by Serhiy Storchaka. 2016-08-29 17:26:43 +01:00
Mark Dickinson 583c6e860c Issue #27214: Fix potential bug and remove useless optimization in long_invert. Thanks Oren Milman. 2016-08-29 16:40:29 +01:00
Martin Panter 1b6c6da85d Issue #27506: Support bytes/bytearray.translate() delete as keyword argument
Patch by Xiang Zhang.
2016-08-27 08:35:02 +00: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 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 f7507dd3e8 Issue #27830: Fix _PyObject_FastCallKeywords()
Pass stack, not unrelated and uninitialized args!
2016-08-25 01:00:31 +02:00
Victor Stinner 53cb489ed0 _PyObject_FastCallDict(): avoid _Py_CheckFunctionResult()
_PyObject_FastCallDict() only requires _Py_CheckFunctionResult() for the
slow-path. Other cases already check for the result.
2016-08-25 00:39:34 +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 dd69564c38 PyObject_CallMethodObjArgs() now uses fast call
Issue #27809:

* PyObject_CallMethodObjArgs(), _PyObject_CallMethodIdObjArgs() and
  PyObject_CallFunctionObjArgs() now use fast call to avoid the creation of a
  temporary tuple
* Rename objargs_mktuple() to objargs_mkstack()
* objargs_mkstack() now stores objects in a C array using borrowed references,
  instead of storing arguments into a tuple

objargs_mkstack() uses a small buffer allocated on the C stack for 5 arguments
or less, or allocates a buffer in the heap memory.

Note: this change is different than the change 0e4f26083bbb, I fixed the test
to decide if the small stack can be used or not. sizeof(PyObject**) was also
replaced with sizeof(stack[0]) since the sizeof() was wrong (but gave the same
result).
2016-08-24 01:14:54 +02:00
Victor Stinner d48af09043 Backed out changeset 0e4f26083bbb (PyObject_CallMethodObjArgs) 2016-08-24 00:59:40 +02:00
Victor Stinner e62b852605 PyObject_CallMethodObjArgs() now uses fast call
Issue #27809:

* PyObject_CallMethodObjArgs(), _PyObject_CallMethodIdObjArgs() and
  PyObject_CallFunctionObjArgs() now use fast call to avoid the creation of a
  temporary tuple
* Rename objargs_mktuple() to objargs_mkstack()
* objargs_mkstack() now stores objects in a C array using borrowed references,
  instead of storing arguments into a tuple

objargs_mkstack() uses a small buffer allocated on the C stack for 5 arguments
or less, or allocates a buffer in the heap memory.
2016-08-24 00:01:56 +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 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 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
Mark Dickinson b820d7f631 Issue #27792: force int return type for modulo operations involving bools. 2016-08-22 12:24:46 +01:00
Serhiy Storchaka 54cd1969ea Issue #26984: int() now always returns an instance of exact int. 2016-08-21 20:03:08 +03:00
Mark Dickinson 1dc3c898a8 Untabify Objects/longobject.c. 2016-08-21 10:33:36 +01:00
Mark Dickinson dc590a4cc3 Issue #25604: Fix minor bug in integer true division, which could
have caused off-by-one-ulp results on certain platforms.
2016-08-21 10:23:23 +01:00
Mark Dickinson 5d13238f6e Issue #27662: don't use PY_SIZE_MAX for overflow checking in List_New. Patch by Xiang Zhang. 2016-08-21 08:55:15 +01:00
Nick Coghlan cbcd221de4 Merge #27782 fix from 3.5 2016-08-21 17:43:58 +10:00
Nick Coghlan 8682f578c1 Issue #27782: Fix m_methods handling in multiphase init
Multi-phase extension module import now correctly allows the
``m_methods`` field to be used to add module level functions
to instances of non-module types returned from ``Py_create_mod``.

Patch by Xiang Zhang.
2016-08-21 17:41:56 +10:00
Serhiy Storchaka 3766572a48 Issue #27692: Removed unnecessary NULL checks in exceptions.c.
Patch by Xiang Zhang.
2016-08-20 21:22:03 +03:00
Victor Stinner 253021dd94 Issue #27366: Fix init_subclass()
Handle PyTuple_New(0) failure.
2016-08-20 02:37:41 +02:00
Victor Stinner 9def0901e2 PyFile_WriteObject() now uses fast call
Issue #27128: PyFile_WriteObject() now calls _PyObject_FastCall() to avoid the
creation of a temporary tuple.
2016-08-20 00:44:04 +02:00
Victor Stinner 99ee9c70a7 calliter_iternext() now uses fast call
Issue #27128: calliter_iternext() now calls _PyObject_FastCall() to avoid a
temporary empty tuple.

Cleanup also the code to reduce the indentation level.
2016-08-19 18:47:10 +02:00
Victor Stinner 6911267615 slot_tp_iter() now uses fast call
Issue #27128: slot_tp_iter() now calls _PyObject_FastCall() to avoid a
temporary empty tuple.
2016-08-19 18:41:02 +02:00
Victor Stinner 20a3007a8d slot_nb_bool() now uses fast call
Issue #27128: slot_nb_bool() now calls _PyObject_FastCall() to avoid a
temporary empty tuple to call the slot function.
2016-08-19 18:28:25 +02:00
Victor Stinner a12eec48b6 Issue #27128: Cleanup slot_nb_bool()
Use an error label to reduce the level of indentation.
2016-08-19 18:26:05 +02:00
Victor Stinner 5e87749a8e Issue #27128: slot_sq_item() uses fast call
slot_sq_item() now calls _PyObject_FastCall() to avoid the creation of a
temporary tuple of 1 item to pass the 'item' argument to the slot function.
2016-08-19 18:19:42 +02:00
Victor Stinner 018016d8e3 Issue #27128: Cleanup slot_sq_item()
* Invert condition of test to avoid levels of indentation
* Remove useless Py_XDECREF(args) in the error block
* Replace Py_XDECREF(func) with Py_DECREF(func) in the error block: func cannot
  be NULL when reaching the error block
2016-08-19 18:17:37 +02:00
Victor Stinner f736c261a2 call_method() and call_maybe() now use fast call
Issue #27128. The call_method() and call_maybe() functions of typeobject.c now
use fast call for empty format string to avoid the creation of a temporary
empty tuple.
2016-08-19 18:05:37 +02:00
Victor Stinner 94463c980e Cleanup call_method() and call_maybe()
Issue #27128. Move va_start/va_end around Py_VaBuildValue().
2016-08-19 18:01:41 +02:00
Victor Stinner 56142c701b Merge 3.5 (fix refleak in call_maybe()) 2016-08-19 17:58:30 +02:00
Victor Stinner 6902ddf2ca Fix a refleak in call_maybe()
Issue #27128. Fix a reference leak if creating the tuple to pass positional
parameters fails.
2016-08-19 17:58:12 +02:00
Victor Stinner 59e9ca6bda Merge 3.5 (fix refleak in call_method) 2016-08-19 17:52:08 +02:00
Victor Stinner d925bd5794 Fix a refleak in call_method()
Issue #27128. Fix a reference leak if creating the tuple to pass positional
parameters fails.
2016-08-19 17:51:49 +02:00
Victor Stinner a7720f61aa contains and rich compare slots use fast call
Issue #27128. Modify slot_sq_contains() and slot_tp_richcompare() to use fast
call to avoid a temporary tuple to pass a single positional parameter.
2016-08-19 17:48:51 +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 0d1a799343 Avoid call_function_tail() for empty format str
Issue #27128, PyObject_CallFunction(), _PyObject_FastCall() and callmethod():
if the format string of parameters is empty, avoid the creation of an empty
tuple: call _PyObject_FastCall() without parameters.
2016-08-19 17:04:54 +02:00
Victor Stinner 71aea8e981 PEP 7: add {...} around null_error() in abstract.c
Issue #27128.
2016-08-19 16:59:55 +02:00
Victor Stinner d042f1f5eb Cleanup callmethod()
Make callmethod() less weird: don't decrement func reference counter,
the caller is now responsible to do that.

Issue #27128.
2016-08-19 16:56:49 +02:00
Victor Stinner 64faad6e45 Cleanup call_function_tail()
Make call_function_tail() less weird: don't decrement args reference counter,
the caller is now responsible to do that. The caller now also checks if args is
NULL.

Issue #27128.
2016-08-19 16:50:49 +02:00
Victor Stinner 8880708f81 call_function_tail() uses fast call
Issue #27128: Modify call_function_tail() to use _PyObject_FastCall() when args
is not a tuple to avoid the creation of a temporary tuple.

call_function_tail() is used by:

* PyObject_CallFunction()
* PyObject_CallMethod()
* _PyObject_CallMethodId()
2016-08-19 16:44:19 +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
Berker Peksag 7fbce56a57 Issue #12946: Remove dead code in PyModule_GetDict
PyModule_NewObject already sets md_dict to PyDict_New():

    m->md_dict = PyDict_New();
2016-08-19 12:00:13 +03:00
Berker Peksag 3f015a64b8 Issue #27157: Make only type() itself accept the one-argument form
Patch by Eryk Sun and Emanuel Barry.
2016-08-19 11:04:07 +03:00
Guido van Rossum 97c1adf393 Anti-registration of various ABC methods.
- Issue #25958: Support "anti-registration" of special methods from
  various ABCs, like __hash__, __iter__ or __len__.  All these (and
  several more) can be set to None in an implementation class and the
  behavior will be as if the method is not defined at all.
  (Previously, this mechanism existed only for __hash__, to make
  mutable classes unhashable.)  Code contributed by Andrew Barnert and
  Ivan Levkivskyi.
2016-08-18 09:22:23 -07:00
Victor Stinner 8bcf312d09 Issue #27786: Simplify x_sub()
The z variable is known to be a fresh number which cannot be shared, Py_SIZE()
can be used directly to negate the number.
2016-08-17 19:48:33 +02:00
Serhiy Storchaka eb24988962 Issue #27704: Optimized creating bytes and bytearray from byte-like objects
and iterables.  Speed up to 3 times for short objects.  Original patch by
Naoki Inada.
2016-08-15 09:46:07 +03: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
Serhiy Storchaka febc332056 Issue #26754: Undocumented support of general bytes-like objects
as path in compile() and similar functions is now deprecated.
2016-08-06 23:29:29 +03: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
Berker Peksag a787e5f31d Issue #27652: Expose ESHUTDOWN conditionally
ESHUTDOWN is also exposed conditionally in Modules/errnomodule.c.

Patch by Ed Schouten.
2016-07-30 14:14:12 +03:00
Berker Peksag 01d1719062 Issue #27366: Tweak PEP 487 documentation
* Added versionadded directives
* Deleted duplicate sentence from __init_subclass__ docstring
* Modernized tests
2016-07-30 14:06:15 +03:00
Nick Coghlan d78448e912 Issue #27366: Implement PEP 487
- __init_subclass__ called when new subclasses defined
- __set_name__ called when descriptors are part of a
  class definition
2016-07-30 16:26:03 +10:00
Martin Panter 8bde911115 Issue #27626: Merge spelling fixes from 3.5 2016-07-28 01:30:58 +00:00
Martin Panter eb9957065a Issue #27626: Spelling fixes in docs, comments and internal names
Based on patch by Ville Skyttä.
2016-07-28 01:11:04 +00:00
Xavier de Gaye 8d4989687c (merge from 3.5) Issue #26662: Set PYTHON_FOR_GEN in configure
as the Python program to be used for file generation during the build.
2016-07-26 12:55:20 +02:00
Xavier de Gaye fd0d5939bd Issue #26662: Set PYTHON_FOR_GEN in configure
as the Python program to be used for file generation during the build.
2016-07-26 12:48:08 +02:00
Martin Panter b93d8637a6 Issue #1621: Avoid signed overflow in list and tuple operations
Patch by Xiang Zhang.
2016-07-25 02:39:20 +00:00
Martin Panter 32d2ce3561 Issue #27581: Merge overflow fix from 3.5 2016-07-25 03:31:29 +00:00
Martin Panter e8db861f47 Issue #27581: Don’t rely on overflow wrapping in PySequence_Tuple()
Patch by Xiang Zhang.
2016-07-25 02:30:05 +00:00
Berker Peksag ced8d4c6eb Issue #27454: Use PyDict_SetDefault in PyUnicode_InternInPlace
Patch by INADA Naoki.
2016-07-25 04:40:39 +03:00
Martin Panter bd09f15b69 Issue #27507: Merge overflow check from 3.5 2016-07-18 08:18:32 +00:00
Martin Panter 371731ebfd Issue #27507: Check for integer overflow in bytearray.extend()
Patch by Xiang Zhang.
2016-07-18 07:53:13 +00:00
Benjamin Peterson ab078e9ed1 Backed out changeset af29d89083b3 (closes #25548) (closes #27498) 2016-07-13 21:13:29 -07:00
Serhiy Storchaka ca0da9b0a3 Issue #27473: Fixed possible integer overflow in bytes and bytearray
concatenations.  Patch by Xiang Zhang.
2016-07-10 20:51:35 +03:00
Serhiy Storchaka 06cfb0cd70 Issue #27473: Fixed possible integer overflow in bytes and bytearray
concatenations.  Patch by Xiang Zhang.
2016-07-10 20:48:43 +03:00
R David Murray ce85acff3a Merge: #20647: Update dictobject.c comments to account for randomized string hashes. 2016-07-10 12:40:03 -04:00
R David Murray 537ad7ad9f #20647: Update dictobject.c comments to account for randomized string hashes.
Patch by Jaysinh Shukla.
2016-07-10 12:33:18 -04:00
Serhiy Storchaka f9efb8b18b Issue #27474: Unified error messages in the __contains__ method of bytes and
bytearray for integers in and out of the Py_ssize_t range.
Patch by Xiang Zhang.
2016-07-10 12:37:30 +03:00
Benjamin Peterson c13d85bf8d merge 3.5 (#27248)
Patch from Xiang Zhang.
2016-07-06 23:28:19 -07:00
Benjamin Peterson 27007dccec fix refleaks in PyDict_SetItem error cases (closes #27248) 2016-07-06 23:26:32 -07:00
Serhiy Storchaka f54d7811c3 Issue #27460: Unified error messages in bytes constructor for integers
in and out of the Py_ssize_t range.  Patch by Xiang Zhang.
2016-07-06 21:39:44 +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 6c94d10a19 Issue #27443: __length_hint__() of bytearray itearator no longer return
negative integer for resized bytearray.
2016-07-03 14:42:17 +03:00