You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rh...@apache.org on 2014/09/15 22:58:30 UTC

svn commit: r1625162 - in /qpid/proton/trunk: proton-c/bindings/python/cproton.i proton-c/bindings/python/proton.py proton-j/src/main/resources/cobject.py

Author: rhs
Date: Mon Sep 15 20:58:30 2014
New Revision: 1625162

URL: http://svn.apache.org/r1625162
Log:
centralized void/PyObject conversion

Modified:
    qpid/proton/trunk/proton-c/bindings/python/cproton.i
    qpid/proton/trunk/proton-c/bindings/python/proton.py
    qpid/proton/trunk/proton-j/src/main/resources/cobject.py

Modified: qpid/proton/trunk/proton-c/bindings/python/cproton.i
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/python/cproton.i?rev=1625162&r1=1625161&r2=1625162&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/python/cproton.i (original)
+++ qpid/proton/trunk/proton-c/bindings/python/cproton.i Mon Sep 15 20:58:30 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/trunk/proton-c/bindings/python/proton.py
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/python/proton.py?rev=1625162&r1=1625161&r2=1625162&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/python/proton.py (original)
+++ qpid/proton/trunk/proton-c/bindings/python/proton.py Mon Sep 15 20:58:30 2014
@@ -2262,7 +2262,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
@@ -2273,7 +2273,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
@@ -2406,7 +2406,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
@@ -2414,7 +2414,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)
 
@@ -2503,7 +2503,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)
@@ -2514,7 +2514,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)
 
@@ -2881,20 +2881,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."""
@@ -3422,7 +3422,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
@@ -3431,14 +3431,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
 
@@ -3509,7 +3509,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
@@ -3518,13 +3518,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/trunk/proton-j/src/main/resources/cobject.py
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/src/main/resources/cobject.py?rev=1625162&r1=1625161&r2=1625162&view=diff
==============================================================================
--- qpid/proton/trunk/proton-j/src/main/resources/cobject.py (original)
+++ qpid/proton/trunk/proton-j/src/main/resources/cobject.py Mon Sep 15 20:58:30 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-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org