temp = _PyLong_DivmodNear(m, n);
if (temp == NULL)
return NULL;
- result = PyTuple_GET_ITEM(temp, 0);
- Py_INCREF(result);
+ result = Py_NewRef(PyTuple_GET_ITEM(temp, 0));
Py_DECREF(temp);
return result;
DATE_SET_SECOND(self, second);
DATE_SET_MICROSECOND(self, usecond);
if (aware) {
- Py_INCREF(tzinfo);
- self->tzinfo = tzinfo;
+ self->tzinfo = Py_NewRef(tzinfo);
}
DATE_SET_FOLD(self, fold);
}
TIME_SET_SECOND(self, second);
TIME_SET_MICROSECOND(self, usecond);
if (aware) {
- Py_INCREF(tzinfo);
- self->tzinfo = tzinfo;
+ self->tzinfo = Py_NewRef(tzinfo);
}
TIME_SET_FOLD(self, fold);
}
if (self == NULL) {
return NULL;
}
- Py_INCREF(offset);
- self->offset = offset;
- Py_XINCREF(name);
- self->name = name;
+ self->offset = Py_NewRef(offset);
+ self->name = Py_XNewRef(name);
return (PyObject *)self;
}
assert(name == NULL || PyUnicode_Check(name));
if (name == NULL && delta_bool((PyDateTime_Delta *)offset) == 0) {
- Py_INCREF(PyDateTime_TimeZone_UTC);
- return PyDateTime_TimeZone_UTC;
+ return Py_NewRef(PyDateTime_TimeZone_UTC);
}
if ((GET_TD_DAYS(offset) == -1 &&
GET_TD_SECONDS(offset) == 0 &&
if (rv == 1) {
// Create a timezone from offset in seconds (0 returns UTC)
if (tzoffset == 0) {
- Py_INCREF(PyDateTime_TimeZone_UTC);
- return PyDateTime_TimeZone_UTC;
+ return Py_NewRef(PyDateTime_TimeZone_UTC);
}
PyObject *delta = new_delta(0, tzoffset, tz_useconds, 1);
Py_DECREF(delta);
}
else {
- tzinfo = Py_None;
- Py_INCREF(Py_None);
+ tzinfo = Py_NewRef(Py_None);
}
return tzinfo;
goto BadDivmod;
}
- num = PyTuple_GET_ITEM(tuple, 0); /* leftover seconds */
- Py_INCREF(num);
+ num = Py_NewRef(PyTuple_GET_ITEM(tuple, 0)); /* leftover seconds */
Py_DECREF(tuple);
tuple = checked_divmod(num, seconds_per_day);
goto BadDivmod;
}
- num = PyTuple_GET_ITEM(tuple, 0); /* leftover days */
- Py_INCREF(num);
+ num = Py_NewRef(PyTuple_GET_ITEM(tuple, 0)); /* leftover days */
d = _PyLong_AsInt(num);
if (d == -1 && PyErr_Occurred()) {
goto Done;
if (year == NULL) {
return NULL;
}
- Py_INCREF(year);
- return year;
+ return Py_NewRef(year);
}
static PyObject *
if (week == NULL) {
return NULL;
}
- Py_INCREF(week);
- return week;
+ return Py_NewRef(week);
}
static PyObject *
if (weekday == NULL) {
return NULL;
}
- Py_INCREF(weekday);
- return weekday;
+ return Py_NewRef(weekday);
}
static PyGetSetDef iso_calendar_date_getset[] = {
char sign;
if (self->name != NULL) {
- Py_INCREF(self->name);
- return self->name;
+ return Py_NewRef(self->name);
}
if ((PyObject *)self == PyDateTime_TimeZone_UTC ||
(GET_TD_DAYS(self->offset) == 0 &&
}
else {
sign = '+';
- offset = self->offset;
- Py_INCREF(offset);
+ offset = Py_NewRef(self->offset);
}
/* Offset is not negative here. */
microseconds = GET_TD_MICROSECONDS(offset);
if (_timezone_check_argument(dt, "utcoffset") == -1)
return NULL;
- Py_INCREF(self->offset);
- return self->offset;
+ return Py_NewRef(self->offset);
}
static PyObject *
time_tzinfo(PyDateTime_Time *self, void *unused)
{
PyObject *result = HASTZINFO(self) ? self->tzinfo : Py_None;
- Py_INCREF(result);
- return result;
+ return Py_NewRef(result);
}
static PyObject *
me->hashcode = -1;
me->hastzinfo = aware;
if (aware) {
- Py_INCREF(tzinfo);
- me->tzinfo = tzinfo;
+ me->tzinfo = Py_NewRef(tzinfo);
}
if (pdata[0] & (1 << 7)) {
me->data[0] -= 128;
result = diff_to_bool(diff, op);
}
else if (op == Py_EQ) {
- result = Py_False;
- Py_INCREF(result);
+ result = Py_NewRef(Py_False);
}
else if (op == Py_NE) {
- result = Py_True;
- Py_INCREF(result);
+ result = Py_NewRef(Py_True);
}
else {
PyErr_SetString(PyExc_TypeError,
return -1;
}
else {
- self0 = (PyObject *)self;
- Py_INCREF(self0);
+ self0 = Py_NewRef(self);
}
offset = time_utcoffset(self0, NULL);
Py_DECREF(self0);
datetime_tzinfo(PyDateTime_DateTime *self, void *unused)
{
PyObject *result = HASTZINFO(self) ? self->tzinfo : Py_None;
- Py_INCREF(result);
- return result;
+ return Py_NewRef(result);
}
static PyObject *
me->hashcode = -1;
me->hastzinfo = aware;
if (aware) {
- Py_INCREF(tzinfo);
- me->tzinfo = tzinfo;
+ me->tzinfo = Py_NewRef(tzinfo);
}
if (pdata[2] & (1 << 7)) {
me->data[2] -= 128;
}
if (surrogate_separator == 0) {
- Py_INCREF(dtstr);
- return dtstr;
+ return Py_NewRef(dtstr);
}
PyObject *str_out = _PyUnicode_Copy(dtstr);
int delta_d, delta_s, delta_us;
if (GET_DT_TZINFO(left) == GET_DT_TZINFO(right)) {
- offset2 = offset1 = Py_None;
- Py_INCREF(offset1);
- Py_INCREF(offset2);
+ offset1 = Py_NewRef(Py_None);
+ offset2 = Py_NewRef(Py_None);
}
else {
offset1 = datetime_utcoffset(left, NULL);
result = diff_to_bool(diff, op);
}
else if (op == Py_EQ) {
- result = Py_False;
- Py_INCREF(result);
+ result = Py_NewRef(Py_False);
}
else if (op == Py_NE) {
- result = Py_True;
- Py_INCREF(result);
+ result = Py_NewRef(Py_True);
}
else {
PyErr_SetString(PyExc_TypeError,
return -1;
}
else {
- self0 = (PyObject *)self;
- Py_INCREF(self0);
+ self0 = Py_NewRef(self);
}
offset = datetime_utcoffset(self0, NULL);
Py_DECREF(self0);
if (self_tzinfo == NULL)
return NULL;
} else {
- self_tzinfo = self->tzinfo;
- Py_INCREF(self_tzinfo);
+ self_tzinfo = Py_NewRef(self->tzinfo);
}
/* Conversion to self's own time zone is a NOP. */
if (self_tzinfo == tzinfo) {
Py_DECREF(self_tzinfo);
- Py_INCREF(self);
- return self;
+ return (PyDateTime_DateTime*)Py_NewRef(self);
}
/* Convert self to UTC. */
else {
/* Result is already aware - just replace tzinfo. */
temp = result->tzinfo;
- result->tzinfo = PyDateTime_TimeZone_UTC;
- Py_INCREF(result->tzinfo);
+ result->tzinfo = Py_NewRef(PyDateTime_TimeZone_UTC);
Py_DECREF(temp);
}
tzinfo = GET_DT_TZINFO(self);
if (tzinfo == Py_None) {
- utcself = self;
- Py_INCREF(utcself);
+ utcself = (PyDateTime_DateTime*)Py_NewRef(self);
}
else {
PyObject *offset;
return NULL;
if (offset == Py_None) {
Py_DECREF(offset);
- utcself = self;
- Py_INCREF(utcself);
+ utcself = (PyDateTime_DateTime*)Py_NewRef(self);
}
else {
utcself = (PyDateTime_DateTime *)add_datetime_timedelta(self,
}
Py_DECREF(rv);
- ((PyZoneInfo_ZoneInfo *)self)->key = key;
- Py_INCREF(key);
+ ((PyZoneInfo_ZoneInfo *)self)->key = Py_NewRef(key);
goto cleanup;
error:
self->source = SOURCE_FILE;
self->file_repr = file_repr;
- self->key = key;
- Py_INCREF(key);
-
+ self->key = Py_NewRef(key);
return obj_self;
+
error:
Py_XDECREF(file_repr);
Py_XDECREF(self);
if (tti == NULL) {
return NULL;
}
- Py_INCREF(tti->utcoff);
- return tti->utcoff;
+ return Py_NewRef(tti->utcoff);
}
static PyObject *
if (tti == NULL) {
return NULL;
}
- Py_INCREF(tti->dstoff);
- return tti->dstoff;
+ return Py_NewRef(tti->dstoff);
}
static PyObject *
if (tti == NULL) {
return NULL;
}
- Py_INCREF(tti->tzname);
- return tti->tzname;
+ return Py_NewRef(tti->tzname);
}
#define GET_DT_TZINFO PyDateTime_DATE_GET_TZINFO
zoneinfo_str(PyZoneInfo_ZoneInfo *self)
{
if (!(self->key == Py_None)) {
- Py_INCREF(self->key);
- return self->key;
+ return Py_NewRef(self->key);
}
else {
return zoneinfo_repr(self);
return -1;
}
- out->tzname = tzname;
- Py_INCREF(tzname);
+ out->tzname = Py_NewRef(tzname);
return 0;
}
if (PyObject_IsTrue(tti->dstoff)) {
_ttinfo *tti_after = &(self->tzrule_after.std);
Py_DECREF(tti_after->dstoff);
- tti_after->dstoff = tti->dstoff;
- Py_INCREF(tti_after->dstoff);
+ tti_after->dstoff = Py_NewRef(tti->dstoff);
}
}
return NULL;
}
- Py_INCREF(key);
- Py_INCREF(zone);
-
node->next = NULL;
node->prev = NULL;
- node->key = key;
- node->zone = zone;
+ node->key = Py_NewRef(key);
+ node->zone = Py_NewRef(zone);
return node;
}
if (node != NULL) {
move_strong_cache_node_to_front(&ZONEINFO_STRONG_CACHE, node);
- Py_INCREF(node->zone);
- return node->zone;
+ return Py_NewRef(node->zone);
}
return NULL; // Cache miss
}
if (NO_TTINFO.utcoff == NULL) {
- NO_TTINFO.utcoff = Py_None;
- NO_TTINFO.dstoff = Py_None;
- NO_TTINFO.tzname = Py_None;
-
- for (size_t i = 0; i < 3; ++i) {
- Py_INCREF(Py_None);
- }
+ NO_TTINFO.utcoff = Py_NewRef(Py_None);
+ NO_TTINFO.dstoff = Py_NewRef(Py_None);
+ NO_TTINFO.tzname = Py_NewRef(Py_None);
}
if (initialize_caches()) {