[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Tracking pool ownership for struct members in the Python bindings

From: David James <james82_at_gmail.com>
Date: 2005-09-23 22:41:44 CEST

Currently, the Python bindings track pool ownership on a per-object
basis. This technique works great in most situations, but there are a
few edge cases. See r16233 for an example. Here's a short test case.

Test Script
=============
import svn.core
import svn.client
client_ctx = svn.client.svn_client_create_context()
config = svn.core.svn_config_get_config(None)
client_ctx.config = config
providers = [
    svn.client.svn_client_get_simple_provider()
]
auth_baton = svn.core.svn_auth_open(providers)
client_ctx.auth_baton = auth_baton
head_rev = svn.core.svn_opt_revision_t()
head_rev.kind = svn.core.svn_opt_revision_head
print svn.client.ls("http://svn.collab.net/repos/svn/trunk",head_rev, 0,
    client_ctx)
del config
del auth_baton
print "Get ready for a segfault..."
print svn.client.ls("http://svn.collab.net/repos/svn/trunk",head_rev, 0,
    client_ctx)
=============

Result: segfault. Here's why: client_ctx.config and
client_ctx.auth_baton are struct members of client_ctx, and therefore
don't have any space to store references to their created pools. So,
when you delete the "config" and "auth_baton" objects, their pools get
garbage collected, and the client_ctx.config and client_ctx.auth_baton
objects are silently invalidated. Thus, when you run svn.client.ls,
you get a segfault.

Any suggestions on how I can fix this?

Here's a shorter example, which also crashes:
=============
import svn.core
import svn.client
client_ctx = svn.client.svn_client_create_context()
client_ctx.config = svn.core.svn_config_get_config(None)
providers = [
    svn.client.svn_client_get_simple_provider()
]
client_ctx.auth_baton = svn.core.svn_auth_open(providers)
head_rev = svn.core.svn_opt_revision_t()
head_rev.kind = svn.core.svn_opt_revision_head
print "Get ready for a segfault..."
print svn.client.ls("http://svn.collab.net/repos/svn/trunk",head_rev, 0,
    client_ctx)
=============

--
David James -- http://www.cs.toronto.edu/~james
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri Sep 23 22:45:16 2005

This is an archived mail posted to the Subversion Dev mailing list.