summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-12-27 13:44:33 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-12-27 13:44:33 (GMT)
commit726fc139a5f40d81a0013c856be1283da08de4a0 (patch)
tree7a7fe3b19e13842df5b5d45a8567fbfb5e7bbd75
parentbdb908ea5466bfa09869fd2e1e7f3b17fe0fb2ea (diff)
parent191321d11bc7e064e1a07830a43fa600de310e1b (diff)
downloadcpython-726fc139a5f40d81a0013c856be1283da08de4a0.zip
cpython-726fc139a5f40d81a0013c856be1283da08de4a0.tar.gz
cpython-726fc139a5f40d81a0013c856be1283da08de4a0.tar.bz2
Issue #20440: More use of Py_SETREF.
This patch is manually crafted and contains changes that couldn't be handled automatically.
-rw-r--r--Modules/_ctypes/_ctypes.c3
-rw-r--r--Modules/_elementtree.c34
-rw-r--r--Modules/_sqlite/cursor.c4
-rw-r--r--Modules/zlibmodule.c18
-rw-r--r--Objects/exceptions.c19
-rw-r--r--Objects/unicodeobject.c2
-rw-r--r--Python/ast.c10
-rw-r--r--Python/errors.c13
8 files changed, 40 insertions, 63 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index ac5e5fa..5db9f90 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -2983,10 +2983,9 @@ PyCFuncPtr_set_restype(PyCFuncPtrObject *self, PyObject *ob)
"restype must be a type, a callable, or None");
return -1;
}
- Py_XDECREF(self->checker);
Py_INCREF(ob);
Py_SETREF(self->restype, ob);
- self->checker = PyObject_GetAttrString(ob, "_check_retval_");
+ Py_SETREF(self->checker, PyObject_GetAttrString(ob, "_check_retval_"));
if (self->checker == NULL)
PyErr_Clear();
return 0;
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index f69ce29..f16d48f 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -965,9 +965,8 @@ element_setstate_from_attributes(ElementObject *self,
return NULL;
}
- Py_CLEAR(self->tag);
- self->tag = tag;
- Py_INCREF(self->tag);
+ Py_INCREF(tag);
+ Py_SETREF(self->tag, tag);
_clear_joined_ptr(&self->text);
self->text = text ? JOIN_SET(text, PyList_CheckExact(text)) : Py_None;
@@ -1010,9 +1009,8 @@ element_setstate_from_attributes(ElementObject *self,
/* Stash attrib. */
if (attrib) {
- Py_CLEAR(self->extra->attrib);
- self->extra->attrib = attrib;
Py_INCREF(attrib);
+ Py_SETREF(self->extra->attrib, attrib);
}
Py_RETURN_NONE;
@@ -1961,8 +1959,7 @@ element_tag_setter(ElementObject *self, PyObject *value, void *closure)
{
_VALIDATE_ATTR_VALUE(value);
Py_INCREF(value);
- Py_DECREF(self->tag);
- self->tag = value;
+ Py_SETREF(self->tag, value);
return 0;
}
@@ -1995,8 +1992,7 @@ element_attrib_setter(ElementObject *self, PyObject *value, void *closure)
return -1;
}
Py_INCREF(value);
- Py_DECREF(self->extra->attrib);
- self->extra->attrib = value;
+ Py_SETREF(self->extra->attrib, value);
return 0;
}
@@ -2533,13 +2529,10 @@ treebuilder_handle_start(TreeBuilderObject* self, PyObject* tag,
}
self->index++;
- Py_DECREF(this);
Py_INCREF(node);
- self->this = node;
-
- Py_DECREF(self->last);
+ Py_SETREF(self->this, node);
Py_INCREF(node);
- self->last = node;
+ Py_SETREF(self->last, node);
if (treebuilder_append_event(self, self->start_event_obj, node) < 0)
goto error;
@@ -2612,15 +2605,12 @@ treebuilder_handle_end(TreeBuilderObject* self, PyObject* tag)
return NULL;
}
- self->index--;
-
- item = PyList_GET_ITEM(self->stack, self->index);
- Py_INCREF(item);
-
- Py_DECREF(self->last);
-
+ item = self->last;
self->last = self->this;
- self->this = item;
+ self->index--;
+ self->this = PyList_GET_ITEM(self->stack, self->index);
+ Py_INCREF(self->this);
+ Py_DECREF(item);
if (treebuilder_append_event(self, self->end_event_obj, self->last) < 0)
return NULL;
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index 1c240d6..cdb91ee 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -524,10 +524,10 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
if (self->statement) {
(void)pysqlite_statement_reset(self->statement);
- Py_DECREF(self->statement);
}
- self->statement = (pysqlite_Statement*)pysqlite_cache_get(self->connection->statement_cache, func_args);
+ Py_SETREF(self->statement,
+ (pysqlite_Statement *)pysqlite_cache_get(self->connection->statement_cache, func_args));
Py_DECREF(func_args);
if (!self->statement) {
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index 7d2f55a..ed4439d 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -961,14 +961,11 @@ zlib_Compress_copy_impl(compobject *self)
goto error;
}
Py_INCREF(self->unused_data);
+ Py_SETREF(retval->unused_data, self->unused_data);
Py_INCREF(self->unconsumed_tail);
+ Py_SETREF(retval->unconsumed_tail, self->unconsumed_tail);
Py_XINCREF(self->zdict);
- Py_XDECREF(retval->unused_data);
- Py_XDECREF(retval->unconsumed_tail);
- Py_XDECREF(retval->zdict);
- retval->unused_data = self->unused_data;
- retval->unconsumed_tail = self->unconsumed_tail;
- retval->zdict = self->zdict;
+ Py_SETREF(retval->zdict, self->zdict);
retval->eof = self->eof;
/* Mark it as being initialized */
@@ -1020,14 +1017,11 @@ zlib_Decompress_copy_impl(compobject *self)
}
Py_INCREF(self->unused_data);
+ Py_SETREF(retval->unused_data, self->unused_data);
Py_INCREF(self->unconsumed_tail);
+ Py_SETREF(retval->unconsumed_tail, self->unconsumed_tail);
Py_XINCREF(self->zdict);
- Py_XDECREF(retval->unused_data);
- Py_XDECREF(retval->unconsumed_tail);
- Py_XDECREF(retval->zdict);
- retval->unused_data = self->unused_data;
- retval->unconsumed_tail = self->unconsumed_tail;
- retval->zdict = self->zdict;
+ Py_SETREF(retval->zdict, self->zdict);
retval->eof = self->eof;
/* Mark it as being initialized */
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 351304f..85f9472 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -561,12 +561,14 @@ SystemExit_init(PySystemExitObject *self, PyObject *args, PyObject *kwds)
if (size == 0)
return 0;
- Py_CLEAR(self->code);
- if (size == 1)
- self->code = PyTuple_GET_ITEM(args, 0);
- else /* size > 1 */
- self->code = args;
- Py_INCREF(self->code);
+ if (size == 1) {
+ Py_INCREF(PyTuple_GET_ITEM(args, 0));
+ Py_SETREF(self->code, PyTuple_GET_ITEM(args, 0));
+ }
+ else { /* size > 1 */
+ Py_INCREF(args);
+ Py_SETREF(self->code, args);
+ }
return 0;
}
@@ -625,9 +627,8 @@ ImportError_init(PyImportErrorObject *self, PyObject *args, PyObject *kwds)
#define GET_KWD(kwd) { \
kwd = PyDict_GetItemString(kwds, #kwd); \
if (kwd) { \
- Py_CLEAR(self->kwd); \
- self->kwd = kwd; \
- Py_INCREF(self->kwd);\
+ Py_INCREF(kwd); \
+ Py_SETREF(self->kwd, kwd); \
if (PyDict_DelItemString(kwds, #kwd)) \
return -1; \
} \
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index bda2469..fb79bd9 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -14443,8 +14443,8 @@ unicode_format_arg_parse(struct unicode_formatter_t *ctx,
if (key == NULL)
return -1;
if (ctx->args_owned) {
- Py_DECREF(ctx->args);
ctx->args_owned = 0;
+ Py_DECREF(ctx->args);
}
ctx->args = PyObject_GetItem(ctx->dict, key);
Py_DECREF(key);
diff --git a/Python/ast.c b/Python/ast.c
index 328ee5d..33f2597 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -4496,8 +4496,7 @@ fstring_find_literal_and_expr(PyObject *str, Py_ssize_t *ofs, int recurse_lvl,
return 0;
error:
- Py_XDECREF(*literal);
- *literal = NULL;
+ Py_CLEAR(*literal);
return -1;
}
@@ -4692,11 +4691,8 @@ FstringParser_ConcatAndDel(FstringParser *state, PyObject *str)
state->last_str = str;
} else {
/* Concatenate this with the previous string. */
- PyObject *temp = PyUnicode_Concat(state->last_str, str);
- Py_DECREF(state->last_str);
- Py_DECREF(str);
- state->last_str = temp;
- if (!temp)
+ PyUnicode_AppendAndDel(&state->last_str, str);
+ if (!state->last_str)
return -1;
}
FstringParser_check_invariants(state);
diff --git a/Python/errors.c b/Python/errors.c
index aed2bdc..7b67566 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -315,14 +315,11 @@ finally:
tstate = PyThreadState_GET();
if (++tstate->recursion_depth > Py_GetRecursionLimit()) {
--tstate->recursion_depth;
- /* throw away the old exception... */
- Py_DECREF(*exc);
- Py_DECREF(*val);
- /* ... and use the recursion error instead */
- *exc = PyExc_RecursionError;
- *val = PyExc_RecursionErrorInst;
- Py_INCREF(*exc);
- Py_INCREF(*val);
+ /* throw away the old exception and use the recursion error instead */
+ Py_INCREF(PyExc_RecursionError);
+ Py_SETREF(*exc, PyExc_RecursionError);
+ Py_INCREF(PyExc_RecursionErrorInst);
+ Py_SETREF(*val, PyExc_RecursionErrorInst);
/* just keeping the old traceback */
return;
}