Commit Graph

11860 Commits

Author SHA1 Message Date
Victor Stinner 62183b8d6d
bpo-40268: Remove explicit pythread.h includes (#19529)
Remove explicit pythread.h includes: it is always included
by Python.h.
2020-04-15 02:04:42 +02:00
Hai Shi 675d9a3d7a
bpo-40170: Convert PyObject_IS_GC() macro to a function (GH-19464) 2020-04-14 20:11:20 +02:00
Victor Stinner e560f90602
bpo-40268: Move struct _gc_runtime_state to pycore_gc.h (GH-19515) 2020-04-14 18:30:41 +02:00
Victor Stinner e5014be049
bpo-40268: Remove a few pycore_pystate.h includes (GH-19510) 2020-04-14 17:52:15 +02:00
Victor Stinner 81a7be3fa2
bpo-40268: Rename _PyInterpreterState_GET_UNSAFE() (GH-19509)
Rename _PyInterpreterState_GET_UNSAFE() to _PyInterpreterState_GET()
for consistency with _PyThreadState_GET() and to have a shorter name
(help to fit into 80 columns).

Add also "assert(tstate != NULL);" to the function.
2020-04-14 15:14:01 +02:00
Victor Stinner 4a3fe08353
bpo-40268: Include explicitly pycore_interp.h (GH-19505)
pycore_pystate.h no longer includes pycore_interp.h:
it's now included explicitly in files accessing PyInterpreterState.
2020-04-14 14:26:24 +02:00
Ethan Smith cecf049673
bpo-39481: Make functools.cached_property, partial, partialmethod generic (#19427) 2020-04-13 21:53:04 -07:00
Benjamin Peterson 584a3cfda4
closes bpo-40266, closes bpo-39953: Use numeric lib code if compiling against old OpenSSL. (GH-19506) 2020-04-13 22:11:40 -05:00
Victor Stinner 0135598d72
bpo-40241: Add pycore_gc.h header file (GH-19494)
Move the PyGC_Head structure and the following private macros to the
internal C API:

* _PyGCHead_FINALIZED()
* _PyGCHead_NEXT()
* _PyGCHead_PREV()
* _PyGCHead_SET_FINALIZED()
* _PyGCHead_SET_NEXT()
* _PyGCHead_SET_PREV()
* _PyGC_FINALIZED()
* _PyGC_PREV_MASK
* _PyGC_PREV_MASK_COLLECTING
* _PyGC_PREV_MASK_FINALIZED
* _PyGC_PREV_SHIFT
* _PyGC_SET_FINALIZED()
* _PyObject_GC_IS_TRACKED()
* _PyObject_GC_MAY_BE_TRACKED()
* _Py_AS_GC(o)

Keep the private _PyGC_FINALIZED() macro in the public C API for
backward compatibility with Python 3.8: make it an alias to the new
PyObject_GC_IsFinalized() function.

Move the SIZEOF_PYGC_HEAD constant from _testcapi module to
_testinternalcapi module.
2020-04-13 11:38:42 +02:00
Victor Stinner da7933ecc3
bpo-40268: Add _PyInterpreterState_GetConfig() (GH-19492)
Don't access PyInterpreterState.config member directly anymore, but
use new functions:

* _PyInterpreterState_GetConfig()
* _PyInterpreterState_SetConfig()
* _Py_GetConfig()
2020-04-13 03:04:28 +02:00
Victor Stinner 14d5331eb5
bpo-40234: Revert "bpo-37266: Daemon threads are now denied in subinterpreters (GH-14049)" (GH-19456)
This reverts commit 066e5b1a91.
2020-04-12 23:45:09 +02:00
Benjamin Peterson 909b87d2bb
closes bpo-39953: Generate ifdefs around library code definitions. (GH-19490) 2020-04-12 13:59:31 -05:00
Oren Milman 402e1cdb13
bpo-31758: Prevent crashes when using an uninitialized _elementtree.XMLParser object (GH-3997) 2020-04-12 16:36:41 +02:00
Serhiy Storchaka 8f87eefe7f
bpo-39943: Add the const qualifier to pointers on non-mutable PyBytes data. (GH-19472) 2020-04-12 14:58:27 +03:00
Benjamin Peterson 3e0dd3730b
closes bpo-39953: Update OpenSSL error codes table. (GH-19082)
I updated the error codes using the OpenSSL 1.1.1f source tree.
2020-04-11 15:36:12 -05:00
Serhiy Storchaka cd8295ff75
bpo-39943: Add the const qualifier to pointers on non-mutable PyUnicode data. (GH-19345) 2020-04-11 10:48:40 +03:00
Pablo Galindo f13072b8a8
bpo-40241: Add PyObject_GC_IsTracked and PyObject_GC_IsFinalized to the public C-API (GH-19461)
Add the functions PyObject_GC_IsTracked and PyObject_GC_IsFinalized to the public API to allow to query if Python objects are being currently tracked or have been already finalized by the garbage collector respectively.
2020-04-11 01:21:54 +01:00
Batuhan Taşkaya 0361556537
bpo-39481: PEP 585 for a variety of modules (GH-19423)
- concurrent.futures
- ctypes
- http.cookies
- multiprocessing
- queue
- tempfile
- unittest.case
- urllib.parse
2020-04-10 07:46:36 -07:00
Ethan Smith 7c4185d62d
bpo-39481: PEP 585 for enumerate, AsyncGeneratorType, mmap (GH-19421) 2020-04-09 21:25:53 -07:00
Ethan Smith a8403d057d
Generic itertools.chain (GH-19417) 2020-04-09 20:28:08 -07:00
Hai Shi dcb04d9c6d
bpo-40077: Remove redundant cast in json module (GH-19438) 2020-04-10 00:10:29 +09:00
Zackery Spytz 97e0de04b8
bpo-25780: Expose CAN_RAW_JOIN_FILTERS in the socket module (GH-19190)
Co-Authored-By: Stefan Tatschner <stefan@rumpelsepp.org>
2020-04-09 13:03:49 +01:00
Victor Stinner b54a99d643
bpo-40082: trip_signal() uses the main interpreter (GH-19441)
Fix the signal handler: it now always uses the main interpreter,
rather than trying to get the current Python thread state.

The following function now accepts an interpreter, instead of a
Python thread state:

* _PyEval_SignalReceived()
* _Py_ThreadCanHandleSignals()
* _PyEval_AddPendingCall()
* COMPUTE_EVAL_BREAKER()
* SET_GIL_DROP_REQUEST(), RESET_GIL_DROP_REQUEST()
* SIGNAL_PENDING_CALLS(), UNSIGNAL_PENDING_CALLS()
* SIGNAL_PENDING_SIGNALS(), UNSIGNAL_PENDING_SIGNALS()
* SIGNAL_ASYNC_EXC(), UNSIGNAL_ASYNC_EXC()

Py_AddPendingCall() now uses the main interpreter if it fails to the
current Python thread state.

Convert _PyThreadState_GET() and PyInterpreterState_GET_UNSAFE()
macros to static inline functions.
2020-04-08 23:35:05 +02:00
Victor Stinner 9205520d8c
bpo-40170: PyObject_NEW() becomes an alias to PyObject_New() (GH-19379)
The PyObject_NEW() macro becomes an alias to the PyObject_New()
macro, and the PyObject_NEW_VAR() macro becomes an alias to the
PyObject_NewVar() macro, to hide implementation details. They no
longer access directly the PyTypeObject.tp_basicsize member.

Exclude _PyObject_SIZE() and _PyObject_VAR_SIZE() macros from
the limited C API.

Replace PyObject_NEW() with PyObject_New() and replace
PyObject_NEW_VAR() with PyObject_NewVar().
2020-04-08 00:38:15 +02:00
Batuhan Taşkaya f9dd51e7db
bpo-39481: Make os.DirEntry generic (GH-19415) 2020-04-07 14:37:19 -07:00
Victor Stinner 87255be696
bpo-40089: Add _at_fork_reinit() method to locks (GH-19195)
Add a private _at_fork_reinit() method to _thread.Lock,
_thread.RLock, threading.RLock and threading.Condition classes:
reinitialize the lock after fork in the child process; reset the lock
to the unlocked state.

Rename also the private _reset_internal_locks() method of
threading.Event to _at_fork_reinit().

* Add _PyThread_at_fork_reinit() private function. It is excluded
  from the limited C API.
* threading.Thread._reset_internal_locks() now calls
  _at_fork_reinit() on self._tstate_lock rather than creating a new
  Python lock object.
2020-04-07 23:11:49 +02:00
Guido van Rossum 48b069a003
bpo-39481: Implementation for PEP 585 (#18239)
This implements things like `list[int]`,
which returns an object of type `types.GenericAlias`.
This object mostly acts as a proxy for `list`,
but has attributes `__origin__` and `__args__`
that allow recovering the parts (with values `list` and `(int,)`.

There is also an approximate notion of type variables;
e.g. `list[T]` has a `__parameters__` attribute equal to `(T,)`.
Type variables are objects of type `typing.TypeVar`.
2020-04-07 09:50:06 -07:00
Victor Stinner 9cc3ebd7e0
bpo-40149: Implement traverse in _abc._abc_data (GH-19412)
Implement traverse and clear slots in _abc._abc_data type.
2020-04-07 18:36:04 +02:00
Victor Stinner 38aefc585f
bpo-40170: PyObject_GET_WEAKREFS_LISTPTR() becomes a function (GH-19377)
Convert the PyObject_GET_WEAKREFS_LISTPTR() macro to a function to
hide implementation details: the macro accessed directly to the
PyTypeObject.tp_weaklistoffset member.

Add _PyObject_GET_WEAKREFS_LISTPTR() static inline function to the
internal C API.
2020-04-06 14:07:02 +02:00
Batuhan Taşkaya 909f4a3009
bpo-40190: Add support for _SC_AIX_REALMEM in sysconf (GH-19380) 2020-04-05 02:40:49 +02:00
Hai Shi b709302f31
bpo-40077: Fix potential refleaks of _json: traverse memo (GH-19344)
Fix possible refleaks in _json module, memo of PyScannerObject
should be traversed.
2020-04-04 21:24:16 +02:00
Hai Shi 7a6f3bcc43
bpo-1635741: Fix refleak in _locale init error handling (GH-19307) 2020-04-02 20:00:47 +02:00
Hai Shi 45f7008a66
bpo-1635741: Port resource extension module to multiphase initialization (PEP 489) (GH-19252)
Fix also reference leaks on error.
2020-04-02 14:35:08 +02:00
Victor Stinner 65a796e527
bpo-40094: Add os.waitstatus_to_exitcode() (GH-19201)
Add os.waitstatus_to_exitcode() function to convert a wait status to an
exitcode.

Suggest waitstatus_to_exitcode() usage in the documentation when
appropriate.

Use waitstatus_to_exitcode() in:

* multiprocessing, os, subprocess and _bootsubprocess modules;
* test.support.wait_process();
* setup.py: run_command();
* and many tests.
2020-04-01 18:49:29 +02:00
Paulo Henrique Silva eacc074395
bpo-40071: Fix potential crash in _functoolsmodule.c (GH-19273)
Changes on 7dd549eb08 made _functools compatible with
PEP-489 and we could have multiple modules instances loaded.

But, right now there is no way to make `kwd_mark` global into
a per module instance variable. kwd_mark is used on lru_cache_new
which does not have a reference to a PyModule*, necessary to use
PyModule_GetState.

PEP-573 will solve this problem and will allow us to move the global
state to per-module data and properly clear the state when unloading
a module instance.

This change temporarily disable cleaning of kwd_mark to avoid NULL
pointer dereference if we clear kwd_mark and other module instances
still alive use it.
2020-04-01 17:06:21 +02:00
Dong-hee Na 5be8241392
bpo-1635741: Port math module to multiphase initialization (GH-19243) 2020-03-31 16:33:22 +02:00
Dong-hee Na 1cb763b880
bpo-1635741: Port _uuid module to multiphase initialization (GH-19242) 2020-03-31 14:43:47 +02:00
Steve Dower 63ba5cccf4
bpo-40121: Fixes audit event raised on creating a new socket (GH-19238) 2020-03-31 12:38:53 +01:00
Dong-hee Na 53e4c91725
bpo-40077: Convert _abc module to use PyType_FromSpec() (GH-19202)
Replace statically allocated types with heap allocated types:
use PyType_FromSpec().

Add a module state to store the _abc_data_type.
Add traverse, clear and free functions to the module.
2020-03-30 16:35:38 +02:00
Dong-hee Na 016bdd519d
bpo-40024: Update _elementtree to use PyModule_AddType() (GH-19205) 2020-03-29 16:12:11 +02:00
Dong-hee Na 33f15a16d4
bpo-40077: Convert _json module to use PyType_FromSpec() (GH-19177)
Replace statically allocated types with heap allocated types:
use PyType_FromSpec().

Add a module state to store the Scanner and Encoder types.
Add traverse, clear and free functions to the module.
2020-03-27 11:59:59 +01:00
Victor Stinner 728189884e
bpo-38644: Pass tstate explicitly in signalmodule.c (GH-19184)
PyOS_InterruptOccurred() now checks _Py_ThreadCanHandleSignals()
before checking if SIGINT is tripped.
2020-03-26 22:28:11 +01:00
Paulo Henrique Silva b09ae3ff43
bpo-40071: Fix refleak in _functools module (GH19172) 2020-03-26 13:47:45 +01:00
Victor Stinner 5c3cda0d1a
bpo-39947: Add PyThreadState_GetID() function (GH-19163)
Add PyThreadState_GetID() function: get the unique identifier of a
Python thread state.
2020-03-25 21:23:53 +01:00
Victor Stinner 0e427c6d15
bpo-39947: Add _PyThreadState_GetDict() function (GH-19160) 2020-03-25 21:22:55 +01:00
Victor Stinner 3072338642
bpo-39947: Use PyThreadState_GetFrame() (GH-19159)
_tracemalloc.c and _xxsubinterpretersmodule.c use
PyThreadState_GetFrame() and PyThreadState_GetInterpreter() to no
longer depend on the PyThreadState structure.
2020-03-25 19:52:02 +01:00
Victor Stinner 87d3b9db4a
bpo-39882: Add _Py_FatalErrorFormat() function (GH-19157) 2020-03-25 19:27:36 +01:00
Andy Lester 7668a8bc93
Use calloc-based functions, not malloc. (GH-19152) 2020-03-24 23:26:44 -05:00
Paulo Henrique Silva 7dd549eb08
bpo-1635741: Port _functools module to multiphase initialization (PEP 489) (GH-19151) 2020-03-25 03:19:58 +01:00
Paulo Henrique Silva f3d5ac4772
bpo-1635741: Port operator module to multiphase initialization (PEP 489) (GH-19150) 2020-03-25 03:18:47 +01:00
Dong-hee Na 37fcbb65d4
bpo-40024: Update C extension modules to use PyModule_AddType() (GH-19119)
Update _asyncio, _bz2, _csv, _curses, _datetime,
_io, _operator, _pickle, _queue, blake2,
multibytecodec and overlapped C extension modules
to use PyModule_AddType().
2020-03-24 23:08:51 +01:00
Victor Stinner 93460d097f
bpo-1635741: Port _weakref extension module to multiphase initialization (PEP 489) (GH-19140)
Co-authored-by: Hai Shi <shihai1992@gmail.com>
2020-03-24 18:31:19 +01:00
Victor Stinner f5c7cabb2b
bpo-40014: Fix os.getgrouplist() (GH-19126)
Fix os.getgrouplist(): if getgrouplist() function fails because the
group list is too small, retry with a larger group list.

On failure, the glibc implementation of getgrouplist() sets ngroups
to the total number of groups. For other implementations, double the
group list size.
2020-03-24 18:22:10 +01:00
Stefan Krah 472fc843ca
bpo-39689: Do not use native packing for format "?" with standard size (GH-18969) 2020-03-24 06:01:13 -07:00
Russell Owen 6000087fe9
closes bpo-40017: Add CLOCK_TAI constant to the time module. (GH-19096)
Co-authored-by: Benjamin Peterson <benjamin@python.org>
2020-03-23 22:41:40 -05:00
Victor Stinner 188078c39d
Revert "bpo-1635741: Port _weakref extension module to multiphase initialization (PEP 489) (GH-19084)" (#19128)
bpo-1635741, bpo-40050: This reverts
commit 8334f30a74.
2020-03-24 00:48:03 +01:00
AlphaHot 8dd1792c68
bpo-40036: Deleting duplicates in itertoolsmodule.c (GH-18958) 2020-03-23 13:14:39 -07:00
Victor Stinner 8ec7370c89
bpo-40014: Fix os.getgrouplist() on macOS (GH-19118)
On macOS, getgrouplist() returns a non-zero value without setting
errno if the group list is too small. Double the list size and call
it again in this case.
2020-03-23 20:00:57 +01:00
Paulo Henrique Silva bd409bb5b7
bpo-1635741: Port time module to multiphase initialization (PEP 489) (GH-19107) 2020-03-23 19:58:23 +01:00
Dong-hee Na 05e4a296ec
bpo-40024: Add PyModule_AddType() helper function (GH-19088) 2020-03-22 17:17:34 +01:00
Serhiy Storchaka b146568dfc
bpo-39652: Truncate the column name after '[' only if PARSE_COLNAMES is set. (GH-18942) 2020-03-21 15:53:28 +02:00
Victor Stinner d2a8e5b42c
bpo-40010: COMPUTE_EVAL_BREAKER() checks for subinterpreter (GH-19087)
COMPUTE_EVAL_BREAKER() now also checks if the Python thread state
belongs to the main interpreter. Don't break the evaluation loop if
there are pending signals but the Python thread state it belongs to a
subinterpeter.

* Add _Py_IsMainThread() function.
* Add _Py_ThreadCanHandleSignals() function.
2020-03-20 13:38:58 +01:00
Hai Shi 8334f30a74
bpo-1635741: Port _weakref extension module to multiphase initialization (PEP 489) (GH-19084) 2020-03-20 09:16:45 +01:00
Hai Shi 13397ee47d
bpo-39824: Convert PyModule_GetState() to get_module_state() (GH-19076)
Automerge-Triggered-By: @vstinner
2020-03-19 10:11:33 -07:00
Dong-hee Na 77248a2889
bpo-1635741: Port _collections module to multiphase initialization (GH-19074) 2020-03-19 17:16:04 +01:00
Victor Stinner 50e6e99178
bpo-39984: Move pending calls to PyInterpreterState (GH-19066)
If Py_AddPendingCall() is called in a subinterpreter, the function is
now scheduled to be called from the subinterpreter, rather than being
called from the main interpreter.

Each subinterpreter now has its own list of scheduled calls.

* Move pending and eval_breaker fields from _PyRuntimeState.ceval
  to PyInterpreterState.ceval.
* new_interpreter() now calls _PyEval_InitThreads() to create
  pending calls lock.
* Fix Py_AddPendingCall() for subinterpreters. It now calls
  _PyThreadState_GET() which works in a subinterpreter if the
  caller holds the GIL, and only falls back on
  PyGILState_GetThisThreadState() if _PyThreadState_GET()
  returns NULL.
2020-03-19 02:41:21 +01:00
Pablo Galindo 3cde88439d
Remove unused variable to fix compiler warning in _threadmodule.c (GH-19064) 2020-03-18 23:33:57 +00:00
Victor Stinner 8849e5962b
bpo-39984: trip_signal() uses PyGILState_GetThisThreadState() (GH-19061)
bpo-37127, bpo-39984:

* trip_signal() and Py_AddPendingCall() now get the current Python
  thread state using PyGILState_GetThisThreadState() rather than
  _PyRuntimeState_GetThreadState() to be able to get it even if the
  GIL is released.
* _PyEval_SignalReceived() now expects tstate rather than ceval.
* Remove ceval parameter of _PyEval_AddPendingCall(): ceval is now
  get from tstate parameter.
2020-03-18 19:28:53 +01:00
Dong-hee Na 4657a8a0d0
bpo-1635741: Port _heapq module to multiphase initialization (GH19057) 2020-03-18 15:29:34 +01:00
Victor Stinner 23ef89db7a
bpo-39984: _PyThreadState_DeleteCurrent() takes tstate (GH-19051)
* _PyThreadState_DeleteCurrent() now takes tstate rather than
  runtime.
* Add ensure_tstate_not_null() helper to pystate.c.
* Add _PyEval_ReleaseLock() function.
* _PyThreadState_DeleteCurrent() now calls
  _PyEval_ReleaseLock(tstate) and frees PyThreadState memory after
  this call, not before.
* PyGILState_Release(): rename "tcur" variable to "tstate".
2020-03-18 02:26:04 +01:00
Dong-hee Na 514c469719
bpo-1635741: Port itertools module to multiphase initialization (GH-19044) 2020-03-17 18:46:24 +01:00
Victor Stinner 5b1ef200d3
bpo-39824: module_traverse() don't call m_traverse if md_state=NULL (GH-18738)
Extension modules: m_traverse, m_clear and m_free functions of
PyModuleDef are no longer called if the module state was requested
but is not allocated yet. This is the case immediately after the
module is created and before the module is executed (Py_mod_exec
function). More precisely, these functions are not called if m_size is
greater than 0 and the module state (as returned by
PyModule_GetState()) is NULL.

Extension modules without module state (m_size <= 0) are not affected.

Co-Authored-By: Petr Viktorin <encukou@gmail.com>
2020-03-17 18:09:46 +01:00
Andy Lester 982307b9cc
bpo-39943: Remove unused self from find_nfc_index() (GH-18973) 2020-03-17 17:38:12 +01:00
Hai Shi 2037502613
bpo-1635741: Port _ctypes_test extension to multiphase initialization (PEP 489) (GH-19012) 2020-03-17 02:15:23 +01:00
Hai Shi 5f104d56fa
bpo-39968: Fix a typo error in get_readline_state() (GH-19028) 2020-03-16 18:16:32 +01:00
Dong-hee Na 356c878fbf
bpo-1635741: Port _statistics module to multiphase initialization (GH-19015) 2020-03-16 16:10:21 +01:00
Hai Shi f707d94af6
bpo-39968: Convert extension modules' macros of get_module_state() to inline functions (GH-19017) 2020-03-16 14:15:01 +01:00
David CARLIER b81f40f0ad
bpo-39582: ossaudiodev module update helpers signature for ioctl calls. (GH-18412) 2020-03-14 15:48:56 +02:00
Zackery Spytz 5208b4b379
bpo-39871: Fix possible SystemError in atan2, copysign and remainder (GH-18806)
In math_2(), the first PyFloat_AsDouble() call should be checked
for failure before the second call.

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
2020-03-14 10:45:32 +00:00
Inada Naoki 3a8c56295d
Revert "bpo-39087: Add _PyUnicode_GetUTF8Buffer()" (GH-18985)
* Revert "bpo-39087: Add _PyUnicode_GetUTF8Buffer() (GH-17659)"

This reverts commit c7ad974d34.

* Update unicodeobject.h
2020-03-14 15:59:27 +09:00
Inada Naoki c7ad974d34
bpo-39087: Add _PyUnicode_GetUTF8Buffer() (GH-17659)
Co-authored-by: Victor Stinner <vstinner@python.org>
2020-03-14 12:43:18 +09:00
Victor Stinner 8fb02b6e19
bpo-39947: Add PyThreadState_GetInterpreter() (GH-18981)
Add PyThreadState_GetInterpreter(tstate): get the interpreter of a
Python thread state.
2020-03-13 23:38:08 +01:00
Victor Stinner be79373a78
bpo-39947: Add PyInterpreterState_Get() function (GH-18979)
* Rename _PyInterpreterState_Get() to PyInterpreterState_Get() and
  move it the limited C API.
* Add _PyInterpreterState_Get() alias to PyInterpreterState_Get() for
  backward compatibility with Python 3.8.
2020-03-13 18:15:33 +01:00
Victor Stinner ff4584caca
bpo-39947: Use _PyInterpreterState_GET_UNSAFE() (GH-18978)
Replace _PyInterpreterState_Get() function call with
_PyInterpreterState_GET_UNSAFE() macro which is more efficient but
don't check if tstate or interp is NULL.

_Py_GetConfigsAsDict() now uses _PyThreadState_GET().
2020-03-13 18:03:56 +01:00
Victor Stinner 309d7cc5df
bpo-35370: Add _PyEval_SetTrace() function (GH-18975)
* sys.settrace(), sys.setprofile() and _lsprof.Profiler.enable() now
  properly report PySys_Audit() error if "sys.setprofile" or
  "sys.settrace" audit event is denied.
* Add _PyEval_SetProfile() and _PyEval_SetTrace() function: similar
  to PyEval_SetProfile() and PyEval_SetTrace() but take a tstate
  parameter and return -1 on error.
* Add _PyObject_FastCallTstate() function.
2020-03-13 16:39:12 +01:00
Victor Stinner 3f2f4fefca
bpo-39947: Move get_recursion_depth() to _testinternalcapi (GH-18974)
Move get_recursion_depth() function from _testcapi to
_testinternalcapi to avoid accessing PyThreadState attributes
directly in _testcapi.
2020-03-13 13:07:31 +01:00
Brandt Bucher 1dd3794b19
Simplify defaultdict.__or__ (#18931) 2020-03-11 21:06:46 -07:00
Hai Shi 196f1eb6ad
bpo-1635741: Fix refleaks of time module error handling (GH-18486) 2020-03-11 17:56:08 +01:00
Hai Shi aa0c0808ef
bpo-1635741: Fix potential refleaks in binascii module (GH-18613) 2020-03-11 17:50:52 +01:00
Hai Shi 41fbf865a3
bpo-1635741: Port audioop extension module to multiphase initialization (PEP 489) (GH-18608)
Co-authored-by: Victor Stinner <vstinner@python.org>
2020-03-11 17:49:11 +01:00
Hai Shi a158168a78
bpo-1635741: Port _locale extension module to multiphase initialization (PEP 489) (GH-18358)
Co-authored-by: Petr Viktorin <pviktori@redhat.com>
2020-03-11 17:46:06 +01:00
Benjamin Peterson 051b9d08d1
closes bpo-39926: Update Unicode to 13.0.0. (GH-18910) 2020-03-10 20:41:34 -07:00
Victor Stinner 00d7cd8ab8
bpo-38075: Fix random_seed(): use PyObject_CallOneArg() (GH-18897)
Fix the random.Random.seed() method when a bool is passed as the
seed.

PyObject_Vectorcall() was misused: use PyObject_CallOneArg() instead.
2020-03-10 15:15:14 +01:00
Victor Stinner 8510f43078
bpo-1294959: Add sys.platlibdir attribute (GH-18381)
Add --with-platlibdir option to the configure script: name of the
platform-specific library directory, stored in the new sys.platlitdir
attribute. It is used to build the path of platform-specific dynamic
libraries and the path of the standard library.

It is equal to "lib" on most platforms. On Fedora and SuSE, it is
equal to "lib64" on 64-bit systems.

Co-Authored-By: Jan Matějek <jmatejek@suse.com>
Co-Authored-By: Matěj Cepl <mcepl@cepl.eu>
Co-Authored-By: Charalampos Stratakis <cstratak@redhat.com>
2020-03-10 09:53:09 +01:00
Victor Stinner 3225b9f973
bpo-39877: Remove useless PyEval_InitThreads() calls (GH-18883)
Py_Initialize() calls PyEval_InitThreads() since Python 3.7. It's no
longer needed to call it explicitly.
2020-03-09 20:56:57 +01:00
Serhiy Storchaka eebaa9bfc5
bpo-38249: Expand Py_UNREACHABLE() to __builtin_unreachable() in the release mode. (GH-16329)
Co-authored-by: Victor Stinner <vstinner@python.org>
2020-03-09 20:49:52 +02:00
Serhiy Storchaka e5ccc94bbb
bpo-38643: Raise SystemError instead of crashing when PyNumber_ToBase is called with invalid base. (GH-18863) 2020-03-09 20:03:38 +02:00
Serhiy Storchaka dccd41e29f
bpo-39822: Use NULL instead of None for empty attrib in Element. (GH-18735) 2020-03-09 15:12:41 +02:00
Serhiy Storchaka 88944a44aa
bpo-39903: Fix double decref in _elementtree.Element.__getstate__ (GH-18850) 2020-03-09 14:37:08 +02:00
Andy Lester 557287075c
bpo-39573: Use Py_IS_TYPE() macro to check for types (GH-18809)
Co-authored-by: Victor Stinner <vstinner@python.org>
2020-03-06 23:53:17 +01:00
Brandt Bucher 57c9d17256
bpo-36144: Implement defaultdict union (GH-18729)
For PEP 585 (this isn't in the PEP but is an obvious follow-up).
2020-03-06 09:24:08 -08:00
Andy Lester e63117a84e
closes bpo-39859: Do not downcast result of hstrerror (GH-18790)
set_herror builds a string by calling hstrerror but downcasts its return value to char *.  It should be const char *.

Automerge-Triggered-By: @benjaminp
2020-03-05 20:43:36 -08:00
Victor Stinner 942f7a2dea
bpo-39674: Revert "bpo-37330: open() no longer accept 'U' in file mode (GH-16959)" (GH-18767)
This reverts commit e471e72977.

The mode will be removed from Python 3.10.
2020-03-04 18:50:22 +01:00
Andy Lester 702e09fd0a
bpo-39770, array module: Remove unnecessary descriptor counting (GH-18675) 2020-03-04 15:52:15 +01:00
Andy Lester dffe4c0709
bpo-39573: Finish converting to new Py_IS_TYPE() macro (GH-18601) 2020-03-04 14:15:20 +01:00
Batuhan Taşkaya 4991cf47c4
bpo-39802: Only expose set_escdelay and set_tabsize when curses extensions are activated (GH-18705) 2020-03-03 02:00:10 +00:00
Serhiy Storchaka 28d0bcac8b
bpo-38913: Fix segfault in Py_BuildValue("(s#O)", ...) if entered with exception raised. (GH-18656) 2020-03-02 08:42:39 +02:00
Shantanu 4edc95cf0a
bpo-39495: Remove default value from C impl of TreeBuilder.start (GH-18275) 2020-03-02 08:33:24 +02:00
Hai Shi 1f577ce363
bpo-39378: partial of PickleState struct should be traversed. (GH-18046) 2020-03-02 08:28:44 +02:00
Stefan Krah eb47fd58ab
Cosmetic change to match the surrounding code. (#18704) 2020-02-29 20:07:48 +01:00
Stefan Krah 815280eb16
bpo-39794: Add --without-decimal-contextvar (#18702) 2020-02-29 19:43:42 +01:00
Ammar Askar e263bb1e97
Fuzz struct.unpack and catch RecursionError in re.compile (GH-18679) 2020-02-27 23:05:02 -08:00
Andy Lester c3fa634096
closes bpo-39736: const strings in Modules/_datetimemodule.c and Modules/_testbuffer.c (GH-18637) 2020-02-23 22:40:43 -08:00
Antoine Pitrou 9f37872e30
bpo-39681: Fix C pickle regression with minimal file-like objects (#18592)
Fix a regression where the C pickle module wouldn't allow unpickling from a
file-like object that doesn't expose a readinto() method.
2020-02-23 23:33:53 +01:00
Serhiy Storchaka 559e7f165a
bpo-39648: Expand math.gcd() and math.lcm() to handle multiple arguments. (GH-18604)
* bpo-39648: Expand math.gcd() and math.lcm() to handle multiple arguments.

* Simplify fast path.

* Difine lcm() without arguments returning 1.

* Apply suggestions from code review

Co-Authored-By: Mark Dickinson <dickinsm@gmail.com>

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
2020-02-23 11:21:29 +00:00
Berker Peksag fd5116c0e7
bpo-35950: Raise UnsupportedOperation in BufferedReader.truncate() (GH-18586)
The truncate() method of io.BufferedReader() should raise
UnsupportedOperation when it is called on a read-only
io.BufferedReader() instance.





https://bugs.python.org/issue35950



Automerge-Triggered-By: @methane
2020-02-21 09:57:26 -08:00
Stefan Krah 90930e6545
bpo-39576: Prevent memory error for overly optimistic precisions (GH-18581) 2020-02-21 01:52:47 +01:00
Stefan Krah 1246d89203
Use the new recommended number of repetitions in the refleak tests. (#18569) 2020-02-20 19:08:53 +01:00
Stefan Krah 9b833e00e4
Update runall.bat to the latest Windows build system. (#18571) 2020-02-20 19:07:31 +01:00
Stefan Krah c0cb8beb38
Valgrind no longer supports --db-attach=yes. (#18568) 2020-02-20 14:39:14 +01:00
ananthan-123 f2ee21d858
bpo-39479:Add math.lcm() function: Least Common Multiple (#18547)
* Update math.rst

* Update math.rst

* updated whats new

* Update test_math.py

* Update mathmodule.c

* Update mathmodule.c.h

* Update ACKS

* 📜🤖 Added by blurb_it.

* Update 3.9.rst

* Update 2020-02-18-12-37-16.bpo-39479.j3UcCq.rst

* Update math.rst

* Update 2020-02-18-12-37-16.bpo-39479.j3UcCq.rst

* Update test_math.py

* Update ACKS

* Update mathmodule.c.h

* Update mathmodule.c

* Update mathmodule.c.h

* Update mathmodule.c.h

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2020-02-19 18:21:37 +00:00
Hai Shi 5d38517aa1
bpo-1635741: Port _bz2 extension module to multiphase initialization(PEP 489) (GH-18050)
https://bugs.python.org/issue1635741
2020-02-18 03:17:38 -08:00
Hai Shi 4c1b6a6f4f
bpo-1635741: Port _abc extension to multiphase initialization (PEP 489) (GH-18030) 2020-02-17 14:50:35 +01:00
Hai Shi 7d7956833c
bpo-1635741: Port _contextvars module to multiphase initialization (PEP 489) (GH-18374) 2020-02-17 14:49:26 +01:00
Dong-hee Na 1b55b65638
bpo-39573: Clean up modules and headers to use Py_IS_TYPE() function (GH-18521) 2020-02-17 11:09:15 +01:00
Hai Shi b2b6e27bca
bpo-1635741: Port _crypt extension module to multiphase initialization (PEP 489) (GH-18404) 2020-02-17 10:11:34 +01:00
Dong-hee Na 9aeb0ef930
bpo-39573: Update clinic to use Py_IS_TYPE() function (GH-18507) 2020-02-14 08:50:19 +01:00
Saiyang Gou 7514f4f625
bpo-39184: Add audit events to functions in `fcntl`, `msvcrt`, `os`, `resource`, `shutil`, `signal`, `syslog` (GH-18407) 2020-02-13 07:47:42 +00:00
Andy Lester 597ebed748
closes bpo-39621: Make buf arg to md5_compress be const. (GH-18497) 2020-02-12 20:53:01 -08:00
Victor Stinner e9e7d284c4
bpo-35081: Move dtoa.h header to the internal C API (GH-18489)
Move the dtoa.h header file to the internal C API as pycore_dtoa.h:
it only contains private functions (prefixed by "_Py").

The math and cmath modules must now be compiled with the
Py_BUILD_CORE macro defined.
2020-02-12 22:54:42 +01:00
Andy Lester e6be9b59a9
closes bpo-39605: Fix some casts to not cast away const. (GH-18453)
gcc -Wcast-qual turns up a number of instances of casting away constness of pointers. Some of these can be safely modified, by either:

Adding the const to the type cast, as in:

-    return _PyUnicode_FromUCS1((unsigned char*)s, size);
+    return _PyUnicode_FromUCS1((const unsigned char*)s, size);

or, Removing the cast entirely, because it's not necessary (but probably was at one time), as in:

-    PyDTrace_FUNCTION_ENTRY((char *)filename, (char *)funcname, lineno);
+    PyDTrace_FUNCTION_ENTRY(filename, funcname, lineno);

These changes will not change code, but they will make it much easier to check for errors in consts
2020-02-11 18:28:35 -08:00
Petr Viktorin ffd9753a94
bpo-39245: Switch to public API for Vectorcall (GH-18460)
The bulk of this patch was generated automatically with:

    for name in \
        PyObject_Vectorcall \
        Py_TPFLAGS_HAVE_VECTORCALL \
        PyObject_VectorcallMethod \
        PyVectorcall_Function \
        PyObject_CallOneArg \
        PyObject_CallMethodNoArgs \
        PyObject_CallMethodOneArg \
    ;
    do
        echo $name
        git grep -lwz _$name | xargs -0 sed -i "s/\b_$name\b/$name/g"
    done

    old=_PyObject_FastCallDict
    new=PyObject_VectorcallDict
    git grep -lwz $old | xargs -0 sed -i "s/\b$old\b/$new/g"

and then cleaned up:

- Revert changes to in docs & news
- Revert changes to backcompat defines in headers
- Nudge misaligned comments
2020-02-11 17:46:57 +01:00
Hai Shi 1ea45ae257
bpo-1635741: Port _codecs extension module to multiphase initialization (PEP 489) (GH-18065)
https://bugs.python.org/issue1635741
2020-02-11 03:16:38 -08:00
sweeneyde c6dedde160
bpo-39590: make deque.__contains__ and deque.count hold strong references (GH-18421) 2020-02-09 00:16:43 -08:00
Dong-hee Na 7f6f7eef52
bpo-39573: Use Py_TYPE() macro in ctypes.h (GH-18411) 2020-02-09 00:45:52 +01:00
Victor Stinner 60ac6ed557
bpo-39573: Use Py_SET_SIZE() function (GH-18402)
Replace direct acccess to PyVarObject.ob_size with usage of
the Py_SET_SIZE() function.
2020-02-07 23:18:08 +01:00
Victor Stinner d2ec81a8c9
bpo-39573: Add Py_SET_TYPE() function (GH-18394)
Add Py_SET_TYPE() function to set the type of an object.
2020-02-07 09:17:07 +01:00
Victor Stinner daa9756cb6
bpo-39573: Use Py_TYPE() macro in Modules directory (GH-18393)
Replace direct access to PyObject.ob_type with Py_TYPE().
2020-02-07 03:37:06 +01:00
Victor Stinner c86a11221d
bpo-39573: Add Py_SET_REFCNT() function (GH-18389)
Add a Py_SET_REFCNT() function to set the reference counter of an
object.
2020-02-07 01:24:29 +01:00
Victor Stinner a93c51e3a8
bpo-39573: Use Py_REFCNT() macro (GH-18388)
Replace direct acccess to PyObject.ob_refcnt with usage of the
Py_REFCNT() macro.
2020-02-07 00:38:59 +01:00
Saiyang Gou 95f6001021
bpo-39184: Add audit events to command execution functions in os and pty modules (GH-17824) 2020-02-05 11:15:00 +11:00
Victor Stinner 40e547dfbb
bpo-39542: Make _Py_NewReference() opaque in C API (GH-18346)
_Py_NewReference() becomes a regular opaque function, rather than a
static inline function in the C API (object.h), to better hide
implementation details.

Move _Py_tracemalloc_config from public pymem.h to internal
pycore_pymem.h header.

Make _Py_AddToAllObjects() private.
2020-02-05 01:11:10 +01:00
Philipp Gesang cb1c0746f2
closes bpo-39510: Fix use-after-free in BufferedReader.readinto() (GH-18295)
When called on a closed object, readinto() segfaults on account
of a write to a freed buffer:

    ==220553== Process terminating with default action of signal 11 (SIGSEGV): dumping core
    ==220553==  Access not within mapped region at address 0x2A
    ==220553==    at 0x48408A0: memmove (vg_replace_strmem.c:1272)
    ==220553==    by 0x58DB0C: _buffered_readinto_generic (bufferedio.c:972)
    ==220553==    by 0x58DCBA: _io__Buffered_readinto_impl (bufferedio.c:1053)
    ==220553==    by 0x58DCBA: _io__Buffered_readinto (bufferedio.c.h:253)

Reproducer:

    reader = open ("/dev/zero", "rb")
    _void  = reader.read (42)
    reader.close ()
    reader.readinto (bytearray (42)) ### BANG!

The problem exists since 2012 when commit dc469454ec added code
to free the read buffer on close().

Signed-off-by: Philipp Gesang <philipp.gesang@intra2net.com>
2020-02-04 13:25:16 -08:00
Victor Stinner 49932fec62
bpo-39542: Simplify _Py_NewReference() (GH-18332)
* Remove _Py_INC_REFTOTAL and _Py_DEC_REFTOTAL macros: modify
  directly _Py_RefTotal.
* _Py_ForgetReference() is no longer defined if the Py_TRACE_REFS
  macro is not defined.
* Remove _Py_NewReference() implementation from object.c:
  unify the two implementations in object.h inline function.
* Fix Py_TRACE_REFS build: _Py_INC_TPALLOCS() macro has been removed.
2020-02-03 17:55:04 +01:00
Victor Stinner c6e5c1123b
bpo-39489: Remove COUNT_ALLOCS special build (GH-18259)
Remove:

* COUNT_ALLOCS macro
* sys.getcounts() function
* SHOW_ALLOC_COUNT code in listobject.c
* SHOW_TRACK_COUNT code in tupleobject.c
* PyConfig.show_alloc_count field
* -X showalloccount command line option
* @test.support.requires_type_collecting decorator
2020-02-03 15:17:15 +01:00
Pierre Glaser 0f2f35e15f
bpo-39492: Fix a reference cycle between reducer_override and a Pickler instance (GH-18266)
This also needs a backport to 3.8


https://bugs.python.org/issue39492



Automerge-Triggered-By: @pitrou
2020-02-02 10:55:21 -08:00
Alex Henrie 78c7183f47
bpo-39496: Remove redundant checks from _sqlite/cursor.c (GH-18270) 2020-02-01 23:45:34 +03:00
Victor Stinner 7dc140126e
bpo-39511: Fix multiprocessing semlock_acquire() (GH-18298)
The Python C API must not be used when the GIL is released: only
access Py_None when the GIL is hold.
2020-02-01 01:25:59 +01:00
Victor Stinner 2a4903fcce
bpo-38631: Add _Py_NO_RETURN to functions calling Py_FatalError() (GH-18278)
Add _Py_NO_RETURN to functions calling Py_FatalError():

* _PyObject_AssertFailed()
* dummy_dealloc()
* faulthandler_fatal_error_thread()
* none_dealloc()
* notimplemented_dealloc()
2020-01-30 13:09:11 +01:00
Alex Henrie 1f44e775df
bpo-39497: Remove unused variable from pysqlite_cursor_executescript (GH-18271) 2020-01-30 12:39:25 +03:00
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