BIND 10 trac2853, updated. 3a874c84baf65289d49be69c041b8340c946617a [2853] Make code safer by using RAII container
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Jun 14 10:34:15 UTC 2013
The branch, trac2853 has been updated
via 3a874c84baf65289d49be69c041b8340c946617a (commit)
from 7775ce49e0e07406db6d7dc158b7c01060aa93dd (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 3a874c84baf65289d49be69c041b8340c946617a
Author: Mukund Sivaraman <muks at isc.org>
Date: Fri Jun 14 16:03:26 2013 +0530
[2853] Make code safer by using RAII container
Also check for SEGMENT_UNUSED directly and return None for the segment
type in that case.
-----------------------------------------------------------------------
Summary of changes:
.../isc/datasrc/configurableclientlist_python.cc | 44 ++++++++------------
1 file changed, 17 insertions(+), 27 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/python/isc/datasrc/configurableclientlist_python.cc b/src/lib/python/isc/datasrc/configurableclientlist_python.cc
index bcb2b9f..7adbb3d 100644
--- a/src/lib/python/isc/datasrc/configurableclientlist_python.cc
+++ b/src/lib/python/isc/datasrc/configurableclientlist_python.cc
@@ -204,39 +204,29 @@ ConfigurableClientList_getStatus(PyObject* po_self, PyObject*) {
try {
const std::vector<DataSourceStatus> status = self->cppobj->getStatus();
- PyObject* slist = PyList_New(status.size());
- if (!slist) {
- return (NULL);
- }
+ PyObjectContainer slist(PyList_New(status.size()));
for (size_t i = 0; i < status.size(); ++i) {
- PyObject* segment_type = NULL;
- try {
- segment_type = Py_BuildValue(
- "s", status[i].getSegmentType().c_str());
- } catch (const isc::InvalidOperation&) {
- Py_INCREF(Py_None);
- segment_type = Py_None;
- }
+ PyObjectContainer segment_type;
- // Py_BuildValue() is a C function and will not throw.
- PyObject* tup = Py_BuildValue("(sOI)",
- status[i].getName().c_str(),
- segment_type,
- status[i].getSegmentState());
- if (segment_type) {
- // The Py_BuildValue() above increments its refcount,
- // so we drop our reference.
- Py_DECREF(segment_type);
- }
- if (!tup) {
- Py_DECREF(slist);
- return (NULL);
+ if (status[i].getSegmentState() != SEGMENT_UNUSED) {
+ segment_type.reset(Py_BuildValue(
+ "s", status[i].getSegmentType().c_str()));
+ } else {
+ Py_INCREF(Py_None);
+ segment_type.reset(Py_None);
}
- PyList_SET_ITEM(slist, i, tup);
+
+ PyObjectContainer tup(Py_BuildValue("(sOI)",
+ status[i].getName().c_str(),
+ segment_type.get(),
+ status[i].getSegmentState()));
+ // The following "steals" our reference on tup, so we must
+ // not decref.
+ PyList_SET_ITEM(slist.get(), i, tup.release());
}
- return (slist);
+ return (slist.release());
} catch (const std::exception& exc) {
PyErr_SetString(getDataSourceException("Error"), exc.what());
return (NULL);
More information about the bind10-changes
mailing list