Core and Builtins
-----------------
+- Issue #20437: Fixed 21 potential bugs when deleting objects references.
+
- Issue #20538: UTF-7 incremental decoder produced inconsistant string when
input was truncated in BASE64 section.
if (-1 == PyDict_DelItem(self->dict, self->key))
/* XXX Error context */
PyErr_WriteUnraisable(Py_None);
- Py_DECREF(self->key);
- self->key = NULL;
- Py_DECREF(self->dict);
- self->dict = NULL;
+ Py_CLEAR(self->key);
+ Py_CLEAR(self->dict);
}
Py_INCREF(Py_None);
return Py_None;
PyCFuncPtr_set_restype(PyCFuncPtrObject *self, PyObject *ob)
{
if (ob == NULL) {
- Py_XDECREF(self->restype);
- self->restype = NULL;
- Py_XDECREF(self->checker);
- self->checker = NULL;
+ Py_CLEAR(self->restype);
+ Py_CLEAR(self->checker);
return 0;
}
if (ob != Py_None && !PyType_stgdict(ob) && !PyCallable_Check(ob)) {
PyObject *converters;
if (ob == NULL || ob == Py_None) {
- Py_XDECREF(self->converters);
- self->converters = NULL;
- Py_XDECREF(self->argtypes);
- self->argtypes = NULL;
+ Py_CLEAR(self->converters);
+ Py_CLEAR(self->argtypes);
} else {
converters = converters_from_argtypes(ob);
if (!converters)
if (converter != Py_None) {
Py_DECREF(converter);
}
- Py_XDECREF(self->row_cast_map);
- self->row_cast_map = NULL;
+ Py_CLEAR(self->row_cast_map);
return -1;
}
self->locked = 1;
self->reset = 0;
- Py_XDECREF(self->next_row);
- self->next_row = NULL;
+ Py_CLEAR(self->next_row);
if (multiple) {
/* executemany() */
if (!self->next_row) {
if (self->statement) {
(void)pysqlite_statement_reset(self->statement);
- Py_DECREF(self->statement);
- self->statement = NULL;
+ Py_CLEAR(self->statement);
}
return NULL;
}
static void
path_cleanup(path_t *path) {
if (path->cleanup) {
- Py_DECREF(path->cleanup);
- path->cleanup = NULL;
+ Py_CLEAR(path->cleanup);
}
}
}
else {
if (trace_frame(tstate, f, PyTrace_RETURN, res) < 0) {
- Py_XDECREF(res);
- res = NULL;
+ Py_CLEAR(res);
}
}
#else
if (!PyArg_ParseTuple(args, buf, &function))
return NULL;
if (function == Py_None) {
- Py_XDECREF(*hook_var);
- *hook_var = NULL;
+ Py_CLEAR(*hook_var);
}
else if (PyCallable_Check(function)) {
PyObject *tmp = *hook_var;
(r != Py_None && PyLong_AsLong(r) == -1 && PyErr_Occurred())) {
goto error;
}
- Py_XDECREF(r); r=NULL;
+ Py_CLEAR(r);
if (0) {
error:
{
int i;
for (i = 0; i < FD_SETSIZE + 1 && fd2obj[i].sentinel >= 0; i++) {
- Py_XDECREF(fd2obj[i].obj);
- fd2obj[i].obj = NULL;
+ Py_CLEAR(fd2obj[i].obj);
}
fd2obj[0].sentinel = -1;
}
Py_XDECREF(func);
}
- Py_XDECREF(IntHandler);
- IntHandler = NULL;
- Py_XDECREF(DefaultHandler);
- DefaultHandler = NULL;
- Py_XDECREF(IgnoreHandler);
- IgnoreHandler = NULL;
+ Py_CLEAR(IntHandler);
+ Py_CLEAR(DefaultHandler);
+ Py_CLEAR(IgnoreHandler);
}
{
if (S_log_open) {
closelog();
- Py_XDECREF(S_ident_o);
- S_ident_o = NULL;
+ Py_CLEAR(S_ident_o);
S_log_open = 0;
}
Py_INCREF(Py_None);
}
error:
- Py_XDECREF(self);
- self = NULL;
+ Py_CLEAR(self);
success:
if (zdict.buf != NULL)
PyBuffer_Release(&zdict);
PyFrame_Fini(void)
{
(void)PyFrame_ClearFreeList();
- Py_XDECREF(builtin_object);
- builtin_object = NULL;
+ Py_CLEAR(builtin_object);
}
/* Print summary info about the state of the optimized allocator */
_Py_ForgetReference((PyObject *) v);
/* DECREF items deleted by shrinkage */
for (i = newsize; i < oldsize; i++) {
- Py_XDECREF(v->ob_item[i]);
- v->ob_item[i] = NULL;
+ Py_CLEAR(v->ob_item[i]);
}
sv = PyObject_GC_Resize(PyTupleObject, v, newsize);
if (sv == NULL) {
#if PyTuple_MAXSAVESIZE > 0
/* empty tuples are used all over the place and applications may
* rely on the fact that an empty tuple is a singleton. */
- Py_XDECREF(free_list[0]);
- free_list[0] = NULL;
+ Py_CLEAR(free_list[0]);
(void)PyTuple_ClearFreeList();
#endif
{
_Py_Identifier *tmp, *s = static_strings;
while (s) {
- Py_DECREF(s->object);
- s->object = NULL;
+ Py_CLEAR(s->object);
tmp = s->next;
s->next = NULL;
s = tmp;
return;
onError:
- Py_DECREF(*exceptionObject);
- *exceptionObject = NULL;
+ Py_CLEAR(*exceptionObject);
}
/* error handling callback helper:
goto onError;
return;
onError:
- Py_DECREF(*exceptionObject);
- *exceptionObject = NULL;
+ Py_CLEAR(*exceptionObject);
}
}
goto onError;
return;
onError:
- Py_DECREF(*exceptionObject);
- *exceptionObject = NULL;
+ Py_CLEAR(*exceptionObject);
}
}
if (call_trace(tstate->c_tracefunc,
tstate->c_traceobj, f,
PyTrace_RETURN, retval)) {
- Py_XDECREF(retval);
- retval = NULL;
+ Py_CLEAR(retval);
why = WHY_EXCEPTION;
}
}
else if (call_trace(tstate->c_profilefunc,
tstate->c_profileobj, f,
PyTrace_RETURN, retval)) {
- Py_XDECREF(retval);
- retval = NULL;
+ Py_CLEAR(retval);
/* why = WHY_EXCEPTION; */
}
}
if (co->co_flags & CO_GENERATOR) {
/* Don't need to keep the reference to f_back, it will be set
* when the generator is resumed. */
- Py_XDECREF(f->f_back);
- f->f_back = NULL;
+ Py_CLEAR(f->f_back);
PCALL(PCALL_GENERATOR);
void
_PyImport_Fini(void)
{
- Py_XDECREF(extensions);
- extensions = NULL;
+ Py_CLEAR(extensions);
#ifdef WITH_THREAD
if (import_lock != NULL) {
PyThread_free_lock(import_lock);
/* Somebody already imported the module,
likely under a different name.
XXX this should really not happen. */
- Py_DECREF(def->m_base.m_copy);
- def->m_base.m_copy = NULL;
+ Py_CLEAR(def->m_base.m_copy);
}
dict = PyModule_GetDict(mod);
if (dict == NULL)
result = call_trampoline(tstate, callback, frame, what, arg);
if (result == NULL) {
PyEval_SetTrace(NULL, NULL);
- Py_XDECREF(frame->f_trace);
- frame->f_trace = NULL;
+ Py_CLEAR(frame->f_trace);
return -1;
}
if (result != Py_None) {