in places where Py_DECREF was used.
*
* As in case of Py_CLEAR "the obvious" code can be deadly:
*
- * Py_XDECREF(op);
+ * Py_DECREF(op);
* op = op2;
*
* The safe way is:
*
- * Py_XSETREF(op, op2);
+ * Py_SETREF(op, op2);
*
* That arranges to set `op` to `op2` _before_ decref'ing, so that any code
* triggered as a side-effect of `op` getting torn down no longer believes
* `op` points to a valid object.
+ *
+ * Py_XSETREF is a variant of Py_SETREF that uses Py_XDECREF instead of
+ * Py_DECREF.
*/
+#define Py_SETREF(op, op2) \
+ do { \
+ PyObject *_py_tmp = (PyObject *)(op); \
+ (op) = (op2); \
+ Py_DECREF(_py_tmp); \
+ } while (0)
+
#define Py_XSETREF(op, op2) \
do { \
PyObject *_py_tmp = (PyObject *)(op); \
Py_DECREF((PyObject *)dict);
return NULL;
}
- Py_XSETREF(result->tp_dict, (PyObject *)dict);
+ Py_SETREF(result->tp_dict, (PyObject *)dict);
dict->format = _ctypes_alloc_format_string(NULL, "B");
if (dict->format == NULL) {
Py_DECREF(result);
Py_DECREF((PyObject *)stgdict);
return NULL;
}
- Py_XSETREF(result->tp_dict, (PyObject *)stgdict);
+ Py_SETREF(result->tp_dict, (PyObject *)stgdict);
return (PyObject *)result;
}
/* replace the class dict by our updated spam dict */
if (-1 == PyDict_Update((PyObject *)stgdict, result->tp_dict))
goto error;
- Py_XSETREF(result->tp_dict, (PyObject *)stgdict); /* steal the reference */
+ Py_SETREF(result->tp_dict, (PyObject *)stgdict); /* steal the reference */
stgdict = NULL;
/* Special case for character arrays.
Py_DECREF((PyObject *)stgdict);
return NULL;
}
- Py_XSETREF(result->tp_dict, (PyObject *)stgdict);
+ Py_SETREF(result->tp_dict, (PyObject *)stgdict);
return (PyObject *)result;
}
Py_DECREF((PyObject *)stgdict);
return NULL;
}
- Py_XSETREF(result->tp_dict, (PyObject *)stgdict);
+ Py_SETREF(result->tp_dict, (PyObject *)stgdict);
/* Install from_param class methods in ctypes base classes.
Overrides the PyCSimpleType_from_param generic method.
Py_DECREF((PyObject *)stgdict);
return NULL;
}
- Py_XSETREF(result->tp_dict, (PyObject *)stgdict);
+ Py_SETREF(result->tp_dict, (PyObject *)stgdict);
if (-1 == make_funcptrtype_dict(stgdict)) {
Py_DECREF(result);
bself = (PyBaseExceptionObject *)self;
Py_INCREF(args);
- Py_XSETREF(bself->args, args);
+ Py_SETREF(bself->args, args);
return 0;
}
return NULL;
}
Py_INCREF(temp);
- Py_XSETREF(po->wo, temp);
+ Py_SETREF(po->wo, temp);
Py_INCREF(Py_None);
return Py_None;
}
if (strcmp(name, "tag") == 0) {
Py_INCREF(value);
- Py_XSETREF(self->tag, value);
+ Py_SETREF(self->tag, value);
} else if (strcmp(name, "text") == 0) {
Py_DECREF(JOIN_OBJ(self->text));
self->text = value;
return -1;
}
Py_INCREF(value);
- Py_XSETREF(self->extra->attrib, value);
+ Py_SETREF(self->extra->attrib, value);
} else {
PyErr_SetString(PyExc_AttributeError,
"Can't set arbitrary attributes on Element");
self->index++;
Py_INCREF(node);
- Py_XSETREF(self->this, node);
+ Py_SETREF(self->this, node);
Py_INCREF(node);
- Py_XSETREF(self->last, node);
+ Py_SETREF(self->last, node);
if (treebuilder_append_event(self, self->start_event_obj, node) < 0)
goto error;
node = node->next;
}
- Py_XSETREF(self->statement_cache,
+ Py_SETREF(self->statement_cache,
(pysqlite_Cache *)PyObject_CallFunction((PyObject *)&pysqlite_CacheType, "O", self));
Py_DECREF(self);
self->statement_cache->decref_factory = 0;
}
}
- Py_XSETREF(self->statements, new_list);
+ Py_SETREF(self->statements, new_list);
}
static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self)
}
}
- Py_XSETREF(self->cursors, new_list);
+ Py_SETREF(self->cursors, new_list);
}
PyObject* pysqlite_connection_create_function(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
/* reset description and rowcount */
Py_INCREF(Py_None);
- Py_XSETREF(self->description, Py_None);
+ Py_SETREF(self->description, Py_None);
self->rowcount = -1L;
func_args = PyTuple_New(1);
}
if (self->statement->in_use) {
- Py_XSETREF(self->statement,
+ Py_SETREF(self->statement,
PyObject_New(pysqlite_Statement, &pysqlite_StatementType));
if (!self->statement) {
goto error;
numcols = sqlite3_column_count(self->statement->st);
Py_END_ALLOW_THREADS
- Py_XSETREF(self->description, PyTuple_New(numcols));
+ Py_SETREF(self->description, PyTuple_New(numcols));
if (!self->description) {
goto error;
}
if (!copy)
return 0;
- Py_XSETREF(*object, copy);
+ Py_SETREF(*object, copy);
return 1; /* success */
}
return -1;
#else
Py_INCREF(value);
- Py_XSETREF(self->ctx, (PySSLContext *)value);
+ Py_SETREF(self->ctx, (PySSLContext *)value);
SSL_set_SSL_CTX(self->ssl, self->ctx->ctx);
#endif
} else {
link = teedataobject_jumplink(to->dataobj);
if (link == NULL)
return NULL;
- Py_XSETREF(to->dataobj, (teedataobject *)link);
+ Py_SETREF(to->dataobj, (teedataobject *)link);
to->index = 0;
}
value = teedataobject_getitem(to->dataobj, to->index);
if (Handlers[SIGINT].func == DefaultHandler) {
/* Install default int handler */
Py_INCREF(IntHandler);
- Py_XSETREF(Handlers[SIGINT].func, IntHandler);
+ Py_SETREF(Handlers[SIGINT].func, IntHandler);
old_siginthandler = PyOS_setsig(SIGINT, signal_handler);
}
tmp = PyUnicode_FromFormat("%U%c", self->prefix, SEP);
if (tmp == NULL)
goto error;
- Py_XSETREF(self->prefix, tmp);
+ Py_SETREF(self->prefix, tmp);
}
}
else
PyBytes_AS_STRING(self->unused_data), old_size);
Py_MEMCPY(PyBytes_AS_STRING(new_data) + old_size,
self->zst.next_in, self->zst.avail_in);
- Py_XSETREF(self->unused_data, new_data);
+ Py_SETREF(self->unused_data, new_data);
self->zst.avail_in = 0;
}
}
(char *)self->zst.next_in, self->zst.avail_in);
if (new_data == NULL)
return -1;
- Py_XSETREF(self->unconsumed_tail, new_data);
+ Py_SETREF(self->unconsumed_tail, new_data);
}
return 0;
}
/* Multiple references, need to create new object */
PyObject *v;
v = bytes_concat(*pv, w);
- Py_XSETREF(*pv, v);
+ Py_SETREF(*pv, v);
}
}
if (name != Py_None) {
Py_INCREF(name);
- Py_XSETREF(newfunc->func_name, name);
+ Py_SETREF(newfunc->func_name, name);
}
if (defaults != Py_None) {
Py_INCREF(defaults);
result = PyNumber_Add(r->start, product);
Py_DECREF(product);
if (result) {
- Py_XSETREF(r->index, new_index);
+ Py_SETREF(r->index, new_index);
}
else {
Py_DECREF(new_index);
type->tp_name = tp_name;
Py_INCREF(value);
- Py_XSETREF(((PyHeapTypeObject*)type)->ht_name, value);
+ Py_SETREF(((PyHeapTypeObject*)type)->ht_name, value);
return 0;
}
et = (PyHeapTypeObject*)type;
Py_INCREF(value);
- Py_XSETREF(et->ht_qualname, value);
+ Py_SETREF(et->ht_qualname, value);
return 0;
}
else
method_cache_misses++;
#endif
- Py_XSETREF(method_cache[h].name, name);
+ Py_SETREF(method_cache[h].name, name);
}
return res;
}
_Py_INCREF_UNICODE_EMPTY();
if (!unicode_empty)
return -1;
- Py_XSETREF(*p_unicode, unicode_empty);
+ Py_SETREF(*p_unicode, unicode_empty);
return 0;
}
PyObject *copy = resize_copy(unicode, length);
if (copy == NULL)
return -1;
- Py_XSETREF(*p_unicode, copy);
+ Py_SETREF(*p_unicode, copy);
return 0;
}
return -1;
_PyUnicode_FastCopyCharacters(newbuffer, 0,
writer->buffer, 0, writer->pos);
- Py_XSETREF(writer->buffer, newbuffer);
+ Py_SETREF(writer->buffer, newbuffer);
}
_PyUnicodeWriter_Update(writer);
return 0;
if (t) {
Py_INCREF(t);
- Py_XSETREF(*p, t);
+ Py_SETREF(*p, t);
return;
}
goto handle_error;
}
else if (!is_true) {
- Py_XSETREF(*filename, PyUnicode_FromString("__main__"));
+ Py_SETREF(*filename, PyUnicode_FromString("__main__"));
if (*filename == NULL)
goto handle_error;
}
Py_INCREF(self);
func = PyMethod_GET_FUNCTION(func);
Py_INCREF(func);
- Py_XSETREF(*pfunc, self);
+ Py_SETREF(*pfunc, self);
na++;
/* n++; */
} else
Py_INCREF(self);
func = PyMethod_GET_FUNCTION(func);
Py_INCREF(func);
- Py_XSETREF(*pfunc, self);
+ Py_SETREF(*pfunc, self);
na++;
n++;
} else
--tstate->recursion_depth;
/* throw away the old exception and use the recursion error instead */
Py_INCREF(PyExc_RecursionError);
- Py_XSETREF(*exc, PyExc_RecursionError);
+ Py_SETREF(*exc, PyExc_RecursionError);
Py_INCREF(PyExc_RecursionErrorInst);
- Py_XSETREF(*val, PyExc_RecursionErrorInst);
+ Py_SETREF(*val, PyExc_RecursionErrorInst);
/* just keeping the old traceback */
return;
}