Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bb5b92d

Browse files
committed
Merge refleak fixes from 3.2
2 parents fff47ab + fc1b6f0 commit bb5b92d

2 files changed

Lines changed: 64 additions & 75 deletions

File tree

Modules/_io/_iomodule.c

Lines changed: 41 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -677,60 +677,47 @@ PyInit__io(void)
677677
ADD_TYPE(&PyIncrementalNewlineDecoder_Type, "IncrementalNewlineDecoder");
678678

679679
/* Interned strings */
680-
if (!(_PyIO_str_close = PyUnicode_InternFromString("close")))
681-
goto fail;
682-
if (!(_PyIO_str_closed = PyUnicode_InternFromString("closed")))
683-
goto fail;
684-
if (!(_PyIO_str_decode = PyUnicode_InternFromString("decode")))
685-
goto fail;
686-
if (!(_PyIO_str_encode = PyUnicode_InternFromString("encode")))
687-
goto fail;
688-
if (!(_PyIO_str_fileno = PyUnicode_InternFromString("fileno")))
689-
goto fail;
690-
if (!(_PyIO_str_flush = PyUnicode_InternFromString("flush")))
691-
goto fail;
692-
if (!(_PyIO_str_getstate = PyUnicode_InternFromString("getstate")))
693-
goto fail;
694-
if (!(_PyIO_str_isatty = PyUnicode_InternFromString("isatty")))
695-
goto fail;
696-
if (!(_PyIO_str_newlines = PyUnicode_InternFromString("newlines")))
697-
goto fail;
698-
if (!(_PyIO_str_nl = PyUnicode_InternFromString("\n")))
699-
goto fail;
700-
if (!(_PyIO_str_read = PyUnicode_InternFromString("read")))
701-
goto fail;
702-
if (!(_PyIO_str_read1 = PyUnicode_InternFromString("read1")))
703-
goto fail;
704-
if (!(_PyIO_str_readable = PyUnicode_InternFromString("readable")))
705-
goto fail;
706-
if (!(_PyIO_str_readall = PyUnicode_InternFromString("readall")))
707-
goto fail;
708-
if (!(_PyIO_str_readinto = PyUnicode_InternFromString("readinto")))
709-
goto fail;
710-
if (!(_PyIO_str_readline = PyUnicode_InternFromString("readline")))
711-
goto fail;
712-
if (!(_PyIO_str_reset = PyUnicode_InternFromString("reset")))
713-
goto fail;
714-
if (!(_PyIO_str_seek = PyUnicode_InternFromString("seek")))
715-
goto fail;
716-
if (!(_PyIO_str_seekable = PyUnicode_InternFromString("seekable")))
717-
goto fail;
718-
if (!(_PyIO_str_setstate = PyUnicode_InternFromString("setstate")))
719-
goto fail;
720-
if (!(_PyIO_str_tell = PyUnicode_InternFromString("tell")))
721-
goto fail;
722-
if (!(_PyIO_str_truncate = PyUnicode_InternFromString("truncate")))
723-
goto fail;
724-
if (!(_PyIO_str_write = PyUnicode_InternFromString("write")))
725-
goto fail;
726-
if (!(_PyIO_str_writable = PyUnicode_InternFromString("writable")))
727-
goto fail;
728-
729-
if (!(_PyIO_empty_str = PyUnicode_FromStringAndSize(NULL, 0)))
730-
goto fail;
731-
if (!(_PyIO_empty_bytes = PyBytes_FromStringAndSize(NULL, 0)))
732-
goto fail;
733-
if (!(_PyIO_zero = PyLong_FromLong(0L)))
680+
#define ADD_INTERNED(name) \
681+
if (!_PyIO_str_ ## name && \
682+
!(_PyIO_str_ ## name = PyUnicode_InternFromString(# name))) \
683+
goto fail;
684+
685+
ADD_INTERNED(close)
686+
ADD_INTERNED(closed)
687+
ADD_INTERNED(decode)
688+
ADD_INTERNED(encode)
689+
ADD_INTERNED(fileno)
690+
ADD_INTERNED(flush)
691+
ADD_INTERNED(getstate)
692+
ADD_INTERNED(isatty)
693+
ADD_INTERNED(newlines)
694+
ADD_INTERNED(read)
695+
ADD_INTERNED(read1)
696+
ADD_INTERNED(readable)
697+
ADD_INTERNED(readall)
698+
ADD_INTERNED(readinto)
699+
ADD_INTERNED(readline)
700+
ADD_INTERNED(reset)
701+
ADD_INTERNED(seek)
702+
ADD_INTERNED(seekable)
703+
ADD_INTERNED(setstate)
704+
ADD_INTERNED(tell)
705+
ADD_INTERNED(truncate)
706+
ADD_INTERNED(write)
707+
ADD_INTERNED(writable)
708+
709+
if (!_PyIO_str_nl &&
710+
!(_PyIO_str_nl = PyUnicode_InternFromString("\n")))
711+
goto fail;
712+
713+
if (!_PyIO_empty_str &&
714+
!(_PyIO_empty_str = PyUnicode_FromStringAndSize(NULL, 0)))
715+
goto fail;
716+
if (!_PyIO_empty_bytes &&
717+
!(_PyIO_empty_bytes = PyBytes_FromStringAndSize(NULL, 0)))
718+
goto fail;
719+
if (!_PyIO_zero &&
720+
!(_PyIO_zero = PyLong_FromLong(0L)))
734721
goto fail;
735722

736723
state->initialized = 1;

Objects/exceptions.c

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2437,27 +2437,29 @@ _PyExc_Init(void)
24372437

24382438
preallocate_memerrors();
24392439

2440-
PyExc_RecursionErrorInst = BaseException_new(&_PyExc_RuntimeError, NULL, NULL);
2441-
if (!PyExc_RecursionErrorInst)
2442-
Py_FatalError("Cannot pre-allocate RuntimeError instance for "
2443-
"recursion errors");
2444-
else {
2445-
PyBaseExceptionObject *err_inst =
2446-
(PyBaseExceptionObject *)PyExc_RecursionErrorInst;
2447-
PyObject *args_tuple;
2448-
PyObject *exc_message;
2449-
exc_message = PyUnicode_FromString("maximum recursion depth exceeded");
2450-
if (!exc_message)
2451-
Py_FatalError("cannot allocate argument for RuntimeError "
2452-
"pre-allocation");
2453-
args_tuple = PyTuple_Pack(1, exc_message);
2454-
if (!args_tuple)
2455-
Py_FatalError("cannot allocate tuple for RuntimeError "
2456-
"pre-allocation");
2457-
Py_DECREF(exc_message);
2458-
if (BaseException_init(err_inst, args_tuple, NULL))
2459-
Py_FatalError("init of pre-allocated RuntimeError failed");
2460-
Py_DECREF(args_tuple);
2440+
if (!PyExc_RecursionErrorInst) {
2441+
PyExc_RecursionErrorInst = BaseException_new(&_PyExc_RuntimeError, NULL, NULL);
2442+
if (!PyExc_RecursionErrorInst)
2443+
Py_FatalError("Cannot pre-allocate RuntimeError instance for "
2444+
"recursion errors");
2445+
else {
2446+
PyBaseExceptionObject *err_inst =
2447+
(PyBaseExceptionObject *)PyExc_RecursionErrorInst;
2448+
PyObject *args_tuple;
2449+
PyObject *exc_message;
2450+
exc_message = PyUnicode_FromString("maximum recursion depth exceeded");
2451+
if (!exc_message)
2452+
Py_FatalError("cannot allocate argument for RuntimeError "
2453+
"pre-allocation");
2454+
args_tuple = PyTuple_Pack(1, exc_message);
2455+
if (!args_tuple)
2456+
Py_FatalError("cannot allocate tuple for RuntimeError "
2457+
"pre-allocation");
2458+
Py_DECREF(exc_message);
2459+
if (BaseException_init(err_inst, args_tuple, NULL))
2460+
Py_FatalError("init of pre-allocated RuntimeError failed");
2461+
Py_DECREF(args_tuple);
2462+
}
24612463
}
24622464

24632465
Py_DECREF(bltinmod);

0 commit comments

Comments
 (0)