mirror of
https://github.com/python/cpython.git
synced 2025-08-01 23:53:15 +00:00
Issue #20440: Cleaning up the code by using Py_SETREF.
This commit is contained in:
parent
dcf76c9d0a
commit
576f132b98
14 changed files with 39 additions and 120 deletions
|
@ -1057,10 +1057,8 @@ format_utcoffset(char *buf, size_t buflen, const char *sep,
|
|||
}
|
||||
/* Offset is normalized, so it is negative if days < 0 */
|
||||
if (GET_TD_DAYS(offset) < 0) {
|
||||
PyObject *temp = offset;
|
||||
sign = '-';
|
||||
offset = delta_negative((PyDateTime_Delta *)offset);
|
||||
Py_DECREF(temp);
|
||||
Py_SETREF(offset, delta_negative((PyDateTime_Delta *)offset));
|
||||
if (offset == NULL)
|
||||
return -1;
|
||||
}
|
||||
|
@ -3047,10 +3045,8 @@ tzinfo_fromutc(PyDateTime_TZInfo *self, PyObject *dt)
|
|||
if (dst == Py_None)
|
||||
goto Inconsistent;
|
||||
if (delta_bool((PyDateTime_Delta *)dst) != 0) {
|
||||
PyObject *temp = result;
|
||||
result = add_datetime_timedelta((PyDateTime_DateTime *)result,
|
||||
(PyDateTime_Delta *)dst, 1);
|
||||
Py_DECREF(temp);
|
||||
Py_SETREF(result, add_datetime_timedelta((PyDateTime_DateTime *)result,
|
||||
(PyDateTime_Delta *)dst, 1));
|
||||
if (result == NULL)
|
||||
goto Fail;
|
||||
}
|
||||
|
@ -4157,10 +4153,7 @@ datetime_datetime_now_impl(PyTypeObject *type, PyObject *tz)
|
|||
tz);
|
||||
if (self != NULL && tz != Py_None) {
|
||||
/* Convert UTC to tzinfo's zone. */
|
||||
PyObject *temp = self;
|
||||
|
||||
self = _PyObject_CallMethodId(tz, &PyId_fromutc, "O", self);
|
||||
Py_DECREF(temp);
|
||||
self = _PyObject_CallMethodId(tz, &PyId_fromutc, "N", self);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -4195,10 +4188,7 @@ datetime_fromtimestamp(PyObject *cls, PyObject *args, PyObject *kw)
|
|||
tzinfo);
|
||||
if (self != NULL && tzinfo != Py_None) {
|
||||
/* Convert UTC to tzinfo's zone. */
|
||||
PyObject *temp = self;
|
||||
|
||||
self = _PyObject_CallMethodId(tzinfo, &PyId_fromutc, "O", self);
|
||||
Py_DECREF(temp);
|
||||
self = _PyObject_CallMethodId(tzinfo, &PyId_fromutc, "N", self);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -4421,9 +4411,7 @@ datetime_subtract(PyObject *left, PyObject *right)
|
|||
return NULL;
|
||||
|
||||
if (offdiff != NULL) {
|
||||
PyObject *temp = result;
|
||||
result = delta_subtract(result, offdiff);
|
||||
Py_DECREF(temp);
|
||||
Py_SETREF(result, delta_subtract(result, offdiff));
|
||||
Py_DECREF(offdiff);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -396,10 +396,8 @@ element_init(PyObject *self, PyObject *args, PyObject *kwds)
|
|||
Py_XDECREF(attrib);
|
||||
|
||||
/* Replace the objects already pointed to by tag, text and tail. */
|
||||
tmp = self_elem->tag;
|
||||
Py_INCREF(tag);
|
||||
self_elem->tag = tag;
|
||||
Py_DECREF(tmp);
|
||||
Py_SETREF(self_elem->tag, tag);
|
||||
|
||||
tmp = self_elem->text;
|
||||
Py_INCREF(Py_None);
|
||||
|
|
|
@ -762,7 +762,6 @@ profiler_dealloc(ProfilerObject *op)
|
|||
static int
|
||||
profiler_init(ProfilerObject *pObj, PyObject *args, PyObject *kw)
|
||||
{
|
||||
PyObject *o;
|
||||
PyObject *timer = NULL;
|
||||
double timeunit = 0.0;
|
||||
int subcalls = 1;
|
||||
|
@ -777,11 +776,9 @@ profiler_init(ProfilerObject *pObj, PyObject *args, PyObject *kw)
|
|||
|
||||
if (setSubcalls(pObj, subcalls) < 0 || setBuiltins(pObj, builtins) < 0)
|
||||
return -1;
|
||||
o = pObj->externalTimer;
|
||||
pObj->externalTimer = timer;
|
||||
Py_XINCREF(timer);
|
||||
Py_XDECREF(o);
|
||||
pObj->externalTimerUnit = timeunit;
|
||||
Py_XINCREF(timer);
|
||||
Py_SETREF(pObj->externalTimer, timer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -4494,8 +4494,6 @@ Pickler_get_persid(PicklerObject *self)
|
|||
static int
|
||||
Pickler_set_persid(PicklerObject *self, PyObject *value)
|
||||
{
|
||||
PyObject *tmp;
|
||||
|
||||
if (value == NULL) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"attribute deletion is not supported");
|
||||
|
@ -4507,10 +4505,8 @@ Pickler_set_persid(PicklerObject *self, PyObject *value)
|
|||
return -1;
|
||||
}
|
||||
|
||||
tmp = self->pers_func;
|
||||
Py_INCREF(value);
|
||||
self->pers_func = value;
|
||||
Py_XDECREF(tmp); /* self->pers_func can be NULL, so be careful. */
|
||||
Py_SETREF(self->pers_func, value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -6946,8 +6942,6 @@ Unpickler_get_persload(UnpicklerObject *self)
|
|||
static int
|
||||
Unpickler_set_persload(UnpicklerObject *self, PyObject *value)
|
||||
{
|
||||
PyObject *tmp;
|
||||
|
||||
if (value == NULL) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"attribute deletion is not supported");
|
||||
|
@ -6960,10 +6954,8 @@ Unpickler_set_persload(UnpicklerObject *self, PyObject *value)
|
|||
return -1;
|
||||
}
|
||||
|
||||
tmp = self->pers_func;
|
||||
Py_INCREF(value);
|
||||
self->pers_func = value;
|
||||
Py_XDECREF(tmp); /* self->pers_func can be NULL, so be careful. */
|
||||
Py_SETREF(self->pers_func, value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -321,10 +321,8 @@ set_hook(const char *funcname, PyObject **hook_var, PyObject *args)
|
|||
Py_CLEAR(*hook_var);
|
||||
}
|
||||
else if (PyCallable_Check(function)) {
|
||||
PyObject *tmp = *hook_var;
|
||||
Py_INCREF(function);
|
||||
*hook_var = function;
|
||||
Py_XDECREF(tmp);
|
||||
Py_SETREF(*hook_var, function);
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue