From: Antoine Pitrou Date: Wed, 18 Jan 2012 15:19:19 +0000 (+0100) Subject: Merge refleak fixes from 3.2 X-Git-Tag: v3.3.0a1~354 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bb5b92d324c06e586dfaef1c980e3de2e94e86ae;p=thirdparty%2FPython%2Fcpython.git Merge refleak fixes from 3.2 --- bb5b92d324c06e586dfaef1c980e3de2e94e86ae diff --cc Modules/_io/_iomodule.c index f9bca1ab73d8,61362c73b2a8..e04691703cb5 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@@ -677,60 -741,46 +677,47 @@@ PyInit__io(void ADD_TYPE(&PyIncrementalNewlineDecoder_Type, "IncrementalNewlineDecoder"); /* Interned strings */ - if (!(_PyIO_str_close = PyUnicode_InternFromString("close"))) - goto fail; - if (!(_PyIO_str_closed = PyUnicode_InternFromString("closed"))) - goto fail; - if (!(_PyIO_str_decode = PyUnicode_InternFromString("decode"))) - goto fail; - if (!(_PyIO_str_encode = PyUnicode_InternFromString("encode"))) - goto fail; - if (!(_PyIO_str_fileno = PyUnicode_InternFromString("fileno"))) - goto fail; - if (!(_PyIO_str_flush = PyUnicode_InternFromString("flush"))) - goto fail; - if (!(_PyIO_str_getstate = PyUnicode_InternFromString("getstate"))) - goto fail; - if (!(_PyIO_str_isatty = PyUnicode_InternFromString("isatty"))) - goto fail; - if (!(_PyIO_str_newlines = PyUnicode_InternFromString("newlines"))) - goto fail; - if (!(_PyIO_str_nl = PyUnicode_InternFromString("\n"))) - goto fail; - if (!(_PyIO_str_read = PyUnicode_InternFromString("read"))) - goto fail; - if (!(_PyIO_str_read1 = PyUnicode_InternFromString("read1"))) - goto fail; - if (!(_PyIO_str_readable = PyUnicode_InternFromString("readable"))) - goto fail; - if (!(_PyIO_str_readall = PyUnicode_InternFromString("readall"))) - goto fail; - if (!(_PyIO_str_readinto = PyUnicode_InternFromString("readinto"))) - goto fail; - if (!(_PyIO_str_readline = PyUnicode_InternFromString("readline"))) - goto fail; - if (!(_PyIO_str_reset = PyUnicode_InternFromString("reset"))) - goto fail; - if (!(_PyIO_str_seek = PyUnicode_InternFromString("seek"))) - goto fail; - if (!(_PyIO_str_seekable = PyUnicode_InternFromString("seekable"))) - goto fail; - if (!(_PyIO_str_setstate = PyUnicode_InternFromString("setstate"))) - goto fail; - if (!(_PyIO_str_tell = PyUnicode_InternFromString("tell"))) - goto fail; - if (!(_PyIO_str_truncate = PyUnicode_InternFromString("truncate"))) - goto fail; - if (!(_PyIO_str_write = PyUnicode_InternFromString("write"))) - goto fail; - if (!(_PyIO_str_writable = PyUnicode_InternFromString("writable"))) - goto fail; - - if (!(_PyIO_empty_str = PyUnicode_FromStringAndSize(NULL, 0))) - goto fail; - if (!(_PyIO_empty_bytes = PyBytes_FromStringAndSize(NULL, 0))) - goto fail; - if (!(_PyIO_zero = PyLong_FromLong(0L))) + #define ADD_INTERNED(name) \ + if (!_PyIO_str_ ## name && \ + !(_PyIO_str_ ## name = PyUnicode_InternFromString(# name))) \ + goto fail; + + ADD_INTERNED(close) + ADD_INTERNED(closed) + ADD_INTERNED(decode) + ADD_INTERNED(encode) + ADD_INTERNED(fileno) + ADD_INTERNED(flush) + ADD_INTERNED(getstate) + ADD_INTERNED(isatty) + ADD_INTERNED(newlines) + ADD_INTERNED(read) + ADD_INTERNED(read1) + ADD_INTERNED(readable) ++ ADD_INTERNED(readall) + ADD_INTERNED(readinto) + ADD_INTERNED(readline) + ADD_INTERNED(reset) + ADD_INTERNED(seek) + ADD_INTERNED(seekable) + ADD_INTERNED(setstate) + ADD_INTERNED(tell) + ADD_INTERNED(truncate) + ADD_INTERNED(write) + ADD_INTERNED(writable) + + if (!_PyIO_str_nl && + !(_PyIO_str_nl = PyUnicode_InternFromString("\n"))) + goto fail; + + if (!_PyIO_empty_str && + !(_PyIO_empty_str = PyUnicode_FromStringAndSize(NULL, 0))) + goto fail; + if (!_PyIO_empty_bytes && + !(_PyIO_empty_bytes = PyBytes_FromStringAndSize(NULL, 0))) + goto fail; + if (!_PyIO_zero && + !(_PyIO_zero = PyLong_FromLong(0L))) goto fail; state->initialized = 1; diff --cc Objects/exceptions.c index a529a3cd1114,fc41853d2657..2eb1aab099d6 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@@ -2394,70 -2091,31 +2394,72 @@@ _PyExc_Init(void POST_INIT(BytesWarning) POST_INIT(ResourceWarning) + errnomap = PyDict_New(); + if (!errnomap) + Py_FatalError("Cannot allocate map from errnos to OSError subclasses"); + + /* OSError subclasses */ + POST_INIT(ConnectionError); + + POST_INIT(BlockingIOError); + ADD_ERRNO(BlockingIOError, EAGAIN); + ADD_ERRNO(BlockingIOError, EALREADY); + ADD_ERRNO(BlockingIOError, EINPROGRESS); + ADD_ERRNO(BlockingIOError, EWOULDBLOCK); + POST_INIT(BrokenPipeError); + ADD_ERRNO(BrokenPipeError, EPIPE); + ADD_ERRNO(BrokenPipeError, ESHUTDOWN); + POST_INIT(ChildProcessError); + ADD_ERRNO(ChildProcessError, ECHILD); + POST_INIT(ConnectionAbortedError); + ADD_ERRNO(ConnectionAbortedError, ECONNABORTED); + POST_INIT(ConnectionRefusedError); + ADD_ERRNO(ConnectionRefusedError, ECONNREFUSED); + POST_INIT(ConnectionResetError); + ADD_ERRNO(ConnectionResetError, ECONNRESET); + POST_INIT(FileExistsError); + ADD_ERRNO(FileExistsError, EEXIST); + POST_INIT(FileNotFoundError); + ADD_ERRNO(FileNotFoundError, ENOENT); + POST_INIT(IsADirectoryError); + ADD_ERRNO(IsADirectoryError, EISDIR); + POST_INIT(NotADirectoryError); + ADD_ERRNO(NotADirectoryError, ENOTDIR); + POST_INIT(InterruptedError); + ADD_ERRNO(InterruptedError, EINTR); + POST_INIT(PermissionError); + ADD_ERRNO(PermissionError, EACCES); + ADD_ERRNO(PermissionError, EPERM); + POST_INIT(ProcessLookupError); + ADD_ERRNO(ProcessLookupError, ESRCH); + POST_INIT(TimeoutError); + ADD_ERRNO(TimeoutError, ETIMEDOUT); + preallocate_memerrors(); - PyExc_RecursionErrorInst = BaseException_new(&_PyExc_RuntimeError, NULL, NULL); - if (!PyExc_RecursionErrorInst) - Py_FatalError("Cannot pre-allocate RuntimeError instance for " - "recursion errors"); - else { - PyBaseExceptionObject *err_inst = - (PyBaseExceptionObject *)PyExc_RecursionErrorInst; - PyObject *args_tuple; - PyObject *exc_message; - exc_message = PyUnicode_FromString("maximum recursion depth exceeded"); - if (!exc_message) - Py_FatalError("cannot allocate argument for RuntimeError " - "pre-allocation"); - args_tuple = PyTuple_Pack(1, exc_message); - if (!args_tuple) - Py_FatalError("cannot allocate tuple for RuntimeError " - "pre-allocation"); - Py_DECREF(exc_message); - if (BaseException_init(err_inst, args_tuple, NULL)) - Py_FatalError("init of pre-allocated RuntimeError failed"); - Py_DECREF(args_tuple); + if (!PyExc_RecursionErrorInst) { + PyExc_RecursionErrorInst = BaseException_new(&_PyExc_RuntimeError, NULL, NULL); + if (!PyExc_RecursionErrorInst) + Py_FatalError("Cannot pre-allocate RuntimeError instance for " + "recursion errors"); + else { + PyBaseExceptionObject *err_inst = + (PyBaseExceptionObject *)PyExc_RecursionErrorInst; + PyObject *args_tuple; + PyObject *exc_message; + exc_message = PyUnicode_FromString("maximum recursion depth exceeded"); + if (!exc_message) + Py_FatalError("cannot allocate argument for RuntimeError " + "pre-allocation"); + args_tuple = PyTuple_Pack(1, exc_message); + if (!args_tuple) + Py_FatalError("cannot allocate tuple for RuntimeError " + "pre-allocation"); + Py_DECREF(exc_message); + if (BaseException_init(err_inst, args_tuple, NULL)) + Py_FatalError("init of pre-allocated RuntimeError failed"); + Py_DECREF(args_tuple); + } } Py_DECREF(bltinmod);