Replace "Py_DECREF(var); var = NULL;" with "Py_SETREF(var, NULL);".
switch (PyObject_IsTrue(result)) {
case -1:
- Py_DECREF(result);
- result = NULL;
+ Py_SETREF(result, NULL);
break;
case 0:
Py_DECREF(result);
PyErr_Format(PyExc_TypeError, "tzinfo.tzname() must "
"return None or a string, not '%s'",
Py_TYPE(result)->tp_name);
- Py_DECREF(result);
- result = NULL;
+ Py_SETREF(result, NULL);
}
return result;
x2 = PyNumber_Multiply(x1, seconds_per_day); /* days in seconds */
if (x2 == NULL)
goto Done;
- Py_DECREF(x1);
- x1 = NULL;
+ Py_SETREF(x1, NULL);
/* x2 has days in seconds */
x1 = PyLong_FromLong(GET_TD_SECONDS(self)); /* seconds */
x1 = PyNumber_Multiply(x3, us_per_second); /* us */
if (x1 == NULL)
goto Done;
- Py_DECREF(x3);
- x3 = NULL;
+ Py_SETREF(x3, NULL);
/* x1 has days+seconds in us */
x2 = PyLong_FromLong(GET_TD_MICROSECONDS(self));
goto error;
}
temp = PyNumber_Multiply(pyus_in, PyTuple_GET_ITEM(ratio, op));
- Py_DECREF(pyus_in);
- pyus_in = NULL;
+ Py_SETREF(pyus_in, NULL);
if (temp == NULL)
goto error;
pyus_out = divide_nearest(temp, PyTuple_GET_ITEM(ratio, !op));
}
attrib = PyDict_Copy(attrib);
if (attrib && PyDict_DelItem(kwds, attrib_str) < 0) {
- Py_DECREF(attrib);
- attrib = NULL;
+ Py_SETREF(attrib, NULL);
}
}
else if (!PyErr_Occurred()) {
goto error;
result = raw;
- Py_DECREF(path_or_fd);
- path_or_fd = NULL;
+ Py_SETREF(path_or_fd, NULL);
modeobj = PyUnicode_FromString(mode);
if (modeobj == NULL)
if (reduce_value != Py_NotImplemented) {
goto reduce;
}
- Py_DECREF(reduce_value);
- reduce_value = NULL;
+ Py_SETREF(reduce_value, NULL);
}
if (type == &PyType_Type) {
if (v == NULL) goto error;
r = PyDict_SetItemString(result, "exclude_simple", v);
- Py_DECREF(v); v = NULL;
+ Py_SETREF(v, NULL);
if (r == -1) goto error;
anArray = CFDictionaryGetValue(proxyDict,
_structmodulestate *state = get_struct_state(module);
if (fmt == NULL) {
- Py_DECREF(*ptr);
- *ptr = NULL;
+ Py_SETREF(*ptr, NULL);
return 1;
}
for (i = 0; i < argc; i++) {
PyObject *s = unicodeFromTclString(argv[i]);
if (!s) {
- Py_DECREF(v);
- v = NULL;
+ Py_SETREF(v, NULL);
goto finally;
}
PyTuple_SET_ITEM(v, i, s);
PyObject *id = (PyObject *)newchannelid(&ChannelIDtype, *cur, 0,
&_globals.channels, 0, 0);
if (id == NULL) {
- Py_DECREF(ids);
- ids = NULL;
+ Py_SETREF(ids, NULL);
break;
}
PyList_SET_ITEM(ids, (Py_ssize_t)i, id);
}
PyObject *rv = PyObject_CallMethod(file_obj, "close", NULL);
- Py_DECREF(file_obj);
- file_obj = NULL;
+ Py_SETREF(file_obj, NULL);
if (rv == NULL) {
goto error;
}
goto errorexit;
}
- Py_DECREF(cres);
- cres = NULL;
+ Py_SETREF(cres, NULL);
if (sizehint < 0 || buf.writer.pos != 0 || rsize == 0)
break;
long i_result = PyLong_AsLongAndOverflow(result, &overflow);
/* If this already overflowed, don't even enter the loop. */
if (overflow == 0) {
- Py_DECREF(result);
- result = NULL;
+ Py_SETREF(result, NULL);
}
/* Loop over all the items in the iterable until we finish, we overflow
* or we found a non integer element */
*/
if (PyFloat_CheckExact(result)) {
double f_result = PyFloat_AS_DOUBLE(result);
- Py_DECREF(result);
- result = NULL;
+ Py_SETREF(result, NULL);
while(result == NULL) {
item = PyIter_Next(iter);
if (item == NULL) {
if (item == NULL) {
/* error, or end-of-sequence */
if (PyErr_Occurred()) {
- Py_DECREF(result);
- result = NULL;
+ Py_SETREF(result, NULL);
}
break;
}
if (!str || PyList_Append(list, str) < 0)
{
Py_XDECREF(str);
- Py_DECREF(list);
- list = NULL;
+ Py_SETREF(list, NULL);
break;
}
Py_DECREF(str);
Py_SETREF(v, PyUnicode_EncodeFSDefault(v));
}
if (v == NULL) {
- Py_DECREF(list);
- list = NULL;
+ Py_SETREF(list, NULL);
break;
}
if (PyList_Append(list, v) != 0) {
Py_DECREF(v);
- Py_DECREF(list);
- list = NULL;
+ Py_SETREF(list, NULL);
break;
}
Py_DECREF(v);
PyObject *attribute = PyUnicode_DecodeFSDefaultAndSize(start,
trace - start);
if (!attribute) {
- Py_DECREF(result);
- result = NULL;
+ Py_SETREF(result, NULL);
goto exit;
}
error = PyList_Append(result, attribute);
Py_DECREF(attribute);
if (error) {
- Py_DECREF(result);
- result = NULL;
+ Py_SETREF(result, NULL);
goto exit;
}
start = trace + 1;
PyErr_Format(PyExc_TypeError,
"__format__ must return a str, not %.200s",
Py_TYPE(result)->tp_name);
- Py_DECREF(result);
- result = NULL;
+ Py_SETREF(result, NULL);
goto done;
}
"iter() returned non-iterator "
"of type '%.100s'",
Py_TYPE(res)->tp_name);
- Py_DECREF(res);
- res = NULL;
+ Py_SETREF(res, NULL);
}
return res;
}
PyErr_Format(PyExc_TypeError,
"aiter() returned not an async iterator of type '%.100s'",
Py_TYPE(it)->tp_name);
- Py_DECREF(it);
- it = NULL;
+ Py_SETREF(it, NULL);
}
return it;
}
}
if (funcname != NULL && !PyUnicode_Check(funcname)) {
- Py_DECREF(funcname);
- funcname = NULL;
+ Py_SETREF(funcname, NULL);
}
/* XXX Shouldn't use repr()/%R here! */
return NULL;
}
if (funcname != NULL && !PyUnicode_Check(funcname)) {
- Py_DECREF(funcname);
- funcname = NULL;
+ Py_SETREF(funcname, NULL);
}
result = PyUnicode_FromFormat("<instancemethod %V at %p>",
descr->d_type = (PyTypeObject*)Py_XNewRef(type);
descr->d_name = PyUnicode_InternFromString(name);
if (descr->d_name == NULL) {
- Py_DECREF(descr);
- descr = NULL;
+ Py_SETREF(descr, NULL);
}
else {
descr->d_qualname = NULL;
}
if (result != NULL && !PyBytes_Check(result) &&
!PyUnicode_Check(result)) {
- Py_DECREF(result);
- result = NULL;
+ Py_SETREF(result, NULL);
PyErr_SetString(PyExc_TypeError,
"object.readline() returned non-string");
}
const char *s = PyBytes_AS_STRING(result);
Py_ssize_t len = PyBytes_GET_SIZE(result);
if (len == 0) {
- Py_DECREF(result);
- result = NULL;
+ Py_SETREF(result, NULL);
PyErr_SetString(PyExc_EOFError,
"EOF when reading a line");
}
if (n < 0 && result != NULL && PyUnicode_Check(result)) {
Py_ssize_t len = PyUnicode_GET_LENGTH(result);
if (len == 0) {
- Py_DECREF(result);
- result = NULL;
+ Py_SETREF(result, NULL);
PyErr_SetString(PyExc_EOFError,
"EOF when reading a line");
}
if (mod == NULL)
PyErr_Clear();
else if (!PyUnicode_Check(mod)) {
- Py_DECREF(mod);
- mod = NULL;
+ Py_SETREF(mod, NULL);
}
name = type_qualname(type, NULL);
if (name == NULL) {
int res = type->tp_init(obj, args, kwds);
if (res < 0) {
assert(_PyErr_Occurred(tstate));
- Py_DECREF(obj);
- obj = NULL;
+ Py_SETREF(obj, NULL);
}
else {
assert(!_PyErr_Occurred(tstate));
if (mod == NULL)
PyErr_Clear();
else if (!PyUnicode_Check(mod)) {
- Py_DECREF(mod);
- mod = NULL;
+ Py_SETREF(mod, NULL);
}
name = type_qualname(type, NULL);
if (name == NULL) {
func = lookup_maybe_method(self, &_Py_ID(__hash__), &unbound);
if (func == Py_None) {
- Py_DECREF(func);
- func = NULL;
+ Py_SETREF(func, NULL);
}
if (func == NULL) {
"__class__ set to %.200R defining %.200R as %.200R";
PyErr_Format(PyExc_TypeError, msg, cell_cls, name, cls);
}
- Py_DECREF(cls);
- cls = NULL;
+ Py_SETREF(cls, NULL);
goto error;
}
}
long i_result = PyLong_AsLongAndOverflow(result, &overflow);
/* If this already overflowed, don't even enter the loop. */
if (overflow == 0) {
- Py_DECREF(result);
- result = NULL;
+ Py_SETREF(result, NULL);
}
while(result == NULL) {
item = PyIter_Next(iter);
if (PyFloat_CheckExact(result)) {
double f_result = PyFloat_AS_DOUBLE(result);
- Py_DECREF(result);
- result = NULL;
+ Py_SETREF(result, NULL);
while(result == NULL) {
item = PyIter_Next(iter);
if (item == NULL) {
if (item == NULL) {
/* error, or end-of-sequence */
if (PyErr_Occurred()) {
- Py_DECREF(result);
- result = NULL;
+ Py_SETREF(result, NULL);
}
break;
}
if (traceback != NULL && !PyTraceBack_Check(traceback)) {
/* XXX Should never happen -- fatal error instead? */
/* Well, it could be None. */
- Py_DECREF(traceback);
- traceback = NULL;
+ Py_SETREF(traceback, NULL);
}
/* Save these in locals to safeguard against recursive
if (!PyErr_Occurred())
PyErr_SetString(PyExc_TypeError,
"NULL object in marshal data for tuple");
- Py_DECREF(v);
- v = NULL;
+ Py_SETREF(v, NULL);
break;
}
PyTuple_SET_ITEM(v, i, v2);
if (!PyErr_Occurred())
PyErr_SetString(PyExc_TypeError,
"NULL object in marshal data for list");
- Py_DECREF(v);
- v = NULL;
+ Py_SETREF(v, NULL);
break;
}
PyList_SET_ITEM(v, i, v2);
Py_DECREF(val);
}
if (PyErr_Occurred()) {
- Py_DECREF(v);
- v = NULL;
+ Py_SETREF(v, NULL);
}
retval = v;
break;
if (!PyErr_Occurred())
PyErr_SetString(PyExc_TypeError,
"NULL object in marshal data for set");
- Py_DECREF(v);
- v = NULL;
+ Py_SETREF(v, NULL);
break;
}
if (PySet_Add(v, v2) == -1) {