Commit Graph

11860 Commits

Author SHA1 Message Date
Victor Stinner c38fd0df2b
bpo-39353: binascii.crc_hqx() is no longer deprecated (GH-18276)
The binascii.crc_hqx() function is no longer deprecated.
2020-01-30 09:56:40 +01:00
Alex Henrie 188bb5b1e8
bpo-39494: Remove extra null terminators from kwlist vars (GH-18267) 2020-01-30 07:12:53 +03:00
Zackery Spytz 13c1c3556f bpo-39393: Misleading error message on dependent DLL resolution failure (GH-18093) 2020-01-28 20:42:43 +11:00
Victor Stinner 656c45ec9a
bpo-38631: Avoid Py_FatalError() in GC collect() (GH-18164)
collect() should not get an exception, but it does, logging the
exception is enough. Override sys.unraisablehook to decide how to
handle unraisable exceptions.

Py_FatalError() should be avoided whenever possible.
2020-01-24 18:05:24 +01:00
Victor Stinner b8d1262e8a
bpo-39395: putenv() and unsetenv() always available (GH-18135)
The os.putenv() and os.unsetenv() functions are now always available.

On non-Windows platforms, Python now requires setenv() and unsetenv()
functions to build.

Remove putenv_dict from posixmodule.c: it's not longer needed.
2020-01-24 14:05:48 +01:00
Victor Stinner 161e7b36b1
bpo-39413: Implement os.unsetenv() on Windows (GH-18163)
The os.unsetenv() function is now also available on Windows.
2020-01-24 11:53:44 +01:00
Mark Dickinson e9652e8d58 bpo-39426: Fix outdated default and highest protocols in docs (GH-18154)
Some portions of the pickle documentation hadn't been updated for the pickle protocol changes in Python 3.8 (new protocol 5, default protocol 4). This PR fixes those docs.


https://bugs.python.org/issue39426
2020-01-24 02:03:22 -08:00
Pablo Galindo 79f89e6e5a
bpo-39421: Fix posible crash in heapq with custom comparison operators (GH-18118)
* bpo-39421: Fix posible crash in heapq with custom comparison operators

* fixup! bpo-39421: Fix posible crash in heapq with custom comparison operators

* fixup! fixup! bpo-39421: Fix posible crash in heapq with custom comparison operators
2020-01-23 14:07:05 +00:00
Victor Stinner b477d19a6b
bpo-39406: Implement os.putenv() with setenv() if available (GH-18128)
If setenv() C function is available, os.putenv() is now implemented
with setenv() instead of putenv(), so Python doesn't have to handle
the environment variable memory.
2020-01-22 22:48:16 +01:00
Victor Stinner 0852c7dd52
bpo-39406: os.putenv() avoids putenv_dict on Windows (GH-18126)
Windows: _wputenv(env) copies the *env* string and doesn't require
the caller to manage the variable memory.
2020-01-22 21:53:26 +01:00
Victor Stinner b73dd02ea7
Revert "bpo-39413: Implement os.unsetenv() on Windows (GH-18104)" (GH-18124)
This reverts commit 56cd3710a1.
2020-01-22 21:11:17 +01:00
Victor Stinner beea26b57e
bpo-39353: Deprecate the binhex module (GH-18025)
Deprecate binhex4 and hexbin4 standards. Deprecate the binhex module
and the following binascii functions:

* b2a_hqx(), a2b_hqx()
* rlecode_hqx(), rledecode_hqx()
* crc_hqx()
2020-01-22 20:44:22 +01:00
Victor Stinner 623ed6171e
bpo-39406: Add PY_PUTENV_DICT macro to posixmodule.c (GH-18106)
Rename posix_putenv_garbage to putenv_dict.
2020-01-21 19:25:32 +01:00
Victor Stinner 56cd3710a1
bpo-39413: Implement os.unsetenv() on Windows (GH-18104)
The os.unsetenv() function is now also available on Windows.

It is implemented with SetEnvironmentVariableW(name, NULL).
2020-01-21 16:13:09 +01:00
Victor Stinner 85ead4fc62
bpo-39396: Fix math.nextafter(-0.0, +0.0) on AIX 7.1 (GH-18094)
Move also math.nextafter() on math.ulp() tests from IsCloseTests to
MathTests.
2020-01-21 11:14:10 +01:00
Niklas Fiekas c5b79003f5 bpo-31031: Unify duplicate bits_in_digit and bit_length (GH-2866)
Add _Py_bit_length() to unify duplicate bits_in_digit() and bit_length().
2020-01-16 15:09:19 +01:00
Hai Shi ed154c387e bpo-1635741: Port _json extension module to multiphase initialization (PEP 489) (GH-17835) 2020-01-15 17:32:51 +01:00
Václav Bartoš f04750bb7a bpo-38361: syslog: fixed making default "ident" from sys.argv[0] (GH-16557)
The default value of "ident" parameter should be sys.argv[0] with leading path
components stripped, but it contained the last slash, i.e. '/program' instead
of 'program'.

BPO issue: https://bugs.python.org/issue38361


https://bugs.python.org/issue38361
2020-01-14 09:57:04 -08:00
Pablo Galindo b6791375b2
bpo-39322: Add gc.is_finalized to the gc module docstring (GH-18000) 2020-01-14 17:38:15 +00:00
Pablo Galindo a2ec3f07f7
bpo-39322: Add gc.is_finalized to check if an object has been finalised by the gc (GH-17989) 2020-01-14 12:06:45 +00:00
Pablo Galindo 97f1267a54
Fix typos in gcmodule.c and restructure comments for clarity (GH-17983) 2020-01-13 12:25:05 +00:00
Victor Stinner 0b2ab21956
bpo-39310: Add math.ulp(x) (GH-17965)
Add math.ulp(): return the value of the least significant bit
of a float.
2020-01-13 12:44:35 +01:00
Vinay Sajip c12440c371
bpo-16575: Disabled checks for union types being passed by value. (GH-17960)
Although the underlying libffi issue remains open, adding these
checks have caused problems in third-party projects which are in
widespread use. See the issue for examples.

The corresponding tests have also been skipped.
2020-01-12 08:54:00 +00:00
Victor Stinner 100fafcf20
bpo-39288: Add math.nextafter(x, y) (GH-17937)
Return the next floating-point value after x towards y.
2020-01-12 02:15:42 +01:00
Alex Henrie a1c1be24cb bpo-39272: Remove dead assignment from _ssl__SSLContext_load_verify_locations_impl (GH-17916) 2020-01-09 10:12:12 +01:00
Alex Henrie 1a183faccb bpo-39271: Remove dead assignment from pattern_subx (GH-17915) 2020-01-09 08:27:51 +02:00
Alex Henrie 5cae042f68 closes bpo-39262: Use specific out-of-memory message in _sharedexception_bind. (GH-17908) 2020-01-08 18:48:52 -08:00
Alex Henrie 998c54948a bpo-39237, datetime: Remove redundant call to round from delta_new (GH-17877) 2020-01-08 13:52:44 +01:00
Victor Stinner 5b23f7618d
bpo-39239: epoll.unregister() no longer ignores EBADF (GH-17882)
The select.epoll.unregister() method no longer ignores the EBADF
error.
2020-01-07 15:00:02 +01:00
Anthony Shaw 7dc72b8d4f bpo-28367: Add additional baud rates for termios (GH-13142)
Co-authored-by: Andrey Smirnov <andrew.smirnov@gmail.com>.

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2020-01-04 13:56:31 +01:00
Zackery Spytz e02ab59fdf bpo-38532: Add missing decrefs in PyCFuncPtr_FromDll() (GH-16857) 2020-01-03 13:16:12 +01:00
Pablo Galindo 90913985b6
Move comment about permanent generation to gcmodule.c (GH-17718)
The comment about the collection rules for the permanent generation was
incorrectly referenced by a comment in gcmodule.c (the comment has been
moved long ago into a header file). Moving the comment into the relevant
code helps with readability and avoids broken references.
2019-12-27 21:55:56 +00:00
Victor Stinner 0131aba5ae
bpo-38916: array.array: remove fromstring() and tostring() (GH-17487)
array.array: Remove tostring() and fromstring() methods.  They were
aliases to tobytes() and frombytes(), deprecated since Python 3.2.
2019-12-09 14:09:14 +01:00
Christian Heimes 2b7de6696b bpo-38820: OpenSSL 3.0.0 compatibility. (GH-17190)
test_openssl_version now accepts version 3.0.0.

getpeercert() no longer returns IPv6 addresses with a trailing new line.

Signed-off-by: Christian Heimes <christian@python.org>


https://bugs.python.org/issue38820
2019-12-07 08:59:36 -08:00
Andrew Svetlov 969ae7aca8
Make repr of C accelerated TaskWakeupMethWrapper the same as of pure Python version (GH-17484) 2019-12-07 13:23:21 +02:00
Batuhan Taşkaya dec367261e bpo-38978: Implement __class_getitem__ for asyncio objects (GH-17491)
https://bugs.python.org/issue38978
2019-12-07 03:05:07 -08:00
Benoit Hudson 723f71abf7 bpo-37931: Fix crash on OSX re-initializing os.environ (GH-15428)
On most platforms, the `environ` symbol is accessible everywhere.

In a dylib on OSX, it's not easily accessible, you need to find it with
_NSGetEnviron.

The code was caching the *value* of environ. But a setenv() can change the value,
leaving garbage at the old value. Fix: don't cache the value of environ, just
read it every time.
2019-12-06 20:15:03 +01:00
Sergey Fedoseev 1f9f69dd4c bpo-27961: Replace PY_LLONG_MAX, PY_LLONG_MIN and PY_ULLONG_MAX with standard macros (GH-15385)
Use standard constants LLONG_MIN, LLONG_MAX and ULLONG_MAX.
2019-12-05 15:55:28 +01:00
Victor Stinner 8b787964e0
bpo-38965: Fix faulthandler._stack_overflow() on GCC 10 (GH-17467)
Use the "volatile" keyword to prevent tail call optimization
on any compiler, rather than relying on compiler specific pragma.
2019-12-04 21:10:06 +01:00
serge-sans-paille 7105319ada bpo-38634: Allow non-apple build to cope with libedit (GH-16986)
The readline module now detects if Python is linked to libedit at runtime
on all platforms.  Previously, the check was only done on macOS.

If Python is used as a library by a binary linking to libedit, the linker
resolves the rl_initialize symbol required by the readline module against
libedit instead of libreadline, which leads to a segfault.

Take advantage of the existing supporting code to have readline module being
compatible with both situations.
2019-12-04 17:02:57 +01:00
Eddie Elizondo e4db1f05e9 closes bpo-38803: Fix leak in posixmodule. (GH-17373) 2019-11-25 19:07:37 -08:00
Claudiu Popa 6f03b236c1 bpo-38876: Raise pickle.UnpicklingError when loading an item from memo for invalid input (GH-17335)
The previous code was raising a `KeyError` for both the Python and C implementation.
This was caused by the specified index of an invalid input which did not exist
in the memo structure, where the pickle stores what objects it has seen.
The malformed input would have caused either a `BINGET` or `LONG_BINGET` load
from the memo, leading to a `KeyError` as the determined index was bogus.

https://bugs.python.org/issue38876



https://bugs.python.org/issue38876
2019-11-24 11:15:08 -08:00
Victor Stinner d68b592dd6
bpo-38896: Remove PyUnicode_ClearFreeList() function (GH-17354)
Remove PyUnicode_ClearFreeList() function: the Unicode free list has
been removed in Python 3.3.
2019-11-23 02:30:32 +01:00
Victor Stinner 310e2d2517
bpo-36854: Fix refleak in subinterpreter (GH-17331)
finalize_interp_clear() now explicitly clears the codec registry and
then trigger a GC collection to clear all references.
2019-11-22 10:58:00 +01:00
Brandt Bucher e5d1f734db bpo-38823: Clean up _xxtestfuzz initialization. (GH-17216)
https://bugs.python.org/issue38823
2019-11-20 16:17:02 -08:00
Victor Stinner fff7bbfdb6
bpo-38858: Add _Py_IsMainInterpreter(tstate) (GH-17293) 2019-11-20 17:34:39 +01:00
Victor Stinner 4dedd0f0dd
bpo-37340: Remove PyMethod_ClearFreeList() and PyCFunction_ClearFreeList() (GH-17284)
Remove PyMethod_ClearFreeList() and PyCFunction_ClearFreeList()
functions: the free lists of bound method objects have been removed.

Remove also _PyMethod_Fini() and _PyCFunction_Fini() functions.
2019-11-20 12:59:12 +01:00
Victor Stinner 7247407c35
bpo-36854: Move _PyRuntimeState.gc to PyInterpreterState (GH-17287)
* Rename _PyGC_InitializeRuntime() to _PyGC_InitState()
* finalize_interp_clear() now also calls _PyGC_Fini() in
  subinterpreters (clear the GC state).
2019-11-20 12:25:50 +01:00
Victor Stinner 67e0de6f0b
bpo-36854: gcmodule.c gets its state from tstate (GH-17285)
* Add GCState type for readability
* gcmodule.c now gets its gcstate from tstate
* _PyGC_DumpShutdownStats() now expects tstate rather than runtime
* Rename "state" to "gcstate" for readability: to avoid confusion
  between "state" and "tstate" for example.
* collect() now only expects tstate: it gets gcstate from tstate.
* Pass tstate to _PyErr_xxx() functions
2019-11-20 11:48:18 +01:00
Victor Stinner 9da7430675
bpo-36854: Clear the current thread later (GH-17279)
Clear the current thread later in the Python finalization.

* The PyInterpreterState_Delete() function is now responsible
  to call PyThreadState_Swap(NULL).
* The tstate_delete_common() function is now responsible to clear the
  "autoTSSKey" thread local storage and it only clears it once the
  thread state is fully cleared. It allows to still get the current
  thread from TSS in tstate_delete_common().
2019-11-20 11:17:17 +01:00
Brandt Bucher d51a363a43 bpo-38823: Fix refleak in _tracemalloc init error handling (GH-17235) 2019-11-20 11:00:31 +01:00
Victor Stinner 7eee5beaf8
bpo-38858: Factorize Py_EndInterpreter() code (GH-17273)
* Factorize code in common between Py_FinalizeEx() and
  Py_EndInterpreter().
* Py_EndInterpreter() now also calls _PyWarnings_Fini().
* Call _PyExc_Fini() and _PyGC_Fini() later in the finalization.
2019-11-20 10:38:34 +01:00
Benjamin Peterson 7483451577
closes bpo-38712: Add signal.pidfd_send_signal. (GH-17070)
This exposes a Linux-specific syscall for sending a signal to a process
identified by a file descriptor rather than a pid.

For simplicity, we don't support the siginfo_t parameter to the syscall. This
parameter allows implementing a pidfd version of rt_sigqueueinfo(2), which
Python also doesn't support.
2019-11-19 20:39:14 -08:00
Victor Stinner be143ec996
bpo-38835: Don't use PyFPE_START_PROTECT and PyFPE_END_PROTECT (GH-17231)
The PyFPE_START_PROTECT() and PyFPE_END_PROTECT() macros are empty:
they have been doing nothing for the last year  (since commit
735ae8d139), so stop using them.
2019-11-20 02:51:30 +01:00
Victor Stinner 01b1cc12e7
bpo-36710: Add PyInterpreterState.runtime field (GH-17270)
Add PyInterpreterState.runtime field: reference to the _PyRuntime
global variable. This field exists to not have to pass runtime in
addition to tstate to a function.  Get runtime from tstate:
tstate->interp->runtime.

Remove "_PyRuntimeState *runtime" parameter from functions already
taking a "PyThreadState *tstate" parameter.

_PyGC_Init() first parameter becomes "PyThreadState *tstate".
2019-11-20 02:27:56 +01:00
Victor Stinner 2e96906da7
bpo-36710: Pass tstate parameter to GC collect() (GH-17267)
Pass tstate parameter (PyThreadState) to GC collect() function and
other GC subfunctions.
2019-11-20 01:49:32 +01:00
Victor Stinner 444b39bb64
bpo-38631: Avoid Py_FatalError() in handle_legacy_finalizers() (GH-17266)
* Rename _PyGC_Initialize() to _PyGC_InitializeRuntime()
* Add _PyGC_Init(): initialize _PyRuntime.gc.garbage list
* Call _PyGC_Init() before _PyTypes_Init()
2019-11-20 01:18:11 +01:00
Brandt Bucher ac2235432c bpo-38823: Fix refleaks in faulthandler init error path on Windows (GH-17250) 2019-11-20 00:13:05 +01:00
Brandt Bucher 54b32c9871 bpo-38823: Clean up refleak in fcntl module initialization. (GH-17236) 2019-11-19 11:16:29 -08:00
Brandt Bucher 79e18ec75d Clean up module initialization. (GH-17215) 2019-11-18 23:16:23 -08:00
Pablo Galindo b028f589dd
Minor fixes to the formatting of the notes of Modules/gcmodule.c (GH-17247) 2019-11-19 01:36:57 +00:00
Steve Dower dcf1f83de8
bpo-38622: Ensure ctypes.PyObj_FromPtr audit event passes tuples as a single argument (GH-17243) 2019-11-18 13:30:01 -08:00
Steve Dower 00923c6399
bpo-38622: Add missing audit events for ctypes module (GH-17158) 2019-11-18 11:32:46 -08:00
Tal Einat 476e76f7cf
Revert "remove a strange non-ASCII character in _iomodule.c" (GH-17240)
This reverts commit bcc1cc5c,  which removed an intentionally placed
"form feed" character.
2019-11-18 21:19:51 +02:00
Tal Einat bcc1cc5cc3
remove a strange non-ASCII character in _iomodule.c (GH-17239) 2019-11-18 20:39:47 +02:00
Victor Stinner bc7d3aa6d7
bpo-38631: Avoid Py_FatalError() in _multibytecodec init (GH-17233)
If an exception is raised and PyInit__multibytecodec() returns NULL,
Python reports properly the exception to the user. There is no need
to crash Python with Py_FatalError().
2019-11-18 17:40:07 +01:00
Brandt Bucher 289cf0fbf7 bpo-38823: Clean up refleaks in _tkinter initialization. (GH-17206)
https://bugs.python.org/issue38823
2019-11-18 06:52:36 -08:00
Zackery Spytz 2bc343417a bpo-36589: Fix the error handling in curses.update_lines_cols(). (GH-12766)
Return None instead of 1.
2019-11-17 19:10:13 +02:00
Brandt Bucher 143a97f641 bpo-38823: Clean up refleaks in _contextvars initialization. (GH-17198)
https://bugs.python.org/issue38823
2019-11-16 15:57:32 -08:00
Brandt Bucher c3f6bdc332 bpo-38823: Clean up refleaks in _asyncio initialization. (GH-17195)
https://bugs.python.org/issue38823
2019-11-16 14:26:54 -08:00
Serhiy Storchaka 5fd5cb8d85
bpo-38639: Optimize floor(), ceil() and trunc() for floats. (GH-16991) 2019-11-16 18:00:57 +02:00
Marco Paolini b44ffc8b40 bpo-38677: Fix arraymodule error handling in module initialization. (GH-17039) 2019-11-15 10:42:51 +02:00
Andrew Svetlov dad6be5ffe bpo-38785: Prevent asyncio from crashing (GH-17144)
if parent `__init__` is not called from a constructor of object derived from `asyncio.Future`



https://bugs.python.org/issue38785
2019-11-13 13:36:46 -08:00
Benjamin Peterson 74fa9f723f
closes bpo-27805: Ignore ESPIPE in initializing seek of append-mode files. (GH-17112)
This change, which follows the behavior of C stdio's fdopen and Python 2's file object, allows pipes to be opened in append mode.
2019-11-12 14:51:34 -08:00
Vinay Sajip 106271568c
bpo-16576: Add checks for bitfields passed by value to functions. (GH-17097) 2019-11-12 12:29:34 +00:00
Raymond Hettinger af46450bb9
Minor readability improvement for argument handling in itertools.repeat() (GH-17101) 2019-11-09 20:28:31 -08:00
Victor Stinner 7e43373317
bpo-38644: Add _PyObject_VectorcallTstate() (GH-17052)
* Add _PyObject_VectorcallTstate() function: similar to
  _PyObject_Vectorcall(), but with tstate parameter
* Add tstate parameter to _PyObject_MakeTpCall()
2019-11-08 10:05:17 +01:00
Benjamin Peterson 5c0c325453 closes bpo-38713: Expose P_PIDFD in os if it's defined. (GH-17071)
https://bugs.python.org/issue38713
2019-11-05 21:58:31 -08:00
Benjamin Peterson 6c4c45efae
bpo-38692: Add os.pidfd_open. (GH-17063) 2019-11-05 19:21:29 -08:00
Eddie Elizondo b3966639d2 bpo-35381 Remove all static state from posixmodule (GH-15892)
After #9665, this moves the remaining types in posixmodule to be heap-allocated to make it compatible with PEP384 as well as modifying all the type accessors to fully make the type opaque.

The original PR that got messed up a rebase: https://github.com/python/cpython/pull/10854. All the issues in that commit have now been addressed since https://github.com/python/cpython/pull/11661 got committed.

This change also removes any state from the data segment and onto the module state itself.


https://bugs.python.org/issue35381



Automerge-Triggered-By: @encukou
2019-11-05 07:16:14 -08:00
Victor Stinner fbbfcce2d6
_json.c: use Py_UNUSED() macro (GH-17053)
Remove UNUSED macro: use Py_UNUSED() macro instead.
2019-11-05 11:44:28 +01:00
Alexandru Ardelean 6552563b3d bpo-38684: haslib: fix build when Blake2 not enabled in OpenSSL (#17043) 2019-11-04 15:55:56 +01:00
Tim Peters d9d3993d1d
Years overdue, explain why unreachable objects are moved. (GH-17030) 2019-11-02 12:06:31 -05:00
Anthony Sottile b32cb97bce bpo-38312: Add curses.{get,set}_escdelay and curses.{get,set}_tabsize. (GH-16938) 2019-10-31 11:13:48 +02:00
Vinay Sajip 79d4ed102a
bpo-16575: Add checks for unions passed by value to functions. (GH-16799) 2019-10-31 08:03:54 +00:00
Victor Stinner 1d8da61f5a
bpo-38631: Avoid Py_FatalError() in readline (GH-16998)
readline now calls PyErr_NoMemory() rather than Py_FatalError() on
memory allocation failure, when importing the module.
2019-10-30 16:39:27 +01:00
Sergey 0078a0c2a5 Permutations Python code equivalent in comment was invalid for Python 3 (GH-16927) 2019-10-28 22:10:24 -07:00
Victor Stinner e471e72977
bpo-37330: open() no longer accept 'U' in file mode (GH-16959)
open(), io.open(), codecs.open() and fileinput.FileInput no longer
accept "U" ("universal newline") in the file mode. This flag was
deprecated since Python 3.3.
2019-10-28 15:40:08 +01:00
Dong-hee Na 3bfc8e0fcc bpo-38602: Add fcntl.F_OFD_XXXX for fcntlmodule (GH-16956) 2019-10-28 09:31:15 +02:00
Sergey Fedoseev b6f5b9dd21 Replace _pysqlite_long_from_int64() with PyLong_FromLongLong() (GH-16882) 2019-10-23 11:09:01 +03:00
Tyler Kieft f548a3e4a2 bpo-38303: Make audioop extension module PEP-384 compatible (GH-16497)
https://bugs.python.org/issue38303



Automerge-Triggered-By: @encukou
2019-10-22 06:07:03 -07:00
Tim Peters 1e73945470
visit_reachable: replace release-mode test with an assert. (GH-16866)
It should be impossible for an untracked object to have the collecting
flag set.  Back when state was stored in gc_refs, it obviously was
impossible (gc_refs couldn't possibly have a positive & negative value
simultaneously).  While the _implementation_ of "state" has gotten much
more complicated, it's still _logically_ just as impossible.
2019-10-21 11:21:35 -05:00
Dong-hee Na 2eba6ad7bf bpo-38493: Add os.CLD_KILLED and os.CLD_STOPPED. (GH-16821) 2019-10-21 10:01:05 +03:00
Sergey Fedoseev a9ed91e6c2 bpo-27961: Replace PY_LONG_LONG with long long. (GH-15386) 2019-10-21 09:49:48 +03:00
Hai Shi 06cd5b6acd bpo-38465: Convert the type of exports counters to Py_ssize_t. (GH-16746) 2019-10-21 09:31:46 +03:00
Tim Peters ea55c51bd9
validate_list: make flags argument impossible to spell wrongly. (GH-16843) 2019-10-18 20:59:14 -05:00
Steve Dower fbe3c76c7c bpo-38418: Fixes audit event for os.system to be named 'os.system' (GH-16670)
https://bugs.python.org/issue38418



Automerge-Triggered-By: @zooba
2019-10-18 00:52:15 -07:00
Taine Zhao d8ca2354ed bpo-34953: Implement `mmap.mmap.__repr__` (GH-9891) 2019-10-17 18:41:35 +08:00
Inada Naoki 9c11029bb4
bpo-37587: json: Use _PyUnicodeWriter when scanning string. (GH-15591) 2019-10-17 16:12:41 +09:00
Neil Schemenauer 392a13bb93
bpo-38006: Add unit test for weakref clear bug (GH-16788) 2019-10-15 20:56:48 -07:00
Julien Danjou 8d59eb1b66 bpo-37961, tracemalloc: add Traceback.total_nframe (GH-15545)
Add a total_nframe field to the traces collected by the tracemalloc module.
This field indicates the original number of frames before it was truncated.
2019-10-15 14:00:16 +02:00
Vinay Sajip 0b60f64e43
bpo-11410: Standardize and use symbol visibility attributes across POSIX and Windows. (GH-16347) 2019-10-15 08:26:12 +01:00
Tim Peters 95bfc8a11a
Misc gc code & comment cleanups. (GH-16752)
* Misc gc code & comment cleanups.

validate_list:  there are two temp flags polluting pointers, but this checked only one.  Now it checks both, and verifies that the list head's pointers are not polluted.

move_unreachable: repaired incoherent comments.  Added new comments.  Cleared the pollution of the unreachable list head's 'next' pointer (it was expedient while the function was running, but there's no excuse for letting this damage survive the function's end).

* Update Modules/gcmodule.c

Co-Authored-By: Pablo Galindo <Pablogsal@gmail.com>
2019-10-13 16:47:04 -05:00
Pablo Galindo 466326dcdf
bpo-38379: Don't block collection of unreachable objects when some objects resurrect (GH-16687)
Currently if any finalizer invoked during garbage collection resurrects any object, the gc gives up and aborts the collection. Although finalizers are assured to only run once per object, this behaviour of the gc can lead to an ever-increasing memory situation if new resurrecting objects are allocated in every new gc collection.

To avoid this, recompute what objects among the unreachable set need to be resurrected and what objects can be safely collected. In this way, resurrecting objects will not block the collection of other objects in the unreachable set.
2019-10-13 16:48:59 +01:00
Serhiy Storchaka 140a7d1f35
bpo-38378: Rename parameters "out" and "in" of os.sendfile(). (GH-16742)
They conflicted with keyword "in".

Also rename positional-only parameters of private os._fcopyfile()
for consistency.
2019-10-13 11:59:31 +03:00
Pablo Galindo 27b33fb41a
bpo-38282: Correctly manage the Bluetooth L2CAP socket structure in FreeBSD (GH-16738) 2019-10-13 02:03:54 +01:00
Gregory P. Smith f3751efb5c
bpo-38417: Add umask support to subprocess (GH-16726)
On POSIX systems, allow the umask to be set in the child process before we exec.
2019-10-12 13:24:56 -07:00
Pablo Galindo 8177404d52
bpo-37731: Reorder includes in xmltok.c to avoid redefinition of _POSIX_C_SOURCE (GH-16733) 2019-10-12 20:14:11 +01:00
Pablo Galindo 320dd504dd
bpo-38437: Activate GC_DEBUG when PY_DEBUG is set (GH-16707) 2019-10-10 22:45:17 +01:00
Victor Stinner d565fb9828
bpo-38282: Rewrite getsockaddrarg() helper function (GH-16698)
Rewrite getsockaddrarg() helper function of socketmodule.c (_socket
module) to prevent a false alarm when compiling codde using GCC with
_FORTIFY_SOURCE=2. Pass a pointer of the sock_addr_t union, rather
than passing a pointer to a sockaddr structure.

Add "struct sockaddr_tipc tipc;" to the sock_addr_t union.
2019-10-10 21:30:20 +02:00
Victor Stinner b6e0fc7426
bpo-38353: Fix typos in calculate_argv0_path_framework() (GH-16695)
bpo-38353, bpo-38429: Fix typos introduced by commit
c02b41b1fb in
calculate_argv0_path_framework() of getpath.c.
2019-10-10 15:42:30 +02:00
Victor Stinner a5447735c3
bpo-38392: Only declare visit_validate() if Py_DEBUG is defined (GH-16689)
bpo-38392, bpo-38426: Fix a compiler warning in gcmodule.c.

Fix also a typo in PYMEM_DEADBYTE macro comment.
2019-10-10 09:32:13 +02:00
Tim Peters ecbf35f933
bpo-38379: don't claim objects are collected when they aren't (#16658)
* bpo-38379:  when a finalizer resurrects an object,
nothing is actually collected in this run of gc.
Change the stats to relect that truth.
2019-10-09 12:37:30 -05:00
Antonio Gutierrez 594e2edfb5 closes bpo-36161: Use thread-safe ttyname_r instead of ttyname. (GH-14868)
Signed-off-by: Antonio Gutierrez <chibby0ne@gmail.com>
2019-10-08 19:19:48 -07:00
Vinay Sajip e8bedbddad
bpo-38368: Added fix for ctypes crash when handling arrays in structs… (GH-16589) 2019-10-08 21:59:06 +01:00
Serhiy Storchaka d05b000c6b
bpo-38371: Tkinter: deprecate the split() method. (GH-16584) 2019-10-08 14:31:35 +03:00
Antonio Gutierrez 0d3fe8ae49 closes bpo-38402: Check error of primitive crypt/crypt_r. (GH-16599)
Checks also for encryption algorithms methods not supported in different
OSs.

Signed-off-by: Antonio Gutierrez <chibby0ne@gmail.com>
2019-10-07 21:22:17 -07:00
Victor Stinner 4d5f94b8cd
bpo-38070: Enhance visit_decref() debug trace (GH-16631)
subtract_refs() now pass the parent object to visit_decref() which
pass it to _PyObject_ASSERT(). So if the "is freed" assertion fails,
the parent is used in debug trace, rather than the freed object. The
parent object is more likely to contain useful information. Freed
objects cannot be inspected are are displayed as "<object at xxx is
freed>" with no other detail.
2019-10-08 02:37:38 +02:00
Victor Stinner 1b18455695
bpo-38392: PyObject_GC_Track() validates object in debug mode (GH-16615)
In debug mode, PyObject_GC_Track() now calls tp_traverse() of the
object type to ensure that the object is valid: test that objects
visited by tp_traverse() are valid.

Fix pyexpat.c: only track the parser in the GC once the parser is
fully initialized.
2019-10-08 00:09:31 +02:00
Victor Stinner 6876257eaa
bpo-36389: _PyObject_CheckConsistency() available in release mode (GH-16612)
bpo-36389, bpo-38376: The _PyObject_CheckConsistency() function is
now also available in release mode. For example, it can be used to
debug a crash in the visit_decref() function of the GC.

Modify the following functions to also work in release mode:

* _PyDict_CheckConsistency()
* _PyObject_CheckConsistency()
* _PyType_CheckConsistency()
* _PyUnicode_CheckConsistency()

Other changes:

* _PyMem_IsPtrFreed(ptr) now also returns 1 if ptr is NULL
  (equals to 0).
* _PyBytesWriter_CheckConsistency() now returns 1 and is only used
  with assert().
* Reorder _PyObject_Dump() to write safe fields first, and only
  attempt to render repr() at the end.
2019-10-07 18:42:01 +02:00
Ben Harper 321def805a bpo-36356: Fix memory leak in _asynciomodule.c (GH-16598) 2019-10-07 12:19:58 -04:00
Xiang Zhang 303475e873
Fix a compile warning in selectmodule.c. (GH-16617) 2019-10-07 20:01:54 +08:00
Victor Stinner b96145a6b5
bpo-38353: Simplify calculate_pybuilddir() (GH-16614)
Calling _Py_wfopen() is enough to check if filename is an existing
file or not. There is no need to check first isfile().
2019-10-07 12:56:59 +02:00
Victor Stinner c02b41b1fb
bpo-38353: getpath.c: allocates strings on the heap (GH-16585)
* _Py_FindEnvConfigValue() now returns a string allocated
  by PyMem_RawMalloc().
* calculate_init() now decodes VPATH macro.
* Add calculate_open_pyenv() function.
* Add substring() and joinpath2() functions.

* Fix add_exe_suffix()

And a few cleanup changes.
2019-10-04 19:53:43 +02:00
Victor Stinner abd7cd856b
bpo-38353: getpath.c uses dynamically allocated strings (GH-16582)
* PyCalculatePath: add "_macro" to the 3 fields storing macro values
* Add dynamically allocated strings to PyCalculatePath
2019-10-04 15:25:50 +02:00
Serhiy Storchaka 06cb94bc84
bpo-13153: Use OS native encoding for converting between Python and Tcl. (GH-16545)
On Windows use UTF-16 (or UTF-32 for 32-bit Tcl_UniChar) with the
"surrogatepass" error handler for converting to/from Tcl Unicode objects.

On Linux use UTF-8 with the "surrogateescape" error handler for converting
to/from Tcl String objects.

Converting strings from Tcl to Python and back now never fails
(except MemoryError).
2019-10-04 13:09:52 +03:00
Victor Stinner f0c85793d2
bpo-38353: Rework ismodule() in getpath.c (GH-16574)
* ismodule() no longer modify the input string.
* copy_absolute(), joinpath(): rename parameters and local variables.
2019-10-04 03:53:26 +02:00
Victor Stinner 03a8a56fac
bpo-38353: Add subfunctions to getpath.c (GH-16572)
Following symbolic links is now limited to 40 attempts, just to
prevent loops.

Add subfunctions:

* Add resolve_symlinks()
* Add calculate_argv0_path_framework()
* Add calculate_which()
* Add calculate_program_macos()

Fix also _Py_wreadlink(): readlink() result type is Py_ssize_t, not
int.
2019-10-04 02:22:39 +02:00
Victor Stinner 86ec5c65fe
bpo-38353: Fix calculate_argv0_path() for symlinks (GH-16549)
calculate_argv0_path() must read argv0_path link, not read
program_full_path link.
2019-10-03 23:17:00 +02:00
Victor Stinner 61691d8336
bpo-38353: Cleanup includes in the internal C API (GH-16548)
Use forward declaration of types to avoid includes in the internal C
API. Add also comment to justify other includes.
2019-10-02 23:51:20 +02:00
Victor Stinner 5e0ea7540f
bpo-37474: Don't call fedisableexcept() on FreeBSD (GH-16515)
On FreeBSD, Python no longer calls fedisableexcept() at startup to
control the floating point control mode. The call became useless
since FreeBSD 6: it became the default mode.
2019-10-01 13:12:29 +02:00
Victor Stinner 2f90261280
bpo-38321: Fix compiler warning in _randommodule.c (GH-16512)
Fix the GCC warning: "initialization discards ‘const’ qualifier from
pointer target type".
2019-10-01 12:45:52 +02:00
Victor Stinner 8462a4936b
bpo-38304: PyConfig_InitPythonConfig() cannot fail anymore (GH-16509)
PyConfig_InitPythonConfig() and PyConfig_InitIsolatedConfig() no
longer return PyStatus: they cannot fail anymore.
2019-10-01 12:06:16 +02:00
Victor Stinner 3c30a76f3d
bpo-38304: Remove PyConfig.struct_size (GH-16500) (GH-16508)
For now, we'll rely on the fact that the config structures aren't covered by the stable ABI.

We may revisit this in the future if we further explore the idea of offering a stable embedding API.

(cherry picked from commit bdace21b76)
2019-10-01 10:56:37 +02:00
Victor Stinner aca8c406ad
bpo-38321: Fix _testcapimodule.c warning (GH-16494)
Fix the following warning:

    modules\_testcapimodule.c(6409):
    warning C4146: unary minus operator applied to unsigned type,
    result still unsigned
2019-09-30 21:14:26 +02:00
Neil Schemenauer bcda460baf Clear weakrefs in garbage found by the GC (#16495)
Fix a bug due to the interaction of weakrefs and the cyclic garbage
collector. We must clear any weakrefs in garbage in order to prevent
their callbacks from executing and causing a crash.
2019-09-30 19:06:45 +02:00
Victor Stinner c9a413ede4 bpo-38321: Fix PyCStructUnionType_update_stgdict() warning (GH-16492)
bpo-22273, bpo-38321: Fix following warning:

    modules\_ctypes\stgdict.c(704):
    warning C4244: 'initializing': conversion from 'Py_ssize_t' to 'int', possible loss of data
2019-09-30 16:49:47 +01:00
Victor Stinner efe74b6369
bpo-38321: Fix _asynciomodule.c compiler warning (GH-16493)
bpo-38248, bpo-38321: Fix warning:

    modules\_asynciomodule.c(2667):
    warning C4102: 'set_exception': unreferenced label

The related goto has been removed by
commit edad4d89e3.
2019-09-30 16:41:34 +02:00
Victor Stinner 441b10cf28
bpo-38304: Add PyConfig.struct_size (GH-16451)
Add a new struct_size field to PyPreConfig and PyConfig structures to
allow to modify these structures in the future without breaking the
backward compatibility.

* Replace private _config_version field with public struct_size field
  in PyPreConfig and PyConfig.
* Public PyPreConfig_InitIsolatedConfig() and
  PyPreConfig_InitPythonConfig()
  return type becomes PyStatus, instead of void.
* Internal _PyConfig_InitCompatConfig(),
  _PyPreConfig_InitCompatConfig(), _PyPreConfig_InitFromConfig(),
  _PyPreConfig_InitFromPreConfig() return type becomes PyStatus,
  instead of void.
* Remove _Py_CONFIG_VERSION
* Update the Initialization Configuration documentation.
2019-09-28 04:28:35 +02:00
Christian Heimes 9055815809 bpo-38270: More fixes for strict crypto policy (GH-16418)
test_hmac and test_hashlib test built-in hashing implementations and
OpenSSL-based hashing implementations. Add more checks to skip OpenSSL
implementations when a strict crypto policy is active.

Use EVP_DigestInit_ex() instead of EVP_DigestInit() to initialize the
EVP context. The EVP_DigestInit() function clears alls flags and breaks
usedforsecurity flag again.

Signed-off-by: Christian Heimes <christian@python.org>



https://bugs.python.org/issue38270
2019-09-27 06:03:53 -07:00
Benjamin Peterson 52b9408038
closes bpo-38174: Update vendored expat library to 2.2.8. (GH-16346)
Fixes CVE-2019-15903. See full changelog at https://github.com/libexpat/libexpat/blob/R_2_2_8/expat/Changes.
2019-09-25 21:33:58 -07:00
Christian Heimes df69e75edc
bpo-38142: Updated _hashopenssl.c to be PEP 384 compliant (#16071)
* Updated _hashopenssl.c to be PEP 384 compliant
* Remove refleak test from test_hashlib. The updated type no longer accepts random arguments to __init__.
2019-09-25 23:03:30 +02:00
Yury Selivanov edad4d89e3 bpo-38248: Fix inconsistent immediate asyncio.Task cancellation (GH-16330) 2019-09-25 03:32:08 -07:00
Vinay Sajip c64af8fad3
Changed conditions for ctypes array-in-struct handling. (GH-16381) 2019-09-25 11:11:57 +01:00
Vinay Sajip 57dc7d5ae8
bpo-22273: Disabled tests while investigating buildbot failures on ARM7L/PPC64. (GH-16377) 2019-09-25 07:58:32 +01:00
Dong-hee Na ad7736faf5 bpo-38265: Update os.pread to accept the length type as Py_ssize_t. (GH-16359) 2019-09-25 08:47:04 +03:00
Vinay Sajip 12f209eccb
bpo-22273: Update ctypes to correctly handle arrays in small structur… (GH-15839) 2019-09-25 04:38:44 +01:00
Victor Stinner 221fd84703
bpo-38234: Cleanup getpath.c (GH-16367)
* search_for_prefix() directly calls reduce() if found is greater
  than 0.
* Add calculate_pybuilddir() subfunction.
* search_for_prefix(): add path string buffer for readability.
* Fix some error handling code paths: release resources on error.
* calculate_read_pyenv(): rename tmpbuffer to filename.
* test.pythoninfo now also logs windows.dll_path
2019-09-25 02:54:25 +02:00
Victor Stinner bb6bf7d342
bpo-38234: Add tests for Python init path config (GH-16358) 2019-09-24 18:21:02 +02:00
Victor Stinner 85ce0a7178
bpo-38234: read_pth_file() now returns PyStatus (GH-16338)
Refactor path configuration code:

* read_pth_file() now returns PyStatus to report errors, rather than
  calling Py_FatalError().
* Move argv0_path and zip_path buffers out of PyCalculatePath
  structures.
* On Windows, _PyPathConfig.home is now preferred over PyConfig.home.
2019-09-24 00:55:48 +02:00
Victor Stinner 9c42f8cda5
bpo-38234: Fix _PyConfig_InitPathConfig() (GH-16335)
* _PyConfig_InitPathConfig() now starts by copying the global path
  configuration, and then override values set in PyConfig.
* _PyPathConfig_Calculate() implementations no longer override
  _PyPathConfig fields which are already computed. For example,
  if _PyPathConfig.prefix is not NULL, leave it unchanged.
* If Py_SetPath() has been called, _PyConfig_InitPathConfig() doesn't
  call _PyPathConfig_Calculate() anymore.
* _PyPathConfig_Calculate() no longer uses PyConfig,
  except to initialize PyCalculatePath structure.
* pathconfig_calculate(): remove useless temporary
  "_PyPathConfig new_config" variable.
* calculate_module_search_path(): remove hack to workaround memory
  allocation failure, call Py_FatalError() instead.
* Fix get_program_full_path(): handle memory allocation failure.
2019-09-23 18:47:29 +02:00
Victor Stinner e267793aa4
bpo-38234: Fix PyConfig_Read() when Py_SetPath() was called (GH-16298)
* If Py_SetPath() has been called, _PyConfig_InitPathConfig() now
  uses its value.
* Py_Initialize() now longer copies path configuration from PyConfig
  to the global path configuration (_Py_path_config).
2019-09-21 01:50:16 +02:00
Orivej Desh 77abf23c67 bpo-6559: Update _posixsubprocess.fork_exec doc (GH-16283)
It did not list the argument added in d4cc7bf993.


https://bugs.python.org/issue6559



Automerge-Triggered-By: @gpshead
2019-09-20 10:01:09 -07:00
Eddie Elizondo 3368f3c6ae bpo-38140: Make dict and weakref offsets opaque for C heap types (#16076)
* Make dict and weakref offsets opaque for C heap types

* Add news
2019-09-19 17:29:05 +01:00
Victor Stinner 0a963fbc9c
bpo-38203: faulthandler.dump_traceback_later() is always available (GH-16249)
dump_traceback_later() and cancel_dump_traceback_later() functions of
the faulthandler module are always available since Python 3.7.
2019-09-18 14:15:10 +02:00
Serhiy Storchaka f669581a95
bpo-38185: Fixed case-insensitive string comparison in sqlite3.Row indexing. (GH-16190) 2019-09-17 09:20:56 +03:00
Christian Heimes 724f1a5723 bpo-33936: Don't call obsolete init methods with OpenSSL 1.1.0+ (GH-16140)
``OPENSSL_VERSION_1_1`` was never defined in ``_hashopenssl.c``. 


https://bugs.python.org/issue33936
2019-09-16 12:10:05 -07:00
Serhiy Storchaka 8debfa5040
bpo-38175: Fix a memory leak in comparison of sqlite3.Row objects. (GH-16155) 2019-09-16 20:15:18 +03:00
Hai Shi 56a45142e7 Fix a possbile refleak in setint() of mmapmodule.c (GH-16136) 2019-09-16 13:56:57 +08:00
Raymond Hettinger 6e27a0d775
bpo-37798: Prevent undefined behavior in direct calls to the C helper function. (#16149) 2019-09-15 09:36:38 -07:00
Dino Viehland 09dc2c672f
Fix missing dec ref (#16158) 2019-09-15 15:51:44 +01:00
Christian Heimes eb2b0c694a
bpo-38153: detect shake independently from sha3 (GH-16143)
XOF digests (SHAKE) are not available in OpenSSL 1.1.0 but SHA3 fixed-length digests are.

Signed-off-by: Christian Heimes <christian@python.org>
2019-09-14 17:29:54 +02:00
Dino Viehland f919054e53
bpo-38116: Convert select module to PEP-384 (#15971)
* Convert select module to PEP-384

Summary: Do the necessary versions to be Pyro-compatible, including migrating `PyType_Ready` to `PyType_FromSpec` and moving static data into a new `_selectstate` struct.

* 📜🤖 Added by blurb_it.

* Fixup Mac OS/X build
2019-09-14 15:20:27 +01:00
Serhiy Storchaka 279f44678c
bpo-37206: Unrepresentable default values no longer represented as None. (GH-13933)
In ArgumentClinic, value "NULL" should now be used only for unrepresentable default values
(like in the optional third parameter of getattr). "None" should be used if None is accepted
as argument and passing None has the same effect as not passing the argument at all.
2019-09-14 12:24:05 +03:00
Serhiy Storchaka bf169915ec
bpo-38005: Fixed comparing and creating of InterpreterID and ChannelID. (GH-15652)
* Fix a crash in comparing with float (and maybe other crashes).
* They are now never equal to strings and non-integer numbers.
* Comparison with a large number no longer raises OverflowError.
* Arbitrary exceptions no longer silenced in constructors and comparisons.
* TypeError raised in the constructor contains now the name of the type.
* Accept only ChannelID and int-like objects in channel functions.
* Accept only InterpreterId, int-like objects and str in the InterpreterId constructor.
* Accept int-like objects, not just int in interpreter related functions.
2019-09-13 22:50:27 +03:00
Eddie Elizondo a67ac2f2d9 bpo-38150 Fix refleak in the finalizer of a _testcapimodule type (GH-16115)
The PyLong created in the finalizer was not being cleaned up


https://bugs.python.org/issue38150



Automerge-Triggered-By: @matrixise
2019-09-13 09:48:03 -07:00
Christian Heimes 995b5d38e7 bpo-38153: Normalize hashlib algorithm names (GH-16083)
Signed-off-by: Christian Heimes <christian@python.org>
2019-09-13 14:31:19 +01:00
Dino Viehland 04f0bbfbed bpo-38075: Port _randommodule.c to PEP-384 (GH-15798)
- Migrate `Random_Type` to `PyType_FromSpec`
- To simulate an old use of `PyLong_Type.tp_as_number->nb_absolute`, I added
  code to the module init function to stash `int.__abs__` for later
  use. Ideally we'd use `PyType_GetSlot()` instead, but it doesn't currently
  work for static types in CPython, and implementing it just for this case
  doesn't seem worth it.
- Do exact check for long and dispatch to PyNumber_Absolute, use vector call when not exact.
2019-09-13 03:12:27 -07:00
Christian Heimes 7cad53e6b0 bpo-9216: Add usedforsecurity to hashlib constructors (GH-16044)
The usedforsecurity keyword only argument added to the hash constructors is useful for FIPS builds and similar restrictive environment with non-technical requirements that legacy algorithms be forbidden by their implementations without being explicitly annotated as not being used for any security related purposes.  Linux distros with FIPS support benefit from this being standard rather than making up their own way(s) to do it.

Contributed and Signed-off-by: Christian Heimes christian@python.org
2019-09-12 19:30:00 -05:00
Patrick McLean 2b2ead7438 bpo-36046: Add user and group parameters to subprocess (GH-11950)
* subprocess: Add user, group and extra_groups paremeters to subprocess.Popen

This adds a `user` parameter to the Popen constructor that will call
setreuid() in the child before calling exec(). This allows processes
running as root to safely drop privileges before running the subprocess
without having to use a preexec_fn.

This also adds a `group` parameter that will call setregid() in
the child process before calling exec().

Finally an `extra_groups` parameter was added that will call
setgroups() to set the supplimental groups.
2019-09-12 18:15:44 +01:00
Christian Heimes 9a4963b932 bpo-38137: Re-add OpenSSL 1.0.2 compat (GH-16051)
The defines are required for OpenSSL 1.0.2 and LibreSSL.


https://bugs.python.org/issue38134



Automerge-Triggered-By: @tiran
2019-09-12 07:33:26 -07:00
animalize 4ffd05d7ec bpo-21872: fix lzma library decompresses data incompletely (GH-14048)
* 1. add test case with wrong behavior
* 2. fix bug when max_length == -1
* 3. allow b"" as valid input data for decompress_buf()
* 4. when max_length >= 0, let needs_input mechanism works
* add more asserts to test case
2019-09-12 15:20:37 +01:00
Christian Heimes 8c74574e0a bpo-38132: Check EVP_DigestUpdate for error (GH-16041) 2019-09-12 14:30:47 +01:00
Christian Heimes 5a4f82f457 bpo-38132: Simplify _hashopenssl code (GH-16023)
Signed-off-by: Christian Heimes <christian@python.org>
2019-09-12 13:42:07 +01:00
Christian Heimes 64117e059b bpo-38134: Remove PKBDF2_HMAC_fast from _hashopenssl (GH-16028)
Signed-off-by: Christian Heimes <christian@python.org>
2019-09-12 12:46:37 +01:00
Zackery Spytz ea683deccc closes bpo-38127: _ctypes: PyObject_IsSubclass() should be checked for failure. (GH-16011)
An exception may occur during a PyObject_IsSubclass() call.
2019-09-12 11:09:32 +01:00
bggardner 954900a3f9 closes bpo-37405: Make socket.getsockname() always return a tuple for AF_CAN. (GH-14392)
This fixes a regression from 3.5. In recent releases, `getsockname()` in the AF_CAN case has returned a string.
2019-09-12 11:02:48 +01:00
Petr Viktorin 5e9caeec76
bpo-37879: Fix warnings in _testcapimodule (GH-16004) 2019-09-12 10:12:53 +01:00
Steve Dower 0b72ccff56 bpo-32592: Set Windows 8 as the minimum required version for API support (GH-15951) 2019-09-11 17:03:37 +01:00
Steve Dower aa929273ca bpo-33166: Change os.cpu_count to return active (real) processors (GH-15949) 2019-09-11 16:15:39 +01:00
Jakub Kulík e20134f889 bpo-38110: Use fdwalk for os.closerange() when available. (GH-15224)
Use fdwalk() on platforms that support it to implement os.closerange().
2019-09-11 10:11:57 -05:00
Eddie Elizondo ff023ed36e bpo-37879: Suppress subtype_dealloc decref when base type is a C heap type (GH-15323)
The instance destructor for a type is responsible for preparing
an instance for deallocation by decrementing the reference counts
of its referents.

If an instance belongs to a heap type, the type object of an instance
has its reference count decremented while for static types, which
are permanently allocated, the type object is unaffected by the
instance destructor.

Previously, the default instance destructor searched the class
hierarchy for an inherited instance destructor and, if present,
would invoke it.

Then, if the instance type is a heap type, it would decrement the
reference count of that heap type.  However, this could result in the
premature destruction of a type because the inherited instance
destructor should have already decremented the reference count
of the type object.

This change avoids the premature destruction of the type object
by suppressing the decrement of its reference count when an
inherited, non-default instance destructor has been invoked.

Finally, an assertion on the Py_SIZE of a type was deleted.  Heap
types have a non zero size, making this into an incorrect assertion.

https://github.com/python/cpython/pull/15323
2019-09-11 10:17:13 +01:00
Jordon Xu 2ec7010206 bpo-37752: Delete redundant Py_CHARMASK in normalizestring() (GH-15095) 2019-09-10 17:04:08 +01:00
Dino Viehland b7f8e52433 bpo-38073: Make pwd module PEP-384 compatible (GH-15790)
Makes the pwd module PEP-384 compatible


https://bugs.python.org/issue38073



Automerge-Triggered-By: @tiran
2019-09-10 05:59:43 -07:00
Petr Viktorin f958377b67 bpo-37499: Test various C calling conventions (GH-15776)
Add functions with various calling conventions to `_testcapi`, expose them as module-level functions, bound methods, class methods, and static methods, and test calling them and introspecting them through GDB.


https://bugs.python.org/issue37499


Co-authored-by: Jeroen Demeyer <J.Demeyer@UGent.be>
Automerge-Triggered-By: @pganssle
2019-09-10 04:21:09 -07:00
Dino Viehland 5a7d2e11aa bpo-38069: Convert _posixsubprocess to PEP-384 (GH-15780)
Summary:
Eliminate uses of `_Py_IDENTIFIER` from `_posixsubprocess`, replacing them with interned strings.

Also tries to find an existing version of the module, which will allow subinterpreters.



https://bugs.python.org/issue38069
2019-09-10 04:01:20 -07:00
Dino Viehland bd0c7a12d9 bpo-38071: Make termios PEP-384 compatible (GH-15785)
Make the termios module PEP-384 compatible.
2019-09-10 03:33:30 -07:00
Dino Viehland 40a5313edf bpo-38072: PEP-384 grpmodule (GH-15788)
Make the grp module PEP-384 compliant.
2019-09-10 03:30:36 -07:00
Kenta Murata 9e61066355 Fix calling order of PyEval_InitThreads. (GH-4602)
As described in Doc/c-api/init.rst, PyEval_InitThreads() cannot be called
before Py_Initialize() function.
2019-09-10 11:29:56 +01:00
Dino Viehland a1ffad0719 bpo-38074: Make zlib extension module PEP-384 compatible (GH-15792)
Updated zlibmodule.c to be PEP 384 compliant.
2019-09-10 03:27:03 -07:00
Dino Viehland 4f384af067 bpo-38076: Make struct module PEP-384 compatible (#15805)
* PEP-384 _struct

* More PEP-384 fixes for _struct

Summary: Add a couple of more fixes for `_struct` that were previously missed such as removing `tp_*` accessors and using `PyBytesWriter` instead of calling `PyBytes_FromStringAndSize` with `NULL`. Also added a test to confirm that `iter_unpack` type is still uninstantiable.

* 📜🤖 Added by blurb_it.
2019-09-10 03:18:37 -07:00
Sergey Fedoseev 92709a263e bpo-37840: Fix handling of negative indices in bytearray_getitem() (GH-15250) 2019-09-09 09:28:34 -07:00
Christian Heimes 915cd3f069 bpo-35941: Fix performance regression in new code (GH-12610)
Accumulate certificates in a set instead of doing a costly list contain
operation. A Windows cert store can easily contain over hundred
certificates. The old code would result in way over 5,000 comparison
operations

Signed-off-by: Christian Heimes <christian@python.org>
2019-09-09 09:06:55 -07:00
Orivej Desh 09090d04ef bpo-37649: Fix exec_prefix check (GH-14897) 2019-09-09 09:05:21 -07:00
Zackery Spytz 682107cf45 bpo-36279: Ensure os.wait3() rusage is initialized (GH-15111)
Co-Authored-By: David Wilson <dw@botanicus.net>
2019-09-09 08:48:32 -07:00
Victor Stinner d91d4de317
bpo-38070: visit_decref() calls _PyObject_IsFreed() (GH-15782)
In debug mode, visit_decref() now calls _PyObject_IsFreed() to ensure
that the object is not freed. If it's freed, the program fails with
an assertion error and Python dumps informations about the freed
object.
2019-09-09 17:44:59 +02:00
animalize 77643c486f bpo-38037: Fix reference counters in signal module (GH-15753) 2019-09-09 15:46:26 +02:00
neonene ed70129e15 bpo-37702: Fix SSL's certificate-store leak on Windows (GH-15632)
ssl_collect_certificates function in _ssl.c has a memory leak.
Calling CertOpenStore() and CertAddStoreToCollection(), a store's refcnt gets incremented by 2.
But CertCloseStore() is called only once and the refcnt leaves 1.
2019-09-09 05:33:43 -07:00
Zackery Spytz a6563650c8 bpo-37445: Include FORMAT_MESSAGE_IGNORE_INSERTS in FormatMessageW() calls (GH-14462)
If FormatMessageW() is passed the FORMAT_MESSAGE_FROM_SYSTEM flag without FORMAT_MESSAGE_IGNORE_INSERTS, it will fail if there are insert sequences in the message definition.
2019-09-09 02:20:38 -07:00
Greg Price 7669cb8b21 bpo-38043: Use `bool` for boolean flags on is_normalized_quickcheck. (GH-15711) 2019-09-09 02:16:31 -07:00
Serhiy Storchaka 526a01467b
bpo-34410: Fix a crash in the tee iterator when re-enter it. (GH-15625)
RuntimeError is now raised in this case.
2019-09-09 11:47:14 +03:00
Serhiy Storchaka 918b468b7d
Revert "Raise a RuntimeError when tee iterator is consumed from different threads (GH-15567)" (GH-15736)
This reverts commit fa220ec763.
2019-09-09 11:18:16 +03:00
HongWeipeng 3c87a667bb bpo-36946:Fix possible signed integer overflow when handling slices. (GH-15639)
This is a complement to PR 13375.
2019-09-08 13:15:56 +03:00
Sergey Fedoseev 32f825393e Remove some unused defines in multiprocessing.h. (GH-15661)
It looks like they are unused since
87cf220972.
2019-09-07 10:44:36 +03:00
Joannah Nanjekye 2bc43cdc01 bpo-37878: Remove PyThreadState_DeleteCurrent() function (GH-15315)
* Rename PyThreadState_DeleteCurrent()
  to _PyThreadState_DeleteCurrent()
* Move it to the internal C API

Co-Authored-By: Carol Willing <carolcode@willingconsulting.com>
2019-09-05 18:06:49 +02:00
Steve Dower 772ec0fad5
bpo-38030: Fix os.stat failures on block devices on Windows (GH-15681) 2019-09-04 14:42:54 -07:00
Greg Price 2f09413947 closes bpo-37966: Fully implement the UAX #15 quick-check algorithm. (GH-15558)
The purpose of the `unicodedata.is_normalized` function is to answer
the question `str == unicodedata.normalized(form, str)` more
efficiently than writing just that, by using the "quick check"
optimization described in the Unicode standard in UAX #15.

However, it turns out the code doesn't implement the full algorithm
from the standard, and as a result we often miss the optimization and
end up having to compute the whole normalized string after all.

Implement the standard's algorithm.  This greatly speeds up
`unicodedata.is_normalized` in many cases where our partial variant
of quick-check had been returning MAYBE and the standard algorithm
returns NO.

At a quick test on my desktop, the existing code takes about 4.4 ms/MB
(so 4.4 ns per byte) when the partial quick-check returns MAYBE and it
has to do the slow normalize-and-compare:

  $ build.base/python -m timeit -s 'import unicodedata; s = "\uf900"*500000' \
      -- 'unicodedata.is_normalized("NFD", s)'
  50 loops, best of 5: 4.39 msec per loop

With this patch, it gets the answer instantly (58 ns) on the same 1 MB
string:

  $ build.dev/python -m timeit -s 'import unicodedata; s = "\uf900"*500000' \
      -- 'unicodedata.is_normalized("NFD", s)'
  5000000 loops, best of 5: 58.2 nsec per loop

This restores a small optimization that the original version of this
code had for the `unicodedata.normalize` use case.

With this, that case is actually faster than in master!

$ build.base/python -m timeit -s 'import unicodedata; s = "\u0338"*500000' \
    -- 'unicodedata.normalize("NFD", s)'
500 loops, best of 5: 561 usec per loop

$ build.dev/python -m timeit -s 'import unicodedata; s = "\u0338"*500000' \
    -- 'unicodedata.normalize("NFD", s)'
500 loops, best of 5: 512 usec per loop
2019-09-03 19:45:44 -07:00
Steve Dower 993ac92418
bpo-38020: Fixes crash in os.readlink() on Windows (GH-15663) 2019-09-03 12:50:51 -07:00
Dong-hee Na 0cf832a9ef bpo-37798: Fix _statistics module doc (GH-15546) 2019-09-03 12:21:45 +03:00
Serhiy Storchaka 1f21eaa15e
bpo-15999: Clean up of handling boolean arguments. (GH-15610)
* Use the 'p' format unit instead of manually called PyObject_IsTrue().
* Pass boolean value instead 0/1 integers to functions that needs boolean.
* Convert some arguments to boolean only once.
2019-09-01 12:16:51 +03:00
Serhiy Storchaka 5eca7f3f38
bpo-15999: Always pass bool instead of int to socket.setblocking(). (GH-15621) 2019-09-01 12:12:52 +03:00
Serhiy Storchaka 41c57b3353
bpo-37994: Fix silencing all errors if an attribute lookup fails. (GH-15630)
Only AttributeError should be silenced.
2019-09-01 12:03:39 +03:00
Serhiy Storchaka f02ea6225b
bpo-36543: Remove old-deprecated ElementTree features. (GH-12707)
Remove methods Element.getchildren(), Element.getiterator() and
ElementTree.getiterator() and the xml.etree.cElementTree module.
2019-09-01 11:18:35 +03:00
Inada Naoki 013e52fd34
bpo-37990: fix gc stats (GH-15626) 2019-08-31 09:13:42 +09:00
Min ho Kim 39d87b5471 Fix typos mostly in comments, docs and test names (GH-15209) 2019-08-30 16:21:19 -04:00
Victor Stinner 96b4087ce7
bpo-37140: Fix StructUnionType_paramfunc() (GH-15612)
Fix a ctypes regression of Python 3.8. When a ctypes.Structure is
passed by copy to a function, ctypes internals created a temporary
object which had the side effect of calling the structure finalizer
(__del__) twice. The Python semantics requires a finalizer to be
called exactly once. Fix ctypes internals to no longer call the
finalizer twice.

Create a new internal StructParam_Type which is only used by
_ctypes_callproc() to call PyMem_Free(ptr) on Py_DECREF(argument).
StructUnionType_paramfunc() creates such object.
2019-08-30 14:30:33 +02:00
Sergey Fedoseev 6a650aaf77 bpo-37976: Prevent shadowing of TypeError in zip() (GH-15592) 2019-08-29 21:25:48 -07:00
Thomas A Caswell e278335a6e bpo-37933: Fix faulthandler.cancel_dump_traceback_later() (GH-15440)
Fix faulthandler.cancel_dump_traceback_later() call
if cancel_dump_traceback_later() was not called previously.
2019-08-29 18:30:04 +02:00
Rémi Lapeyre 4901fe274b bpo-37034: Display argument name on errors with keyword arguments with Argument Clinic. (GH-13593) 2019-08-29 17:49:08 +03:00
Joannah Nanjekye 2c5fb17118 bpo-36833: Add tests for Datetime C API Macros (GH-14842)
Added tests for PyDateTime_xxx_GET_xxx() macros of the C API of
the datetime module.
2019-08-29 14:54:46 +02:00
Justin Blanchard 122376df55 bpo-37372: Fix error unpickling datetime.time objects from Python 2 with seconds>=24. (GH-14307) 2019-08-29 10:36:15 +03:00
Serhiy Storchaka b235a1b473
bpo-37960: Silence only necessary errors in repr() of buffered and text streams. (GH-15543) 2019-08-29 09:25:22 +03:00
HongWeipeng fa220ec763 Raise a RuntimeError when tee iterator is consumed from different threads (GH-15567) 2019-08-28 20:39:25 -07:00
Vinay Sharma 13f37f2ba8 closes bpo-37964: add F_GETPATH command to fcntl (GH-15550)
https://bugs.python.org/issue37964



Automerge-Triggered-By: @benjaminp
2019-08-28 18:56:17 -07:00
Christian Heimes 98d90f745d
bpo-37951: Lift subprocess's fork() restriction (GH-15544) 2019-08-27 23:36:56 +02:00
vrajivk 8bf5fef873 bpo-36205: Fix the rusage implementation of time.process_time() (GH-15538) 2019-08-27 00:13:12 -04:00
Raymond Hettinger 6fee0f8ea7
bpo-37798: Minor code formatting and comment clean-ups. (GH-15526) 2019-08-26 11:25:58 -07:00
Inada Naoki b27cbec801 bpo-37055: fix warnings in _blake2 module (GH-14646)
https://bugs.python.org/issue37055



Automerge-Triggered-By: @tiran
2019-08-26 10:52:36 -07:00
Raymond Hettinger aef9ad82f7
bpo-37942: Improve argument clinic float converter (GH-15470) 2019-08-24 19:10:39 -07:00
Dong-hee Na 0a18ee4be7 bpo-37798: Add C fastpath for statistics.NormalDist.inv_cdf() (GH-15266) 2019-08-23 15:20:30 -07:00
Pablo Galindo 4be11c009a bpo-37915: Fix comparison between tzinfo objects and timezone objects (GH-15390)
https://bugs.python.org/issue37915



Automerge-Triggered-By: @pablogsal
2019-08-22 12:24:25 -07:00
Steve Dower df2d4a6f3d
bpo-37834: Normalise handling of reparse points on Windows (GH-15231)
bpo-37834: Normalise handling of reparse points on Windows
* ntpath.realpath() and nt.stat() will traverse all supported reparse points (previously was mixed)
* nt.lstat() will let the OS traverse reparse points that are not name surrogates (previously would not traverse any reparse point)
* nt.[l]stat() will only set S_IFLNK for symlinks (previous behaviour)
* nt.readlink() will read destinations for symlinks and junction points only

bpo-1311: os.path.exists('nul') now returns True on Windows
* nt.stat('nul').st_mode is now S_IFCHR (previously was an error)
2019-08-21 15:27:33 -07:00
Stefan Krah bcc446f525
Revert mode change that loses information in directory listings on Linux. (#15366) 2019-08-21 23:00:04 +02:00
Victor Stinner d8c5adf6f8
bpo-37851: faulthandler allocates its stack on demand (GH-15358)
The faulthandler module no longer allocates its alternative stack at
Python startup. Now the stack is only allocated at the first
faulthandler usage.

faulthandler no longer ignores memory allocation failure when
allocating the stack. sigaltstack() failure now raises an OSError
exception, rather than being ignored.

The alternative stack is no longer used if sigaction() is
not available. In practice, sigaltstack() should only be available
when sigaction() is avaialble, so this change should have no effect
in practice.

faulthandler.dump_traceback_later() internal locks are now only
allocated at the first dump_traceback_later() call, rather than
always being allocated at Python startup.
2019-08-21 13:40:42 +01:00
Greg Price 9ece4a5057 Unmark files as executable that can't actually be executed. (GH-15353)
There are plenty of legitimate scripts in the tree that begin with a
`#!`, but also a few that seem to be marked executable by mistake.

Found them with this command -- it gets executable files known to Git,
filters to the ones that don't start with a `#!`, and then unmarks
them as executable:

    $ git ls-files --stage \
      | perl -lane 'print $F[3] if (!/^100644/)' \
      | while read f; do
          head -c2 "$f" | grep -qxF '#!' \
          || chmod a-x "$f"; \
        done

Looking at the list by hand confirms that we didn't sweep up any
files that should have the executable bit after all.  In particular

 * The `.psd` files are images from Photoshop.

 * The `.bat` files sure look like things that can be run.
   But we have lots of other `.bat` files, and they don't have
   this bit set, so it must not be needed for them.



Automerge-Triggered-By: @benjaminp
2019-08-20 21:53:59 -07:00
Brett Cannon 1407038e0b
Remove a dead comment from ossaudiodev.c (#15346) 2019-08-20 12:20:47 -07:00
Joannah Nanjekye 9e66aba999 bpo-15913: Implement PyBuffer_SizeFromFormat() (GH-13873)
Implement PyBuffer_SizeFromFormat() function (previously
documented but not implemented): call struct.calcsize().
2019-08-20 15:46:36 +01:00
Alex Gaynor 40dad9545a Replace usage of the obscure PEM_read_bio_X509_AUX with the more standard PEM_read_bio_X509 (GH-15303)
X509_AUX is an odd, note widely used, OpenSSL extension to the X509 file format. This function doesn't actually use any of the extra metadata that it parses, so just use the standard API.

Automerge-Triggered-By: @tiran
2019-08-15 05:31:28 -07:00
Victor Stinner ac827edc49
bpo-21131: Fix faulthandler.register(chain=True) stack (GH-15276)
faulthandler now allocates a dedicated stack of SIGSTKSZ*2 bytes,
instead of just SIGSTKSZ bytes. Calling the previous signal handler
in faulthandler signal handler uses more than SIGSTKSZ bytes of stack
memory on some platforms.
2019-08-14 23:35:27 +02:00
Artem Khramov 2814620657 bpo-37811: FreeBSD, OSX: fix poll(2) usage in sockets module (GH-15202)
FreeBSD implementation of poll(2) restricts the timeout argument to be
either zero, or positive, or equal to INFTIM (-1).

Unless otherwise overridden, socket timeout defaults to -1. This value
is then converted to milliseconds (-1000) and used as argument to the
poll syscall. poll returns EINVAL (22), and the connection fails.

This bug was discovered during the EINTR handling testing, and the
reproduction code can be found in
https://bugs.python.org/issue23618 (see connect_eintr.py,
attached). On GNU/Linux, the example runs as expected.

This change is trivial:
If the supplied timeout value is negative, truncate it to -1.
2019-08-14 23:21:48 +02:00
Victor Stinner 077af8c2c9
bpo-37738: Fix curses addch(str, color_pair) (GH-15071)
Fix the implementation of curses addch(str, color_pair): pass the
color pair to setcchar(), instead of always passing 0 as the color
pair.
2019-08-14 12:31:43 +02:00
Greg Price 51aac15f6d Delete leftover clinic-generated file for C zipimport. (GH-15174) 2019-08-10 10:20:27 +03:00
Ngalim Siregar 92c7e30adf bpo-37642: Update acceptable offsets in timezone (GH-14878)
This fixes an inconsistency between the Python and C implementations of
the datetime module. The pure python version of the code was not
accepting offsets greater than 23:59 but less than 24:00. This is an
accidental legacy of the original implementation, which was put in place
before tzinfo allowed sub-minute time zone offsets.

GH-14878
2019-08-09 10:22:16 -04:00
Inada Naoki 2a570af12a
bpo-37587: optimize json.loads (GH-15134)
Use a tighter scope temporary variable to help register allocation.
1% speedup for large string.

Use PyDict_SetItemDefault() for memoizing keys.
At most 4% speedup when the cache hit ratio is low.
2019-08-08 17:57:10 +09:00
Sergey Fedoseev 3e41f3cabb bpo-34488: optimize BytesIO.writelines() (GH-8904)
Avoid the creation of unused int object for each line.
2019-08-07 09:38:31 +09:00
Serhiy Storchaka 18b711c5a7
bpo-37648: Fixed minor inconsistency in some __contains__. (GH-14904)
The collection's item is now always at the left and
the needle is on the right of ==.
2019-08-04 14:12:48 +03:00
Serhiy Storchaka 17e52649c0
bpo-37685: Fixed comparisons of datetime.timedelta and datetime.timezone. (GH-14996)
There was a discrepancy between the Python and C implementations.

Add singletons ALWAYS_EQ, LARGEST and SMALLEST in test.support
to test mixed type comparison.
2019-08-04 12:38:46 +03:00
Greg Bowser 8fbece135d bpo-36590: Add Bluetooth RFCOMM and support for Windows. (GH-12767)
Support for RFCOMM, L2CAP, HCI, SCO is based on the BTPROTO_* macros
being defined. Winsock only supports RFCOMM, even though it has a
BTHPROTO_L2CAP macro. L2CAP support would build on windows, but not
necessarily work.

This also adds some basic unittests for constants (all of which existed
prior to this commit, just not on windows) and creating sockets.

pair: Nate Duarte <slacknate@gmail.com>
2019-08-02 13:29:52 -07:00
Inada Naoki bf8162c8c4
bpo-37729: gc: write stats at once (GH-15050)
gc used several PySys_WriteStderr() calls to write stats.
It caused stats mixed up when stderr is shared by multiple
processes like this:

  gc: collecting generation 2...
  gc: objects in each generation: 0 0gc: collecting generation 2...
  gc: objects in each generation: 0 0 126077 126077
  gc: objects in permanent generation: 0

  gc: objects in permanent generation: 0
  gc: done, 112575 unreachable, 0 uncollectablegc: done, 112575 unreachable, 0 uncollectable, 0.2223s elapsed
  , 0.2344s elapsed
2019-08-02 16:25:29 +09:00
Anthony Sottile c9345e382c bpo-37695: Correct unget_wch error message. (GH-14986) 2019-07-31 15:11:24 +03:00
karl ding 31c4fd2a10 bpo-37085: Expose SocketCAN bcm_msg_head flags (#13646)
Expose the CAN_BCM SocketCAN constants used in the bcm_msg_head struct
flags (provided by <linux/can/bcm.h>) under the socket library.

This adds the following constants with a CAN_BCM prefix:

  * SETTIMER
  * STARTTIMER
  * TX_COUNTEVT
  * TX_ANNOUNCE
  * TX_CP_CAN_ID
  * RX_FILTER_ID
  * RX_CHECK_DLC
  * RX_NO_AUTOTIMER
  * RX_ANNOUNCE_RESUME
  * TX_RESET_MULTI_IDX
  * RX_RTR_FRAME
  * CAN_FD_FRAME

The CAN_FD_FRAME flag was introduced in the 4.8 kernel, while the other
ones were present since SocketCAN drivers were mainlined in 2.6.25. As
such, it is probably unnecessary to guard against these constants being
missing.
2019-07-31 10:47:16 +02:00
Min ho Kim c4cacc8c5e Fix typos in comments, docs and test names (#15018)
* Fix typos in comments, docs and test names

* Update test_pyparse.py

account for change in string length

* Apply suggestion: splitable -> splittable

Co-Authored-By: Terry Jan Reedy <tjreedy@udel.edu>

* Apply suggestion: splitable -> splittable

Co-Authored-By: Terry Jan Reedy <tjreedy@udel.edu>

* Apply suggestion: Dealloccte -> Deallocate

Co-Authored-By: Terry Jan Reedy <tjreedy@udel.edu>

* Update posixmodule checksum.

* Reverse idlelib changes.
2019-07-30 18:16:13 -04:00
Marco Paolini 8a758f5b99 bpo-37587: Make json.loads faster for long strings (GH-14752)
When scanning the string, most characters are valid, so
checking for invalid characters first means never needing
to check the value of strict on valid strings, and only
needing to check it on invalid characters when doing
non-strict parsing of invalid strings.

This provides a measurable reduction in per-character
processing time (~11% in the pre-merge patch testing).
2019-07-31 00:16:34 +10:00
Pablo Galindo 9211e2fd81 bpo-37268: Add deprecation notice and a DeprecationWarning for the parser module (GH-15017)
Deprecate the parser module and add a deprecation warning triggered on import and a warning block in the documentation.





https://bugs.python.org/issue37268



Automerge-Triggered-By: @pablogsal
2019-07-30 04:04:01 -07:00
Raymond Hettinger 6b5f1b496f
bpo-37691: Let math.dist() accept sequences and iterables for coordinates (GH-14975) 2019-07-27 14:04:29 -07:00
Markus Mohrhard 898318b53d bpo-37502: handle default parameter for buffers argument of pickle.loads correctly (GH-14593) 2019-07-25 18:00:34 +02:00
Stefan Behnel c6cb4cdd21
bpo-37399: Correctly attach tail text to the last element/comment/pi (GH-14856)
* bpo-37399: Correctly attach tail text to the last element/comment/pi, even when comments or pis are discarded.
Also fixes the insertion of PIs when "insert_pis=True" is configured for a TreeBuilder.
2019-07-24 20:08:02 +02:00
Min ho Kim 96e12d5f4f Fix typos in docs, comments and test assert messages (#14872) 2019-07-21 16:12:33 -04:00
Hai Shi 5623ac87bb bpo-37476: Adding tests for asutf8 and asutf8andsize (GH-14531) 2019-07-20 15:56:23 +08:00
Zackery Spytz d395209653 bpo-37547: Fix a compiler warning in winconsoleio.c (GH-14785)
The compiler warning was introduced in
59ad110d7a.
2019-07-19 15:07:06 +09:00
Sergey Fedoseev 1c5e68e714 bpo-34749: Improved performance of binascii.a2b_base64(). (GH-9444)
https://bugs.python.org/issue34749
2019-07-14 05:15:32 -07:00
Mark Dickinson 014847034b
Fix inconsequential typo in math.remainder algorithm comments. (#14746) 2019-07-13 16:50:03 +01:00
Jeroen Demeyer ed184c06e2 bpo-37358: Use vectorcall for functools.partial (GH-14284)
https://bugs.python.org/issue37358
2019-07-13 07:39:18 -07:00
Giovanni Cappellotto dc3f99fa77 bpo-37548: Document range of atan, acos and asin (GH-14717) 2019-07-13 14:59:55 +01:00
gescheit b9a0376b0d closes bpo-37347: Fix refcount problem in sqlite3. (GH-14268) 2019-07-12 20:15:48 -07:00
Disconnect3d 13ab570feb Remove redundant check from arraymodule b_getitem (GH-14676)
The `arraymodule`'s `b_getitem` function returns a `PyLong` converted 
from `arrayobject`'s array, by dereferencing a pointer to `char`.

When the `char` type is `signed char`, the `if (x >= 128) x -= 256;` comparison/code is redundant because a `signed char` will have a value of `[-128, 127]` and so `x` will never be greater or equal than 128.

This check was indeed needed for situations where a given compiler would assume `char` being `unsigned char` which would make `x` in `[0, 256]` range.

However, the check can be removed if we cast the `ob_item` into a signed char pointer (`signed char*`) instead of `char*`.

This PR/commit introduces this change.
2019-07-11 14:57:42 -07:00
Jeroen Demeyer 1dbd084f1f bpo-29548: no longer use PyEval_Call* functions (GH-14683) 2019-07-12 00:57:32 +09:00
Jeroen Demeyer 59ad110d7a bpo-37547: add _PyObject_CallMethodOneArg (GH-14685) 2019-07-11 17:59:05 +09:00
Stefan Krah f117d871c4
Rename memory.c to mpalloc.c for consistency with the header file. (#14687) 2019-07-10 18:27:38 +02:00
Stefan Krah 4749dbe54c
Really remove vcstdint.h. (#14686) 2019-07-10 17:55:48 +02:00
Hai Shi 3a3db970de bpo-27679: Remove set_bitfields() from _ctypes_test (GH-14648) 2019-07-09 20:00:27 +02:00
Victor Stinner 76611c7c0a bpo-37120: Fix _ssl get_num_tickets() (GH-14668)
Replace PyLong_FromLong() with PyLong_FromSize_t():
SSL_CTX_get_num_tickets() return type is size_t.


https://bugs.python.org/issue37120
2019-07-09 04:30:52 -07:00
Jeroen Demeyer 762f93ff2e bpo-37337: Add _PyObject_CallMethodNoArgs() (GH-14267) 2019-07-08 17:19:25 +09:00
Min ho Kim f7d72e48fb Fix some typos (GH-14435) 2019-07-05 14:39:32 -07:00
Jeroen Demeyer 7f41c8e0dd bpo-37493: use _PyObject_CallNoArg in more places (GH-14575) 2019-07-04 19:35:31 +09:00
Jeroen Demeyer 196a530e00 bpo-37483: add _PyObject_CallOneArg() function (#14558) 2019-07-04 19:31:34 +09:00
Benjamin Peterson 2cd07920bb
Put pyexpatns.h include back. bpo-37437 (GH-14539) 2019-07-01 22:07:44 -07:00
Steve Dower e226e83d36
bpo-37363: Add audit events on startup for the run commands (GH-14524) 2019-07-01 16:03:53 -07:00
Victor Stinner 67310023f2
bpo-36763: Use PyConfig_Clear() (GH-14445)
Stop using "static PyConfig", PyConfig must now always use
dynamically allocated strings: use PyConfig_SetString(),
PyConfig_SetArgv() and PyConfig_Clear().
2019-07-01 19:52:45 +02:00
Christian Heimes f0f5930ac8 bpo-37428: Don't set PHA verify flag on client side (GH-14421)
SSLContext.post_handshake_auth = True no longer sets
SSL_VERIFY_POST_HANDSHAKE verify flag for client connections. Although the
option is documented as ignored for clients, OpenSSL implicitly enables cert
chain validation when the flag is set.

Signed-off-by: Christian Heimes <christian@python.org>



https://bugs.python.org/issue37428
2019-06-30 23:29:17 -07:00
Ammar Askar 5cbbbd73a6 bpo-29505: Add more fuzzing for re.compile, re.load and csv.reader (GH-14255)
Add more fuzz testing for re.compile, re.load and csv.reader
2019-06-29 22:54:42 -07:00
Victor Stinner ec3e20a2d1
bpo-37412: Fix os.getcwd() for long path on Windows (GH-14424)
* Fix test for integer overflow.
* Add an unit test.
2019-06-28 18:01:59 +02:00
Victor Stinner 3029035ef3
bpo-20443: Fix calculate_program_full_path() warning (GH-14446)
Don't call _Py_isabs() with a bytes string (char*), the function
expects as wide string.
2019-06-28 16:49:38 +02:00
Jeroen Demeyer b1263d5a60 bpo-37337: Add _PyObject_VectorcallMethod() (GH-14228) 2019-06-28 18:49:00 +09:00
Benjamin Peterson 3b03b09fc9
closes bpo-37437: Update vendorized expat to 2.2.7. (GH-14436) 2019-06-27 20:54:44 -07:00
Brandt Bucher 45a30af109 closes bpo-37420: Handle errors during iteration in os.sched_setaffinity. (GH-14414) 2019-06-27 09:10:57 -07:00
Zackery Spytz d52a83a3d4 bpo-37419: Fix possible segfaults when passing large sequences to os.posix_spawn() (GH-14409)
Use Py_ssize_t instead of int for i.
2019-06-26 21:54:19 +01:00
Victor Stinner 689830ee62
bpo-37412: os.getcwdb() now uses UTF-8 on Windows (GH-14396)
The os.getcwdb() function now uses the UTF-8 encoding on Windows,
rather than the ANSI code page: see PEP 529 for the rationale. The
function is no longer deprecated on Windows.

os.getcwd() and os.getcwdb() now detect integer overflow on memory
allocations. On Unix, these functions properly report MemoryError on
memory allocation failure.
2019-06-26 17:31:12 +02:00
Victor Stinner c6a2320e87
bpo-37406: sqlite3 raises TypeError for wrong operation type (GH-14386)
The sqlite3 module now raises TypeError, rather than ValueError, if
operation argument type is not str: execute(), executemany() and
calling a connection.
2019-06-26 03:16:24 +02:00
Victor Stinner 22eb689cf3
bpo-37388: Development mode check encoding and errors (GH-14341)
In development mode and in debug build, encoding and errors arguments
are now checked on string encoding and decoding operations. Examples:
open(), str.encode() and bytes.decode().

By default, for best performances, the errors argument is only
checked at the first encoding/decoding error, and the encoding
argument is sometimes ignored for empty strings.
2019-06-26 00:51:05 +02:00
Victor Stinner 3939c321c9
bpo-20443: _PyConfig_Read() gets the absolute path of run_filename (GH-14053)
Python now gets the absolute path of the script filename specified on
the command line (ex: "python3 script.py"): the __file__ attribute of
the __main__ module, sys.argv[0] and sys.path[0] become an absolute
path, rather than a relative path.

* Add _Py_isabs() and _Py_abspath() functions.
* _PyConfig_Read() now tries to get the absolute path of
  run_filename, but keeps the relative path if _Py_abspath() fails.
* Reimplement os._getfullpathname() using _Py_abspath().
* Use _Py_isabs() in getpath.c.
2019-06-25 15:02:43 +02:00
ziheng 6ffd9b05df bpo-32627: Fix compile error when conflicting `_uuid` headers included (GH-11751) 2019-06-24 13:59:50 -04:00
Steve Dower 60419a7e96
bpo-37363: Add audit events for a range of modules (GH-14301) 2019-06-24 08:42:54 -07:00
Gabe Appleton 2ac3bab2a6 bpo-37345: Add formal UDPLITE support (GH-14258)
At the moment you can definitely use UDPLITE sockets on Linux systems, but it would be good if this support were formalized such that you can detect support at runtime easily.

At the moment, to make and use a UDPLITE socket requires something like the following code:

```
>>> import socket
>>> a = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 136)
>>> b = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 136)
>>> a.bind(('localhost', 44444))
>>> b.sendto(b'test'*256, ('localhost', 44444))
>>> b.setsockopt(136, 10, 16)
>>> b.sendto(b'test'*256, ('localhost', 44444))
>>> b.setsockopt(136, 10, 32)
>>> b.sendto(b'test'*256, ('localhost', 44444))
>>> b.setsockopt(136, 10, 64)
>>> b.sendto(b'test'*256, ('localhost', 44444))
```

If you look at this through Wireshark, you can see that the packets are different in that the checksums and checksum coverages change.

With the pull request that I am submitting momentarily, you could do the following code instead:

```
>>> import socket
>>> a = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDPLITE)
>>> b = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDPLITE)
>>> a.bind(('localhost', 44444))
>>> b.sendto(b'test'*256, ('localhost', 44444))
>>> b.set_send_checksum_coverage(16)
>>> b.sendto(b'test'*256, ('localhost', 44444))
>>> b.set_send_checksum_coverage(32)
>>> b.sendto(b'test'*256, ('localhost', 44444))
>>> b.set_send_checksum_coverage(64)
>>> b.sendto(b'test'*256, ('localhost', 44444))
```

One can also detect support for UDPLITE just by checking

```
>>> hasattr(socket, 'IPPROTO_UDPLITE')
```


https://bugs.python.org/issue37345
2019-06-24 02:58:56 -07:00
Zackery Spytz 08286d52b2 bpo-37316: mmap.mmap() passes the wrong variable to PySys_Audit() (GH-14152)
Also, add a missing call to va_end() in PySys_Audit().
2019-06-21 08:31:59 -07:00
Benjamin Peterson 7821b4c6d2
Fix name of '\0'. (GH-14222)
'\0' is the NUL byte not NULL.
2019-06-18 21:37:58 -07:00
Victor Stinner 01b63ecac6
bpo-35134: Add Include/cpython/import.h header file (GH-14213)
* Add Include/cpython/import.h and Include/internal/pycore_import.h
  header files.
* Move _PyImport_ReInitLock() to the internal C API. Don't export the
  symbol anymore.
2019-06-19 00:48:09 +02:00
Serhiy Storchaka 231aad3849
bpo-37315: Deprecate accepting floats in math.factorial(). (GH-14147) 2019-06-17 16:57:27 +03:00
Victor Stinner 2ff58a24e8
bpo-37194: Add a new public PyObject_CallNoArgs() function (GH-13890)
Add a new public PyObject_CallNoArgs() function to the C API: call a
callable Python object without any arguments.

It is the most efficient way to call a callback without any argument.
On x86-64, for example, PyObject_CallFunctionObjArgs(func, NULL)
allocates 960 bytes on the stack per call, whereas
PyObject_CallNoArgs(func) only allocates 624 bytes per call.

It is excluded from stable ABI 3.8.

Replace private _PyObject_CallNoArg() with public
PyObject_CallNoArgs() in C extensions: _asyncio, _datetime,
_elementtree, _pickle, _tkinter and readline.
2019-06-17 14:27:23 +02:00
Mark Dickinson 2dfeaa9222
Turn math.isqrt assertion into a comment to clarify its purpose. (GH-14131) 2019-06-16 17:53:21 +01:00
Mark Dickinson 45e0411eee
Simplify negativity checks in math.comb and math.perm. (GH-13870) 2019-06-16 11:06:06 +01:00
Victor Stinner 066e5b1a91
bpo-37266: Daemon threads are now denied in subinterpreters (GH-14049)
In a subinterpreter, spawning a daemon thread now raises an
exception. Daemon threads were never supported in subinterpreters.
Previously, the subinterpreter finalization crashed with a Pyton
fatal error if a daemon thread was still running.

* Add _thread._is_main_interpreter()
* threading.Thread.start() now raises RuntimeError if the thread is a
  daemon thread and the method is called from a subinterpreter.
* The _thread module now uses Argument Clinic for the new function.
* Use textwrap.dedent() in test_threading.SubinterpThreadingTests
2019-06-14 18:55:22 +02:00
Jeffrey Kintscher 8725c83ed5 bpo-35070: test_getgrouplist may fail on macOS if too many groups (GH-13071) 2019-06-13 03:01:29 -04:00
Victor Stinner 37d66d7d4b
bpo-37253: Add _PyCompilerFlags_INIT macro (GH-14018)
Add a new _PyCompilerFlags_INIT macro to initialize PyCompilerFlags
variables, rather than initializing cf_flags and cf_feature_version
explicitly in each variable.
2019-06-13 02:16:41 +02:00
Paul Monson b4c7defe58 bpo-36779: time.tzname returns empty string on Windows if default cod… (GH-13073)
Calling setlocale(LC_CTYPE, "") on a system where GetACP() returns CP_UTF8 results in empty strings in _tzname[].

This causes time.tzname to be an empty string.
I have reported the bug to the UCRT team and will follow up, but it will take some time get a fix into production.

In the meantime one possible workaround is to temporarily change the locale by calling setlocale(LC_CTYPE, "C") before calling _tzset and restore the current locale after if the GetACP() == CP_UTF8 or CP_UTF7

@zooba 


https://bugs.python.org/issue36779
2019-06-12 16:13:27 -07:00
Ammar Askar a6e190e94b bpo-29505: Fuzz json module, enforce size limit on int(x) fuzz (GH-13991)
* bpo-29505: Enable fuzz testing of the json module, enforce size limit on int(x) fuzz and json input size to avoid timeouts.

Contributed by by Ammar Askar for Google.
2019-06-11 21:30:34 -07:00
aaronpaulhurst 408a2ef1ac closes bpo-35184: Fix XML_POOR_ENTROPY option that breaks makesetup parsing of pyexpat line in Setup. (GH-13064)
When the line is uncommented, the equals character causes it to be incorrectly interpreted
as a macro definition by makesetup.  This results in invalid Makefile output.

The expat code only requires XML_POOR_ENTROPY to be defined; the value is unnecessary.
2019-06-10 18:54:24 -07:00
Raymond Hettinger e119b3d136
bpo-37178: Allow a one argument form of math.perm() (GH-13905) 2019-06-08 08:58:11 -07:00
Ammar Askar a15a7bcaea bpo-29505: Fix interpreter in fuzzing targets to be relocatable (GH-13907) 2019-06-08 07:43:16 -07:00
Victor Stinner 3bf0f3ad20
bpo-37169: Rewrite _PyObject_IsFreed() unit tests (GH-13888)
Replace two Python function calls with a single one to ensure that no
memory allocation is done between the invalid object is created and
when _PyObject_IsFreed() is called.
2019-06-07 16:22:21 +02:00
Eric Wieser 0690c79c41 bpo-37188: Fix a divide-by-zero in arrays of size-0 objects (#13881) 2019-06-07 10:13:26 +02:00
Zackery Spytz dc2476500d bpo-37170: Fix the cast on error in PyLong_AsUnsignedLongLongMask() (GH-13860) 2019-06-06 22:39:23 +02:00
Raymond Hettinger e985804207
bpo-37165: Convert _count_elements to the argument clinic (GH-13848) 2019-06-05 16:05:25 -07:00
Raymond Hettinger 963eb0f473
bpo-35431: Drop the k <= n requirement (GH-13798) 2019-06-04 01:23:06 -07:00
Victor Stinner 0fd2c300c2
Revert "bpo-36818: Add PyInterpreterState.runtime field. (gh-13129)" (GH-13795)
This reverts commit 396e0a8d9d.
2019-06-04 03:15:09 +02:00
Christian Heimes 78c7d52779
bpo-37120: Add SSLContext.num_tickets (GH-13719)
Signed-off-by: Christian Heimes <christian@python.org>
2019-06-03 21:00:10 +02:00
Christian Heimes e35d1ba9ea
bpo-34271: Fix compatibility with 1.0.2 (GH-13728)
Fix various compatibility issues with LibreSSL and OpenSSL 1.0.2
introduced by bpo-34271.

Signed-off-by: Christian Heimes <christian@python.org>
2019-06-03 20:40:15 +02:00
Victor Stinner e225bebc14
Revert "bpo-33608: Factor out a private, per-interpreter _Py_AddPendingCall(). (gh-13714)" (GH-13780)
This reverts commit 6a150bcaeb.
2019-06-03 18:14:24 +02:00
Petr Viktorin e584cbff1e
bpo-36027 bpo-36974: Fix "incompatible pointer type" compiler warnings (GH-13758) 2019-06-03 01:08:14 +02:00
Petr Viktorin fb9423fd0a
bpo-36974: Make tp_call=PyVectorcall_Call work for inherited types (GH-13699)
When inheriting a heap subclass from a vectorcall class that sets
`.tp_call=PyVectorcall_Call` (as recommended in PEP 590), the subclass does
not inherit `_Py_TPFLAGS_HAVE_VECTORCALL`, and thus `PyVectorcall_Call` does
not work for it.

This attempts to solve the issue by:
* always inheriting `tp_vectorcall_offset` unless `tp_call` is overridden
  in the subclass
* inheriting _Py_TPFLAGS_HAVE_VECTORCALL for static types, unless `tp_call`
  is overridden
* making `PyVectorcall_Call` ignore `_Py_TPFLAGS_HAVE_VECTORCALL`

This means it'll be ever more important to only call `PyVectorcall_Call`
on classes that support vectorcall. In `PyVectorcall_Call`'s intended role
as `tp_call` filler, that's not a problem.
2019-06-02 23:52:20 +02:00
Serhiy Storchaka 5ae299ac78
bpo-37128: Add math.perm(). (GH-13731) 2019-06-02 11:16:49 +03:00
Eric Snow 6a150bcaeb
bpo-33608: Factor out a private, per-interpreter _Py_AddPendingCall(). (gh-13714) 2019-06-01 15:39:46 -06:00
Zackery Spytz 36dcaab7fd Fix the error handling in bytesio_sizeof(). (GH-10459)
bytesio_sizeof() must check if an error has occurred in _PySys_GetSizeOf().
2019-06-02 00:07:45 +03:00
Sergey Fedoseev e5f6207ba6 bpo-34303: Micro-optimizations in functools.reduce() (GH-8598) 2019-06-01 13:32:17 -07:00
Serhiy Storchaka 2b843ac0ae
bpo-35431: Refactor math.comb() implementation. (GH-13725)
* Fixed some bugs.
* Added support for index-likes objects.
* Improved error messages.
* Cleaned up and optimized the code.
* Added more tests.
2019-06-01 22:09:02 +03:00
Yash Aggarwal 4a686504eb bpo-35431: Implemented math.comb (GH-11414) 2019-06-01 00:21:27 -07:00
Eric Snow 396e0a8d9d
bpo-36818: Add PyInterpreterState.runtime field. (gh-13129)
https://bugs.python.org/issue36818
2019-05-31 21:16:47 -06:00
Pablo Galindo aac4d0342c
bpo-26826: Expose copy_file_range in the os module (GH-7255) 2019-05-31 19:39:47 +01:00
Christian Heimes 8cbb5b6625
bpo-26835: Add file sealing constants to fcntl (GH-13694)
Co-authored-by: nanjekyejoannah <nanjekyejoannah@gmail.com>
2019-05-31 18:32:33 +02:00
Zackery Spytz c7f803b08e bpo-36379: __ipow__ must be a ternaryfunc, not a binaryfunc (GH-13546)
If a type's __ipow__ method was implemented in C, attempting to use
the *modulo* parameter would cause crashes.


https://bugs.python.org/issue36379
2019-05-31 02:46:36 -07:00
Christian Heimes c7f7069e77
bpo-34271: Add ssl debugging helpers (GH-10031)
The ssl module now can dump key material to a keylog file and trace TLS
protocol messages with a tracing callback. The default and stdlib
contexts also support SSLKEYLOGFILE env var.

The msg_callback and related enums are private members. The feature
is designed for internal debugging and not for end users.

Signed-off-by: Christian Heimes <christian@python.org>
2019-05-31 11:44:05 +02:00
Serhiy Storchaka 38ab7d4721
bpo-31829: Make protocol 0 pickles be loadable in text mode in Python 2. (GH-11859)
Escape ``\r``, ``\0`` and ``\x1a`` (end-of-file on Windows) in Unicode strings.
2019-05-31 11:29:39 +03:00
Serhiy Storchaka 65fb2c08c0
bpo-339827: Do not swallow exceptions in the _ssl module. (GH-12756) 2019-05-31 10:39:15 +03:00
Jeroen Demeyer 530f506ac9 bpo-36974: tp_print -> tp_vectorcall_offset and tp_reserved -> tp_as_async (GH-13464)
Automatically replace
tp_print -> tp_vectorcall_offset
tp_compare -> tp_as_async
tp_reserved -> tp_as_async
2019-05-30 19:13:39 -07:00
Alex Grönholm 98ef92002e bpo-36999: Add asyncio.Task.get_coro() (GH-13680)
https://bugs.python.org/issue36999
2019-05-30 08:30:09 -07:00
Jeroen Demeyer c145f3bfbe bpo-36974: remove _PyObject_HasFastCall (GH-13460) 2019-05-30 12:43:58 +02:00
Jeroen Demeyer 735e8afa9e bpo-36974: inherit the vectorcall protocol (GH-13498) 2019-05-30 12:43:19 +02:00
Zackery Spytz eda385c0dc bpo-36935: Remove usage of the deprecated PyErr_SetFromWindowsErrWithUnicodeFilename() (GH-13355)
In e895de3e7f, the
deprecated function PyErr_SetFromWindowsErrWithUnicodeFilename() was
added in two functions in Modules/_winapi.c. This function was
deprecated in 3.3.
2019-05-30 09:58:50 +02:00
Zackery Spytz 8f96c9f8ed bpo-37007: Implement socket.if_nametoindex(), if_indextoname() and if_nameindex() on Windows (GH-13522) 2019-05-29 14:02:37 -07:00
Zackery Spytz e70bfa95e6 bpo-26836: Add ifdefs for all MFD_HUGE* constants (GH-13666)
https://bugs.python.org/issue26836
2019-05-29 13:43:49 -07:00
Antoine Pitrou ada319bb6d
bpo-32388: Remove cross-version binary compatibility requirement in tp_flags (GH-4944)
It is now allowed to add new fields at the end of the PyTypeObject struct without having to allocate a dedicated compatibility flag in tp_flags.

This will reduce the risk of running out of bits in the 32-bit tp_flags value.
2019-05-29 22:12:38 +02:00
Zackery Spytz 43fdbd2729 bpo-26836: Add os.memfd_create() (#13567)
* bpo-26836: Add os.memfd_create()

* Use the glibc wrapper for memfd_create()

Co-Authored-By: Christian Heimes <christian@python.org>

* Fix deletions caused by autoreconf.

* Use MFD_CLOEXEC as the default value for *flags*.

* Add memset_s to configure.ac.

* Revert memset_s changes.

* Apply the requested changes.

* Tweak the docs.
2019-05-29 21:57:03 +02:00
Gregory P. Smith 0c2f930564
bpo-22385: Support output separators in hex methods. (#13578)
* bpo-22385: Support output separators in hex methods.

Also in binascii.hexlify aka b2a_hex.

The underlying implementation behind all hex generation in CPython uses the
same pystrhex.c implementation.  This adds support to bytes, bytearray,
and memoryview objects.

The binascii module functions exist rather than being slated for deprecation
because they return bytes rather than requiring an intermediate step through a
str object.

This change was inspired by MicroPython which supports sep in its binascii
implementation (and does not yet support the .hex methods).

https://bugs.python.org/issue22385
2019-05-29 11:46:58 -07:00
Jeroen Demeyer aacc77fbd7 bpo-36974: implement PEP 590 (GH-13185)
Co-authored-by: Jeroen Demeyer <J.Demeyer@UGent.be>
Co-authored-by: Mark Shannon <mark@hotpy.org>
2019-05-29 20:31:52 +02:00
David Carlier d8b7551672 bpo-33164: blake2 fix for HP-UX (GH-13633) 2019-05-29 19:58:11 +09:00
Victor Stinner 8b09500345
bpo-37076: _thread.start_new_thread() calls _PyErr_WriteUnraisableMsg() (GH-13617)
_thread.start_new_thread() now logs uncaught exception raised by the
function using sys.unraisablehook(), rather than sys.excepthook(), so
the hook gets access to the function which raised the exception.
2019-05-29 02:57:56 +02:00
Dino Viehland 415406999d
bpo-37001: Makes symtable.symtable have parity with compile for input (#13483)
* Makes symtable.symtable have parity for accepted datatypes
for source code as compile()

* Add NEWS blurb
2019-05-28 16:21:17 -07:00
Jeroen Demeyer eb65e2443a bpo-36922: implement PEP-590 Py_TPFLAGS_METHOD_DESCRIPTOR (GH-13338)
Co-authored-by: Mark Shannon <mark@hotpy.org>
2019-05-28 14:42:53 +02:00
Andrew Svetlov bafd4b5ac8 bpo-29883: Asyncio proactor udp (GH-13440)
Follow-up for #1067


https://bugs.python.org/issue29883
2019-05-28 02:52:15 -07:00
Victor Stinner cd590a7ced
bpo-1230540: Add threading.excepthook() (GH-13515)
Add a new threading.excepthook() function which handles uncaught
Thread.run() exception. It can be overridden to control how uncaught
exceptions are handled.

threading.ExceptHookArgs is not documented on purpose: it should not
be used directly.

* threading.excepthook() and threading.ExceptHookArgs.
* Add _PyErr_Display(): similar to PyErr_Display(), but accept a
  'file' parameter.
* Add _thread._excepthook(): C implementation of the exception hook
  calling _PyErr_Display().
* Add _thread._ExceptHookArgs: structseq type.
* Add threading._invoke_excepthook_wrapper() which handles the gory
  details to ensure that everything remains alive during Python
  shutdown.
* Add unit tests.
2019-05-28 00:39:52 +02:00
Zackery Spytz 02db696732 bpo-32941: Add madvise() for mmap objects (GH-6172)
Allow mmap objects to access the madvise() system call.
2019-05-27 18:48:16 +02:00
Victor Stinner 331a6a56e9
bpo-36763: Implement the PEP 587 (GH-13592)
* Add a whole new documentation page:
  "Python Initialization Configuration"
* PyWideStringList_Append() return type is now PyStatus,
  instead of int
* PyInterpreterState_New() now calls PyConfig_Clear() if
  PyConfig_InitPythonConfig() fails.
* Rename files:

  * Python/coreconfig.c => Python/initconfig.c
  * Include/cpython/coreconfig.h => Include/cpython/initconfig.h
  * Include/internal/: pycore_coreconfig.h => pycore_initconfig.h

* Rename structures

  * _PyCoreConfig => PyConfig
  * _PyPreConfig => PyPreConfig
  * _PyInitError => PyStatus
  * _PyWstrList => PyWideStringList

* Rename PyConfig fields:

  * use_module_search_paths => module_search_paths_set
  * module_search_path_env => pythonpath_env

* Rename PyStatus field: _func => func
* PyInterpreterState: rename core_config field to config
* Rename macros and functions:

  * _PyCoreConfig_SetArgv() => PyConfig_SetBytesArgv()
  * _PyCoreConfig_SetWideArgv() => PyConfig_SetArgv()
  * _PyCoreConfig_DecodeLocale() => PyConfig_SetBytesString()
  * _PyInitError_Failed() => PyStatus_Exception()
  * _Py_INIT_ERROR_TYPE_xxx enums => _PyStatus_TYPE_xxx
  * _Py_UnixMain() => Py_BytesMain()
  * _Py_ExitInitError() => Py_ExitStatusException()
  * _Py_PreInitializeFromArgs() => Py_PreInitializeFromBytesArgs()
  * _Py_PreInitializeFromWideArgs() => Py_PreInitializeFromArgs()
  * _Py_PreInitialize() => Py_PreInitialize()
  * _Py_RunMain() => Py_RunMain()
  * _Py_InitializeFromConfig() => Py_InitializeFromConfig()
  * _Py_INIT_XXX() => _PyStatus_XXX()
  * _Py_INIT_FAILED() => _PyStatus_EXCEPTION()

* Rename 'err' PyStatus variables to 'status'
* Convert RUN_CODE() macro to config_run_code() static inline function
* Remove functions:

  * _Py_InitializeFromArgs()
  * _Py_InitializeFromWideArgs()
  * _PyInterpreterState_GetCoreConfig()
2019-05-27 16:39:22 +02:00
Yury Selivanov 431b540bf7
bpo-32528: Make asyncio.CancelledError a BaseException. (GH-13528)
This will address the common mistake many asyncio users make:
an "except Exception" clause breaking Tasks cancellation.

In addition to this change, we stop inheriting asyncio.TimeoutError
and asyncio.InvalidStateError from their concurrent.futures.*
counterparts.  There's no point for these exceptions to share the
inheritance chain.

In 3.9 we'll focus on implementing supervisors and cancel scopes,
which should allow better handling of all exceptions, including
SystemExit and KeyboardInterrupt
2019-05-27 14:45:12 +02:00
Victor Stinner 71c52e3048
bpo-36829: Add _PyErr_WriteUnraisableMsg() (GH-13488)
* sys.unraisablehook: add 'err_msg' field to UnraisableHookArgs.
* Use _PyErr_WriteUnraisableMsg() in _ctypes _DictRemover_call()
  and gc delete_garbage().
2019-05-27 08:57:14 +02:00
Antoine Pitrou 91f4380ced
bpo-36785: PEP 574 implementation (GH-7076) 2019-05-26 17:10:09 +02:00
Pablo Galindo 561612d845
bpo-37021: Port _randommodule to the argument clinic (GH-13532) 2019-05-24 22:09:23 +01:00
Victor Stinner 438a12dd9d
bpo-36710: Add tstate parameter in ceval.c (GH-13547)
* Fix a possible reference leak in _PyErr_Print() if exception
  is NULL.
* PyErr_BadInternalCall(): replace PyErr_Format() with _PyErr_SetString().
* Add pycore_pyerrors.h header file.
* New functions:

  * _PyErr_Clear()
  * _PyErr_Fetch()
  * _PyErr_Print()
  * _PyErr_Restore()
  * _PyErr_SetObject()
  * _PyErr_SetString()

* Add 'tstate' parameter to _PyEval_AddPendingCall().
2019-05-24 17:01:38 +02:00
Victor Stinner b49858b4b7
bpo-37031: Fix PyOS_AfterFork_Child() (GH-13537)
PyOS_AfterFork_Child(): _PyInterpreterState_DeleteExceptMain() must
be called after _PyRuntimeState_ReInitThreads().

_PyRuntimeState_ReInitThreads() resets interpreters mutex after fork,
mutex used by _PyInterpreterState_DeleteExceptMain().
2019-05-24 15:20:23 +02:00
Victor Stinner d8613dc86f
bpo-37031: Reuse _PyRuntime.main_thread in signalmodule.c (GH-13538)
Remove main_thread and main_interp variables from signalmodule.c:
reuse _PyRuntime which already track the main thread and the main
interpreter.

* Remove #include <sys/types.h> which became useless: getpid() call
  has been removed.
* Add runtime argument to is_main()
* is_main() now gets the interpreter from runtime.
2019-05-24 13:43:55 +02:00
Matěj Cepl 608876b6b1 bpo-23395: Fix PyErr_SetInterrupt if the SIGINT signal is ignored or not handled (GH-7778)
``_thread.interrupt_main()`` now avoids setting the Python error status if the ``SIGINT`` signal is ignored or not handled by Python.
2019-05-23 22:30:00 +02:00
Steve Dower b82e17e626
bpo-36842: Implement PEP 578 (GH-12613)
Adds sys.audit, sys.addaudithook, io.open_code, and associated C APIs.
2019-05-23 08:45:22 -07:00
David Carlier 51aa35e9e1 bpo-33164: update blake2 implementation (GH-6286) 2019-05-23 13:32:44 +09:00
Jake Tesler b121f63155 bpo-36084: Add native thread ID (TID) to threading.Thread (GH-13463)
Add native thread ID (TID) to threading.Thread objects
(supported platforms: Windows, FreeBSD, Linux, macOS).
2019-05-22 17:43:16 +02:00
Marcel Plch 33e71e01e9 bpo-31862: Port binascii to PEP 489 multiphase initialization (GH-4108) 2019-05-22 13:51:25 +02:00
Victor Stinner ef9d9b6312
bpo-36829: Add sys.unraisablehook() (GH-13187)
Add new sys.unraisablehook() function which can be overridden to
control how "unraisable exceptions" are handled. It is called when an
exception has occurred but there is no way for Python to handle it.
For example, when a destructor raises an exception or during garbage
collection (gc.collect()).

Changes:

* Add an internal UnraisableHookArgs type used to pass arguments to
  sys.unraisablehook.
* Add _PyErr_WriteUnraisableDefaultHook().
* The default hook now ignores exception on writing the traceback.
* test_sys now uses unittest.main() to automatically discover tests:
  remove test_main().
* Add _PyErr_Init().
* Fix PyErr_WriteUnraisable(): hold a strong reference to sys.stderr
  while using it
2019-05-22 11:28:22 +02:00
Lihua Zhao 4fb1502189 bpo-36648: fix mmap issue for VxWorks (GH-12394)
The mmap module set MAP_SHARED flag when map anonymous memory, however VxWorks
only support MAP_PRIVATE when map anonymous memory, this commit clear MAP_SHARED
and set MAP_PRIVATE.
2019-05-21 12:50:14 +02:00
pxinwr f2d7ac7e5b bpo-31904: Add posix module support for VxWorks (GH-12118) 2019-05-21 12:46:37 +02:00
Victor Stinner d12e75734d
Revert "bpo-36084: Add native thread ID to threading.Thread objects (GH-11993)" (GH-13458)
This reverts commit 4959c33d25.
2019-05-21 12:44:57 +02:00
Erik Janssens 925af1d99b bpo-36965: Fix includes in main.c on Windows with non-MSC compilers (GH-13421)
Include windows.h rather than crtdbg.h to get STATUS_CONTROL_C_EXIT constant.
Moreover, include windows.h on Windows, not only when MSC is used.
2019-05-21 12:11:11 +02:00
Thomas Moreau c09a9f56c0 bpo-36888: Add multiprocessing.parent_process() (GH-13247) 2019-05-20 21:37:05 +02:00
Victor Stinner ed48866c55
bpo-35134: Split traceback.h header (GH-13430)
Add new Include/cpython/traceback.h and Include/internal/traceback.h
header files.
2019-05-20 00:14:57 +02:00
Mark Dickinson 5c08ce9bf7
bpo-36957: Speed up math.isqrt (#13405)
* Add math.isqrt function computing the integer square root.

* Code cleanup: remove redundant comments, rename some variables.

* Tighten up code a bit more; use Py_XDECREF to simplify error handling.

* Update Modules/mathmodule.c

Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com>

* Update Modules/mathmodule.c

Use real argument clinic type instead of an alias

Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com>

* Add proof sketch

* Updates from review.

* Correct and expand documentation.

* Fix bad reference handling on error; make some variables block-local; other tidying.

* Style and consistency fixes.

* Add missing error check; don't try to DECREF a NULL a

* Simplify some error returns.

* Another two test cases:

- clarify that floats are rejected even if they happen to be
  squares of small integers
- TypeError beats ValueError for a negative float

* Add fast path for small inputs. Needs tests.

* Speed up isqrt for n >= 2**64 as well; add extra tests.

* Reduce number of test-cases to avoid dominating the run-time of test_math.

* Don't perform unnecessary extra iterations when computing c_bit_length.

* Abstract common uint64_t code out into a separate function.

* Cleanup.

* Add a missing Py_DECREF in an error branch. More cleanup.

* Update Modules/mathmodule.c

Add missing `static` declaration to helper function.

Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com>

* Add missing backtick.
2019-05-19 17:51:56 +01:00
Serhiy Storchaka a5119e7d75
bpo-36957: Add _PyLong_Rshift() and _PyLong_Lshift(). (GH-13416) 2019-05-19 14:14:38 +03:00
Mark Dickinson 73934b9da0
bpo-36887: add math.isqrt (GH-13244)
* Add math.isqrt function computing the integer square root.

* Code cleanup: remove redundant comments, rename some variables.

* Tighten up code a bit more; use Py_XDECREF to simplify error handling.

* Update Modules/mathmodule.c

Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com>

* Update Modules/mathmodule.c

Use real argument clinic type instead of an alias

Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com>

* Add proof sketch

* Updates from review.

* Correct and expand documentation.

* Fix bad reference handling on error; make some variables block-local; other tidying.

* Style and consistency fixes.

* Add missing error check; don't try to DECREF a NULL a

* Simplify some error returns.

* Another two test cases:

- clarify that floats are rejected even if they happen to be
  squares of small integers
- TypeError beats ValueError for a negative float

* Documentation and markup improvements; thanks Serhiy for the suggestions!

* Cleaner Misc/NEWS entry wording.

* Clean up (with one fix) to the algorithm explanation and proof.
2019-05-18 12:29:50 +01:00
Victor Stinner 871ff77c1c
bpo-36763: Add _PyInitError functions (GH-13395)
* Add _PyInitError functions:

  * _PyInitError_Ok()
  * _PyInitError_Error()
  * _PyInitError_NoMemory()
  * _PyInitError_Exit()
  * _PyInitError_IsError()
  * _PyInitError_IsExit()
  * _PyInitError_Failed()

* frozenmain.c and _testembed.c now use functions rather than macros.
* Move _Py_INIT_xxx() macros to the internal API.
* Move _PyWstrList_INIT macro to the internal API.
2019-05-17 23:54:00 +02:00
Victor Stinner 12083284c5
bpo-36763: _Py_RunMain() doesn't call Py_Exit() anymore (GH-13390)
Py_Main() and _Py_RunMain() now return the exitcode rather than
calling Py_Exit(exitcode) when calling PyErr_Print() if the current
exception type is SystemExit.

* Add _Py_HandleSystemExit().
* Add pymain_exit_err_print().
* Add pymain_exit_print().
2019-05-17 23:05:29 +02:00
Edison A 98ff4d5fb6 bpo-36782: Created C API wrappers and added missing tests for functions in the PyDateTimeAPI. (#13088)
* created a c API wrapper for pyDate_FromDate and added the test

* 📜🤖 Added by blurb_it.

* fixed auto-alignment by vscode

* made changes as per PEP7

* Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst

* Refactored code as per requested changes

* Remove Whitespace to Fix failed travis build

* Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst

* Add a new line at end of ACKS

* Added C API function for PyDateTime_FromDateAndTime

* Added a test for the C API wrapper of PyDateTime_FromDateAndTime

* Added C API function for PyDateTime_FromDateAndTime

* Added a test for the C API wrapper of PyDateTime_FromDateAndTimeAndFold

* Remove Whitespace using patchcheck

* Added a C API function for PyTime_FromTime

* Added a test for the C API wrapper of PyTime_FromTime

* Added a C API function for PyTime_FromTimeAndFold

* Added a test for the C API wrapper of PyTime_FromTimeAndFold

* Added a C API function for PyDelta_FromDSU

* Added a test for the C API wrapper of PyDelta_FromDSU

* Refactor code, re-edit lines longer than 80 chars

* Fix Whitespace issues in DatetimeTester

* List all tests that were added in this PR

* Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst

* Reformat code as per PEP7 guidelines

* Remove unused varibles from another function

* Added specific tests for the Fold Attribute

* Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst

* Reformat code according to requested changes

* Reformat code to PEP7 Guidelines

* Reformat code to PEP7 Guidelines

* Re-add name to blurb

* Added a backtick to blurb file

* Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst

* Remove the need to initialize mandatory parameters

* Make the macro parameter mandatory

* Re-arrange the order of unit-test args

* Removed the need to initialize macro

change all the int macro = 0 to int macro; now that macro is required

Co-Authored-By: Paul Ganssle <pganssle@users.noreply.github.com>

* Removed the need to initialize macro

change all the `int macro = 0` to `int macro`; now that macro is required

Co-Authored-By: Paul Ganssle <pganssle@users.noreply.github.com>

* Removed the need to initialize macro

change all the `int macro = 0` to `int macro`; now that macro is required

Co-Authored-By: Paul Ganssle <pganssle@users.noreply.github.com>

* Removed the need to initialize macro

change all the `int macro = 0` to `int macro`; now that macro is required

Co-Authored-By: Paul Ganssle <pganssle@users.noreply.github.com>

* Removed the need to initialize macro

change all the `int macro = 0` to `int macro`; now that macro is required

Co-Authored-By: Paul Ganssle <pganssle@users.noreply.github.com>

* Removed the need to initialize macro

change all the `int macro = 0` to `int macro`; now that macro is required

Co-Authored-By: Paul Ganssle <pganssle@users.noreply.github.com>
2019-05-17 22:28:42 +02:00
Victor Stinner cab5d0741e
bpo-36763: Add _PyCoreConfig_InitPythonConfig() (GH-13388)
Add new functions to get the Python interpreter behavior:

* _PyPreConfig_InitPythonConfig()
* _PyCoreConfig_InitPythonConfig()

Add new functions to get an isolated configuration:

* _PyPreConfig_InitIsolatedConfig()
* _PyCoreConfig_InitIsolatedConfig()

Replace _PyPreConfig_INIT and _PyCoreConfig_INIT with new functions
_PyPreConfig_Init() and _PyCoreConfig_Init().

_PyCoreConfig: set configure_c_stdio and parse_argv to 0 by default
to behave as Python 3.6 in the default configuration.

_PyCoreConfig_Read() no longer sets coerce_c_locale_warn to 1 if it's
equal to 0. coerce_c_locale_warn must now be set to -1 (ex: using
_PyCoreConfig_InitPythonConfig()) to enable C locale coercion
warning.

Add unit tests for _PyCoreConfig_InitPythonConfig()
and _PyCoreConfig_InitIsolatedConfig().

Changes:

* Rename _PyCoreConfig_GetCoreConfig() to _PyPreConfig_GetCoreConfig()
* Fix core_read_precmdline(): handle parse_argv=0
* Fix _Py_PreInitializeFromCoreConfig(): pass coreconfig.argv
  to _Py_PreInitializeFromPyArgv(), except if parse_argv=0
2019-05-17 19:01:14 +02:00
Victor Stinner b16b4e4592
bpo-36763: Add PyMemAllocatorName (GH-13387)
* Add PyMemAllocatorName enum
* _PyPreConfig.allocator type becomes PyMemAllocatorName, instead of
  char*
* Remove _PyPreConfig_Clear()
* Add _PyMem_GetAllocatorName()
* Rename _PyMem_GetAllocatorsName() to
  _PyMem_GetCurrentAllocatorName()
* Remove _PyPreConfig_SetAllocator(): just call
  _PyMem_SetupAllocators() directly, we don't have do reallocate the
  configuration with the new allocator anymore!
* _PyPreConfig_Write() parameter becomes const, as it should be in
  the first place!
2019-05-17 15:20:52 +02:00
Ned Batchelder 6faad355db bpo-36908: 'This module is always available' isn't helpful. (#13297)
Makes the documentation of math and cmath module
more helpful for the beginners.
2019-05-17 15:29:13 +05:30
Victor Stinner fed02e15b3
bpo-36763: Remove _PyCoreConfig.program (GH-13373)
Use _PyCoreConfig.program_name instead.
2019-05-17 11:12:09 +02:00
Zackery Spytz 14514d9084 bpo-36946: Fix possible signed integer overflow when handling slices. (GH-13375)
The final addition (cur += step) may overflow, so use size_t for "cur".
"cur" is always positive (even for negative steps), so it is safe to use
size_t here.

Co-Authored-By: Martin Panter <vadmium+py@gmail.com>
2019-05-17 10:13:03 +03:00
Victor Stinner 9ef5dcaa0b
bpo-36763: Add _Py_InitializeMain() (GH-13362)
* Add a private _Py_InitializeMain() function.
* Add again _PyCoreConfig._init_main.
* _Py_InitializeFromConfig() now uses _init_main to decide
  if _Py_InitializeMainInterpreter() should be called.
* _PyCoreConfig: rename _frozen to pathconfig_warnings, its value is
  now the opposite of Py_FrozenFlag.
* Add an unit test for _init_main=0 and _Py_InitializeMain().
2019-05-16 17:38:16 +02:00
Victor Stinner ae239f6b06
bpo-36763: Add _PyCoreConfig.parse_argv (GH-13361)
* _PyCoreConfig_Read() doesn't parse nor update argv
  if parse_argv is 0.
* Move path configuration fields in _PyCoreConfig.
* Add an unit test for parse_argv=0.
* Remove unused "done": label in _Py_RunMain().
2019-05-16 17:02:56 +02:00
Victor Stinner dbacfc2273
bpo-36763: _PyInitError always use int for exitcode (GH-13360)
We cannot use "unsigned int" for exitcode on Windows, since
Py_Main() and _Py_RunMain() always return an "int".

Changes:

* _PyPathConfig_ComputeSysPath0() now returns -1 if an exception is
  raised.
* pymain_run_python() no longer uses _PyInitError but display the
  exception and set exitcode to 1 in case of error.
* Fix _Py_RunMain(): return an exitcode rather than calling
  exit() on pymain_run_python() failure.
* _Py_ExitInitError() no longer uses ExitProcess() on Windows, use
  exit() on all platforms.
* _Py_ExitInitError() now fails with a fatal error if 'err' is not an
  error not an exit.
2019-05-16 16:39:26 +02:00
Inada Naoki bfba8c373e
bpo-36748: optimize TextIOWrapper.write() for ASCII string (GH-13002) 2019-05-16 15:03:20 +09:00
Paul Monson fb7e7505ed bpo-35926: Add support for OpenSSL 1.1.1b on Windows (GH-11779) 2019-05-15 15:38:55 -07:00
Victor Stinner c96be811fa
bpo-36900: Replace global conf vars with config (GH-13299)
Replace global configuration variables with core_config read from the
current interpreter.

Cleanup dynload_hpux.c.
2019-05-14 17:34:56 +02:00
Rémi Lapeyre 2bc158fefe Change WriterObj.writeline to WriterObj.write (GH-12344)
This cleans the csv module a bit, I don't think it requires a bpo issue or a news entry.
2019-05-14 06:45:14 -07:00
Victor Stinner d5d9e81ce9
bpo-36728: Remove PyEval_ReInitThreads() from C API (GH-13241)
Remove the PyEval_ReInitThreads() function from the Python C API.
It should not be called explicitly: use PyOS_AfterFork_Child()
instead.

Rename PyEval_ReInitThreads() to _PyEval_ReInitThreads() and add a
'runtime' parameter.
2019-05-13 12:35:37 +02:00
Matthias Bussonnier e2500610c6 bpo-36895: remove time.clock() as per removal notice. (GH-13270)
`time.clock()` was deprecated in 3.3, and marked for removal removal in
3.8; this thus remove it from the time module.
2019-05-12 18:34:44 -07:00
Jake Tesler 4959c33d25 bpo-36084: Add native thread ID to threading.Thread objects (GH-11993) 2019-05-12 19:08:24 +02:00
Xi Ruoyao 6236c9823e bpo-36856: Handle possible overflow in faulthandler_stack_overflow (GH-13205) 2019-05-11 19:13:23 +02:00
Victor Stinner 09532feeec
bpo-36710: Add 'ceval' local variable to ceval.c (GH-12934)
Add "struct _ceval_runtime_state *ceval = &_PyRuntime.ceval;" local
variables to function to better highlight the dependency on the
global variable _PyRuntime and to point directly to _PyRuntime.ceval
field rather than on the larger _PyRuntime.

Changes:

* Add _PyRuntimeState_GetThreadState(runtime) macro.
* Add _PyEval_AddPendingCall(ceval, ...) and
  _PyThreadState_Swap(gilstate, ...) functions.
* _PyThreadState_GET() macro now calls
  _PyRuntimeState_GetThreadState() using &_PyRuntime.
* Add 'ceval' parameter to COMPUTE_EVAL_BREAKER(),
  SIGNAL_PENDING_SIGNALS(), _PyEval_SignalAsyncExc(),
  _PyEval_SignalReceived() and _PyEval_FiniThreads() macros and
  functions.
* Add 'tstate' parameter to call_function(), do_call_core() and
  do_raise().
* Add 'runtime' parameter to _Py_CURRENTLY_FINALIZING(),
  _Py_FinishPendingCalls() and _PyThreadState_DeleteExcept()
  macros and functions.
* Declare 'runtime', 'tstate', 'ceval' and 'eval_breaker' variables
  as constant.
2019-05-10 23:39:09 +02:00
Jeroen Demeyer 351c67416b bpo-35983: skip trashcan for subclasses (GH-11841)
Add new trashcan macros to deal with a double deallocation that could occur when the `tp_dealloc` of a subclass calls the `tp_dealloc` of a base class and that base class uses the trashcan mechanism.

Patch by Jeroen Demeyer.
2019-05-10 19:21:10 +02:00
Anthony Shaw 948ed8c96b bpo-36814: ensure os.posix_spawn() handles None (GH-13144)
Fix an issue where os.posix_spawn() would incorrectly raise a TypeError
when file_actions is None.
2019-05-10 04:00:06 +02:00
Jeroen Demeyer d237b3f0f6 bpo-36601: clarify signal handler comment and remove unnecessary pid check. (GH-12784)
https://bugs.python.org/issue36601
2019-05-09 18:28:56 -07:00
Aviv Palivoda e6576248e5 bpo-30262: Don't expose private objects in sqlite3 (GH-1440)
The Cache and Statement objects are undocumented and implementation
details of the sqlite3 module.

They aren't usable from pure Python code.
2019-05-09 21:05:45 +03:00
Benjamin Peterson 3aca40d3cb
closes bpo-36861: Update Unicode database to 12.1.0. (GH-13214)
Adds ㋿.
2019-05-08 20:59:35 -07:00
Pierre Glaser 289f1f80ee bpo-35900: Enable custom reduction callback registration in _pickle (GH-12499)
Enable custom reduction callback registration for functions and classes in
_pickle.c, using the new Pickler's attribute ``reducer_override``.
2019-05-08 23:08:25 +02:00
Pierre Glaser 65d98d0f53 bpo-35900: Add a state_setter arg to save_reduce (GH-12588)
Allow reduction methods to return a 6-item tuple where the 6th item specifies a
custom state-setting method that's called instead of the regular
``__setstate__`` method.
2019-05-08 21:40:25 +02:00
Serhiy Storchaka 96aeaec647
bpo-36793: Remove unneeded __str__ definitions. (GH-13081)
Classes that define __str__ the same as __repr__ can
just inherit it from object.
2019-05-06 22:29:40 +03:00
Zackery Spytz 1a2252ed39 bpo-36594: Fix incorrect use of %p in format strings (GH-12769)
In addition, fix some other minor violations of C99.
2019-05-06 12:56:50 -04:00
Stefan Behnel 6b95149ecc
bpo-36811: Fix a C compiler warning in _elementtree.c. (GH-13109) 2019-05-06 17:36:35 +02:00
Rémi Lapeyre f0900199d5 Suppress clang warning (GH-12384) 2019-05-04 08:30:53 +09:00
Stefan Behnel 47541689cc
bpo-28238: Implement "{*}tag" and "{ns}*" wildcard tag selection support for ElementPath, and extend the surrounding tests and docs. (GH-12997) 2019-05-03 20:58:16 +02:00
Victor Stinner 70005ac0fd
bpo-36763: _PyCoreConfig_SetPyArgv() preinitializes Python (GH-13037)
_PyCoreConfig_SetPyArgv() and _PyCoreConfig_SetWideString() now
pre-initialize Python if needed to ensure that the locale encoding is
properly configured.

* Add _Py_PreInitializeFromPyArgv() internal function.
* Add 'args' parameter to _Py_PreInitializeFromCoreConfig()
2019-05-02 15:25:34 -04:00
Stefan Behnel dde3eebdaa
bpo-36676: Namespace prefix aware parsing support for the ET.XMLParser target (GH-12885)
* bpo-36676: Implement namespace prefix aware parsing support for the XMLParser target in ElementTree.
2019-05-01 21:49:58 +02:00
Stefan Behnel 43851a202c
bpo-36673: Implement comment/PI parsing support for the TreeBuilder in ElementTree. (#12883)
* bpo-36673: Implement comment/PI parsing support for the TreeBuilder in ElementTree.

* bpo-36673: Rewrite the comment/PI factory handling for the TreeBuilder in "_elementtree" to make it use the same factories as the ElementTree module, and to make it explicit when the comments/PIs are inserted into the tree and when they are not (which is the default).
2019-05-01 21:20:38 +02:00
Victor Stinner db71975431
bpo-36763: Rework _PyInitError API (GH-13031)
* Remove _PyInitError.user_err field and _Py_INIT_USER_ERR() macro:
  use _Py_INIT_ERR() instead. _Py_ExitInitError() now longer calls
  abort() on error: exit with exit code 1 instead.
* Add _PyInitError._type private field.
* exitcode field type is now unsigned int on Windows.
* Rename prefix field to _func.
* Rename msg field to err_msg.
2019-05-01 05:35:33 +02:00
Victor Stinner b84cb70880
bpo-36734: Fix compilation of faulthandler.c on HP-UX (GH-12970)
Initialize "stack_t current_stack" to zero using memset().
2019-04-30 12:19:34 +02:00
Paul Ganssle 88c0937056 bpo-36004: Add date.fromisocalendar (GH-11888)
This commit implements the first version of date.fromisocalendar, the
inverse function for date.isocalendar.
2019-04-29 15:22:03 +02:00
Victor Stinner 99fcc616d4
Revert "bpo-36356: Destroy the GIL at exit (GH-12453)" (GH613006)
This reverts commit b36e5d627d.
2019-04-29 13:04:07 +02:00
Victor Stinner b36e5d627d
bpo-36356: Destroy the GIL at exit (GH-12453)
* Add _PyEval_FiniThreads2(). _PyEval_FiniThreads() now only clears
  the pending lock, whereas _PyEval_FiniThreads2() destroys the GIL.
* pymain_free() now calls _PyEval_FiniThreads2().
* Py_FinalizeEx() now calls _PyEval_FiniThreads().
2019-04-29 11:15:56 +02:00
Berker Peksag 21a9ba1992
bpo-2091: Fix typo in exception message (GH-12987) 2019-04-27 22:40:45 +03:00
Paul Ganssle 4d8c8c0ad6 bpo-36025: Fix PyDate_FromTimestamp API (GH-11922)
In the process of converting the date.fromtimestamp function to use
argument clinic in GH-8535, the C API for PyDate_FromTimestamp was
inadvertently changed to expect a timestamp object rather than an
argument tuple.

This PR fixes this backwards-incompatible change by adding a new wrapper
function for the C API function that unwraps the argument tuple and
passes it to the underlying function.

This PR also adds tests for both PyDate_FromTimestamp and
PyDateTime_FromTimestamp to prevent any further regressions.
2019-04-27 22:39:40 +03:00
Victor Stinner 4cb525a1f0
bpo-36356: pymain_exit_error() only call pymain_free() for exit (GH-12968)
Add _Py_INIT_HAS_EXITCODE() macro.
2019-04-26 13:05:47 +02:00
Victor Stinner 9db0324712
bpo-36710: Add runtime parameter in gcmodule.c (GH-12958)
Add 'state' or 'runtime' parameter to functions in gcmodule.c to
avoid to rely directly on the global variable _PyRuntime.
2019-04-26 02:32:01 +02:00
Victor Stinner 8e91c246e4
bpo-36710: Add runtime variable to Py_FinalizeEx() (GH-12937)
* Add a 'runtime' variable to Py_FinalizeEx() rather than working
  directly on the global variable _PyRuntime
* Add a 'runtime' parameter to _PyGC_Fini(), _PyGILState_Fini()
  and call_ll_exitfuncs()
2019-04-24 17:24:01 +02:00
Victor Stinner b930a2d2b1
bpo-36710: PyOS_AfterFork_Child() pass runtime parameter (GH-12936)
The PyOS_AfterFork_Child() function now pass a 'runtime' parameter to
subfunctions.

* Fix _PyRuntimeState_ReInitThreads(): use the correct memory allocator
* Add runtime parameter to _PyRuntimeState_ReInitThreads(),
  _PyGILState_Reinit() and _PyInterpreterState_DeleteExceptMain()
* Move _PyGILState_Reinit() to the internal C API.
2019-04-24 17:14:33 +02:00
Victor Stinner 8bb3230149
bpo-36710: Add runtime parameter to _PyThreadState_Init() (GH-12935)
* Add 'runtime' parameter to _PyThreadState_Init()
* Add 'gilstate' parameter to _PyGILState_NoteThreadState()
* Move _PyThreadState_Init() and _PyThreadState_DeleteExcept()
   to the internal C API.
2019-04-24 16:47:40 +02:00
Zackery Spytz 359bd4f61b bpo-18372: Add missing PyObject_GC_Track() calls in the pickle module (GH-8505) 2019-04-23 20:56:08 +09:00
Inada Naoki 09415ff0eb
fix warnings by adding more const (GH-12924) 2019-04-23 20:39:37 +09:00
Marcin Niemira ab86521a9d bpo-36523: Add docstring to io.IOBase.writelines (GH-12683) 2019-04-22 20:13:51 +09:00
Joannah Nanjekye 9541bd321a bpo-24011: Use PyModule_Add{Object,IntMacro} in PyInit__signal() (GH-12765) 2019-04-22 04:47:06 +03:00
Raymond Hettinger 14adbd4598
bpo-36650: Fix handling of empty keyword args in C version of lru_cache. (GH-12881) 2019-04-20 07:20:44 -10:00
Inada Naoki 9d062d690b
ctypes: remove use of legacy unicode API (GH-12340)
PyUnicode_AsUnicodeAndSize() -> PyUnicode_AsWideChar()
2019-04-19 16:07:19 +09:00
Victor Stinner 23bace26ec
bpo-36635: Add _testinternalcapi module (GH-12841)
Add a new _testinternalcapi module to test the internal C API.

Move _Py_GetConfigsAsDict() function to the internal C API:
_testembed now uses _testinternalcapi to access the function.
2019-04-18 11:37:26 +02:00
Paul Monson 11efd79076 bpo-36071 Add support for Windows ARM32 in ctypes/libffi (GH-12059) 2019-04-17 18:09:16 -07:00
Victor Stinner 5c75f37d47
bpo-36635: Change pyport.h for Py_BUILD_CORE_MODULE define (GH-12853)
Change PyAPI_FUNC(type), PyAPI_DATA(type) and PyMODINIT_FUNC macros
of pyport.h when Py_BUILD_CORE_MODULE is defined.

The Py_BUILD_CORE_MODULE define must be now be used to build a C
extension as a dynamic library accessing Python internals: export the
PyInit_xxx() function in DLL exports on Windows.

Changes:

* Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE now imply
  Py_BUILD_CORE directy in pyport.h.
* ceval.c compilation now fails with an error if Py_BUILD_CORE is not
  defined, just to ensure that Python is build with the correct
  defines.
* setup.py now compiles _pickle.c with Py_BUILD_CORE_MODULE define.
* setup.py compiles _json.c with Py_BUILD_CORE_MODULE define, rather
  than Py_BUILD_CORE_BUILTIN define
* PCbuild/pythoncore.vcxproj: Add Py_BUILD_CORE_BUILTIN define.
2019-04-17 23:02:26 +02:00
Inada Naoki 6fec905de5
bpo-36642: make unicodedata const (GH-12855) 2019-04-17 08:40:34 +09:00
Inada Naoki 926b0cb5f6
bpo-36641: Add "const" to PyDoc_VAR macro (GH-12854)
It reduces "data" segment in python about 200KB.
2019-04-17 08:39:46 +09:00
Victor Stinner 0810fa7988
bpo-36389: Cleanup gc.set_threshold() (GH-12844)
Don't assign generations[2].threshold to generations[2].threshold:
useless operation.
2019-04-15 17:54:09 +02:00
pxinwr f1464f4d2e bpo-31904: Port the time module on VxWorks (GH-12305)
time.clock() is not available on VxWorks.
2019-04-15 11:06:21 +02:00
Eric Snow b75b1a3504
bpo-33608: Revert "Factor out a private, per-interpreter _Py_AddPendingCall()." (gh-12806)
This reverts commit f13c5c8b94 (gh-12360).
2019-04-12 10:20:10 -06:00
Eric Snow f13c5c8b94
bpo-33608: Factor out a private, per-interpreter _Py_AddPendingCall(). (gh-12360)
This is effectively an un-revert of #11617 and #12024 (reverted in #12159). Portions of those were merged in other PRs (with lower risk) and this represents the remainder. Note that I found 3 different bugs in the original PRs and have fixed them here.
2019-04-12 09:18:16 -06:00
Victor Stinner 44235041f3
bpo-18748: io.IOBase destructor now logs close() errors in dev mode (GH-12786)
In development mode (-X dev) and in debug build, the io.IOBase
destructor now logs close() exceptions. These exceptions are silent
by default in release mode.
2019-04-12 17:06:47 +02:00
Inada Naoki 536a35b3f1
bpo-36575: lsprof: Use _PyTime_GetPerfCounter() (GH-8378) 2019-04-11 19:11:46 +09:00
Victor Stinner 2b00db6855
bpo-36389: _PyObject_IsFreed() now also detects uninitialized memory (GH-12770)
Replace _PyMem_IsFreed() function with _PyMem_IsPtrFreed() inline
function. The function is now way more efficient, it became a simple
comparison on integers, rather than a short loop. It detects also
uninitialized bytes and "forbidden bytes" filled by debug hooks
on memory allocators.

Add unit tests on _PyObject_IsFreed().
2019-04-11 11:33:27 +02:00
Vidar Tonaas Fauske 0e10766574 bpo-31512: Add non-elevated symlink support for Windows (GH-3652) 2019-04-09 11:19:46 -07:00
Victor Stinner 8709490f48
bpo-34373: Fix time.mktime() on AIX (GH-12726)
Fix time.mktime() error handling on AIX for year before 1970.

Other changes:

* mktime(): rename variable 'buf' to 'tm'.
* _PyTime_localtime():

  * Use "localtime" rather than "ctime" in the error message
    (specific to AIX).
  * Always initialize errno to 0 just in case if localtime_r()
    doesn't set errno on error.
  * On AIX, avoid abs() which is limited to int type.
  * EINVAL constant is now always available.
2019-04-09 19:12:26 +02:00
tyomitch cb0748d393 bpo-36440: include node names in ParserError messages, instead of numeric IDs (GH-12565)
The error messages in the parser module are referring to numeric IDs for the nodes. To improve readability, use the node names when reporting errors.
2019-04-03 01:12:07 -04:00
Zackery Spytz 487b73ab39 bpo-36504: Fix signed integer overflow in _ctypes.c's PyCArrayType_new(). (GH-12660) 2019-04-02 13:47:51 +03:00
Inada Naoki 10654c19b5
bpo-20844: open script file with "rb" mode (GH-12616) 2019-04-01 18:35:20 +09:00
Zackery Spytz 5f2c50810a bpo-36150: Fix possible assertion failures due to _ctypes.c's PyCData_reduce(). (GH-12106) 2019-03-31 19:02:11 +03:00
Zackery Spytz 48600c72c1 bpo-35947: Fix a compiler warning in _ctypes.c's StructUnionType_paramfunc(). (GH-12629) 2019-03-31 19:00:12 +03:00
Steve Dower 2438cdf0e9
bpo-36085: Enable better DLL resolution on Windows (GH-12302) 2019-03-29 16:37:16 -07:00
Paul Monson 32119e10b7 bpo-35947: Update Windows to the current version of libffi (GH-11797)
We now use a pre-built libffi binary from our binaries repository, and no longer vendor the full implementation.
2019-03-29 16:30:10 -07:00
Victor Stinner 2f54908afc
bpo-36471: Add _Py_RunMain() (GH-12618)
* Add config_read_cmdline() subfunction. Remove _PyCmdline structure.
* _PyCoreConfig_Read() now also parses config->argv command line
  arguments
2019-03-29 15:13:46 +01:00
Alexey Izbyshev 5f45979b63 bpo-35194: cjkcodec: check the encoded value is not truncated (GH-10432) 2019-03-29 16:48:47 +09:00