Browse Source

last of the cpp review comments: factoring out common code in creation of statics, added a few explanatory comments

git-svn-id: svn://bind10.isc.org/svn/bind10/experiments/python-binding@2259 e5f2f494-b856-4b98-b285-d166d9295462
Jelte Jansen 15 years ago
parent
commit
60da6a175e

+ 63 - 372
src/lib/dns/python/message_python.cc

@@ -144,94 +144,47 @@ MessageFlag_getBit(s_MessageFlag* self) {
 }
 }
 
 
 static PyObject*
 static PyObject*
-MessageFlag_QR(s_MessageFlag* self UNUSED_PARAM) {
+MessageFlag_createStatic(const MessageFlag& flag) {
     s_MessageFlag* ret = PyObject_New(s_MessageFlag, &messageflag_type);
     s_MessageFlag* ret = PyObject_New(s_MessageFlag, &messageflag_type);
     if (ret != NULL) {
     if (ret != NULL) {
-        ret->messageflag = &MessageFlag::QR();
-        if (ret->messageflag == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
+        ret->messageflag = &flag;
     }
     }
-    return static_cast<PyObject*>(ret);
+    return (ret);
+}
+
+static PyObject*
+MessageFlag_QR(s_MessageFlag* self UNUSED_PARAM) {
+    return MessageFlag_createStatic(MessageFlag::QR());
 }
 }
 
 
 static PyObject*
 static PyObject*
 MessageFlag_AA(s_MessageFlag* self UNUSED_PARAM) {
 MessageFlag_AA(s_MessageFlag* self UNUSED_PARAM) {
-    s_MessageFlag* ret = PyObject_New(s_MessageFlag, &messageflag_type);
-    if (ret != NULL) {
-        ret->messageflag = &MessageFlag::AA();
-        if (ret->messageflag == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return MessageFlag_createStatic(MessageFlag::AA());
 }
 }
 
 
 static PyObject*
 static PyObject*
 MessageFlag_TC(s_MessageFlag* self UNUSED_PARAM) {
 MessageFlag_TC(s_MessageFlag* self UNUSED_PARAM) {
-    s_MessageFlag* ret = PyObject_New(s_MessageFlag, &messageflag_type);
-    if (ret != NULL) {
-        ret->messageflag = &MessageFlag::TC();
-        if (ret->messageflag == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return MessageFlag_createStatic(MessageFlag::TC());
 }
 }
 
 
 static PyObject*
 static PyObject*
 MessageFlag_RD(s_MessageFlag* self UNUSED_PARAM) {
 MessageFlag_RD(s_MessageFlag* self UNUSED_PARAM) {
-    s_MessageFlag* ret = PyObject_New(s_MessageFlag, &messageflag_type);
-    if (ret != NULL) {
-        ret->messageflag = &MessageFlag::RD();
-        if (ret->messageflag == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return MessageFlag_createStatic(MessageFlag::RD());
 }
 }
 
 
 static PyObject*
 static PyObject*
 MessageFlag_RA(s_MessageFlag* self UNUSED_PARAM) {
 MessageFlag_RA(s_MessageFlag* self UNUSED_PARAM) {
-    s_MessageFlag* ret = PyObject_New(s_MessageFlag, &messageflag_type);
-    if (ret != NULL) {
-        ret->messageflag = &MessageFlag::RA();
-        if (ret->messageflag == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return MessageFlag_createStatic(MessageFlag::RA());
 }
 }
 
 
 static PyObject*
 static PyObject*
 MessageFlag_AD(s_MessageFlag* self UNUSED_PARAM) {
 MessageFlag_AD(s_MessageFlag* self UNUSED_PARAM) {
-    s_MessageFlag* ret = PyObject_New(s_MessageFlag, &messageflag_type);
-    if (ret != NULL) {
-        ret->messageflag = &MessageFlag::AD();
-        if (ret->messageflag == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return MessageFlag_createStatic(MessageFlag::AD());
 }
 }
 
 
 static PyObject*
 static PyObject*
 MessageFlag_CD(s_MessageFlag* self UNUSED_PARAM) {
 MessageFlag_CD(s_MessageFlag* self UNUSED_PARAM) {
-    s_MessageFlag* ret = PyObject_New(s_MessageFlag, &messageflag_type);
-    if (ret != NULL) {
-        ret->messageflag = &MessageFlag::CD();
-        if (ret->messageflag == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return MessageFlag_createStatic(MessageFlag::CD());
 }
 }
 
 
 //
 //
@@ -379,211 +332,92 @@ Opcode_str(PyObject* self) {
 }
 }
 
 
 static PyObject*
 static PyObject*
-Opcode_QUERY(s_Opcode* self UNUSED_PARAM) {
+Opcode_createStatic(const Opcode& opcode) {
     s_Opcode* ret = PyObject_New(s_Opcode, &opcode_type);
     s_Opcode* ret = PyObject_New(s_Opcode, &opcode_type);
     if (ret != NULL) {
     if (ret != NULL) {
-        ret->opcode = &Opcode::QUERY();
-        if (ret->opcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
+        ret->opcode = &opcode;
     }
     }
-    return static_cast<PyObject*>(ret);
+    return (ret);
+}
+
+static PyObject*
+Opcode_QUERY(s_Opcode* self UNUSED_PARAM) {
+    return Opcode_createStatic(Opcode::QUERY());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Opcode_IQUERY(s_Opcode* self UNUSED_PARAM) {
 Opcode_IQUERY(s_Opcode* self UNUSED_PARAM) {
-    s_Opcode* ret = PyObject_New(s_Opcode, &opcode_type);
-    if (ret != NULL) {
-        ret->opcode = &Opcode::IQUERY();
-        if (ret->opcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Opcode_createStatic(Opcode::IQUERY());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Opcode_STATUS(s_Opcode* self UNUSED_PARAM) {
 Opcode_STATUS(s_Opcode* self UNUSED_PARAM) {
-    s_Opcode* ret = PyObject_New(s_Opcode, &opcode_type);
-    if (ret != NULL) {
-        ret->opcode = &Opcode::STATUS();
-        if (ret->opcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Opcode_createStatic(Opcode::STATUS());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Opcode_RESERVED3(s_Opcode* self UNUSED_PARAM) {
 Opcode_RESERVED3(s_Opcode* self UNUSED_PARAM) {
-    s_Opcode* ret = PyObject_New(s_Opcode, &opcode_type);
-    if (ret != NULL) {
-        ret->opcode = &Opcode::RESERVED3();
-        if (ret->opcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Opcode_createStatic(Opcode::RESERVED3());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Opcode_NOTIFY(s_Opcode* self UNUSED_PARAM) {
 Opcode_NOTIFY(s_Opcode* self UNUSED_PARAM) {
-    s_Opcode* ret = PyObject_New(s_Opcode, &opcode_type);
-    if (ret != NULL) {
-        ret->opcode = &Opcode::NOTIFY();
-        if (ret->opcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Opcode_createStatic(Opcode::NOTIFY());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Opcode_UPDATE(s_Opcode* self UNUSED_PARAM) {
 Opcode_UPDATE(s_Opcode* self UNUSED_PARAM) {
-    s_Opcode* ret = PyObject_New(s_Opcode, &opcode_type);
-    if (ret != NULL) {
-        ret->opcode = &Opcode::UPDATE();
-        if (ret->opcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Opcode_createStatic(Opcode::UPDATE());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Opcode_RESERVED6(s_Opcode* self UNUSED_PARAM) {
 Opcode_RESERVED6(s_Opcode* self UNUSED_PARAM) {
-    s_Opcode* ret = PyObject_New(s_Opcode, &opcode_type);
-    if (ret != NULL) {
-        ret->opcode = &Opcode::RESERVED6();
-        if (ret->opcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Opcode_createStatic(Opcode::RESERVED6());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Opcode_RESERVED7(s_Opcode* self UNUSED_PARAM) {
 Opcode_RESERVED7(s_Opcode* self UNUSED_PARAM) {
-    s_Opcode* ret = PyObject_New(s_Opcode, &opcode_type);
-    if (ret != NULL) {
-        ret->opcode = &Opcode::RESERVED7();
-        if (ret->opcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Opcode_createStatic(Opcode::RESERVED7());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Opcode_RESERVED8(s_Opcode* self UNUSED_PARAM) {
 Opcode_RESERVED8(s_Opcode* self UNUSED_PARAM) {
-    s_Opcode* ret = PyObject_New(s_Opcode, &opcode_type);
-    if (ret != NULL) {
-        ret->opcode = &Opcode::RESERVED8();
-        if (ret->opcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Opcode_createStatic(Opcode::RESERVED8());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Opcode_RESERVED9(s_Opcode* self UNUSED_PARAM) {
 Opcode_RESERVED9(s_Opcode* self UNUSED_PARAM) {
-    s_Opcode* ret = PyObject_New(s_Opcode, &opcode_type);
-    if (ret != NULL) {
-        ret->opcode = &Opcode::RESERVED9();
-        if (ret->opcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Opcode_createStatic(Opcode::RESERVED9());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Opcode_RESERVED10(s_Opcode* self UNUSED_PARAM) {
 Opcode_RESERVED10(s_Opcode* self UNUSED_PARAM) {
-    s_Opcode* ret = PyObject_New(s_Opcode, &opcode_type);
-    if (ret != NULL) {
-        ret->opcode = &Opcode::RESERVED10();
-        if (ret->opcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Opcode_createStatic(Opcode::RESERVED10());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Opcode_RESERVED11(s_Opcode* self UNUSED_PARAM) {
 Opcode_RESERVED11(s_Opcode* self UNUSED_PARAM) {
-    s_Opcode* ret = PyObject_New(s_Opcode, &opcode_type);
-    if (ret != NULL) {
-        ret->opcode = &Opcode::RESERVED11();
-        if (ret->opcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Opcode_createStatic(Opcode::RESERVED11());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Opcode_RESERVED12(s_Opcode* self UNUSED_PARAM) {
 Opcode_RESERVED12(s_Opcode* self UNUSED_PARAM) {
-    s_Opcode* ret = PyObject_New(s_Opcode, &opcode_type);
-    if (ret != NULL) {
-        ret->opcode = &Opcode::RESERVED12();
-        if (ret->opcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Opcode_createStatic(Opcode::RESERVED12());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Opcode_RESERVED13(s_Opcode* self UNUSED_PARAM) {
 Opcode_RESERVED13(s_Opcode* self UNUSED_PARAM) {
-    s_Opcode* ret = PyObject_New(s_Opcode, &opcode_type);
-    if (ret != NULL) {
-        ret->opcode = &Opcode::RESERVED13();
-        if (ret->opcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Opcode_createStatic(Opcode::RESERVED13());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Opcode_RESERVED14(s_Opcode* self UNUSED_PARAM) {
 Opcode_RESERVED14(s_Opcode* self UNUSED_PARAM) {
-    s_Opcode* ret = PyObject_New(s_Opcode, &opcode_type);
-    if (ret != NULL) {
-        ret->opcode = &Opcode::RESERVED14();
-        if (ret->opcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Opcode_createStatic(Opcode::RESERVED14());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Opcode_RESERVED15(s_Opcode* self UNUSED_PARAM) {
 Opcode_RESERVED15(s_Opcode* self UNUSED_PARAM) {
-    s_Opcode* ret = PyObject_New(s_Opcode, &opcode_type);
-    if (ret != NULL) {
-        ret->opcode = &Opcode::RESERVED15();
-        if (ret->opcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Opcode_createStatic(Opcode::RESERVED15());
 }
 }
 
 
 static PyObject* 
 static PyObject* 
@@ -768,8 +602,8 @@ Rcode_init(s_Rcode* self UNUSED_PARAM, PyObject* args UNUSED_PARAM) {
 
 
 static void
 static void
 Rcode_destroy(s_Rcode* self) {
 Rcode_destroy(s_Rcode* self) {
-    // We only use the consts from Rcode, so don't
-    // delete self->rcode here
+    // Depending on whether we created the rcode or are referring
+    // to a global static one, we do or do not delete self->rcode here
     if (!self->static_code) {
     if (!self->static_code) {
         delete self->rcode;
         delete self->rcode;
     }
     }
@@ -796,241 +630,98 @@ Rcode_str(PyObject* self) {
 }
 }
 
 
 static PyObject*
 static PyObject*
-Rcode_NOERROR(s_Rcode* self UNUSED_PARAM) {
+Rcode_createStatic(const Rcode& rcode) {
     s_Rcode* ret = PyObject_New(s_Rcode, &rcode_type);
     s_Rcode* ret = PyObject_New(s_Rcode, &rcode_type);
     if (ret != NULL) {
     if (ret != NULL) {
-        ret->rcode = &Rcode::NOERROR();
+        ret->rcode = &rcode;
         ret->static_code = true;
         ret->static_code = true;
-        if (ret->rcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
     }
     }
-    return static_cast<PyObject*>(ret);
+    return (ret);
+}
+
+static PyObject*
+Rcode_NOERROR(s_Rcode* self UNUSED_PARAM) {
+    return Rcode_createStatic(Rcode::NOERROR());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Rcode_FORMERR(s_Rcode* self UNUSED_PARAM) {
 Rcode_FORMERR(s_Rcode* self UNUSED_PARAM) {
-    s_Rcode* ret = PyObject_New(s_Rcode, &rcode_type);
-    if (ret != NULL) {
-        ret->rcode = &Rcode::FORMERR();
-        ret->static_code = true;
-        if (ret->rcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Rcode_createStatic(Rcode::FORMERR());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Rcode_SERVFAIL(s_Rcode* self UNUSED_PARAM) {
 Rcode_SERVFAIL(s_Rcode* self UNUSED_PARAM) {
-    s_Rcode* ret = PyObject_New(s_Rcode, &rcode_type);
-    if (ret != NULL) {
-        ret->rcode = &Rcode::SERVFAIL();
-        ret->static_code = true;
-        if (ret->rcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Rcode_createStatic(Rcode::SERVFAIL());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Rcode_NXDOMAIN(s_Rcode* self UNUSED_PARAM) {
 Rcode_NXDOMAIN(s_Rcode* self UNUSED_PARAM) {
-    s_Rcode* ret = PyObject_New(s_Rcode, &rcode_type);
-    if (ret != NULL) {
-        ret->rcode = &Rcode::NXDOMAIN();
-        ret->static_code = true;
-        if (ret->rcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Rcode_createStatic(Rcode::NXDOMAIN());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Rcode_NOTIMP(s_Rcode* self UNUSED_PARAM) {
 Rcode_NOTIMP(s_Rcode* self UNUSED_PARAM) {
-    s_Rcode* ret = PyObject_New(s_Rcode, &rcode_type);
-    if (ret != NULL) {
-        ret->rcode = &Rcode::NOTIMP();
-        ret->static_code = true;
-        if (ret->rcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Rcode_createStatic(Rcode::NOTIMP());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Rcode_REFUSED(s_Rcode* self UNUSED_PARAM) {
 Rcode_REFUSED(s_Rcode* self UNUSED_PARAM) {
-    s_Rcode* ret = PyObject_New(s_Rcode, &rcode_type);
-    if (ret != NULL) {
-        ret->rcode = &Rcode::REFUSED();
-        ret->static_code = true;
-        if (ret->rcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Rcode_createStatic(Rcode::REFUSED());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Rcode_YXDOMAIN(s_Rcode* self UNUSED_PARAM) {
 Rcode_YXDOMAIN(s_Rcode* self UNUSED_PARAM) {
-    s_Rcode* ret = PyObject_New(s_Rcode, &rcode_type);
-    if (ret != NULL) {
-        ret->rcode = &Rcode::YXDOMAIN();
-        ret->static_code = true;
-        if (ret->rcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Rcode_createStatic(Rcode::YXDOMAIN());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Rcode_YXRRSET(s_Rcode* self UNUSED_PARAM) {
 Rcode_YXRRSET(s_Rcode* self UNUSED_PARAM) {
-    s_Rcode* ret = PyObject_New(s_Rcode, &rcode_type);
-    if (ret != NULL) {
-        ret->rcode = &Rcode::YXRRSET();
-        ret->static_code = true;
-        if (ret->rcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Rcode_createStatic(Rcode::YXRRSET());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Rcode_NXRRSET(s_Rcode* self UNUSED_PARAM) {
 Rcode_NXRRSET(s_Rcode* self UNUSED_PARAM) {
-    s_Rcode* ret = PyObject_New(s_Rcode, &rcode_type);
-    if (ret != NULL) {
-        ret->rcode = &Rcode::NXRRSET();
-        ret->static_code = true;
-        if (ret->rcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Rcode_createStatic(Rcode::NXRRSET());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Rcode_NOTAUTH(s_Rcode* self UNUSED_PARAM) {
 Rcode_NOTAUTH(s_Rcode* self UNUSED_PARAM) {
-    s_Rcode* ret = PyObject_New(s_Rcode, &rcode_type);
-    if (ret != NULL) {
-        ret->rcode = &Rcode::NOTAUTH();
-        ret->static_code = true;
-        if (ret->rcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Rcode_createStatic(Rcode::NOTAUTH());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Rcode_NOTZONE(s_Rcode* self UNUSED_PARAM) {
 Rcode_NOTZONE(s_Rcode* self UNUSED_PARAM) {
-    s_Rcode* ret = PyObject_New(s_Rcode, &rcode_type);
-    if (ret != NULL) {
-        ret->rcode = &Rcode::NOTZONE();
-        ret->static_code = true;
-        if (ret->rcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Rcode_createStatic(Rcode::NOTZONE());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Rcode_RESERVED11(s_Rcode* self UNUSED_PARAM) {
 Rcode_RESERVED11(s_Rcode* self UNUSED_PARAM) {
-    s_Rcode* ret = PyObject_New(s_Rcode, &rcode_type);
-    if (ret != NULL) {
-        ret->rcode = &Rcode::RESERVED11();
-        ret->static_code = true;
-        if (ret->rcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Rcode_createStatic(Rcode::RESERVED11());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Rcode_RESERVED12(s_Rcode* self UNUSED_PARAM) {
 Rcode_RESERVED12(s_Rcode* self UNUSED_PARAM) {
-    s_Rcode* ret = PyObject_New(s_Rcode, &rcode_type);
-    if (ret != NULL) {
-        ret->rcode = &Rcode::RESERVED12();
-        ret->static_code = true;
-        if (ret->rcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Rcode_createStatic(Rcode::RESERVED12());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Rcode_RESERVED13(s_Rcode* self UNUSED_PARAM) {
 Rcode_RESERVED13(s_Rcode* self UNUSED_PARAM) {
-    s_Rcode* ret = PyObject_New(s_Rcode, &rcode_type);
-    if (ret != NULL) {
-        ret->rcode = &Rcode::RESERVED13();
-        ret->static_code = true;
-        if (ret->rcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Rcode_createStatic(Rcode::RESERVED13());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Rcode_RESERVED14(s_Rcode* self UNUSED_PARAM) {
 Rcode_RESERVED14(s_Rcode* self UNUSED_PARAM) {
-    s_Rcode* ret = PyObject_New(s_Rcode, &rcode_type);
-    if (ret != NULL) {
-        ret->rcode = &Rcode::RESERVED14();
-        ret->static_code = true;
-        if (ret->rcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Rcode_createStatic(Rcode::RESERVED14());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Rcode_RESERVED15(s_Rcode* self UNUSED_PARAM) {
 Rcode_RESERVED15(s_Rcode* self UNUSED_PARAM) {
-    s_Rcode* ret = PyObject_New(s_Rcode, &rcode_type);
-    if (ret != NULL) {
-        ret->rcode = &Rcode::RESERVED15();
-        ret->static_code = true;
-        if (ret->rcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Rcode_createStatic(Rcode::RESERVED15());
 }
 }
 
 
 static PyObject*
 static PyObject*
 Rcode_BADVERS(s_Rcode* self UNUSED_PARAM) {
 Rcode_BADVERS(s_Rcode* self UNUSED_PARAM) {
-    s_Rcode* ret = PyObject_New(s_Rcode, &rcode_type);
-    if (ret != NULL) {
-        ret->rcode = &Rcode::BADVERS();
-        ret->static_code = true;
-        if (ret->rcode == NULL) {
-            Py_DECREF(ret);
-            return NULL;
-        }
-    }
-    return static_cast<PyObject*>(ret);
+    return Rcode_createStatic(Rcode::BADVERS());
 }
 }
 
 
 static PyObject* 
 static PyObject* 

+ 5 - 20
src/lib/dns/python/question_python.cc

@@ -127,9 +127,8 @@ static PyTypeObject question_type = {
 
 
 static int
 static int
 Question_init(s_Question* self, PyObject* args) {
 Question_init(s_Question* self, PyObject* args) {
-    // The constructor argument can be a string ("IN"), an integer (1),
-    // or a sequence of numbers between 0 and 255 (wire code)
-
+    // Try out the various combinations of arguments to call the
+    // correct cpp constructor.
     // Note that PyArg_ParseType can set PyError, and we need to clear
     // Note that PyArg_ParseType can set PyError, and we need to clear
     // that if we try several like here. Otherwise the *next* python
     // that if we try several like here. Otherwise the *next* python
     // call will suddenly appear to throw an exception.
     // call will suddenly appear to throw an exception.
@@ -193,11 +192,6 @@ Question_getName(s_Question* self) {
     name = static_cast<s_Name*>(name_type.tp_alloc(&name_type, 0));
     name = static_cast<s_Name*>(name_type.tp_alloc(&name_type, 0));
     if (name != NULL) {
     if (name != NULL) {
         name->name = new Name(self->question->getName());
         name->name = new Name(self->question->getName());
-        if (name->name == NULL)
-          {
-            Py_DECREF(name);
-            return NULL;
-          }
     }
     }
 
 
     return static_cast<PyObject*>(name);
     return static_cast<PyObject*>(name);
@@ -210,11 +204,6 @@ Question_getType(s_Question* self) {
     rrtype = static_cast<s_RRType*>(rrtype_type.tp_alloc(&rrtype_type, 0));
     rrtype = static_cast<s_RRType*>(rrtype_type.tp_alloc(&rrtype_type, 0));
     if (rrtype != NULL) {
     if (rrtype != NULL) {
         rrtype->rrtype = new RRType(self->question->getType());
         rrtype->rrtype = new RRType(self->question->getType());
-        if (rrtype->rrtype == NULL)
-          {
-            Py_DECREF(rrtype);
-            return NULL;
-          }
     }
     }
 
 
     return static_cast<PyObject*>(rrtype);
     return static_cast<PyObject*>(rrtype);
@@ -227,11 +216,6 @@ Question_getClass(s_Question* self) {
     rrclass = static_cast<s_RRClass*>(rrclass_type.tp_alloc(&rrclass_type, 0));
     rrclass = static_cast<s_RRClass*>(rrclass_type.tp_alloc(&rrclass_type, 0));
     if (rrclass != NULL) {
     if (rrclass != NULL) {
         rrclass->rrclass = new RRClass(self->question->getClass());
         rrclass->rrclass = new RRClass(self->question->getClass());
-        if (rrclass->rrclass == NULL)
-          {
-            Py_DECREF(rrclass);
-            return NULL;
-          }
     }
     }
 
 
     return static_cast<PyObject*>(rrclass);
     return static_cast<PyObject*>(rrclass);
@@ -259,8 +243,9 @@ Question_toWire(s_Question* self, PyObject* args) {
     
     
     if (PyArg_ParseTuple(args, "O", &bytes) && PySequence_Check(bytes)) {
     if (PyArg_ParseTuple(args, "O", &bytes) && PySequence_Check(bytes)) {
         PyObject* bytes_o = bytes;
         PyObject* bytes_o = bytes;
-        
-        OutputBuffer buffer(255);
+
+        // Max length is Name::MAX_WIRE + rrclass (2) + rrtype (2)
+        OutputBuffer buffer(Name::MAX_WIRE + 4);
         self->question->toWire(buffer);
         self->question->toWire(buffer);
         PyObject* n = PyBytes_FromStringAndSize((const char*) buffer.getData(),
         PyObject* n = PyBytes_FromStringAndSize((const char*) buffer.getData(),
                                                 buffer.getLength());
                                                 buffer.getLength());

+ 11 - 8
src/lib/dns/python/rdata_python.cc

@@ -40,6 +40,12 @@ static PyObject* po_CharStringTooLong;
 //
 //
 
 
 // The s_* Class simply coverst one instantiation of the object
 // The s_* Class simply coverst one instantiation of the object
+
+// Using a shared_ptr here should not really be necessary (PyObject
+// is already reference-counted), however internally on the cpp side,
+// not doing so might result in problems, since we can't copy construct
+// rdata field, adding them to rrsets results in a problem when the
+// rrset is destroyed later
 class s_Rdata : public PyObject {
 class s_Rdata : public PyObject {
 public:
 public:
     RdataPtr rdata;
     RdataPtr rdata;
@@ -143,9 +149,7 @@ Rdata_init(s_Rdata* self, PyObject* args) {
     
     
     if (PyArg_ParseTuple(args, "O!O!s", &rrtype_type, &rrtype,
     if (PyArg_ParseTuple(args, "O!O!s", &rrtype_type, &rrtype,
                                         &rrclass_type, &rrclass,
                                         &rrclass_type, &rrclass,
-                                        &s, &s
-       )) {
-        const std::string str(s);
+                                        &s)) {
         self->rdata = createRdata(*rrtype->rrtype, *rrclass->rrclass, s);
         self->rdata = createRdata(*rrtype->rrtype, *rrclass->rrclass, s);
         return 0;
         return 0;
     }
     }
@@ -183,13 +187,13 @@ Rdata_toWire(s_Rdata* self, PyObject* args) {
     if (PyArg_ParseTuple(args, "O", &bytes) && PySequence_Check(bytes)) {
     if (PyArg_ParseTuple(args, "O", &bytes) && PySequence_Check(bytes)) {
         PyObject* bytes_o = bytes;
         PyObject* bytes_o = bytes;
         
         
-        OutputBuffer buffer(2);
+        OutputBuffer buffer(4);
         self->rdata->toWire(buffer);
         self->rdata->toWire(buffer);
-        PyObject* n = PyBytes_FromStringAndSize((const char*) buffer.getData(), buffer.getLength());
-        PyObject* result = PySequence_InPlaceConcat(bytes_o, n);
+        PyObject* rd_bytes = PyBytes_FromStringAndSize((const char*) buffer.getData(), buffer.getLength());
+        PyObject* result = PySequence_InPlaceConcat(bytes_o, rd_bytes);
         // We need to release the object we temporarily created here
         // We need to release the object we temporarily created here
         // to prevent memory leak
         // to prevent memory leak
-        Py_DECREF(n);
+        Py_DECREF(rd_bytes);
         return result;
         return result;
     } else if (PyArg_ParseTuple(args, "O!", &messagerenderer_type, (PyObject**) &mr)) {
     } else if (PyArg_ParseTuple(args, "O!", &messagerenderer_type, (PyObject**) &mr)) {
         self->rdata->toWire(*mr->messagerenderer);
         self->rdata->toWire(*mr->messagerenderer);
@@ -249,7 +253,6 @@ RData_richcmp(s_Rdata* self, s_Rdata* other, int op) {
 // end of Rdata
 // end of Rdata
 
 
 
 
-
 // Module Initialization, all statics are initialized here
 // Module Initialization, all statics are initialized here
 bool
 bool
 initModulePart_Rdata(PyObject* mod) {
 initModulePart_Rdata(PyObject* mod) {

+ 6 - 0
src/lib/dns/python/rrset_python.cc

@@ -33,6 +33,12 @@ static PyObject* po_EmptyRRset;
 using namespace isc::dns;
 using namespace isc::dns;
 
 
 // RRset
 // RRset
+
+// Using a shared_ptr here should not really be necessary (PyObject
+// is already reference-counted), however internally on the cpp side,
+// not doing so might result in problems, since we can't copy construct
+// rrsets, adding them to messages results in a problem when the
+// message is destroyed or cleared later
 class s_RRset : public PyObject {
 class s_RRset : public PyObject {
 public:
 public:
     RRsetPtr rrset;
     RRsetPtr rrset;