[Python-checkins] r45435 - in python/trunk: Modules/_csv.c Modules/cPickle.c Modules/collectionsmodule.c Modules/pyexpat.c Objects/cellobject.c Objects/funcobject.c Objects/typeobject.c Python/traceback.c
thomas.wouters
python-checkins at python.org
Sat Apr 15 19:28:36 CEST 2006
Author: thomas.wouters
Date: Sat Apr 15 19:28:34 2006
New Revision: 45435
Modified:
python/trunk/Modules/_csv.c
python/trunk/Modules/cPickle.c
python/trunk/Modules/collectionsmodule.c
python/trunk/Modules/pyexpat.c
python/trunk/Objects/cellobject.c
python/trunk/Objects/funcobject.c
python/trunk/Objects/typeobject.c
python/trunk/Python/traceback.c
Log:
Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
tp_clear methods.
Modified: python/trunk/Modules/_csv.c
==============================================================================
--- python/trunk/Modules/_csv.c (original)
+++ python/trunk/Modules/_csv.c Sat Apr 15 19:28:34 2006
@@ -828,12 +828,9 @@
static int
Reader_clear(ReaderObj *self)
{
- Py_XDECREF(self->dialect);
- Py_XDECREF(self->input_iter);
- Py_XDECREF(self->fields);
- self->dialect = NULL;
- self->input_iter = NULL;
- self->fields = NULL;
+ Py_CLEAR(self->dialect);
+ Py_CLEAR(self->input_iter);
+ Py_CLEAR(self->fields);
return 0;
}
@@ -1260,10 +1257,8 @@
static int
Writer_clear(WriterObj *self)
{
- Py_XDECREF(self->dialect);
- Py_XDECREF(self->writeline);
- self->dialect = NULL;
- self->writeline = NULL;
+ Py_CLEAR(self->dialect);
+ Py_CLEAR(self->writeline);
return 0;
}
Modified: python/trunk/Modules/cPickle.c
==============================================================================
--- python/trunk/Modules/cPickle.c (original)
+++ python/trunk/Modules/cPickle.c Sat Apr 15 19:28:34 2006
@@ -2931,16 +2931,14 @@
static int
Pickler_clear(Picklerobject *self)
{
-#define CLEAR(SLOT) Py_XDECREF(SLOT); SLOT = NULL;
- CLEAR(self->write);
- CLEAR(self->memo);
- CLEAR(self->fast_memo);
- CLEAR(self->arg);
- CLEAR(self->file);
- CLEAR(self->pers_func);
- CLEAR(self->inst_pers_func);
- CLEAR(self->dispatch_table);
-#undef CLEAR
+ Py_CLEAR(self->write);
+ Py_CLEAR(self->memo);
+ Py_CLEAR(self->fast_memo);
+ Py_CLEAR(self->arg);
+ Py_CLEAR(self->file);
+ Py_CLEAR(self->pers_func);
+ Py_CLEAR(self->inst_pers_func);
+ Py_CLEAR(self->dispatch_table);
return 0;
}
@@ -5284,17 +5282,15 @@
static int
Unpickler_clear(Unpicklerobject *self)
{
-#define CLEAR(SLOT) Py_XDECREF(SLOT); SLOT = NULL
- CLEAR(self->readline);
- CLEAR(self->read);
- CLEAR(self->file);
- CLEAR(self->memo);
- CLEAR(self->stack);
- CLEAR(self->pers_func);
- CLEAR(self->arg);
- CLEAR(self->last_string);
- CLEAR(self->find_class);
-#undef CLEAR
+ Py_CLEAR(self->readline);
+ Py_CLEAR(self->read);
+ Py_CLEAR(self->file);
+ Py_CLEAR(self->memo);
+ Py_CLEAR(self->stack);
+ Py_CLEAR(self->pers_func);
+ Py_CLEAR(self->arg);
+ Py_CLEAR(self->last_string);
+ Py_CLEAR(self->find_class);
return 0;
}
Modified: python/trunk/Modules/collectionsmodule.c
==============================================================================
--- python/trunk/Modules/collectionsmodule.c (original)
+++ python/trunk/Modules/collectionsmodule.c Sat Apr 15 19:28:34 2006
@@ -1236,10 +1236,7 @@
static int
defdict_tp_clear(defdictobject *dd)
{
- if (dd->default_factory != NULL) {
- Py_DECREF(dd->default_factory);
- dd->default_factory = NULL;
- }
+ Py_CLEAR(dd->default_factory);
return PyDict_Type.tp_clear((PyObject *)dd);
}
Modified: python/trunk/Modules/pyexpat.c
==============================================================================
--- python/trunk/Modules/pyexpat.c (original)
+++ python/trunk/Modules/pyexpat.c Sat Apr 15 19:28:34 2006
@@ -1669,8 +1669,7 @@
xmlparse_clear(xmlparseobject *op)
{
clear_handlers(op, 0);
- Py_XDECREF(op->intern);
- op->intern = 0;
+ Py_CLEAR(op->intern);
return 0;
}
#endif
Modified: python/trunk/Objects/cellobject.c
==============================================================================
--- python/trunk/Objects/cellobject.c (original)
+++ python/trunk/Objects/cellobject.c Sat Apr 15 19:28:34 2006
@@ -81,8 +81,7 @@
static int
cell_clear(PyCellObject *op)
{
- Py_XDECREF(op->ob_ref);
- op->ob_ref = NULL;
+ Py_CLEAR(op->ob_ref);
return 0;
}
Modified: python/trunk/Objects/funcobject.c
==============================================================================
--- python/trunk/Objects/funcobject.c (original)
+++ python/trunk/Objects/funcobject.c Sat Apr 15 19:28:34 2006
@@ -655,9 +655,7 @@
static int
cm_clear(classmethod *cm)
{
- Py_XDECREF(cm->cm_callable);
- cm->cm_callable = NULL;
-
+ Py_CLEAR(cm->cm_callable);
return 0;
}
Modified: python/trunk/Objects/typeobject.c
==============================================================================
--- python/trunk/Objects/typeobject.c (original)
+++ python/trunk/Objects/typeobject.c Sat Apr 15 19:28:34 2006
@@ -559,8 +559,8 @@
char *addr = (char *)self + mp->offset;
PyObject *obj = *(PyObject **)addr;
if (obj != NULL) {
- Py_DECREF(obj);
*(PyObject **)addr = NULL;
+ Py_DECREF(obj);
}
}
}
@@ -2236,13 +2236,6 @@
for heaptypes. */
assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE);
-#define CLEAR(SLOT) \
- if (SLOT) { \
- tmp = (PyObject *)(SLOT); \
- SLOT = NULL; \
- Py_DECREF(tmp); \
- }
-
/* The only field we need to clear is tp_mro, which is part of a
hard cycle (its first element is the class itself) that won't
be broken otherwise (it's a tuple and tuples don't have a
@@ -2268,9 +2261,7 @@
A tuple of strings can't be part of a cycle.
*/
- CLEAR(type->tp_mro);
-
-#undef CLEAR
+ Py_CLEAR(type->tp_mro);
return 0;
}
Modified: python/trunk/Python/traceback.c
==============================================================================
--- python/trunk/Python/traceback.c (original)
+++ python/trunk/Python/traceback.c Sat Apr 15 19:28:34 2006
@@ -53,10 +53,8 @@
static void
tb_clear(PyTracebackObject *tb)
{
- Py_XDECREF(tb->tb_next);
- Py_XDECREF(tb->tb_frame);
- tb->tb_next = NULL;
- tb->tb_frame = NULL;
+ Py_CLEAR(tb->tb_next);
+ Py_CLEAR(tb->tb_frame);
}
PyTypeObject PyTraceBack_Type = {
More information about the Python-checkins
mailing list