From 03bd7fbc50232177bd1dc1d39a202cf11931e5dd Mon Sep 17 00:00:00 2001 From: Vincent Castellano Date: Wed, 20 May 2015 15:16:16 -0700 Subject: [PATCH] Added error handling to failed calls to get peer. --- python-types.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/python-types.c b/python-types.c index db2df62..2092e5f 100644 --- a/python-types.c +++ b/python-types.c @@ -588,7 +588,14 @@ tgl_Msg_getsrc (tgl_Msg *self, void *closure) PyObject *ret; if(tgl_get_peer_type (self->msg->from_id)) { - ret = tgl_Peer_FromTglPeer(tgl_peer_get (TLS, self->msg->from_id)); + tgl_peer_t *peer = tgl_peer_get (TLS, self->msg->from_id); + if(peer) + ret = tgl_Peer_FromTglPeer(peer); + else { + PyErr_SetString(PeerError, "Cannot Retrieve Peer. Internal tgl error"); + Py_RETURN_NONE; + } + } else { Py_RETURN_NONE; } @@ -603,7 +610,13 @@ tgl_Msg_getdest (tgl_Msg *self, void *closure) PyObject *ret; if(tgl_get_peer_type (self->msg->to_id)) { - ret = tgl_Peer_FromTglPeer(tgl_peer_get (TLS, self->msg->to_id)); + tgl_peer_t *peer = tgl_peer_get (TLS, self->msg->to_id); + if(peer) + ret = tgl_Peer_FromTglPeer(peer); + else { + PyErr_SetString(PeerError, "Cannot Retrieve Peer. Internal tgl error"); + Py_RETURN_NONE; + } } else { Py_RETURN_NONE; } @@ -709,7 +722,13 @@ tgl_Msg_getfwd_src (tgl_Msg *self, void *closure) PyObject *ret; if(tgl_get_peer_type (self->msg->fwd_from_id)) { - ret = tgl_Peer_FromTglPeer(tgl_peer_get (TLS, self->msg->fwd_from_id)); + tgl_peer_t *peer = tgl_peer_get (TLS, self->msg->fwd_from_id); + if(peer) + ret = tgl_Peer_FromTglPeer(peer); + else { + PyErr_SetString(PeerError, "Cannot Retrieve Peer. Internal tgl error"); + Py_RETURN_NONE; + } } else { Py_RETURN_NONE; }