[svn] commit: r1847 - in /experiments/python-binding/src/lib/dns/python: message_python.cc question_python.cc rdata_python.cc rrset_python.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue May 18 09:50:05 UTC 2010
Author: jelte
Date: Tue May 18 09:50:04 2010
New Revision: 1847
Log:
some incref/memory issues
made s_Question also use a shared_ptr
Modified:
experiments/python-binding/src/lib/dns/python/message_python.cc
experiments/python-binding/src/lib/dns/python/question_python.cc
experiments/python-binding/src/lib/dns/python/rdata_python.cc
experiments/python-binding/src/lib/dns/python/rrset_python.cc
Modified: experiments/python-binding/src/lib/dns/python/message_python.cc
==============================================================================
--- experiments/python-binding/src/lib/dns/python/message_python.cc (original)
+++ experiments/python-binding/src/lib/dns/python/message_python.cc Tue May 18 09:50:04 2010
@@ -1490,10 +1490,8 @@
PyErr_Clear();
if (i == Message::PARSE) {
self->message = new Message(Message::PARSE);
- Py_INCREF(self);
return 0;
} else if (i == Message::RENDER) {
- Py_INCREF(self);
self->message = new Message(Message::RENDER);
return 0;
} else {
@@ -1711,7 +1709,7 @@
++qi) {
s_Question *question = (s_Question*)question_type.tp_alloc(&question_type, 0);
if (question != NULL) {
- question->question = new Question(*qi->get());
+ question->question = *qi;
if (question->question == NULL)
{
Py_DECREF(question);
@@ -1768,10 +1766,8 @@
return NULL;
}
- Py_INCREF(question);
- QuestionPtr question_ptr = QuestionPtr(question->question);
- self->message->addQuestion(question_ptr);
-
+ self->message->addQuestion(question->question);
+
Py_RETURN_NONE;
}
@@ -1786,7 +1782,6 @@
&PyBool_Type, &sign)) {
return NULL;
}
- Py_INCREF(rrset);
if (sign == Py_True) {
self->message->addRRset(*section->section, rrset->rrset, true);
Modified: experiments/python-binding/src/lib/dns/python/question_python.cc
==============================================================================
--- experiments/python-binding/src/lib/dns/python/question_python.cc (original)
+++ experiments/python-binding/src/lib/dns/python/question_python.cc Tue May 18 09:50:04 2010
@@ -38,7 +38,7 @@
// The s_* Class simply coverst one instantiation of the object
typedef struct {
PyObject_HEAD
- Question* question;
+ QuestionPtr question;
} s_Question;
//
@@ -153,14 +153,14 @@
&rrclass_type, &rrclass,
&rrtype_type, &rrtype
)) {
- self->question = new Question(*name->name, *rrclass->rrclass,
- *rrtype->rrtype);
+ self->question = QuestionPtr(new Question(*name->name, *rrclass->rrclass,
+ *rrtype->rrtype));
return 0;
} else if (PyArg_ParseTuple(args, "y#|I", &b, &len, &position)) {
PyErr_Clear();
InputBuffer inbuf(b, len);
inbuf.setPosition(position);
- self->question = new Question(inbuf);
+ self->question = QuestionPtr(new Question(inbuf));
return 0;
}
} catch (isc::dns::DNSMessageFORMERR dmfe) {
@@ -177,7 +177,7 @@
return -1;
}
- self->question = NULL;
+ self->question = QuestionPtr();
PyErr_Clear();
PyErr_SetString(PyExc_TypeError,
@@ -188,9 +188,7 @@
static void
Question_destroy(s_Question* self)
{
- if (self->question != NULL)
- delete self->question;
- self->question = NULL;
+ self->question.reset();
Py_TYPE(self)->tp_free(self);
}
Modified: experiments/python-binding/src/lib/dns/python/rdata_python.cc
==============================================================================
--- experiments/python-binding/src/lib/dns/python/rdata_python.cc (original)
+++ experiments/python-binding/src/lib/dns/python/rdata_python.cc Tue May 18 09:50:04 2010
@@ -150,6 +150,9 @@
static void
Rdata_destroy(s_Rdata* self)
{
+ // Clear the shared_ptr so that its reference count is zero
+ // before we call tp_free() (there is no direct release())
+ self->rdata.reset();
Py_TYPE(self)->tp_free(self);
}
Modified: experiments/python-binding/src/lib/dns/python/rrset_python.cc
==============================================================================
--- experiments/python-binding/src/lib/dns/python/rrset_python.cc (original)
+++ experiments/python-binding/src/lib/dns/python/rrset_python.cc Tue May 18 09:50:04 2010
@@ -150,7 +150,6 @@
&rrtype_type, &rrtype,
&rrttl_type, &rrttl
)) {
- Py_INCREF(self);
self->rrset = RRsetPtr(new RRset(*name->name, *rrclass->rrclass,
*rrtype->rrtype, *rrttl->rrttl));
return 0;
@@ -163,6 +162,9 @@
static void
RRset_destroy(s_RRset* self)
{
+ // Clear the shared_ptr so that its reference count is zero
+ // before we call tp_free() (there is no direct release())
+ self->rrset.reset();
Py_TYPE(self)->tp_free(self);
}
More information about the bind10-changes
mailing list