Skip to content

Commit 8c21768

Browse files
committed
Merge branch 'master' into signal_pyatomic
2 parents 1b6b61d + 18974c3 commit 8c21768

File tree

82 files changed

+2096
-1442
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+2096
-1442
lines changed

Doc/c-api/unicode.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -934,16 +934,22 @@ wchar_t Support
934934
Convert the Unicode object to a wide character string. The output string
935935
always ends with a null character. If *size* is not *NULL*, write the number
936936
of wide characters (excluding the trailing null termination character) into
937-
*\*size*.
937+
*\*size*. Note that the resulting :c:type:`wchar_t` string might contain
938+
null characters, which would cause the string to be truncated when used with
939+
most C functions. If *size* is *NULL* and the :c:type:`wchar_t*` string
940+
contains null characters a :exc:`ValueError` is raised.
938941
939942
Returns a buffer allocated by :c:func:`PyMem_Alloc` (use
940-
:c:func:`PyMem_Free` to free it) on success. On error, returns *NULL*,
941-
*\*size* is undefined and raises a :exc:`MemoryError`. Note that the
942-
resulting :c:type:`wchar_t` string might contain null characters, which
943-
would cause the string to be truncated when used with most C functions.
943+
:c:func:`PyMem_Free` to free it) on success. On error, returns *NULL*
944+
and *\*size* is undefined. Raises a :exc:`MemoryError` if memory allocation
945+
is failed.
944946
945947
.. versionadded:: 3.2
946948
949+
.. versionchanged:: 3.7
950+
Raises a :exc:`ValueError` if *size* is *NULL* and the :c:type:`wchar_t*`
951+
string contains null characters.
952+
947953
948954
.. _builtincodecs:
949955

Doc/tutorial/controlflow.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Later we will see more functions that return iterables and take iterables as arg
157157
:keyword:`break` and :keyword:`continue` Statements, and :keyword:`else` Clauses on Loops
158158
=========================================================================================
159159

160-
The :keyword:`break` statement, like in C, breaks out of the smallest enclosing
160+
The :keyword:`break` statement, like in C, breaks out of the innermost enclosing
161161
:keyword:`for` or :keyword:`while` loop.
162162

163163
Loop statements may have an ``else`` clause; it is executed when the loop

Doc/whatsnew/3.7.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,25 @@ Changes in the C API
360360
:c:type:`unsigned long`.
361361
(Contributed by Serhiy Storchaka in :issue:`6532`.)
362362

363+
- :c:func:`PyUnicode_AsWideCharString` now raises a :exc:`ValueError` if the
364+
second argument is *NULL* and the :c:type:`wchar_t*` string contains null
365+
characters. (Contributed by Serhiy Storchaka in :issue:`30708`.)
366+
367+
368+
Windows Only
369+
------------
370+
- The python launcher, (py.exe), can accept 32 & 64 bit specifiers **without**
371+
having to specify a minor version as well. So ``py -3-32`` and ``py -3-64``
372+
become valid as well as ``py -3.7-32``, also the -*m*-64 and -*m.n*-64 forms
373+
are now accepted to force 64 bit python even if 32 bit would have otherwise
374+
been used. If the specified version is not available py.exe will error exit.
375+
(Contributed by Steve Barnes in :issue:`30291`.)
376+
377+
- The launcher can be run as "py -0" to produce a list of the installed pythons,
378+
*with default marked with an asterix*. Running "py -0p" will include the paths.
379+
If py is run with a version specifier that cannot be matched it will also print
380+
the *short form* list of available specifiers.
381+
(Contributed by Steve Barnes in :issue:`30362`.)
363382

364383
Removed
365384
=======
@@ -432,6 +451,10 @@ Changes in the Python API
432451
* The :attr:`struct.Struct.format` type is now :class:`str` instead of
433452
:class:`bytes`. (Contributed by Victor Stinner in :issue:`21071`.)
434453

454+
* Due to internal changes in :mod:`socket` you won't be able to
455+
:func:`socket.fromshare` a socket :func:`~socket.socket.share`-ed in older
456+
Python versions.
457+
435458

436459
CPython bytecode changes
437460
------------------------

Include/unicodeobject.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -756,23 +756,27 @@ PyAPI_FUNC(Py_UCS4*) PyUnicode_AsUCS4(
756756
PyAPI_FUNC(Py_UCS4*) PyUnicode_AsUCS4Copy(PyObject *unicode);
757757
#endif
758758

759+
#ifndef Py_LIMITED_API
759760
/* Return a read-only pointer to the Unicode object's internal
760761
Py_UNICODE buffer.
761762
If the wchar_t/Py_UNICODE representation is not yet available, this
762763
function will calculate it. */
763764

764-
#ifndef Py_LIMITED_API
765765
PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode(
766766
PyObject *unicode /* Unicode object */
767767
) /* Py_DEPRECATED(3.3) */;
768-
#endif
768+
769+
/* Similar to PyUnicode_AsUnicode(), but raises a ValueError if the string
770+
contains null characters. */
771+
PyAPI_FUNC(const Py_UNICODE *) _PyUnicode_AsUnicode(
772+
PyObject *unicode /* Unicode object */
773+
);
769774

770775
/* Return a read-only pointer to the Unicode object's internal
771776
Py_UNICODE buffer and save the length at size.
772777
If the wchar_t/Py_UNICODE representation is not yet available, this
773778
function will calculate it. */
774779

775-
#ifndef Py_LIMITED_API
776780
PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicodeAndSize(
777781
PyObject *unicode, /* Unicode object */
778782
Py_ssize_t *size /* location where to save the length */

Lib/ctypes/test/test_loading.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def test_load_library(self):
6262
windll["kernel32"].GetModuleHandleW
6363
windll.LoadLibrary("kernel32").GetModuleHandleW
6464
WinDLL("kernel32").GetModuleHandleW
65+
# embedded null character
66+
self.assertRaises(ValueError, windll.LoadLibrary, "kernel32\0")
6567

6668
@unittest.skipUnless(os.name == "nt",
6769
'test specific to Windows')

Lib/ctypes/test/test_slicing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def test_wchar_ptr(self):
134134
dll.my_wcsdup.restype = POINTER(c_wchar)
135135
dll.my_wcsdup.argtypes = POINTER(c_wchar),
136136
dll.my_free.restype = None
137-
res = dll.my_wcsdup(s)
137+
res = dll.my_wcsdup(s[:-1])
138138
self.assertEqual(res[:len(s)], s)
139139
self.assertEqual(res[:len(s):], s)
140140
self.assertEqual(res[len(s)-1:-1:-1], s[::-1])
@@ -153,7 +153,7 @@ def test_wchar_ptr(self):
153153
dll.my_wcsdup.restype = POINTER(c_long)
154154
else:
155155
self.skipTest('Pointers to c_wchar are not supported')
156-
res = dll.my_wcsdup(s)
156+
res = dll.my_wcsdup(s[:-1])
157157
tmpl = list(range(ord("a"), ord("z")+1))
158158
self.assertEqual(res[:len(s)-1], tmpl)
159159
self.assertEqual(res[:len(s)-1:], tmpl)

Lib/email/_header_value_parser.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,7 @@ def _fold(self, folded):
341341
# avoid infinite recursion.
342342
ws = part.pop_leading_fws()
343343
if ws is not None:
344-
# Peel off the leading whitespace and make it sticky, to
345-
# avoid infinite recursion.
346-
folded.stickyspace = str(part.pop(0))
344+
folded.stickyspace = str(ws)
347345
if folded.append_if_fits(part):
348346
continue
349347
if part.has_fws:

Lib/idlelib/autocomplete.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def force_open_completions_event(self, event):
6060
if a function call is needed.
6161
"""
6262
self.open_completions(True, False, True)
63+
return "break"
6364

6465
def try_open_completions_event(self, event):
6566
"""Happens when it would be nice to open a completion list, but not

Lib/idlelib/calltip_w.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,27 @@ def checkhide_event(self, event=None):
8989
# If the event was triggered by the same event that unbinded
9090
# this function, the function will be called nevertheless,
9191
# so do nothing in this case.
92-
return
92+
return None
9393
curline, curcol = map(int, self.widget.index("insert").split('.'))
9494
if curline < self.parenline or \
9595
(curline == self.parenline and curcol <= self.parencol) or \
9696
self.widget.compare("insert", ">", MARK_RIGHT):
9797
self.hidetip()
98+
return "break"
9899
else:
99100
self.position_window()
100101
if self.checkhide_after_id is not None:
101102
self.widget.after_cancel(self.checkhide_after_id)
102103
self.checkhide_after_id = \
103104
self.widget.after(CHECKHIDE_TIME, self.checkhide_event)
105+
return None
104106

105107
def hide_event(self, event):
106108
if not self.tipwindow:
107109
# See the explanation in checkhide_event.
108-
return
110+
return None
109111
self.hidetip()
112+
return "break"
110113

111114
def hidetip(self):
112115
if not self.tipwindow:

Lib/idlelib/calltips.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def _remove_calltip_window(self, event=None):
4747
def force_open_calltip_event(self, event):
4848
"The user selected the menu entry or hotkey, open the tip."
4949
self.open_calltip(True)
50+
return "break"
5051

5152
def try_open_calltip_event(self, event):
5253
"""Happens when it would be nice to open a CallTip, but not really

Lib/idlelib/codecontext.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def toggle_code_context_event(self, event=None):
8989
idleConf.SetOption("extensions", "CodeContext", "visible",
9090
str(self.label is not None))
9191
idleConf.SaveUserCfgFiles()
92+
return "break"
9293

9394
def get_line_info(self, linenum):
9495
"""Get the line indent value, text, and any block start keyword

Lib/idlelib/config_key.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,10 @@ def KeysOK(self, keys):
250250
'''
251251
finalKey = self.listKeysFinal.get(ANCHOR)
252252
modifiers = self.GetModifiers()
253-
# create a key sequence list for overlap check:
254-
keySequence = keys.split()
255253
keysOK = False
256254
title = self.keyerror_title
255+
key_sequences = [key for keylist in self.currentKeySequences
256+
for key in keylist]
257257
if not keys.endswith('>'):
258258
self.showerror(title, parent=self,
259259
message='Missing the final Key')
@@ -267,7 +267,7 @@ def KeysOK(self, keys):
267267
msg = 'The shift modifier by itself may not be used with'\
268268
' this key symbol.'
269269
self.showerror(title=title, parent=self, message=msg)
270-
elif keySequence in self.currentKeySequences:
270+
elif keys in key_sequences:
271271
msg = 'This key combination is already in use.'
272272
self.showerror(title=title, parent=self, message=msg)
273273
else:

0 commit comments

Comments
 (0)