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

Re: Question about Python bindings

From: David Glasser <glasser_at_davidglasser.net>
Date: Wed, 21 May 2008 21:27:29 -0700

On Wed, May 21, 2008 at 6:41 PM, John Peacock
<john.peacock_at_havurah-software.org> wrote:
> I'm trying to translate the Python SWIG bindings to Perl and I came across
> this code:
>
> ...
> hash = apr_hash_make(pool);
> keys = PyDict_Keys(dict);
> num_keys = PyList_Size(keys);
> for (i = 0; i < num_keys; i++)
> {
> PyObject *key = PyList_GetItem(keys, i);
> PyObject *value = PyDict_GetItem(dict, key);
> const char *pathname = make_string_from_ob(key, pool);
> apr_array_header_t *ranges = svn_swig_py_rangelist_to_array(value,
> pool);
>
> if (! (pathname && ranges))
> {
> PyErr_SetString(PyExc_TypeError,
> "dictionary keys aren't strings or values aren't
> svn_merge_range_t *'s");
> Py_DECREF(keys);
> return NULL;
> }
> ...
>
> If the error path is followed, isn't that hash leaked, or does the pool
> automatically get cleaned up somewhere else? I'm trying desperately not to
> engage in cargo-cult programming.

While this may not be a good thing or worth continuing, failure to
destroy/clear pools on error is pretty endemic in Subversion. I guess
the assumption is that it's likely the program is about to destroy a
top-level pool anyway, so who cares; it would be neat if there was a
better idiom for dealing.

--dave

-- 
David Glasser | glasser@davidglasser.net | http://www.davidglasser.net/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe_at_subversion.tigris.org
For additional commands, e-mail: dev-help_at_subversion.tigris.org
Received on 2008-05-22 06:27:42 CEST

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

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.