summaryrefslogtreecommitdiff
path: root/Python/bltinmodule.c
AgeCommit message (Collapse)AuthorLines
2018-08-24closes bpo-34474: Python/bltinmodule.c: Add missing NULL check in ↵Miss Islington (bot)-0/+5
builtin_sum_impl() (GH-8872) Reported by Svace static analyzer. (cherry picked from commit 2b824b2538c4a5f9f520c5de8a1eae5a0c181a94) Co-authored-by: Alexey Izbyshev <izbyshev@ispras.ru>
2018-02-01bpo-32674: Improve the docstring for __import__ (GH-5339) (GH-5488)Miss Islington (bot)-3/+3
Clarify that the level argument is used to determine whether to perform absolute or relative imports: 0 is absolute, while a positive number is the number of parent directories to search relative to the current module. (cherry picked from commit 461d225b195eec5269f317323b41115516144c41) Co-authored-by: oldk <oldk1331@users.noreply.github.com>
2018-01-25 bpo-32571: Avoid raising unneeded AttributeError and silencing it in C code ↵Serhiy Storchaka-24/+13
(GH-5222) Add two new private APIs: _PyObject_LookupAttr() and _PyObject_LookupAttrId()
2018-01-18bpo-9566: Fix size_t=>int downcast warnings (#5230)Victor Stinner-2/+2
* Use wider types (int => Py_ssize_t) to avoid integer overflows. * Fix gc.get_freeze_count(): use Py_ssize_t type rather than int, since gc_list_size() returns a Py_ssize_t.
2018-01-16bpo-32544: Speed up hasattr() and getattr() (GH-5173)INADA Naoki-10/+11
AttributeError was raised always when attribute is not found. This commit skip raising AttributeError when `tp_getattro` is `PyObject_GenericGetAttr`. It makes hasattr() and getattr() about 4x faster when attribute is not found.
2017-12-16bpo-29240, bpo-32030: Py_Main() re-reads config if encoding changes (#4899)Victor Stinner-3/+4
bpo-29240, bpo-32030: If the encoding change (C locale coerced or UTF-8 Mode changed), Py_Main() now reads again the configuration with the new encoding. Changes: * Add _Py_UnixMain() called by main(). * Rename pymain_free_pymain() to pymain_clear_pymain(), it can now be called multipled times. * Rename pymain_parse_cmdline_envvars() to pymain_read_conf(). * Py_Main() now clears orig_argc and orig_argv at exit. * Remove argv_copy2, Py_Main() doesn't modify argv anymore. There is no need anymore to get two copies of the wchar_t** argv. * _PyCoreConfig: add coerce_c_locale and coerce_c_locale_warn. * Py_UTF8Mode is now initialized to -1. * Locale coercion (PEP 538) now respects -I and -E options.
2017-12-15bpo-32240: Add the const qualifier to declarations of PyObject* array ↵Serhiy Storchaka-6/+6
arguments. (#4746)
2017-12-14bpo-32226: Implementation of PEP 560 (core components) (#4732)Ivan Levkivskyi-3/+92
This part of the PEP implementation adds support for __mro_entries__ and __class_getitem__ by updating __build_class__ and PyObject_GetItem.
2017-12-13bpo-29240: PEP 540: Add a new UTF-8 Mode (#855)Victor Stinner-0/+3
* Add -X utf8 command line option, PYTHONUTF8 environment variable and a new sys.flags.utf8_mode flag. * If the LC_CTYPE locale is "C" at startup: enable automatically the UTF-8 mode. * Add _winapi.GetACP(). encodings._alias_mbcs() now calls _winapi.GetACP() to get the ANSI code page * locale.getpreferredencoding() now returns 'UTF-8' in the UTF-8 mode. As a side effect, open() now uses the UTF-8 encoding by default in this mode. * Py_DecodeLocale() and Py_EncodeLocale() now use the UTF-8 encoding in the UTF-8 Mode. * Update subprocess._args_from_interpreter_flags() to handle -X utf8 * Skip some tests relying on the current locale if the UTF-8 mode is enabled. * Add test_utf8mode.py. * _Py_DecodeUTF8_surrogateescape() gets a new optional parameter to return also the length (number of wide characters). * pymain_get_global_config() and pymain_set_global_config() now always copy flag values, rather than only copying if the new value is greater than the old value.
2017-11-15bpo-30950: Convert round() to Argument Clinic. (#2740)Serhiy Storchaka-19/+16
2017-11-11Add the const qualifier to "char *" variables that refer to literal strings. ↵Serhiy Storchaka-1/+1
(#4370)
2017-10-05PEP 553 built-in breakpoint() function (bpo-31353) (#3355)Barry Warsaw-0/+23
Implement PEP 553, built-in breakpoint() with support from sys.breakpointhook(), along with documentation and tests. Closes bpo-31353
2017-09-28bpo-31588: Validate return value of __prepare__() methods (GH-3764)Oren Milman-0/+7
Class execution requires that __prepare__() methods return a proper execution namespace. Check for that immediately after calling __prepare__(), rather than passing it through to the code execution machinery and potentially triggering SystemError (in debug builds) or a cryptic TypeError (in release builds). Patch by Oren Milman.
2017-09-14bpo-28411: Isolate PyInterpreterState.modules (#3575)Eric Snow-1/+1
A bunch of code currently uses PyInterpreterState.modules directly instead of PyImport_GetModuleDict(). This complicates efforts to make changes relative to sys.modules. This patch switches to using PyImport_GetModuleDict() uniformly. Also, a number of related uses of sys.modules are updated for uniformity for the same reason. Note that this code was already reviewed and merged as part of #1638. I reverted that and am now splitting it up into more focused parts.
2017-09-13bpo-31404: Revert "remove modules from Py_InterpreterState (#1638)" (#3565)Eric Snow-1/+1
PR #1638, for bpo-28411, causes problems in some (very) edge cases. Until that gets sorted out, we're reverting the merge. PR #3506, a fix on top of #1638, is also getting reverted.
2017-09-04bpo-28411: Remove "modules" field from Py_InterpreterState. (#1638)Eric Snow-1/+1
sys.modules is the one true source.
2017-08-21bpo-31236: Improved some error messages of min() and max().Oren Milman-2/+3
2017-07-03bpo-29464: Rename METH_FASTCALL to METH_FASTCALL|METH_KEYWORDS and make (#1955)Serhiy Storchaka-15/+5
the bare METH_FASTCALL be used for functions with positional-only parameters.
2017-06-15bpo-20627: Fix error message when keyword arguments are used (#2115)Sylvain-6/+6
2017-06-08bpo-30592: Fixed error messages for some builtins. (#1996)Serhiy Storchaka-3/+3
Error messages when pass keyword arguments to some builtins that don't support keyword arguments contained double parenthesis: "()()". The regression was introduced by bpo-30534.
2017-05-29Add reference to help('FORMATTING') in format() builtin (GH-166)Amit Kumar-2/+4
2017-04-19bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() (#1096)Serhiy Storchaka-1/+2
raised an error. Replace them with using concrete types API that never fails if appropriate.
2017-04-16bpo-29838: Add asserts for checking results of sq_length and mq_length ↵Serhiy Storchaka-1/+3
slots. (#700) Negative result should be returned only when an error is set.
2017-03-12bpo-8256: Fixed possible failing or crashing input() (#517)Serhiy Storchaka-5/+16
if attributes "encoding" or "errors" of sys.stdin or sys.stdout are not set or are not strings.
2017-03-12bpo-24037: Add Argument Clinic converter `bool(accept={int})`. (#485)Serhiy Storchaka-2/+2
2017-02-16bpo-29556: Remove unused #include <langinfo.h> (#98)Yen Chi Hsuan-4/+0
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-01-23Issue #26729: Fixed __text_signature__ for sorted().Serhiy Storchaka-1/+1
Patch by Erik Welch.
2017-01-23Issue #26729: Fixed __text_signature__ for sorted().Serhiy Storchaka-1/+1
Patch by Erik Welch.
2017-01-23Issue #26729: Fixed __text_signature__ for sorted().Serhiy Storchaka-1/+1
Patch by Erik Welch.
2017-01-23Issue #28999: Use Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE whereverSerhiy Storchaka-4/+2
possible. Patch is writen with Coccinelle.
2017-01-21Issue #29331: Simplified argument parsing in sorted() and list.sort().Serhiy Storchaka-8/+4
2017-01-20Issue #29327: Fixed a crash when pass the iterable keyword argument to sorted().Serhiy Storchaka-1/+2
2017-01-20Issue #29327: Fixed a crash when pass the iterable keyword argument to sorted().Serhiy Storchaka-1/+2
2017-01-19Issue #29296: convert print() to METH_FASTCALLINADA Naoki-11/+11
* 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-17sorted() uses METH_FASTCALLVictor Stinner-11/+9
2017-01-17next() uses FASTCALLVictor Stinner-3/+9
2017-01-17getattr() uses METH_FASTCALLVictor Stinner-3/+8
2017-01-16__build_class__() builtin uses METH_FASTCALLVictor Stinner-15/+9
2016-12-15Add _PY_FASTCALL_SMALL_STACK constantVictor Stinner-1/+1
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-06Use _PyObject_CallNoArg()Victor Stinner-1/+1
Replace: PyObject_CallFunctionObjArgs(callable, NULL) with: _PyObject_CallNoArg(callable)
2016-12-05Merge #23722 from 3.6Nick Coghlan-5/+35
2016-12-05Issue #23722: improve __classcell__ compatibilityNick Coghlan-5/+35
Handling zero-argument super() in __init_subclass__ and __set_name__ involved moving __class__ initialisation to type.__new__. This requires cooperation from custom metaclasses to ensure that the new __classcell__ entry is passed along appropriately. The initial implementation of that change resulted in abruptly broken zero-argument super() support in metaclasses that didn't adhere to the new requirements (such as Django's metaclass for Model definitions). The updated approach adopted here instead emits a deprecation warning for those cases, and makes them work the same way they did in Python 3.5. This patch also improves the related class machinery documentation to cover these details and to include more reader-friendly cross-references and index entries.
2016-12-04Backed out changeset b9c9691c72c5Victor Stinner-4/+4
Issue #28858: The change b9c9691c72c5 introduced a regression. It seems like _PyObject_CallArg1() uses more stack memory than PyObject_CallFunctionObjArgs().
2016-12-01Replace PyObject_CallFunctionObjArgs() with fastcallVictor Stinner-4/+4
* PyObject_CallFunctionObjArgs(func, NULL) => _PyObject_CallNoArg(func) * PyObject_CallFunctionObjArgs(func, arg, NULL) => _PyObject_CallArg1(func, arg) PyObject_CallFunctionObjArgs() allocates 40 bytes on the C stack and requires extra work to "parse" C arguments to build a C array of PyObject*. _PyObject_CallNoArg() and _PyObject_CallArg1() are simpler and don't allocate memory on the C stack. This change is part of the fastcall project. The change on listsort() is related to the issue #23507.
2016-11-20Added the const qualifier to char* variables that refer to readonly internalSerhiy Storchaka-2/+2
UTF-8 represenatation of Unicode objects.
2016-11-20Replaced outdated macros _PyUnicode_AsString and _PyUnicode_AsStringAndSizeSerhiy Storchaka-4/+4
with PyUnicode_AsUTF8 and PyUnicode_AsUTF8AndSize.
2016-09-11Issue #23722: Initialize __class__ from type.__new__()Nick Coghlan-6/+4
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-08Issue #24254: Drop cls.__definition_order__.Eric Snow-1/+1
2016-09-03Issue 27936: Fix inconsistent round() behavior between float and intRaymond Hettinger-1/+1
2016-09-08Issue #27781: Change file system encoding on Windows to UTF-8 (PEP 529)Steve Dower-3/+5