Author: gsim Date: Fri Oct 10 12:53:38 2014 New Revision: 1630824 URL: http://svn.apache.org/r1630824 Log: fixed refcounting bug for posting python objects to a collector
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-c/include/proton/object.h qpid/proton/branches/examples/proton-c/src/object/object.c 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=1630824&r1=1630823&r2=1630824&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:53:38 2014 @@ -227,7 +227,38 @@ bool pn_ssl_get_protocol_name(pn_ssl_t * int pn_ssl_get_peer_hostname(pn_ssl_t *ssl, char *OUTPUT, size_t *OUTPUT_SIZE); %ignore pn_ssl_get_peer_hostname; +%immutable PN_PYREF; %inline %{ + PN_EXTERN extern const pn_class_t *PN_PYREF; + + #define CID_pn_pyref CID_pn_void + #define pn_pyref_new NULL + #define pn_pyref_initialize NULL + #define pn_pyref_finalize NULL + #define pn_pyref_free NULL + #define pn_pyref_hashcode pn_void_hashcode + #define pn_pyref_compare pn_void_compare + #define pn_pyref_inspect pn_void_inspect + + static void pn_pyref_incref(void *object) { + Py_XINCREF(object); + } + + static void pn_pyref_decref(void *object) { + Py_XDECREF(object); + } + + static int pn_pyref_refcount(void *object) { + return 1; + } + + static const pn_class_t *pn_pyref_reify(void *object) { + return PN_PYREF; + } + + PN_EXTERN const pn_class_t PNI_PYREF = PN_METACLASS(pn_pyref); + PN_EXTERN const pn_class_t *PN_PYREF = &PNI_PYREF; + void *pn_py2void(PyObject *object) { return object; } 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=1630824&r1=1630823&r2=1630824&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:53:38 2014 @@ -3326,6 +3326,7 @@ class SSLSessionDetails(object): wrappers = { "pn_void": lambda x: pn_void2py(x), + "pn_pyref": lambda x: pn_void2py(x), "pn_connection": lambda x: Connection._wrap_connection(pn_cast_pn_connection(x)), "pn_session": lambda x: Session._wrap_session(pn_cast_pn_session(x)), "pn_link": lambda x: Link._wrap_link(pn_cast_pn_link(x)), @@ -3340,7 +3341,7 @@ class Collector: self._contexts = set() def put(self, obj, etype): - pn_collector_put(self._impl, PN_VOID, pn_py2void(obj), etype) + pn_collector_put(self._impl, PN_PYREF, pn_py2void(obj), etype) def peek(self): event = pn_collector_peek(self._impl) Modified: qpid/proton/branches/examples/proton-c/include/proton/object.h URL: http://svn.apache.org/viewvc/qpid/proton/branches/examples/proton-c/include/proton/object.h?rev=1630824&r1=1630823&r2=1630824&view=diff ============================================================================== --- qpid/proton/branches/examples/proton-c/include/proton/object.h (original) +++ qpid/proton/branches/examples/proton-c/include/proton/object.h Fri Oct 10 12:53:38 2014 @@ -109,6 +109,10 @@ PN_EXTERN intptr_t pn_class_compare(cons PN_EXTERN bool pn_class_equals(const pn_class_t *clazz, void *a, void *b); PN_EXTERN int pn_class_inspect(const pn_class_t *clazz, void *object, pn_string_t *dst); +PN_EXTERN uintptr_t pn_void_hashcode(void *object); +PN_EXTERN intptr_t pn_void_compare(void *a, void *b); +PN_EXTERN int pn_void_inspect(void *object, pn_string_t *dst); + PN_EXTERN void *pn_object_new(const pn_class_t *clazz, size_t size); PN_EXTERN const pn_class_t *pn_object_reify(void *object); PN_EXTERN void pn_object_incref(void *object); Modified: qpid/proton/branches/examples/proton-c/src/object/object.c URL: http://svn.apache.org/viewvc/qpid/proton/branches/examples/proton-c/src/object/object.c?rev=1630824&r1=1630823&r2=1630824&view=diff ============================================================================== --- qpid/proton/branches/examples/proton-c/src/object/object.c (original) +++ qpid/proton/branches/examples/proton-c/src/object/object.c Fri Oct 10 12:53:38 2014 @@ -40,9 +40,9 @@ static int pn_void_refcount(void *object #define pn_void_finalize NULL static void pn_void_free(void *object) { free(object); } static const pn_class_t *pn_void_reify(void *object) { return PN_VOID; } -static uintptr_t pn_void_hashcode(void *object) { return (uintptr_t) object; } -static intptr_t pn_void_compare(void *a, void *b) { return (intptr_t) b - (intptr_t) a; } -static int pn_void_inspect(void *object, pn_string_t *dst) { return pn_string_addf(dst, "%p", object); } +uintptr_t pn_void_hashcode(void *object) { return (uintptr_t) object; } +intptr_t pn_void_compare(void *a, void *b) { return (intptr_t) b - (intptr_t) a; } +int pn_void_inspect(void *object, pn_string_t *dst) { return pn_string_addf(dst, "%p", object); } const pn_class_t PNI_VOID = PN_METACLASS(pn_void); const pn_class_t *PN_VOID = &PNI_VOID; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org