BIND 10 #317: suggested cleanups for the python bindings of libdns++

BIND 10 Development do-not-reply at isc.org
Tue Aug 24 23:30:19 UTC 2010


#317: suggested cleanups for the python bindings of libdns++
--------------------------------+-------------------------------------------
      Reporter:  jinmei         |        Owner:  jinmei              
          Type:  enhancement    |       Status:  new                 
      Priority:  minor          |    Milestone:  y2 6 month milestone
     Component:  DNSPacket API  |   Resolution:                      
      Keywords:                 |    Sensitive:  0                   
Estimatedhours:  0.0            |        Hours:  0                   
      Billable:  1              |   Totalhours:  0                   
      Internal:  0              |  
--------------------------------+-------------------------------------------

Comment(by jinmei):

 One more point, raised on jabber.

 There seems to be exception unsafe code.  e.g. See Message_getRcode:

 {{{
     rcode = static_cast<s_Rcode*>(rcode_type.tp_alloc(&rcode_type, 0));
     if (rcode != NULL) {
         rcode->rcode = new Rcode(self->message->getRcode());
     [...]
 }}}

 If this 'new Rcode' fails memory allocated for rcode will leak.  Also, the
 C++ bad_alloc exception will be propagated to the python code.  Even
 though there's not much that can be done anyway if it's really memory
 exhaustion, it's generaly better to hide C++ exception within the wrapper
 layer.

 I sugget we use no-throw new in the wrapper code, and explicitly check if
 the return value is NULL:

 {{{
     rcode_body = new(nothrow) Rcode(self->message->getRcode());
     if (rcode_body == NULL) {
         return (PyErr_NoMemory());
     }
     rcode = static_cast<s_Rcode*>(rcode_type.tp_alloc(&rcode_type, 0));
     if (rcode != NULL) {
         rcode->rcode = rcode_body;
     [...]
 }}}

 Another approach is to wrap the new attmpt with try-catch, but in this
 case I don't see much advantage by catching the exception because it won't
 make the code simpler (it may even look more complicated)

-- 
Ticket URL: <http://bind10.isc.org/ticket/317#comment:2>
BIND 10 Development <http://bind10.isc.org>
BIND 10 Development


More information about the bind10-tickets mailing list