[Zope3-checkins] CVS: Zope3/src/persistence - persistence.c:1.9
Barry Warsaw
barry@wooz.org
Wed, 2 Apr 2003 18:07:01 -0500
Update of /cvs-repository/Zope3/src/persistence
In directory cvs.zope.org:/tmp/cvs-serv27351
Modified Files:
persistence.c
Log Message:
Whitespace normalization <wink>.
Also, fixed a bunch of potential leaks by adding decrefs observed via
6-eye code review.
I think we still need to review PyPersist_New() and
init_persistence().
=== Zope3/src/persistence/persistence.c 1.8 => 1.9 ===
--- Zope3/src/persistence/persistence.c:1.8 Wed Apr 2 16:02:42 2003
+++ Zope3/src/persistence/persistence.c Wed Apr 2 18:07:00 2003
@@ -251,7 +251,7 @@
return 0;
}
func = PyObject_GetAttrString((PyObject *)self, "_p_deactivate");
- if (!func)
+ if (!func)
return 0;
r = PyObject_Call(func, t, NULL);
if (unraisable && !r) {
@@ -346,16 +346,14 @@
static PyObject *
convert_name(PyObject *name)
{
- /* The ifdef block is copied from PyObject_GenericGetAttr. */
#ifdef Py_USING_UNICODE
/* The Unicode to string conversion is done here because the
existing tp_setattro slots expect a string object as name
and we wouldn't want to break those. */
if (PyUnicode_Check(name)) {
name = PyUnicode_AsEncodedString(name, NULL, NULL);
- if (name == NULL)
- return NULL;
- } else
+ }
+ else
#endif
if (!PyString_Check(name)) {
PyErr_SetString(PyExc_TypeError, "attribute name must be a string");
@@ -421,6 +419,7 @@
to print the exception to stderr. It would probably be
better to log it but that would be painful from C.
*/
+ Py_DECREF(name);
if (!call_p_deactivate(self, 1))
return NULL;
self->po_state = GHOST;
@@ -448,8 +447,7 @@
*/
static int
-persist_setattr_prep(PyPersistObject *self, PyObject *name,
- PyObject *value)
+persist_setattr_prep(PyPersistObject *self, PyObject *name, PyObject *value)
{
char *s_name;
@@ -510,17 +508,18 @@
name = convert_name(name);
if (!name)
return -1;
- if (persist_setattr_prep(self, name, value) < 0)
+ if (persist_setattr_prep(self, name, value) < 0) {
+ Py_DECREF(name);
return -1;
-
+ }
r = PyObject_GenericSetAttr((PyObject *)self, name, value);
Py_DECREF(name);
return r;
}
static PyObject *
-persist_p_set_or_delattr(PyPersistObject *self, PyObject *name,
- PyObject *value)
+persist_p_set_or_delattr(PyPersistObject *self, PyObject *name,
+ PyObject *value)
{
PyObject *res;
int r;
@@ -529,8 +528,10 @@
if (!name)
return NULL;
r = persist_setattr_prep(self, name, value);
- if (r < 0)
+ if (r < 0) {
+ Py_DECREF(name);
return NULL;
+ }
else if (r > 0)
res = Py_False;
else {
@@ -539,8 +540,10 @@
*/
res = Py_True;
r = PyObject_GenericSetAttr((PyObject *)self, name, value);
- if (r < 0)
+ if (r < 0) {
+ Py_DECREF(name);
return NULL;
+ }
}
Py_INCREF(res);
Py_DECREF(name);