From: Hynek Schlawack Date: Thu, 21 Jun 2012 18:58:31 +0000 (+0200) Subject: #10053: Don't close FDs when FileIO.__init__ fails X-Git-Tag: v3.3.0b1~169 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=69168354c254f72b7a13d35aff8bb02752d00d26;p=python #10053: Don't close FDs when FileIO.__init__ fails Loosely based on the work by Hirokazu Yamamoto. --- 69168354c254f72b7a13d35aff8bb02752d00d26 diff --cc Misc/NEWS index 211599d55f,e59ed37d61..5ce4f12460 --- a/Misc/NEWS +++ b/Misc/NEWS @@@ -10,87 -10,79 +10,90 @@@ What's New in Python 3.3.0 Beta 1 Core and Builtins ----------------- + - Issue #10053: Don't close FDs when FileIO.__init__ fails. Loosely based on + the work by Hirokazu Yamamoto. + -- Issue #14775: Fix a potential quadratic dict build-up due to the garbage - collector repeatedly trying to untrack dicts. +- Issue #15096: Removed support for ur'' as the raw notation isn't + compatible with Python 2.x's raw unicode strings. -- Issue #14494: Fix __future__.py and its documentation to note that - absolute imports are the default behavior in 3.0 instead of 2.7. - Patch by Sven Marnach. +- Issue #13783: Generator objects now use the identifier APIs internally -- Issue #14761: Fix potential leak on an error case in the import machinery. +- Issue #14874: Restore charmap decoding speed to pre-PEP 393 levels. + Patch by Serhiy Storchaka. -- Issue #14699: Fix calling the classmethod descriptor directly. +- Issue #15026: utf-16 encoding is now significantly faster (up to 10x). + Patch by Serhiy Storchaka. -- Issue #14433: Prevent msvcrt crash in interactive prompt when stdin - is closed. +- Issue #11022: open() and io.TextIOWrapper are now calling + locale.getpreferredencoding(False) instead of locale.getpreferredencoding() + in text mode if the encoding is not specified. Don't change temporary the + locale encoding using locale.setlocale(), use the current locale encoding + instead of the user preferred encoding. -- Issue #11603 (again): Setting __repr__ to __str__ now raises a RuntimeError - when repr() or str() is called on such an object. +- Issue #14673: Add Eric Snow's sys.implementation implementation. -- Issue #14658: Fix binding a special method to a builtin implementation of a - special method with a different name. +- Issue #15038: Optimize python Locks on Windows. -- Issue #14630: Fix a memory access bug for instances of a subclass of int - with value 0. +Library +------- -- Issue #14612: Fix jumping around with blocks by setting f_lineno. +- Issue #14684: zlib.compressobj() and zlib.decompressobj() now support the use + of predefined compression dictionaries. Original patch by Sam Rushing. -- Issue #14607: Fix keyword-only arguments which started with ``__``. +- Fix GzipFile's handling of filenames given as bytes objects. -- Issue #13889: Check and (if necessary) set FPU control word before calling - any of the dtoa.c string <-> float conversion functions, on MSVC builds of - Python. This fixes issues when embedding Python in a Delphi app. +- Issue #14772: Return destination values from some shutil functions. -- Issue #14474: Save and restore exception state in thread.start_new_thread() - while writing error message if the thread leaves a unhandled exception. +- Issue #15064: Implement context manager protocol for multiprocessing types -- Issue #13019: Fix potential reference leaks in bytearray.extend(). Patch - by Suman Saha. +- Issue #15101: Make pool finalizer avoid joining current thread. -- Issue #14378: Fix compiling ast.ImportFrom nodes with a "__future__" string as - the module name that was not interned. +- Issue #14657: The frozen instance of importlib used for bootstrap is now + also the module imported as importlib._bootstrap. -- Issue #14331: Use significantly less stack space when importing modules by - allocating path buffers on the heap instead of the stack. +- Issue #14055: Add __sizeof__ support to _elementtree. -- Issue #14334: Prevent in a segfault in type.__getattribute__ when it was not - passed strings. +- Issue #15054: A bug in tokenize.tokenize that caused string literals + with 'b' prefixes to be incorrectly tokenized has been fixed. + Patch by Serhiy Storchaka. -- Issue #1469629: Allow cycles through an object's __dict__ slot to be - collected. (For example if ``x.__dict__ is x``). +- Issue #15006: Allow equality comparison between naive and aware + time or datetime objects. -- Issue #14172: Fix reference leak when marshalling a buffer-like object - (other than a bytes object). +- Issue #14982: Document that pkgutil's iteration functions require the + non-standard iter_modules() method to be defined by an importer (something + the importlib importers do not define). -- Issue #13521: dict.setdefault() now does only one lookup for the given key, - making it "atomic" for many purposes. Patch by Filip Gruszczyński. +- Issue #15036: Mailbox no longer throws an error if a flush is done + between operations when removing or changing multiple items in mbox, + MMDF, or Babyl mailboxes. -- Issue #14471: Fix a possible buffer overrun in the winreg module. +- Issue #14059: Implement multiprocessing.Barrier. -Library -------- +- Issue #15061: The inappropriately named hmac.secure_compare has been + renamed to hmac.compare_digest, restricted to operating on bytes inputs + only and had its documentation updated to more accurately reflect both its + intent and its limitations -- Fix GzipFile's handling of filenames given as bytes objects. +- Issue #13841: Make child processes exit using sys.exit() on Windows. -- Issue #15101: Make pool finalizer avoid joining current thread. +- Issue #14936: curses_panel was converted to PEP 3121 and PEP 384 API. + Patch by Robin Schreiber. -- Issue #15036: Mailbox no longer throws an error if a flush is done - between operations when removing or changing multiple items in mbox, - MMDF, or Babyl mailboxes. +- Issue #1667546: On platforms supporting tm_zone and tm_gmtoff fields + in struct tm, time.struct_time objects returned by time.gmtime(), + time.localtime() and time.strptime() functions now have tm_zone and + tm_gmtoff attributes. Original patch by Paul Boddie. + +- Rename adjusted attribute to adjustable in time.get_clock_info() result. + +- Issue #3518: Remove references to non-existent BaseManager.from_address() + method. + +- Issue #13857: Added textwrap.indent() function (initial patch by Ezra + Berch) -- Issue #10133: Make multiprocessing deallocate buffer if socket read - fails. Patch by Hallvard B Furuseth. +- Issue #2736: Added datetime.timestamp() method. - Issue #13854: Make multiprocessing properly handle non-integer non-string argument to SystemExit. diff --cc Modules/_io/fileio.c index 726d17b67e,6feca2137f..31e2994a0e --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@@ -366,35 -354,16 +367,37 @@@ fileio_init(PyObject *oself, PyObject * goto error; } - Py_BEGIN_ALLOW_THREADS errno = 0; + if (opener == Py_None) { + Py_BEGIN_ALLOW_THREADS #ifdef MS_WINDOWS - if (widename != NULL) - self->fd = _wopen(widename, flags, 0666); - else + if (widename != NULL) + self->fd = _wopen(widename, flags, 0666); + else #endif - self->fd = open(name, flags, 0666); - Py_END_ALLOW_THREADS - fd_is_own = 1; + self->fd = open(name, flags, 0666); + Py_END_ALLOW_THREADS ++ fd_is_own = 1; + } else { + PyObject *fdobj = PyObject_CallFunction( + opener, "Oi", nameobj, flags); + if (fdobj == NULL) + goto error; + if (!PyLong_Check(fdobj)) { + Py_DECREF(fdobj); + PyErr_SetString(PyExc_TypeError, + "expected integer from opener"); + goto error; + } + + self->fd = PyLong_AsLong(fdobj); + Py_DECREF(fdobj); + if (self->fd == -1) { + goto error; + } ++ fd_is_own = 1; + } + if (self->fd < 0) { #ifdef MS_WINDOWS if (widename != NULL)