Commit f58095d1 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

parenthesized return statements

also removed the now unnecessary static_casts


git-svn-id: svn://bind10.isc.org/svn/bind10/experiments/python-binding@2265 e5f2f494-b856-4b98-b285-d166d9295462
parent e6406c76
......@@ -76,7 +76,7 @@ PyMODINIT_FUNC
PyInit_libdns_python(void) {
PyObject *mod = PyModule_Create(&libdns_python);
if (mod == NULL) {
return NULL;
return (NULL);
}
po_IscException = PyErr_NewException("libdns_python.IscException", NULL, NULL);
......@@ -85,41 +85,41 @@ PyInit_libdns_python(void) {
// for each part included above, we call its specific initializer
if (!initModulePart_Name(mod)) {
return NULL;
return (NULL);
}
if (!initModulePart_MessageRenderer(mod)) {
return NULL;
return (NULL);
}
if (!initModulePart_RRClass(mod)) {
return NULL;
return (NULL);
}
if (!initModulePart_RRType(mod)) {
return NULL;
return (NULL);
}
if (!initModulePart_RRTTL(mod)) {
return NULL;
return (NULL);
}
if (!initModulePart_Rdata(mod)) {
return NULL;
return (NULL);
}
if (!initModulePart_RRset(mod)) {
return NULL;
return (NULL);
}
if (!initModulePart_Question(mod)) {
return NULL;
return (NULL);
}
if (!initModulePart_Message(mod)) {
return NULL;
return (NULL);
}
return mod;
return (mod);
}
......@@ -25,24 +25,24 @@ readDataFromSequence(uint8_t *data, size_t len, PyObject* sequence) {
if (!el) {
PyErr_SetString(PyExc_TypeError,
"sequence too short");
return -1;
return (-1);
}
if (PyLong_Check(el)) {
long l = PyLong_AsLong(el);
if (l < 0 || l > 255) {
PyErr_SetString(PyExc_TypeError,
"number in fromWire sequence not between 0 and 255");
return -1;
return (-1);
}
data[i] = static_cast<uint8_t>(PyLong_AsLong(el));
} else {
PyErr_SetString(PyExc_TypeError,
"not a number in fromWire sequence");
return -1;
return (-1);
}
}
PySequence_DelSlice(sequence, 0, len);
return 0;
return (0);
}
......
This diff is collapsed.
......@@ -119,7 +119,7 @@ static int
MessageRenderer_init(s_MessageRenderer* self) {
self->outputbuffer = new OutputBuffer(4096);
self->messagerenderer = new MessageRenderer(*self->outputbuffer);
return 0;
return (0);
}
static void
......@@ -140,7 +140,7 @@ MessageRenderer_getData(s_MessageRenderer* self) {
static PyObject*
MessageRenderer_getLength(s_MessageRenderer* self) {
return Py_BuildValue("I", self->messagerenderer->getLength());
return (Py_BuildValue("I", self->messagerenderer->getLength()));
}
static PyObject*
......@@ -154,7 +154,7 @@ MessageRenderer_isTruncated(s_MessageRenderer* self) {
static PyObject*
MessageRenderer_getLengthLimit(s_MessageRenderer* self) {
return Py_BuildValue("I", self->messagerenderer->getLengthLimit());
return (Py_BuildValue("I", self->messagerenderer->getLengthLimit()));
}
static PyObject*
......@@ -169,7 +169,7 @@ MessageRenderer_setLengthLimit(s_MessageRenderer* self,
{
size_t lengthlimit;
if (!PyArg_ParseTuple(args, "I", &lengthlimit)) {
return NULL;
return (NULL);
}
self->messagerenderer->setLengthLimit(lengthlimit);
Py_RETURN_NONE;
......@@ -193,13 +193,13 @@ initModulePart_MessageRenderer(PyObject* mod) {
// NameComparisonResult
if (PyType_Ready(&messagerenderer_type) < 0) {
return false;
return (false);
}
Py_INCREF(&messagerenderer_type);
PyModule_AddObject(mod, "MessageRenderer",
reinterpret_cast<PyObject*>(&messagerenderer_type));
return true;
return (true);
}
......@@ -128,7 +128,7 @@ NameComparisonResult_init(s_NameComparisonResult* self UNUSED_PARAM,
{
PyErr_SetString(PyExc_NotImplementedError,
"NameComparisonResult can't be built directly");
return -1;
return (-1);
}
static void
......@@ -140,17 +140,17 @@ NameComparisonResult_destroy(s_NameComparisonResult* self) {
static PyObject*
NameComparisonResult_getOrder(s_NameComparisonResult* self) {
return Py_BuildValue("i", self->ncr->getOrder());
return (Py_BuildValue("i", self->ncr->getOrder()));
}
static PyObject*
NameComparisonResult_getCommonLabels(s_NameComparisonResult* self) {
return Py_BuildValue("I", self->ncr->getCommonLabels());
return (Py_BuildValue("I", self->ncr->getCommonLabels()));
}
static PyObject*
NameComparisonResult_getRelation(s_NameComparisonResult* self) {
return Py_BuildValue("I", self->ncr->getRelation());
return (Py_BuildValue("I", self->ncr->getRelation()));
}
// end of NameComparisonResult
......@@ -293,32 +293,32 @@ Name_init(s_Name* self, PyObject* args) {
self->position = 0;
} catch (EmptyLabel) {
PyErr_SetString(po_EmptyLabel, "EmptyLabel");
return -1;
return (-1);
} catch (TooLongLabel) {
PyErr_SetString(po_TooLongLabel, "TooLongLabel");
return -1;
return (-1);
} catch (BadLabelType) {
PyErr_SetString(po_BadLabelType, "BadLabelType");
return -1;
return (-1);
} catch (BadEscape) {
PyErr_SetString(po_BadEscape, "BadEscape");
return -1;
return (-1);
} catch (TooLongName) {
PyErr_SetString(po_TooLongName, "TooLongName");
return -1;
return (-1);
} catch (IncompleteName) {
PyErr_SetString(po_IncompleteName, "IncompleteName");
return -1;
return (-1);
#ifdef CATCHMEMERR
} catch (std::bad_alloc) {
PyErr_NoMemory();
return -1;
return (-1);
#endif
} catch (...) {
PyErr_SetString(po_IscException, "Unexpected?!");
return -1;
return (-1);
}
return 0;
return (0);
}
PyErr_Clear();
......@@ -341,21 +341,21 @@ Name_init(s_Name* self, PyObject* args) {
} catch (InvalidBufferPosition) {
PyErr_SetString(po_InvalidBufferPosition,
"InvalidBufferPosition");
return -1;
return (-1);
} catch (DNSMessageFORMERR) {
PyErr_SetString(po_DNSMessageFORMERR, "DNSMessageFORMERR");
return -1;
return (-1);
} catch (...) {
PyErr_SetString(po_IscException, "Unexpected?!");
return -1;
return (-1);
}
return 0;
return (0);
}
PyErr_Clear();
PyErr_SetString(PyExc_TypeError,
"No valid types in Name constructor (should be string or sequence and offset");
return -1;
return (-1);
}
static void
......@@ -369,30 +369,30 @@ static PyObject*
Name_at(s_Name* self, PyObject* args) {
size_t pos;
if (!PyArg_ParseTuple(args, "i", &pos)) {
return NULL;
return (NULL);
}
try {
return Py_BuildValue("i", self->name->at(pos));
return (Py_BuildValue("i", self->name->at(pos)));
} catch (isc::OutOfRange oor) {
PyErr_SetString(PyExc_IndexError,
"name index out of range");
return NULL;
return (NULL);
}
}
static PyObject*
Name_getLength(s_Name* self) {
return Py_BuildValue("i", self->name->getLength());
return (Py_BuildValue("i", self->name->getLength()));
}
static PyObject*
Name_getLabelCount(s_Name* self) {
return Py_BuildValue("i", self->name->getLabelCount());
return (Py_BuildValue("i", self->name->getLabelCount()));
}
static PyObject*
Name_toText(s_Name* self) {
return Py_BuildValue("s", self->name->toText().c_str());
return (Py_BuildValue("s", self->name->toText().c_str()));
}
static PyObject*
......@@ -420,7 +420,7 @@ Name_toWire(s_Name* self, PyObject* args) {
// We need to release the object we temporarily created here
// to prevent memory leak
Py_DECREF(name_bytes);
return result;
return (result);
} else if (PyArg_ParseTuple(args, "O!", &messagerenderer_type, (PyObject**) &mr)) {
self->name->toWire(*mr->messagerenderer);
// If we return NULL it is seen as an error, so use this for
......@@ -430,7 +430,7 @@ Name_toWire(s_Name* self, PyObject* args) {
PyErr_Clear();
PyErr_SetString(PyExc_TypeError,
"toWire argument must be a sequence object or a MessageRenderer");
return NULL;
return (NULL);
}
static PyObject*
......@@ -438,14 +438,14 @@ Name_compare(s_Name* self, PyObject* args) {
s_Name* other;
if (!PyArg_ParseTuple(args, "O!", &name_type, (PyObject* *) &other))
return NULL;
return (NULL);
s_NameComparisonResult* ret = PyObject_New(s_NameComparisonResult, &name_comparison_result_type);
if (ret != NULL) {
ret->ncr = new NameComparisonResult(
self->name->compare(*other->name));
}
return static_cast<PyObject*>(ret);
return (ret);
}
static PyObject*
......@@ -453,7 +453,7 @@ Name_equals(s_Name* self, PyObject* args) {
s_Name* other;
if (!PyArg_ParseTuple(args, "O!", &name_type, (PyObject* *) &other))
return NULL;
return (NULL);
if (self->name->equals(*other->name))
Py_RETURN_TRUE;
......@@ -478,7 +478,7 @@ Name_split(s_Name* self, PyObject* args) {
}
if (ret->name == NULL) {
Py_DECREF(ret);
return NULL;
return (NULL);
}
}
} else if (PyArg_ParseTuple(args, "I", &n)) {
......@@ -493,11 +493,11 @@ Name_split(s_Name* self, PyObject* args) {
}
if (ret->name == NULL) {
Py_DECREF(ret);
return NULL;
return (NULL);
}
}
}
return static_cast<PyObject*>(ret);
return (ret);
}
#include <iostream>
......@@ -538,7 +538,7 @@ Name_richcmp(s_Name* self, s_Name* other, int op) {
default:
PyErr_SetString(PyExc_IndexError,
"Unhandled rich comparison operator");
return NULL;
return (NULL);
}
if (c) {
Py_RETURN_TRUE;
......@@ -555,10 +555,10 @@ Name_reverse(s_Name* self) {
ret->name = new Name(self->name->reverse());
if (ret->name == NULL) {
Py_DECREF(ret);
return NULL;
return (NULL);
}
}
return static_cast<PyObject*>(ret);
return (ret);
}
static PyObject*
......@@ -566,7 +566,7 @@ Name_concatenate(s_Name* self, PyObject* args) {
s_Name* other;
if (!PyArg_ParseTuple(args, "O!", &name_type, (PyObject**) &other))
return NULL;
return (NULL);
s_Name* ret = PyObject_New(s_Name, &name_type);
if (ret != NULL) {
......@@ -574,17 +574,17 @@ Name_concatenate(s_Name* self, PyObject* args) {
ret->name = new Name(self->name->concatenate(*other->name));
} catch (isc::dns::TooLongName tln) {
PyErr_SetString(po_TooLongName, tln.what());
return NULL;
return (NULL);
}
}
return static_cast<PyObject*>(ret);
return (ret);
}
static PyObject*
Name_downcase(s_Name* self) {
self->name->downcase();
Py_INCREF(self);
return static_cast<PyObject*>(self);
return (self);
}
static PyObject*
......@@ -609,7 +609,7 @@ initModulePart_Name(PyObject* mod) {
// NameComparisonResult
//
if (PyType_Ready(&name_comparison_result_type) < 0) {
return false;
return (false);
}
Py_INCREF(&name_comparison_result_type);
......@@ -629,7 +629,7 @@ initModulePart_Name(PyObject* mod) {
//
if (PyType_Ready(&name_type) < 0) {
return false;
return (false);
}
Py_INCREF(&name_type);
......@@ -643,7 +643,7 @@ initModulePart_Name(PyObject* mod) {
s_Name* root_name = PyObject_New(s_Name, &name_type);
root_name->name = new Name(".");
PyObject* po_ROOT_NAME = static_cast<PyObject*>(root_name);
PyObject* po_ROOT_NAME = root_name;
Py_INCREF(po_ROOT_NAME);
addClassVariable(name_type, "ROOT_NAME", po_ROOT_NAME);
......@@ -678,5 +678,5 @@ initModulePart_Name(PyObject* mod) {
po_DNSMessageFORMERR = PyErr_NewException("libdns_python.DNSMessageFORMERR", NULL, NULL);
PyModule_AddObject(mod, "DNSMessageFORMERR", po_DNSMessageFORMERR);
return true;
return (true);
}
......@@ -148,26 +148,26 @@ Question_init(s_Question* self, PyObject* args) {
)) {
self->question = QuestionPtr(new Question(*name->name, *rrclass->rrclass,
*rrtype->rrtype));
return 0;
return (0);
} else if (PyArg_ParseTuple(args, "y#|I", &b, &len, &position)) {
PyErr_Clear();
InputBuffer inbuf(b, len);
inbuf.setPosition(position);
self->question = QuestionPtr(new Question(inbuf));
return 0;
return (0);
}
} catch (isc::dns::DNSMessageFORMERR dmfe) {
PyErr_Clear();
PyErr_SetString(po_DNSMessageFORMERR, dmfe.what());
return -1;
return (-1);
} catch (isc::dns::IncompleteRRClass irc) {
PyErr_Clear();
PyErr_SetString(po_IncompleteRRClass, irc.what());
return -1;
return (-1);
} catch (isc::dns::IncompleteRRType irt) {
PyErr_Clear();
PyErr_SetString(po_IncompleteRRType, irt.what());
return -1;
return (-1);
}
self->question = QuestionPtr();
......@@ -175,7 +175,7 @@ Question_init(s_Question* self, PyObject* args) {
PyErr_Clear();
PyErr_SetString(PyExc_TypeError,
"no valid type in constructor argument");
return -1;
return (-1);
}
static void
......@@ -194,7 +194,7 @@ Question_getName(s_Question* self) {
name->name = new Name(self->question->getName());
}
return static_cast<PyObject*>(name);
return (name);
}
static PyObject*
......@@ -206,7 +206,7 @@ Question_getType(s_Question* self) {
rrtype->rrtype = new RRType(self->question->getType());
}
return static_cast<PyObject*>(rrtype);
return (rrtype);
}
static PyObject*
......@@ -218,14 +218,14 @@ Question_getClass(s_Question* self) {
rrclass->rrclass = new RRClass(self->question->getClass());
}
return static_cast<PyObject*>(rrclass);
return (rrclass);
}
static PyObject*
Question_toText(s_Question* self) {
// Py_BuildValue makes python objects from native data
return Py_BuildValue("s", self->question->toText().c_str());
return (Py_BuildValue("s", self->question->toText().c_str()));
}
static PyObject*
......@@ -253,7 +253,7 @@ Question_toWire(s_Question* self, PyObject* args) {
// We need to release the object we temporarily created here
// to prevent memory leak
Py_DECREF(n);
return result;
return (result);
} else if (PyArg_ParseTuple(args, "O!", &messagerenderer_type,
reinterpret_cast<PyObject**>(&mr))) {
self->question->toWire(*mr->messagerenderer);
......@@ -264,7 +264,7 @@ Question_toWire(s_Question* self, PyObject* args) {
PyErr_Clear();
PyErr_SetString(PyExc_TypeError,
"toWire argument must be a sequence object or a MessageRenderer");
return NULL;
return (NULL);
}
// end of Question
......@@ -279,11 +279,11 @@ initModulePart_Question(PyObject* mod) {
// then add it to the module. This is not just a check! (leaving
// this out results in segmentation faults)
if (PyType_Ready(&question_type) < 0) {
return false;
return (false);
}
Py_INCREF(&question_type);
PyModule_AddObject(mod, "Question",
reinterpret_cast<PyObject*>(&question_type));
return true;
return (true);
}
......@@ -151,10 +151,10 @@ Rdata_init(s_Rdata* self, PyObject* args) {
&rrclass_type, &rrclass,
&s)) {
self->rdata = createRdata(*rrtype->rrtype, *rrclass->rrclass, s);
return 0;
return (0);
}
return -1;
return (-1);
}
static void
......@@ -168,7 +168,7 @@ Rdata_destroy(s_Rdata* self) {
static PyObject*
Rdata_toText(s_Rdata* self) {
// Py_BuildValue makes python objects from native data
return Py_BuildValue("s", self->rdata->toText().c_str());
return (Py_BuildValue("s", self->rdata->toText().c_str()));
}
static PyObject*
......@@ -194,7 +194,7 @@ Rdata_toWire(s_Rdata* self, PyObject* args) {
// We need to release the object we temporarily created here
// to prevent memory leak
Py_DECREF(rd_bytes);
return result;
return (result);
} else if (PyArg_ParseTuple(args, "O!", &messagerenderer_type, (PyObject**) &mr)) {
self->rdata->toWire(*mr->messagerenderer);
// If we return NULL it is seen as an error, so use this for
......@@ -204,7 +204,7 @@ Rdata_toWire(s_Rdata* self, PyObject* args) {
PyErr_Clear();
PyErr_SetString(PyExc_TypeError,
"toWire argument must be a sequence object or a MessageRenderer");
return NULL;
return (NULL);
}
......@@ -243,7 +243,7 @@ RData_richcmp(s_Rdata* self, s_Rdata* other, int op) {
default:
PyErr_SetString(PyExc_IndexError,
"Unhandled rich comparison operator");
return NULL;
return (NULL);
}
if (c)
Py_RETURN_TRUE;
......@@ -260,7 +260,7 @@ initModulePart_Rdata(PyObject* mod) {
// then add it to the module. This is not just a check! (leaving
// this out results in segmentation faults)
if (PyType_Ready(&rdata_type) < 0) {
return false;
return (false);
}
Py_INCREF(&rdata_type);
PyModule_AddObject(mod, "Rdata",
......@@ -277,5 +277,5 @@ initModulePart_Rdata(PyObject* mod) {
PyModule_AddObject(mod, "CharStringTooLong", po_CharStringTooLong);
return true;
return (true);
}
......@@ -166,37 +166,37 @@ RRClass_init(s_RRClass* self, PyObject* args) {
try {
if (PyArg_ParseTuple(args, "s", &s)) {
self->rrclass = new RRClass(s);
return 0;
return (0);
} else if (PyArg_ParseTuple(args, "I", &i)) {
PyErr_Clear();
if (i > 65535) {
PyErr_SetString(po_InvalidRRClass, "Class number too high");
return -1;
return (-1);
}
self->rrclass = new RRClass(i);
return 0;
return (0);
} else if (PyArg_ParseTuple(args, "O", &bytes) && PySequence_Check(bytes)) {
uint8_t data[2];
int result = readDataFromSequence(data, 2, bytes);
if (result != 0) {
return result;
return (result);
}
InputBuffer ib(data, 2);
self->rrclass = new RRClass(ib);
PyErr_Clear();