if (PyObject_SetAttrString(self, "details", details) < 0)
return -1;
- bself = (PyBaseExceptionObject *)self;
Py_INCREF(args);
- Py_SETREF(((PyBaseExceptionObject *)self)->args, args);
- Py_XSETREF(bself->args, args);
++ Py_XSETREF(((PyBaseExceptionObject *)self)->args, args);
return 0;
}
}
/* Offset is normalized, so it is negative if days < 0 */
if (GET_TD_DAYS(offset) < 0) {
- PyObject *temp = offset;
sign = '-';
- Py_SETREF(offset, delta_negative((PyDateTime_Delta *)offset));
- offset = delta_negative((PyDateTime_Delta *)offset);
- Py_DECREF(temp);
++ Py_XSETREF(offset, delta_negative((PyDateTime_Delta *)offset));
if (offset == NULL)
return -1;
}
if (dst == Py_None)
goto Inconsistent;
if (delta_bool((PyDateTime_Delta *)dst) != 0) {
- Py_SETREF(result, add_datetime_timedelta((PyDateTime_DateTime *)result,
- PyObject *temp = result;
- result = add_datetime_timedelta((PyDateTime_DateTime *)result,
- (PyDateTime_Delta *)dst, 1);
- Py_DECREF(temp);
++ Py_XSETREF(result, add_datetime_timedelta((PyDateTime_DateTime *)result,
+ (PyDateTime_Delta *)dst, 1));
if (result == NULL)
goto Fail;
}
return NULL;
if (offdiff != NULL) {
- Py_SETREF(result, delta_subtract(result, offdiff));
- PyObject *temp = result;
- result = delta_subtract(result, offdiff);
- Py_DECREF(temp);
++ Py_XSETREF(result, delta_subtract(result, offdiff));
Py_DECREF(offdiff);
}
}
return (PyObject *) pylong;
}
- Py_SETREF(exponent, long_methods->nb_power(tmp, exponent, Py_None));
+/* Convert a Decimal to its exact integer ratio representation. */
+static PyObject *
+dec_as_integer_ratio(PyObject *self, PyObject *args UNUSED)
+{
+ PyObject *numerator = NULL;
+ PyObject *denominator = NULL;
+ PyObject *exponent = NULL;
+ PyObject *result = NULL;
+ PyObject *tmp;
+ mpd_ssize_t exp;
+ PyObject *context;
+ uint32_t status = 0;
+ PyNumberMethods *long_methods = PyLong_Type.tp_as_number;
+
+ if (mpd_isspecial(MPD(self))) {
+ if (mpd_isnan(MPD(self))) {
+ PyErr_SetString(PyExc_ValueError,
+ "cannot convert NaN to integer ratio");
+ }
+ else {
+ PyErr_SetString(PyExc_OverflowError,
+ "cannot convert Infinity to integer ratio");
+ }
+ return NULL;
+ }
+
+ CURRENT_CONTEXT(context);
+
+ tmp = dec_alloc();
+ if (tmp == NULL) {
+ return NULL;
+ }
+
+ if (!mpd_qcopy(MPD(tmp), MPD(self), &status)) {
+ Py_DECREF(tmp);
+ PyErr_NoMemory();
+ return NULL;
+ }
+
+ exp = mpd_iszero(MPD(tmp)) ? 0 : MPD(tmp)->exp;
+ MPD(tmp)->exp = 0;
+
+ /* context and rounding are unused here: the conversion is exact */
+ numerator = dec_as_long(tmp, context, MPD_ROUND_FLOOR);
+ Py_DECREF(tmp);
+ if (numerator == NULL) {
+ goto error;
+ }
+
+ exponent = PyLong_FromSsize_t(exp < 0 ? -exp : exp);
+ if (exponent == NULL) {
+ goto error;
+ }
+
+ tmp = PyLong_FromLong(10);
+ if (tmp == NULL) {
+ goto error;
+ }
+
- Py_SETREF(numerator, long_methods->nb_multiply(numerator, exponent));
++ Py_XSETREF(exponent, long_methods->nb_power(tmp, exponent, Py_None));
+ Py_DECREF(tmp);
+ if (exponent == NULL) {
+ goto error;
+ }
+
+ if (exp >= 0) {
- Py_SETREF(numerator, long_methods->nb_floor_divide(numerator, tmp));
- Py_SETREF(denominator, long_methods->nb_floor_divide(denominator, tmp));
++ Py_XSETREF(numerator, long_methods->nb_multiply(numerator, exponent));
+ if (numerator == NULL) {
+ goto error;
+ }
+ denominator = PyLong_FromLong(1);
+ if (denominator == NULL) {
+ goto error;
+ }
+ }
+ else {
+ denominator = exponent;
+ exponent = NULL;
+ tmp = _PyLong_GCD(numerator, denominator);
+ if (tmp == NULL) {
+ goto error;
+ }
++ Py_XSETREF(numerator, long_methods->nb_floor_divide(numerator, tmp));
++ Py_XSETREF(denominator, long_methods->nb_floor_divide(denominator, tmp));
+ Py_DECREF(tmp);
+ if (numerator == NULL || denominator == NULL) {
+ goto error;
+ }
+ }
+
+ result = PyTuple_Pack(2, numerator, denominator);
+
+
+error:
+ Py_XDECREF(exponent);
+ Py_XDECREF(denominator);
+ Py_XDECREF(numerator);
+ return result;
+}
+
static PyObject *
PyDec_ToIntegralValue(PyObject *dec, 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);
- Py_SETREF(self_elem->tag, tag);
- self_elem->tag = tag;
- Py_DECREF(tmp);
++ Py_XSETREF(self_elem->tag, tag);
tmp = self_elem->text;
Py_INCREF(Py_None);
}
static PyObject*
-element_getattro(ElementObject* self, PyObject* nameobj)
+element_tag_getter(ElementObject *self, void *closure)
{
- PyObject* res;
- char *name = "";
+ PyObject *res = self->tag;
+ Py_INCREF(res);
+ return res;
+}
- if (PyUnicode_Check(nameobj))
- name = _PyUnicode_AsString(nameobj);
+static PyObject*
+element_text_getter(ElementObject *self, void *closure)
+{
+ PyObject *res = element_get_text(self);
+ Py_XINCREF(res);
+ return res;
+}
- if (name == NULL)
- return NULL;
+static PyObject*
+element_tail_getter(ElementObject *self, void *closure)
+{
+ PyObject *res = element_get_tail(self);
+ Py_XINCREF(res);
+ return res;
+}
- /* handle common attributes first */
- if (strcmp(name, "tag") == 0) {
- res = self->tag;
- Py_INCREF(res);
- return res;
- } else if (strcmp(name, "text") == 0) {
- res = element_get_text(self);
- Py_XINCREF(res);
- return res;
+static PyObject*
+element_attrib_getter(ElementObject *self, void *closure)
+{
+ PyObject *res;
+ if (!self->extra) {
+ if (create_extra(self, NULL) < 0)
+ return NULL;
}
+ res = element_get_attrib(self);
+ Py_XINCREF(res);
+ return res;
+}
- /* methods */
- res = PyObject_GenericGetAttr((PyObject*) self, nameobj);
- if (res)
- return res;
-
- /* less common attributes */
- if (strcmp(name, "tail") == 0) {
- PyErr_Clear();
- res = element_get_tail(self);
- } else if (strcmp(name, "attrib") == 0) {
- PyErr_Clear();
- if (!self->extra) {
- if (create_extra(self, NULL) < 0)
- return NULL;
- }
- res = element_get_attrib(self);
+/* macro for setter validation */
+#define _VALIDATE_ATTR_VALUE(V) \
+ if ((V) == NULL) { \
+ PyErr_SetString( \
+ PyExc_AttributeError, \
+ "can't delete element attribute"); \
+ return -1; \
}
- if (!res)
- return NULL;
-
- Py_INCREF(res);
- return res;
+static int
+element_tag_setter(ElementObject *self, PyObject *value, void *closure)
+{
+ _VALIDATE_ATTR_VALUE(value);
+ Py_INCREF(value);
- Py_SETREF(self->tag, value);
++ Py_XSETREF(self->tag, value);
+ return 0;
}
static int
-element_setattro(ElementObject* self, PyObject* nameobj, PyObject* value)
+element_text_setter(ElementObject *self, PyObject *value, void *closure)
{
- char *name = "";
+ _VALIDATE_ATTR_VALUE(value);
+ Py_INCREF(value);
+ Py_DECREF(JOIN_OBJ(self->text));
+ self->text = value;
+ return 0;
+}
- if (value == NULL) {
- PyErr_SetString(PyExc_AttributeError,
- "can't delete attribute");
- return -1;
- }
- if (PyUnicode_Check(nameobj))
- name = _PyUnicode_AsString(nameobj);
- if (name == NULL)
- return -1;
+static int
+element_tail_setter(ElementObject *self, PyObject *value, void *closure)
+{
+ _VALIDATE_ATTR_VALUE(value);
+ Py_INCREF(value);
+ Py_DECREF(JOIN_OBJ(self->tail));
+ self->tail = value;
+ return 0;
+}
- if (strcmp(name, "tag") == 0) {
- Py_INCREF(value);
- Py_XSETREF(self->tag, value);
- } else if (strcmp(name, "text") == 0) {
- Py_DECREF(JOIN_OBJ(self->text));
- self->text = value;
- Py_INCREF(self->text);
- } else if (strcmp(name, "tail") == 0) {
- Py_DECREF(JOIN_OBJ(self->tail));
- self->tail = value;
- Py_INCREF(self->tail);
- } else if (strcmp(name, "attrib") == 0) {
- if (!self->extra) {
- if (create_extra(self, NULL) < 0)
- return -1;
- }
- Py_INCREF(value);
- Py_XSETREF(self->extra->attrib, value);
- } else {
- PyErr_SetString(PyExc_AttributeError,
- "Can't set arbitrary attributes on Element");
- return -1;
+static int
+element_attrib_setter(ElementObject *self, PyObject *value, void *closure)
+{
+ _VALIDATE_ATTR_VALUE(value);
+ if (!self->extra) {
+ if (create_extra(self, NULL) < 0)
+ return -1;
}
-
+ Py_INCREF(value);
- Py_SETREF(self->extra->attrib, value);
++ Py_XSETREF(self->extra->attrib, value);
return 0;
}
PyObject *element_factory)
/*[clinic end generated code: output=91cfa7558970ee96 input=1b424eeefc35249c]*/
{
- PyObject *tmp;
-
if (element_factory) {
Py_INCREF(element_factory);
- Py_SETREF(self->element_factory, element_factory);
- tmp = self->element_factory;
- self->element_factory = element_factory;
- Py_XDECREF(tmp);
++ Py_XSETREF(self->element_factory, element_factory);
}
return 0;
target = (TreeBuilderObject*) self->target;
- Py_INCREF(events_queue);
- Py_XSETREF(target->events, events_queue);
+ events_append = PyObject_GetAttrString(events_queue, "append");
+ if (events_append == NULL)
+ return NULL;
- Py_SETREF(target->events_append, events_append);
++ Py_XSETREF(target->events_append, events_append);
/* clear out existing events */
Py_CLEAR(target->start_event_obj);
return -1;
memcpy(PyBytes_AS_STRING(new_buf), PyBytes_AS_STRING(self->buf),
self->string_size);
- Py_SETREF(self->buf, new_buf);
- old_buf = self->buf;
- self->buf = new_buf;
- Py_DECREF(old_buf);
++ Py_XSETREF(self->buf, new_buf);
return 0;
}
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_SETREF(pObj->externalTimer, timer);
+ Py_XINCREF(timer);
++ Py_XSETREF(pObj->externalTimer, timer);
return 0;
}
return -1;
}
- tmp = self->pers_func;
Py_INCREF(value);
- Py_SETREF(self->pers_func, value);
- self->pers_func = value;
- Py_XDECREF(tmp); /* self->pers_func can be NULL, so be careful. */
++ Py_XSETREF(self->pers_func, value);
return 0;
}
return -1;
}
- tmp = self->pers_func;
Py_INCREF(value);
- Py_SETREF(self->pers_func, value);
- self->pers_func = value;
- Py_XDECREF(tmp); /* self->pers_func can be NULL, so be careful. */
++ Py_XSETREF(self->pers_func, value);
return 0;
}
}
}
- Py_SETREF(gbo->currkey, newkey);
- Py_SETREF(gbo->currvalue, newvalue);
- tmp = gbo->currkey;
- gbo->currkey = newkey;
- Py_XDECREF(tmp);
-
- tmp = gbo->currvalue;
- gbo->currvalue = newvalue;
- Py_XDECREF(tmp);
++ Py_XSETREF(gbo->currkey, newkey);
++ Py_XSETREF(gbo->currvalue, newvalue);
}
Py_INCREF(gbo->currkey);
- Py_SETREF(gbo->tgtkey, gbo->currkey);
- tmp = gbo->tgtkey;
- gbo->tgtkey = gbo->currkey;
- Py_XDECREF(tmp);
++ Py_XSETREF(gbo->tgtkey, gbo->currkey);
grouper = _grouper_create(gbo, gbo->tgtkey);
if (grouper == NULL)
{
PyObject *saved=NULL;
int firstpass;
- if (!PyArg_ParseTuple(state, "Oi", &saved, &firstpass))
+
+ if (!PyArg_ParseTuple(state, "O!i", &PyList_Type, &saved, &firstpass))
return NULL;
- Py_XINCREF(saved);
+ Py_INCREF(saved);
- Py_SETREF(lz->saved, saved);
+ Py_XSETREF(lz->saved, saved);
lz->firstpass = firstpass != 0;
+ lz->index = 0;
Py_RETURN_NONE;
}
if (newtotal == NULL)
return NULL;
- oldtotal = lz->total;
- lz->total = newtotal;
- Py_DECREF(oldtotal);
-
Py_INCREF(newtotal);
- Py_SETREF(lz->total, newtotal);
++ Py_XSETREF(lz->total, newtotal);
return newtotal;
}
Py_INCREF(v);
c_handler = handler_info[handlernum].handler;
}
- Py_SETREF(self->handlers[handlernum], v);
- self->handlers[handlernum] = v;
- Py_XDECREF(temp);
++ Py_XSETREF(self->handlers[handlernum], v);
handler_info[handlernum].setter(self->itself, c_handler);
return 1;
}
Py_CLEAR(*hook_var);
}
else if (PyCallable_Check(function)) {
- PyObject *tmp = *hook_var;
Py_INCREF(function);
- Py_SETREF(*hook_var, function);
- *hook_var = function;
- Py_XDECREF(tmp);
++ Py_XSETREF(*hook_var, function);
}
else {
PyErr_Format(PyExc_TypeError,
if (!_PyArg_NoKeywords(Py_TYPE(self)->tp_name, kwds))
return -1;
- tmp = self->args;
- self->args = args;
- Py_INCREF(self->args);
- Py_XDECREF(tmp);
+ Py_INCREF(args);
- Py_SETREF(self->args, args);
++ Py_XSETREF(self->args, args);
return 0;
}
/* Steals a reference to cause */
void
-PyException_SetCause(PyObject *self, PyObject *cause) {
- PyObject *old_cause = ((PyBaseExceptionObject *)self)->cause;
- ((PyBaseExceptionObject *)self)->cause = cause;
+PyException_SetCause(PyObject *self, PyObject *cause)
+{
((PyBaseExceptionObject *)self)->suppress_context = 1;
- Py_SETREF(((PyBaseExceptionObject *)self)->cause, cause);
- Py_XDECREF(old_cause);
++ Py_XSETREF(((PyBaseExceptionObject *)self)->cause, cause);
}
PyObject *
/* Steals a reference to context */
void
-PyException_SetContext(PyObject *self, PyObject *context) {
- PyObject *old_context = ((PyBaseExceptionObject *)self)->context;
- ((PyBaseExceptionObject *)self)->context = context;
- Py_XDECREF(old_context);
+PyException_SetContext(PyObject *self, PyObject *context)
+{
- Py_SETREF(((PyBaseExceptionObject *)self)->context, context);
++ Py_XSETREF(((PyBaseExceptionObject *)self)->context, context);
}
to be truncated by PyLong_FromDouble(). */
numerator = PyLong_FromDouble(float_part);
- if (numerator == NULL) goto error;
+ if (numerator == NULL)
+ goto error;
+ denominator = PyLong_FromLong(1);
+ if (denominator == NULL)
+ goto error;
+ py_exponent = PyLong_FromLong(Py_ABS(exponent));
+ if (py_exponent == NULL)
+ goto error;
/* fold in 2**exponent */
- denominator = PyLong_FromLong(1);
- py_exponent = PyLong_FromLong(labs((long)exponent));
- if (py_exponent == NULL) goto error;
- INPLACE_UPDATE(py_exponent,
- long_methods->nb_lshift(denominator, py_exponent));
- if (py_exponent == NULL) goto error;
if (exponent > 0) {
- Py_SETREF(numerator,
- INPLACE_UPDATE(numerator,
- long_methods->nb_multiply(numerator, py_exponent));
- if (numerator == NULL) goto error;
++ Py_XSETREF(numerator,
+ long_methods->nb_lshift(numerator, py_exponent));
+ if (numerator == NULL)
+ goto error;
}
else {
- Py_SETREF(denominator,
- Py_DECREF(denominator);
- denominator = py_exponent;
- py_exponent = NULL;
++ Py_XSETREF(denominator,
+ long_methods->nb_lshift(denominator, py_exponent));
+ if (denominator == NULL)
+ goto error;
}
result_pair = PyTuple_Pack(2, numerator, denominator);
/* We rely on f_lineno being accurate when f_trace is set. */
f->f_lineno = PyFrame_GetLineNumber(f);
- old_value = f->f_trace;
Py_XINCREF(v);
- Py_SETREF(f->f_trace, v);
- f->f_trace = v;
- Py_XDECREF(old_value);
++ Py_XSETREF(f->f_trace, v);
return 0;
}
nclosure, nfree);
return -1;
}
- tmp = op->func_code;
Py_INCREF(value);
- Py_SETREF(op->func_code, value);
- op->func_code = value;
- Py_DECREF(tmp);
++ Py_XSETREF(op->func_code, value);
return 0;
}
"__name__ must be set to a string object");
return -1;
}
- tmp = op->func_name;
Py_INCREF(value);
- Py_SETREF(op->func_name, value);
- op->func_name = value;
- Py_DECREF(tmp);
++ Py_XSETREF(op->func_name, value);
return 0;
}
"__qualname__ must be set to a string object");
return -1;
}
- tmp = op->func_qualname;
Py_INCREF(value);
- Py_SETREF(op->func_qualname, value);
- op->func_qualname = value;
- Py_DECREF(tmp);
++ Py_XSETREF(op->func_qualname, value);
return 0;
}
"__defaults__ must be set to a tuple object");
return -1;
}
- tmp = op->func_defaults;
Py_XINCREF(value);
- Py_SETREF(op->func_defaults, value);
- op->func_defaults = value;
- Py_XDECREF(tmp);
++ Py_XSETREF(op->func_defaults, value);
return 0;
}
"__kwdefaults__ must be set to a dict object");
return -1;
}
- tmp = op->func_kwdefaults;
Py_XINCREF(value);
- Py_SETREF(op->func_kwdefaults, value);
- op->func_kwdefaults = value;
- Py_XDECREF(tmp);
++ Py_XSETREF(op->func_kwdefaults, value);
return 0;
}
"__annotations__ must be set to a dict object");
return -1;
}
- tmp = op->func_annotations;
Py_XINCREF(value);
- Py_SETREF(op->func_annotations, value);
- op->func_annotations = value;
- Py_XDECREF(tmp);
++ Py_XSETREF(op->func_annotations, value);
return 0;
}
"__name__ must be set to a string object");
return -1;
}
- tmp = op->gi_name;
Py_INCREF(value);
- Py_SETREF(op->gi_name, value);
- op->gi_name = value;
- Py_DECREF(tmp);
++ Py_XSETREF(op->gi_name, value);
return 0;
}
"__qualname__ must be set to a string object");
return -1;
}
- tmp = op->gi_qualname;
Py_INCREF(value);
- Py_SETREF(op->gi_qualname, value);
- op->gi_qualname = value;
- Py_DECREF(tmp);
++ Py_XSETREF(op->gi_qualname, value);
return 0;
}
return -1;
}
p = ((PyListObject *)op) -> ob_item + i;
- Py_SETREF(*p, newitem);
- olditem = *p;
- *p = newitem;
- Py_XDECREF(olditem);
++ Py_XSETREF(*p, newitem);
return 0;
}
if (v == NULL)
return list_ass_slice(a, i, i+1, v);
Py_INCREF(v);
- Py_SETREF(a->ob_item[i], v);
- old_value = a->ob_item[i];
- a->ob_item[i] = v;
- Py_DECREF(old_value);
++ Py_XSETREF(a->ob_item[i], v);
return 0;
}
"not a '%.200s'", Py_TYPE(value)->tp_name);
return -1;
}
- dict = *dictptr;
- Py_XINCREF(value);
- *dictptr = value;
- Py_XDECREF(dict);
+ Py_INCREF(value);
- Py_SETREF(*dictptr, value);
++ Py_XSETREF(*dictptr, value);
return 0;
}
return -1;
}
p = ((PyTupleObject *)op) -> ob_item + i;
- Py_SETREF(*p, newitem);
- olditem = *p;
- *p = newitem;
- Py_XDECREF(olditem);
++ Py_XSETREF(*p, newitem);
return 0;
}
"not a '%.200s'", Py_TYPE(value)->tp_name);
return -1;
}
- dict = *dictptr;
Py_XINCREF(value);
- Py_SETREF(*dictptr, value);
- *dictptr = value;
- Py_XDECREF(dict);
++ Py_XSETREF(*dictptr, value);
return 0;
}
if (PyUnicode_Compare(co->co_filename, oldname))
return;
- tmp = co->co_filename;
- co->co_filename = newname;
- Py_INCREF(co->co_filename);
- Py_DECREF(tmp);
+ Py_INCREF(newname);
- Py_SETREF(co->co_filename, newname);
++ Py_XSETREF(co->co_filename, newname);
constants = co->co_consts;
n = PyTuple_GET_SIZE(constants);
(always_trim ||
PyUnicode_CompareWithASCIIString(code->co_name,
remove_frames) == 0)) {
- PyObject *tmp = *outer_link;
- *outer_link = next;
Py_XINCREF(next);
- Py_SETREF(*outer_link, next);
- Py_DECREF(tmp);
++ Py_XSETREF(*outer_link, next);
prev_link = outer_link;
}
else {
/* If it's a BUILD_SET, use the PyTuple we just built to create a
PyFrozenSet, and use that as the constant instead: */
if (codestr[0] == BUILD_SET) {
- Py_SETREF(newconst, PyFrozenSet_New(newconst));
- PyObject *tuple = newconst;
- newconst = PyFrozenSet_New(tuple);
- Py_DECREF(tuple);
++ Py_XSETREF(newconst, PyFrozenSet_New(newconst));
if (newconst == NULL)
return 0;
}
return -1;
}
if (result != Py_None) {
- Py_SETREF(frame->f_trace, result);
- PyObject *temp = frame->f_trace;
- frame->f_trace = NULL;
- Py_XDECREF(temp);
- frame->f_trace = result;
++ Py_XSETREF(frame->f_trace, result);
}
else {
Py_DECREF(result);