Commit 4353cffb authored by Jelte Jansen's avatar Jelte Jansen
Browse files

changed our type-specific structs to classes derived from PyObject, so we can...

changed our type-specific structs to classes derived from PyObject, so we can use static_cast instead of interpret_cast


git-svn-id: svn://bind10.isc.org/svn/bind10/experiments/python-binding@2239 e5f2f494-b856-4b98-b285-d166d9295462
parent a2ce4084
......@@ -40,10 +40,10 @@ static PyObject* po_DNSMessageBADVERS;
//
// MessageFlag
//
typedef struct {
PyObject_HEAD
class s_MessageFlag : public PyObject {
public:
const MessageFlag* messageflag;
} s_MessageFlag;
};
static int MessageFlag_init(s_MessageFlag* self, PyObject* args);
static void MessageFlag_destroy(s_MessageFlag* self);
......@@ -156,7 +156,7 @@ MessageFlag_QR(s_MessageFlag* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -169,7 +169,7 @@ MessageFlag_AA(s_MessageFlag* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -182,7 +182,7 @@ MessageFlag_TC(s_MessageFlag* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -195,7 +195,7 @@ MessageFlag_RD(s_MessageFlag* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -208,7 +208,7 @@ MessageFlag_RA(s_MessageFlag* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -221,7 +221,7 @@ MessageFlag_AD(s_MessageFlag* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -234,7 +234,7 @@ MessageFlag_CD(s_MessageFlag* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
//
......@@ -245,10 +245,10 @@ MessageFlag_CD(s_MessageFlag* self UNUSED_PARAM) {
//
// Opcode
//
typedef struct {
PyObject_HEAD
class s_Opcode : public PyObject {
public:
const Opcode* opcode;
} s_Opcode;
};
static int Opcode_init(s_Opcode* self, PyObject* args);
static void Opcode_destroy(s_Opcode* self);
......@@ -394,7 +394,7 @@ Opcode_QUERY(s_Opcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -407,7 +407,7 @@ Opcode_IQUERY(s_Opcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -420,7 +420,7 @@ Opcode_STATUS(s_Opcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -433,7 +433,7 @@ Opcode_RESERVED3(s_Opcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -446,7 +446,7 @@ Opcode_NOTIFY(s_Opcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -459,7 +459,7 @@ Opcode_UPDATE(s_Opcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -472,7 +472,7 @@ Opcode_RESERVED6(s_Opcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -485,7 +485,7 @@ Opcode_RESERVED7(s_Opcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -498,7 +498,7 @@ Opcode_RESERVED8(s_Opcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -511,7 +511,7 @@ Opcode_RESERVED9(s_Opcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -524,7 +524,7 @@ Opcode_RESERVED10(s_Opcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -537,7 +537,7 @@ Opcode_RESERVED11(s_Opcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -550,7 +550,7 @@ Opcode_RESERVED12(s_Opcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -563,7 +563,7 @@ Opcode_RESERVED13(s_Opcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -576,7 +576,7 @@ Opcode_RESERVED14(s_Opcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -589,7 +589,7 @@ Opcode_RESERVED15(s_Opcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -599,7 +599,7 @@ Opcode_richcmp(s_Opcode* self, s_Opcode* other, int op) {
// Check for null and if the types match. If different type,
// simply return False
if (!other ||
(reinterpret_cast<PyObject*>(self))->ob_type != (reinterpret_cast<PyObject*>(other))->ob_type
(static_cast<PyObject*>(self))->ob_type != (static_cast<PyObject*>(other))->ob_type
) {
Py_RETURN_FALSE;
}
......@@ -650,11 +650,11 @@ Opcode_richcmp(s_Opcode* self, s_Opcode* other, int op) {
// case Rcode_destroy should not free it (the other option is to
// allocate new Rcodes for every use of the static ones, but this
// seems more efficient).
typedef struct {
PyObject_HEAD
class s_Rcode : public PyObject {
public:
const Rcode* rcode;
bool static_code;
} s_Rcode;
};
static int Rcode_init(s_Rcode* self, PyObject* args);
static void Rcode_destroy(s_Rcode* self);
......@@ -817,7 +817,7 @@ Rcode_NOERROR(s_Rcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -831,7 +831,7 @@ Rcode_FORMERR(s_Rcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -845,7 +845,7 @@ Rcode_SERVFAIL(s_Rcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -859,7 +859,7 @@ Rcode_NXDOMAIN(s_Rcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -873,7 +873,7 @@ Rcode_NOTIMP(s_Rcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -887,7 +887,7 @@ Rcode_REFUSED(s_Rcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -901,7 +901,7 @@ Rcode_YXDOMAIN(s_Rcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -915,7 +915,7 @@ Rcode_YXRRSET(s_Rcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -929,7 +929,7 @@ Rcode_NXRRSET(s_Rcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -943,7 +943,7 @@ Rcode_NOTAUTH(s_Rcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -957,7 +957,7 @@ Rcode_NOTZONE(s_Rcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -971,7 +971,7 @@ Rcode_RESERVED11(s_Rcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -985,7 +985,7 @@ Rcode_RESERVED12(s_Rcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -999,7 +999,7 @@ Rcode_RESERVED13(s_Rcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -1013,7 +1013,7 @@ Rcode_RESERVED14(s_Rcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -1027,7 +1027,7 @@ Rcode_RESERVED15(s_Rcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -1041,7 +1041,7 @@ Rcode_BADVERS(s_Rcode* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -1051,7 +1051,7 @@ Rcode_richcmp(s_Rcode* self, s_Rcode* other, int op) {
// Check for null and if the types match. If different type,
// simply return False
if (!other ||
(reinterpret_cast<PyObject*>(self))->ob_type != (reinterpret_cast<PyObject*>(other))->ob_type
(static_cast<PyObject*>(self))->ob_type != (static_cast<PyObject*>(other))->ob_type
) {
Py_RETURN_FALSE;
}
......@@ -1098,10 +1098,10 @@ Rcode_richcmp(s_Rcode* self, s_Rcode* other, int op) {
// TODO: iterator?
typedef struct {
PyObject_HEAD
class s_Section : public PyObject {
public:
const Section* section;
} s_Section;
};
static int Section_init(s_Section* self, PyObject* args);
static void Section_destroy(s_Section* self);
......@@ -1209,7 +1209,7 @@ Section_QUESTION(s_Section* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -1222,7 +1222,7 @@ Section_ANSWER(s_Section* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -1235,7 +1235,7 @@ Section_AUTHORITY(s_Section* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -1248,7 +1248,7 @@ Section_ADDITIONAL(s_Section* self UNUSED_PARAM) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -1258,7 +1258,7 @@ Section_richcmp(s_Section* self, s_Section* other, int op) {
// Check for null and if the types match. If different type,
// simply return False
if (!other ||
(reinterpret_cast<PyObject*>(self))->ob_type != (reinterpret_cast<PyObject*>(other))->ob_type
(static_cast<PyObject*>(self))->ob_type != (static_cast<PyObject*>(other))->ob_type
) {
Py_RETURN_FALSE;
}
......@@ -1305,10 +1305,10 @@ Section_richcmp(s_Section* self, s_Section* other, int op) {
//
// The s_* Class simply coverst one instantiation of the object
typedef struct {
PyObject_HEAD
class s_Message : public PyObject {
public:
Message* message;
} s_Message;
};
//
// We declare the functions here, the definitions are below
......@@ -1675,7 +1675,7 @@ static PyObject*
Message_getRcode(s_Message* self) {
s_Rcode* rcode;
rcode = reinterpret_cast<s_Rcode*>(rcode_type.tp_alloc(&rcode_type, 0));
rcode = static_cast<s_Rcode*>(rcode_type.tp_alloc(&rcode_type, 0));
if (rcode != NULL) {
rcode->rcode = new Rcode(self->message->getRcode());
if (rcode->rcode == NULL)
......@@ -1685,7 +1685,7 @@ Message_getRcode(s_Message* self) {
}
}
return reinterpret_cast<PyObject*>(rcode);
return static_cast<PyObject*>(rcode);
}
static PyObject*
......@@ -1702,7 +1702,7 @@ static PyObject*
Message_getOpcode(s_Message* self) {
s_Opcode* opcode;
opcode = reinterpret_cast<s_Opcode*>(opcode_type.tp_alloc(&opcode_type, 0));
opcode = static_cast<s_Opcode*>(opcode_type.tp_alloc(&opcode_type, 0));
if (opcode != NULL) {
// Note that we do not new and delete for opcodes.
// all rcodes point to the statics defined in
......@@ -1715,7 +1715,7 @@ Message_getOpcode(s_Message* self) {
}
}
return reinterpret_cast<PyObject*>(opcode);
return static_cast<PyObject*>(opcode);
}
static PyObject*
......@@ -1745,7 +1745,7 @@ Message_getQuestion(s_Message* self) {
for (QuestionIterator qi = self->message->beginQuestion();
qi != self->message->endQuestion();
++qi) {
s_Question *question = reinterpret_cast<s_Question*>(question_type.tp_alloc(&question_type, 0));
s_Question *question = static_cast<s_Question*>(question_type.tp_alloc(&question_type, 0));
if (question != NULL) {
question->question = *qi;
if (question->question == NULL)
......@@ -1754,7 +1754,7 @@ Message_getQuestion(s_Message* self) {
return NULL;
}
}
PyList_Append(list, reinterpret_cast<PyObject*>(question));
PyList_Append(list, static_cast<PyObject*>(question));
}
return list;
}
......@@ -1771,7 +1771,7 @@ Message_getSection(s_Message* self, PyObject* args) {
rrsi != self->message->endSection(*section->section);
++rrsi) {
s_RRset *rrset = reinterpret_cast<s_RRset*>(rrset_type.tp_alloc(&rrset_type, 0));
s_RRset *rrset = static_cast<s_RRset*>(rrset_type.tp_alloc(&rrset_type, 0));
if (rrset != NULL) {
rrset->rrset = *rrsi;
if (rrset->rrset == NULL)
......@@ -1781,7 +1781,7 @@ Message_getSection(s_Message* self, PyObject* args) {
return NULL;
}
}
PyList_Append(list, reinterpret_cast<PyObject*>(rrset));
PyList_Append(list, static_cast<PyObject*>(rrset));
// PyList_Append increases refcount, so we remove ours since
// we don't need it anymore
Py_DECREF(rrset);
......
......@@ -26,11 +26,11 @@ using namespace isc::dns;
// since we don't use *Buffer in the python version (but work with
// the already existing bytearray type where we use these custom buffers
// in c++, we need to keep track of one here.
typedef struct {
PyObject_HEAD
class s_MessageRenderer : public PyObject {
public:
OutputBuffer* outputbuffer;
MessageRenderer* messagerenderer;
} s_MessageRenderer;
};
static int MessageRenderer_init(s_MessageRenderer* self);
static void MessageRenderer_destroy(s_MessageRenderer* self);
......
......@@ -49,10 +49,10 @@ static PyObject* po_NameRelation;
using namespace isc::dns;
// NameComparisonResult
typedef struct {
PyObject_HEAD
class s_NameComparisonResult : public PyObject {
public:
isc::dns::NameComparisonResult* ncr;
} s_NameComparisonResult;
};
static int NameComparisonResult_init(s_NameComparisonResult* self UNUSED_PARAM, PyObject* args UNUSED_PARAM);
static void NameComparisonResult_destroy(s_NameComparisonResult* self);
......@@ -164,11 +164,11 @@ NameComparisonResult_getRelation(s_NameComparisonResult* self) {
// Name
typedef struct {
PyObject_HEAD
class s_Name : public PyObject {
public:
isc::dns::Name* name;
size_t position;
} s_Name;
};
static int Name_init(s_Name* self, PyObject* args);
static void Name_destroy(s_Name* self);
......@@ -450,7 +450,7 @@ Name_compare(s_Name* self, PyObject* args) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -502,7 +502,7 @@ Name_split(s_Name* self, PyObject* args) {
}
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
#include <iostream>
......@@ -513,8 +513,8 @@ Name_richcmp(s_Name* n1, s_Name* n2, int op) {
// Check for null and if the types match. If different type,
// simply return False
if (!n2 ||
(reinterpret_cast<PyObject*>(n1))->ob_type !=
(reinterpret_cast<PyObject*>(n2))->ob_type
(static_cast<PyObject*>(n1))->ob_type !=
(static_cast<PyObject*>(n2))->ob_type
) {
Py_RETURN_FALSE;
}
......@@ -559,7 +559,7 @@ Name_reverse(s_Name* self) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
......@@ -582,14 +582,14 @@ Name_concatenate(s_Name* self, PyObject* args) {
return NULL;
}
}
return reinterpret_cast<PyObject*>(ret);
return static_cast<PyObject*>(ret);
}
static PyObject*
Name_downcase(s_Name* self) {
self->name->downcase();
Py_INCREF(self);
return reinterpret_cast<PyObject*>(self);
return static_cast<PyObject*>(self);
}