[Xapian-tickets] [Xapian] #341: Python bindings should keep a reference to user-subclassable proxies when registered with consumers/users
Xapian
nobody at xapian.org
Wed Mar 4 13:20:48 GMT 2009
#341: Python bindings should keep a reference to user-subclassable proxies when
registered with consumers/users
-----------------------------+----------------------------------------------
Reporter: james | Owner: richard
Type: defect | Status: assigned
Priority: normal | Milestone: 1.1.1
Component: Xapian-bindings | Version: SVN trunk
Severity: normal | Resolution:
Keywords: | Blockedby:
Platform: All | Blocking:
-----------------------------+----------------------------------------------
Old description:
> Due to #186 and the way the bindings work, if (for instance) you create a
> ValueRangeProcessor proxy object and register it with the QueryParser
> proxy object, then throw away your reference to the ValueRangeProcessor
> proxy, python is left with no references to it, and so will garbage
> collect it. This then causes a segfault when the underlying Xapian
> QueryParser object tries to go ahead and use the ValueRangeProcessor
> object.
>
> A proposed interim solution until this can be solved more cleanly is to
> stash a reference to the VRP proxy on the QueryParser proxy. Something
> like:
>
> {{{
> real_add_valuerangeprocessor = QueryParser.add_valuerangeprocessor
> def intercept_add_valuerangeprocessor(self, vrproc):
> self._vrps.append(vrproc)
> real_add_valuerangeprocessor(self, vrproc)
> QueryParser._vrps = []
> QueryParser.add_valuerangeprocessor = intercept_add_valuerangeprocessor
> }}}
>
> in python/extra.i should do it. Note that this is only one situation
> where we want to be able to make things easier for python users; this
> should be considered in every situation where something is user-
> subclassable, and then documented very clearly.
New description:
Due to #186 and the way the bindings work, if (for instance) you create a
!ValueRangeProcessor proxy object and register it with the !QueryParser
proxy object, then throw away your reference to the !ValueRangeProcessor
proxy, python is left with no references to it, and so will garbage
collect it. This then causes a segfault when the underlying Xapian
!QueryParser object tries to go ahead and use the !ValueRangeProcessor
object.
A proposed interim solution until this can be solved more cleanly is to
stash a reference to the VRP proxy on the !QueryParser proxy. Something
like:
{{{
real_add_valuerangeprocessor = QueryParser.add_valuerangeprocessor
def intercept_add_valuerangeprocessor(self, vrproc):
self._vrps.append(vrproc)
real_add_valuerangeprocessor(self, vrproc)
QueryParser._vrps = []
QueryParser.add_valuerangeprocessor = intercept_add_valuerangeprocessor
}}}
in python/extra.i should do it. Note that this is only one situation where
we want to be able to make things easier for python users; this should be
considered in every situation where something is user-subclassable, and
then documented very clearly.
--
Comment(by olly):
If this works, I think we should bother - moving to boost::shared_ptr is
probably 2.0 territory and this repeatedly trips up users.
James: Did you check this works and fixes the problem?
--
Ticket URL: <http://trac.xapian.org/ticket/341#comment:3>
Xapian <http://xapian.org/>
Xapian
More information about the Xapian-tickets
mailing list