Author: gsim Date: Fri Oct 10 12:51:26 2014 New Revision: 1630818 URL: http://svn.apache.org/r1630818 Log: centralized void/PyObject conversion
Modified: qpid/proton/branches/examples/proton-c/bindings/python/cproton.i qpid/proton/branches/examples/proton-c/bindings/python/proton.py qpid/proton/branches/examples/proton-j/src/main/resources/cobject.py Modified: qpid/proton/branches/examples/proton-c/bindings/python/cproton.i URL: http://svn.apache.org/viewvc/qpid/proton/branches/examples/proton-c/bindings/python/cproton.i?rev=1630818&r1=1630817&r2=1630818&view=diff ============================================================================== --- qpid/proton/branches/examples/proton-c/bindings/python/cproton.i (original) +++ qpid/proton/branches/examples/proton-c/bindings/python/cproton.i Fri Oct 10 12:51:26 2014 @@ -184,154 +184,6 @@ ssize_t pn_transport_push(pn_transport_t %} %ignore pn_message_data; -%rename(pn_listener_set_context) wrap_pn_listener_set_context; -%inline { - void wrap_pn_listener_set_context(pn_listener_t *l, PyObject *context) { - // don't incref context: we 'borrow' the reference - prevents - // reference loops. Should be safe as the Python object must - // outlive the C object. - pn_listener_set_context(l, context); - } -} -%ignore pn_listener_set_context; - -%rename(pn_listener_context) wrap_pn_listener_context; -%inline { - PyObject *wrap_pn_listener_context(pn_listener_t *l) { - PyObject *result = (PyObject *) pn_listener_context(l); - // incref the returned context, as the caller expects this - if (result) { - Py_INCREF(result); - return result; - } else { - Py_RETURN_NONE; - } - } -} -%ignore pn_listener_context; - -%rename(pn_connector_set_context) wrap_pn_connector_set_context; -%inline { - void wrap_pn_connector_set_context(pn_connector_t *c, PyObject *context) { - // don't incref context: we 'borrow' the reference - prevents - // reference loops. Should be safe as the Python object must - // outlive the C object. - pn_connector_set_context(c, context); - } -} -%ignore pn_connector_set_context; - -%rename(pn_connector_context) wrap_pn_connector_context; -%inline { - PyObject *wrap_pn_connector_context(pn_connector_t *c) { - PyObject *result = (PyObject *) pn_connector_context(c); - // incref the returned context, as the caller expects this - if (result) { - Py_INCREF(result); - return result; - } else { - Py_RETURN_NONE; - } - } -} -%ignore pn_connector_context; - -%rename(pn_connection_get_context) wrap_pn_connection_get_context; -%inline { - PyObject *wrap_pn_connection_get_context(pn_connection_t *c) { - PyObject *result = (PyObject *) pn_connection_get_context(c); - // incref the returned context, as the caller expects this - if (result) { - Py_INCREF(result); - return result; - } else { - Py_RETURN_NONE; - } - } -} -%ignore pn_connection_get_context; - -%rename(pn_connection_set_context) wrap_pn_connection_set_context; -%inline { - void wrap_pn_connection_set_context(pn_connection_t *c, PyObject *context) { - // don't incref context: we 'borrow' the reference - pn_connection_set_context(c, context); - } -} -%ignore pn_connection_set_context; - -%rename(pn_session_get_context) wrap_pn_session_get_context; -%inline { - PyObject *wrap_pn_session_get_context(pn_session_t *s) { - PyObject *result = (PyObject *) pn_session_get_context(s); - // incref the returned context, as the caller expects this - if (result) { - Py_INCREF(result); - return result; - } else { - Py_RETURN_NONE; - } - } -} -%ignore pn_session_get_context; - -%rename(pn_session_set_context) wrap_pn_session_set_context; -%inline { - void wrap_pn_session_set_context(pn_session_t *s, PyObject *context) { - // don't incref context: we 'borrow' the reference - pn_session_set_context(s, context); - } -} -%ignore pn_session_set_context; - -%rename(pn_link_get_context) wrap_pn_link_get_context; -%inline { - PyObject *wrap_pn_link_get_context(pn_link_t *l) { - PyObject *result = (PyObject *) pn_link_get_context(l); - // incref the returned context, as the caller expects this - if (result) { - Py_INCREF(result); - return result; - } else { - Py_RETURN_NONE; - } - } -} -%ignore pn_link_get_context; - -%rename(pn_link_set_context) wrap_pn_link_set_context; -%inline { - void wrap_pn_link_set_context(pn_link_t *l, PyObject *context) { - // don't incref context: we 'borrow' the reference - pn_link_set_context(l, context); - } -} -%ignore pn_link_set_context; - -%rename(pn_delivery_get_context) wrap_pn_delivery_get_context; -%inline { - PyObject *wrap_pn_delivery_get_context(pn_delivery_t *d) { - PyObject *result = (PyObject *) pn_delivery_get_context(d); - // incref the returned context, as the caller expects this - if (result) { - Py_INCREF(result); - return result; - } else { - Py_RETURN_NONE; - } - } -} -%ignore pn_delivery_get_context; - -%rename(pn_delivery_set_context) wrap_pn_delivery_set_context; -%inline { - void wrap_pn_delivery_set_context(pn_delivery_t *d, PyObject *context) { - // don't incref context: we 'borrow' the reference - pn_delivery_set_context(d, context); - } -} -%ignore pn_delivery_set_context; - ssize_t pn_data_decode(pn_data_t *data, char *STRING, size_t LENGTH); %ignore pn_data_decode; Modified: qpid/proton/branches/examples/proton-c/bindings/python/proton.py URL: http://svn.apache.org/viewvc/qpid/proton/branches/examples/proton-c/bindings/python/proton.py?rev=1630818&r1=1630817&r2=1630818&view=diff ============================================================================== --- qpid/proton/branches/examples/proton-c/bindings/python/proton.py (original) +++ qpid/proton/branches/examples/proton-c/bindings/python/proton.py Fri Oct 10 12:51:26 2014 @@ -2265,7 +2265,7 @@ class Connection(Endpoint): reference to the python instance in the context field of the C object. """ if not c_conn: return None - py_conn = pn_connection_get_context(c_conn) + py_conn = pn_void2py(pn_connection_get_context(c_conn)) if py_conn: return py_conn wrapper = Connection(_conn=c_conn) return wrapper @@ -2276,7 +2276,7 @@ class Connection(Endpoint): self._conn = _conn else: self._conn = pn_connection() - pn_connection_set_context(self._conn, self) + pn_connection_set_context(self._conn, pn_py2void(self)) self.offered_capabilities = None self.desired_capabilities = None self.properties = None @@ -2409,7 +2409,7 @@ class Session(Endpoint): exists in the C Engine. """ if c_ssn is None: return None - py_ssn = pn_session_get_context(c_ssn) + py_ssn = pn_void2py(pn_session_get_context(c_ssn)) if py_ssn: return py_ssn wrapper = Session(c_ssn) return wrapper @@ -2417,7 +2417,7 @@ class Session(Endpoint): def __init__(self, ssn): Endpoint.__init__(self) self._ssn = ssn - pn_session_set_context(self._ssn, self) + pn_session_set_context(self._ssn, pn_py2void(self)) self._links = set() self.connection._sessions.add(self) @@ -2506,7 +2506,7 @@ class Link(Endpoint): exists in the C Engine. """ if c_link is None: return None - py_link = pn_link_get_context(c_link) + py_link = pn_void2py(pn_link_get_context(c_link)) if py_link: return py_link if pn_link_is_sender(c_link): wrapper = Sender(c_link) @@ -2517,7 +2517,7 @@ class Link(Endpoint): def __init__(self, c_link): Endpoint.__init__(self) self._link = c_link - pn_link_set_context(self._link, self) + pn_link_set_context(self._link, pn_py2void(self)) self._deliveries = set() self.session._links.add(self) @@ -2884,20 +2884,20 @@ class Delivery(object): exists in the C Engine. """ if not c_dlv: return None - py_dlv = pn_delivery_get_context(c_dlv) + py_dlv = pn_void2py(pn_delivery_get_context(c_dlv)) if py_dlv: return py_dlv wrapper = Delivery(c_dlv) return wrapper def __init__(self, dlv): self._dlv = dlv - pn_delivery_set_context(self._dlv, self) + pn_delivery_set_context(self._dlv, pn_py2void(self)) self.local = Disposition(pn_delivery_local(self._dlv), True) self.remote = Disposition(pn_delivery_remote(self._dlv), False) self.link._deliveries.add(self) def __del__(self): - pn_delivery_set_context(self._dlv, None) + pn_delivery_set_context(self._dlv, pn_py2void(None)) def _release(self): """Release the underlying C Engine resource.""" @@ -3425,7 +3425,7 @@ class Connector(object): exists in the C Driver. """ if not c_cxtr: return None - py_cxtr = pn_connector_context(c_cxtr) + py_cxtr = pn_void2py(pn_connector_context(c_cxtr)) if py_cxtr: return py_cxtr wrapper = Connector(_cxtr=c_cxtr, _py_driver=py_driver) return wrapper @@ -3434,14 +3434,14 @@ class Connector(object): self._cxtr = _cxtr assert(_py_driver) self._driver = weakref.ref(_py_driver) - pn_connector_set_context(self._cxtr, self) + pn_connector_set_context(self._cxtr, pn_py2void(self)) self._connection = None self._driver()._connectors.add(self) def _release(self): """Release the underlying C Engine resource.""" if self._cxtr: - pn_connector_set_context(self._cxtr, None) + pn_connector_set_context(self._cxtr, pn_py2void(None)) pn_connector_free(self._cxtr) self._cxtr = None @@ -3512,7 +3512,7 @@ class Listener(object): exists in the C Driver. """ if not c_lsnr: return None - py_lsnr = pn_listener_context(c_lsnr) + py_lsnr = pn_void2py(pn_listener_context(c_lsnr)) if py_lsnr: return py_lsnr wrapper = Listener(_lsnr=c_lsnr, _py_driver=py_driver) return wrapper @@ -3521,13 +3521,13 @@ class Listener(object): self._lsnr = _lsnr assert(_py_driver) self._driver = weakref.ref(_py_driver) - pn_listener_set_context(self._lsnr, self) + pn_listener_set_context(self._lsnr, pn_py2void(self)) self._driver()._listeners.add(self) def _release(self): """Release the underlying C Engine resource.""" if self._lsnr: - pn_listener_set_context(self._lsnr, None); + pn_listener_set_context(self._lsnr, pn_py2void(None)); pn_listener_free(self._lsnr) self._lsnr = None Modified: qpid/proton/branches/examples/proton-j/src/main/resources/cobject.py URL: http://svn.apache.org/viewvc/qpid/proton/branches/examples/proton-j/src/main/resources/cobject.py?rev=1630818&r1=1630817&r2=1630818&view=diff ============================================================================== --- qpid/proton/branches/examples/proton-j/src/main/resources/cobject.py (original) +++ qpid/proton/branches/examples/proton-j/src/main/resources/cobject.py Fri Oct 10 12:51:26 2014 @@ -23,6 +23,9 @@ def pn_class_name(cls): def pn_void2py(obj): return obj +def pn_py2void(obj): + return obj + def pn_cast_pn_connection(obj): return obj --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org