From 8f328d0c1d86096b3d4e5f1c1ac497663e197a0d Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Mon, 30 Jul 2012 00:01:06 +0200 Subject: [PATCH 1/8] Issue #15489: Add a __sizeof__ implementation for BytesIO objects. Patch by Serhiy Storchaka. --- Lib/test/test_memoryio.py | 11 +++++++++++ Misc/NEWS | 3 +++ Modules/_io/bytesio.c | 12 ++++++++++++ 3 files changed, 26 insertions(+) diff --git a/Lib/test/test_memoryio.py b/Lib/test/test_memoryio.py index 49ca44f102c..92480989aca 100644 --- a/Lib/test/test_memoryio.py +++ b/Lib/test/test_memoryio.py @@ -654,6 +654,17 @@ class CBytesIOTest(PyBytesIOTest): memio.close() self.assertRaises(ValueError, memio.__setstate__, (b"closed", 0, None)) + check_sizeof = support.check_sizeof + + @support.cpython_only + def test_sizeof(self): + basesize = support.calcobjsize('P2PP2PP') + check = self.check_sizeof + self.assertEqual(object.__sizeof__(io.BytesIO()), basesize) + check(io.BytesIO(), basesize ) + check(io.BytesIO(b'a'), basesize + 1 + 1 ) + check(io.BytesIO(b'a' * 1000), basesize + 1000 + 1 ) + class CStringIOTest(PyStringIOTest): ioclass = io.StringIO diff --git a/Misc/NEWS b/Misc/NEWS index 3e6b8f8cc44..1b3d24405cc 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -98,6 +98,9 @@ Core and Builtins Library ------- +- Issue #15489: Add a __sizeof__ implementation for BytesIO objects. + Patch by Serhiy Storchaka. + - Issue #15487: Add a __sizeof__ implementation for buffered I/O objects. Patch by Serhiy Storchaka. diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c index b40513f7a77..03f4c7d14aa 100644 --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -834,6 +834,17 @@ bytesio_init(bytesio *self, PyObject *args, PyObject *kwds) return 0; } +static PyObject * +bytesio_sizeof(bytesio *self, void *unused) +{ + Py_ssize_t res; + + res = sizeof(bytesio); + if (self->buf) + res += self->buf_size; + return PyLong_FromSsize_t(res); +} + static int bytesio_traverse(bytesio *self, visitproc visit, void *arg) { @@ -876,6 +887,7 @@ static struct PyMethodDef bytesio_methods[] = { {"truncate", (PyCFunction)bytesio_truncate, METH_VARARGS, truncate_doc}, {"__getstate__", (PyCFunction)bytesio_getstate, METH_NOARGS, NULL}, {"__setstate__", (PyCFunction)bytesio_setstate, METH_O, NULL}, + {"__sizeof__", (PyCFunction)bytesio_sizeof, METH_NOARGS, NULL}, {NULL, NULL} /* sentinel */ }; From 5d6aeb8d9968fff9a132947e8420105af6856d0c Mon Sep 17 00:00:00 2001 From: Ned Deily Date: Mon, 30 Jul 2012 02:34:03 -0700 Subject: [PATCH 2/8] Fix invalid UTF-8 encoding in commit message. --- Misc/NEWS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS b/Misc/NEWS index e7110caf692..29bc01b3d48 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -265,7 +265,7 @@ Build ----- - Issue #15431: Add _freeze_importlib project to regenerate importlib.h - on Windows. Patch by Kristján Valur Jónsson. + on Windows. Patch by Kristján Valur Jónsson. - Issue #14197: For OS X framework builds, ensure links to the shared library are created with the proper ABI suffix. From 2910a7ba6bac0e51c05a5405de1c858da73687b4 Mon Sep 17 00:00:00 2001 From: Ned Deily Date: Mon, 30 Jul 2012 02:35:58 -0700 Subject: [PATCH 3/8] Issue #14018: Fix OS X Tcl/Tk framework checking when using OS X SDKs. Also add tests in the OS X installer build to ensure that the desired dynamic linking with an optional newer Tcl/Tk in /Library actually happens. --- Mac/BuildScript/build-installer.py | 57 +++++++++++++++++++++++------- Misc/NEWS | 2 ++ setup.py | 4 ++- 3 files changed, 50 insertions(+), 13 deletions(-) diff --git a/Mac/BuildScript/build-installer.py b/Mac/BuildScript/build-installer.py index 69f9c8247e0..688834e3d50 100755 --- a/Mac/BuildScript/build-installer.py +++ b/Mac/BuildScript/build-installer.py @@ -161,6 +161,13 @@ USAGE = textwrap.dedent("""\ --universal-archs=x universal architectures (options: %(UNIVERSALOPTS)r, default: %(UNIVERSALARCHS)r) """)% globals() +# Dict of object file names with shared library names to check after building. +# This is to ensure that we ended up dynamically linking with the shared +# library paths and versions we expected. For example: +# EXPECTED_SHARED_LIBS['_tkinter.so'] = [ +# '/Library/Frameworks/Tcl.framework/Versions/8.5/Tcl', +# '/Library/Frameworks/Tk.framework/Versions/8.5/Tk'] +EXPECTED_SHARED_LIBS = {} # Instructions for building libraries that are necessary for building a # batteries included python. @@ -460,27 +467,40 @@ def checkEnvironment(): # Because we only support dynamic load of only one major/minor version of # Tcl/Tk, ensure: # 1. there are no user-installed frameworks of Tcl/Tk with version - # higher than the Apple-supplied system version - # 2. there is a user-installed framework in /Library/Frameworks with the - # same version as the system version. This allows users to choose - # to install a newer patch level. + # higher than the Apple-supplied system version in + # SDKROOT/System/Library/Frameworks + # 2. there is a user-installed framework (usually ActiveTcl) in (or linked + # in) SDKROOT/Library/Frameworks with the same version as the system + # version. This allows users to choose to install a newer patch level. + frameworks = {} for framework in ['Tcl', 'Tk']: - #fw = dict(lower=framework.lower(), - # upper=framework.upper(), - # cap=framework.capitalize()) - #fwpth = "Library/Frameworks/%(cap)s.framework/%(lower)sConfig.sh" % fw - fwpth = 'Library/Frameworks/Tcl.framework/Versions/Current' + fwpth = 'Library/Frameworks/%s.framework/Versions/Current' % framework sysfw = os.path.join(SDKPATH, 'System', fwpth) - libfw = os.path.join('/', fwpth) + libfw = os.path.join(SDKPATH, fwpth) usrfw = os.path.join(os.getenv('HOME'), fwpth) - #version = "%(upper)s_VERSION" % fw + frameworks[framework] = os.readlink(sysfw) + if not os.path.exists(libfw): + fatal("Please install a link to a current %s %s as %s so " + "the user can override the system framework." + % (framework, frameworks[framework], libfw)) if os.readlink(libfw) != os.readlink(sysfw): fatal("Version of %s must match %s" % (libfw, sysfw) ) if os.path.exists(usrfw): fatal("Please rename %s to avoid possible dynamic load issues." % usrfw) + if frameworks['Tcl'] != frameworks['Tk']: + fatal("The Tcl and Tk frameworks are not the same version.") + + # add files to check after build + EXPECTED_SHARED_LIBS['_tkinter.so'] = [ + "/Library/Frameworks/Tcl.framework/Versions/%s/Tcl" + % frameworks['Tcl'], + "/Library/Frameworks/Tk.framework/Versions/%s/Tk" + % frameworks['Tk'], + ] + # Remove inherited environment variables which might influence build environ_var_prefixes = ['CPATH', 'C_INCLUDE_', 'DYLD_', 'LANG', 'LC_', 'LD_', 'LIBRARY_', 'PATH', 'PYTHON'] @@ -861,12 +881,12 @@ def buildPython(): frmDir = os.path.join(rootDir, 'Library', 'Frameworks', 'Python.framework') gid = grp.getgrnam('admin').gr_gid + shared_lib_error = False for dirpath, dirnames, filenames in os.walk(frmDir): for dn in dirnames: os.chmod(os.path.join(dirpath, dn), STAT_0o775) os.chown(os.path.join(dirpath, dn), -1, gid) - for fn in filenames: if os.path.islink(fn): continue @@ -877,6 +897,19 @@ def buildPython(): os.chmod(p, stat.S_IMODE(st.st_mode) | stat.S_IWGRP) os.chown(p, -1, gid) + if fn in EXPECTED_SHARED_LIBS: + # check to see that this file was linked with the + # expected library path and version + data = captureCommand("otool -L %s" % shellQuote(p)) + for sl in EXPECTED_SHARED_LIBS[fn]: + if ("\t%s " % sl) not in data: + print("Expected shared lib %s was not linked with %s" + % (sl, p)) + shared_lib_error = True + + if shared_lib_error: + fatal("Unexpected shared library errors.") + if PYTHON_3: LDVERSION=None VERSION=None diff --git a/Misc/NEWS b/Misc/NEWS index 29bc01b3d48..15ef12b2cfa 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -264,6 +264,8 @@ Tests Build ----- +- Issue #14018: Fix OS X Tcl/Tk framework checking when using OS X SDKs. + - Issue #15431: Add _freeze_importlib project to regenerate importlib.h on Windows. Patch by Kristján Valur Jónsson. diff --git a/setup.py b/setup.py index c7c5929b652..d419d4850d7 100644 --- a/setup.py +++ b/setup.py @@ -69,7 +69,9 @@ def is_macosx_sdk_path(path): """ Returns True if 'path' can be located in an OSX SDK """ - return (path.startswith('/usr/') and not path.startswith('/usr/local')) or path.startswith('/System/') + return ( (path.startswith('/usr/') and not path.startswith('/usr/local')) + or path.startswith('/System/') + or path.startswith('/Library/') ) def find_file(filename, std_dirs, paths): """Searches for the directory where a given file is located, From c556c6440593c36cdfd407a6e192de86ac1b0df6 Mon Sep 17 00:00:00 2001 From: Ned Deily Date: Mon, 30 Jul 2012 03:31:21 -0700 Subject: [PATCH 4/8] Issue #14018: Update the OS X IDLE Tcl/Tk warning check to include the Apple-supplied Tck/Tk versions shipped with OS X 10.7 and 10.8. They are not as buggy as the 10.6 version but can still easily crash. --- Lib/idlelib/NEWS.txt | 4 ++++ Lib/idlelib/macosxSupport.py | 16 ++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt index 3a641a019eb..3160c74561d 100644 --- a/Lib/idlelib/NEWS.txt +++ b/Lib/idlelib/NEWS.txt @@ -18,6 +18,10 @@ What's New in IDLE 3.2.4? - Issue #14937: Perform auto-completion of filenames in strings even for non-ASCII filenames. Likewise for identifiers. +- Issue #14018: Update checks for unstable system Tcl/Tk versions on OS X + to include versions shipped with OS X 10.7 and 10.8 in addition to 10.6. + + What's New in IDLE 3.2.3? ========================= diff --git a/Lib/idlelib/macosxSupport.py b/Lib/idlelib/macosxSupport.py index f93ef118dbf..96904429af8 100644 --- a/Lib/idlelib/macosxSupport.py +++ b/Lib/idlelib/macosxSupport.py @@ -37,17 +37,21 @@ def isCarbonAquaTk(root): def tkVersionWarning(root): """ Returns a string warning message if the Tk version in use appears to - be one known to cause problems with IDLE. The Apple Cocoa-based Tk 8.5 - that was shipped with Mac OS X 10.6. + be one known to cause problems with IDLE. + 1. Apple Cocoa-based Tk 8.5.7 shipped with Mac OS X 10.6 is unusable. + 2. Apple Cocoa-based Tk 8.5.9 in OS X 10.7 and 10.8 is better but + can still crash unexpectedly. """ if (runningAsOSXApp() and - ('AppKit' in root.tk.call('winfo', 'server', '.')) and - (root.tk.call('info', 'patchlevel') == '8.5.7') ): - return (r"WARNING: The version of Tcl/Tk (8.5.7) in use may" + ('AppKit' in root.tk.call('winfo', 'server', '.')) ): + patchlevel = root.tk.call('info', 'patchlevel') + if patchlevel not in ('8.5.7', '8.5.9'): + return False + return (r"WARNING: The version of Tcl/Tk ({0}) in use may" r" be unstable.\n" r"Visit http://www.python.org/download/mac/tcltk/" - r" for current information.") + r" for current information.".format(patchlevel)) else: return False From 54f939b9ae9cf91ed4cb3cd1b0f1e6aaff19782a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 30 Jul 2012 13:08:58 +0200 Subject: [PATCH 5/8] Issue #15463: the faulthandler module truncates strings to 500 characters, instead of 100, to be able to display long file paths --- Misc/NEWS | 3 +++ Python/traceback.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS b/Misc/NEWS index 15ef12b2cfa..ba367510afa 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -68,6 +68,9 @@ Core and Builtins Library ------- +- Issue #15463: the faulthandler module truncates strings to 500 characters, + instead of 100, to be able to display long file paths + - Issue #6056: Make multiprocessing use setblocking(True) on the sockets it uses. Original patch by J Derek Wilson. diff --git a/Python/traceback.c b/Python/traceback.c index ce670f3d2cb..b928902ef02 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -14,7 +14,7 @@ #define OFF(x) offsetof(PyTracebackObject, x) #define PUTS(fd, str) write(fd, str, strlen(str)) -#define MAX_STRING_LENGTH 100 +#define MAX_STRING_LENGTH 500 #define MAX_FRAME_DEPTH 100 #define MAX_NTHREADS 100 From 3b796680c3cbc1d43f3e1157cacc8e6b668f65f6 Mon Sep 17 00:00:00 2001 From: Ned Deily Date: Mon, 30 Jul 2012 04:09:32 -0700 Subject: [PATCH 6/8] Issue #14018: Fix OS X Tcl/Tk framework checking when using OS X SDKs. --- Misc/NEWS | 2 ++ setup.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/Misc/NEWS b/Misc/NEWS index 1b3d24405cc..5ede32413d5 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -435,6 +435,8 @@ Build - Issue #14359: Only use O_CLOEXEC in _posixmodule.c if it is defined. Based on patch from Hervé Coatanhay. +- Issue #14018: Fix OS X Tcl/Tk framework checking when using OS X SDKs. + Documentation ------------- diff --git a/setup.py b/setup.py index 2539f50fa8e..f3886bf4376 100644 --- a/setup.py +++ b/setup.py @@ -60,6 +60,9 @@ def is_macosx_sdk_path(path): Returns True if 'path' can be located in an OSX SDK """ return (path.startswith('/usr/') and not path.startswith('/usr/local')) or path.startswith('/System/') + return ( (path.startswith('/usr/') and not path.startswith('/usr/local')) + or path.startswith('/System/') + or path.startswith('/Library/') ) def find_file(filename, std_dirs, paths): """Searches for the directory where a given file is located, From 754d5ef8da92d71b72be4b129af5011cd4480dd0 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Mon, 30 Jul 2012 13:58:42 +0200 Subject: [PATCH 7/8] Better test for BytesIO.__sizeof__, now that the struct module supports (s)size_t. Followup to issue #15489. --- Lib/test/test_memoryio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_memoryio.py b/Lib/test/test_memoryio.py index 92480989aca..04ec8e72d91 100644 --- a/Lib/test/test_memoryio.py +++ b/Lib/test/test_memoryio.py @@ -658,7 +658,7 @@ class CBytesIOTest(PyBytesIOTest): @support.cpython_only def test_sizeof(self): - basesize = support.calcobjsize('P2PP2PP') + basesize = support.calcobjsize('P2nN2Pn') check = self.check_sizeof self.assertEqual(object.__sizeof__(io.BytesIO()), basesize) check(io.BytesIO(), basesize ) From 1fb0e3f3a2dde81f428ec0a8bcffffdb6f622292 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Mon, 30 Jul 2012 19:59:53 +0300 Subject: [PATCH 8/8] Issue #12288: Consider '0' and '0.0' as valid initialvalue for tkinter SimpleDialog. --- Lib/tkinter/simpledialog.py | 2 +- Misc/ACKS | 1 + Misc/NEWS | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Lib/tkinter/simpledialog.py b/Lib/tkinter/simpledialog.py index 885804b3c70..45302b4569b 100644 --- a/Lib/tkinter/simpledialog.py +++ b/Lib/tkinter/simpledialog.py @@ -282,7 +282,7 @@ class _QueryDialog(Dialog): self.entry = Entry(master, name="entry") self.entry.grid(row=1, padx=5, sticky=W+E) - if self.initialvalue: + if self.initialvalue is not None: self.entry.insert(0, self.initialvalue) self.entry.select_range(0, END) diff --git a/Misc/ACKS b/Misc/ACKS index e04677ede1a..1a094a17497 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -633,6 +633,7 @@ Carl Meyer Mike Meyer Steven Miale Trent Mick +Tom Middleton Stan Mihai Stefan Mihaila Aristotelis Mikropoulos diff --git a/Misc/NEWS b/Misc/NEWS index 5ede32413d5..454a70cc173 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -98,6 +98,9 @@ Core and Builtins Library ------- +- Issue #12288: Consider '0' and '0.0' as valid initialvalue + for tkinter SimpleDialog. + - Issue #15489: Add a __sizeof__ implementation for BytesIO objects. Patch by Serhiy Storchaka.