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

Re: How do the Python bindings call apr_initialize() ?

From: David James <james82_at_gmail.com>
Date: 2005-09-30 17:47:08 CEST

On 9/30/05, Max Bowsher <maxb@ukf.net> wrote:
> David James wrote:
> > On 9/30/05, Max Bowsher <maxb@ukf.net> wrote:
> >> I am having a problem getting the new Python bindings to function on
> >> Cygwin.
> >>
> >> The following sequence of events occurs:
> >>
> >> $ python -c 'import svn.core'
> >> svn.core then does:
> >> from libsvn.core import *
> >> import libsvn.core as _core
> >> Pool = svn_pool_create
> >> Pool()
> >>
> >> and that last line then causes a segfault, because apr has not been
> >> initialized.
> >> When was apr supposed to have been initialized?
>
> > It's supposed to be initialized in swig/proxy/proxy_apr.swg, but it's
> > initialized at the wrong time.
> >
> > Does the attached patch fix the problem?
> >
> > [[[
> > * swig/proxy/proxy_apr.swg: Call apr_initialize() at import time.
> > ]]]
>
> Yes, it does, thanks.
Great! But I'm not sure this is the right solution. See below.

> I'm very confused as to why this affected Cygwin but not Linux.
If ACQUIRE_PYTHON_LOCK is defined, we call apr_initialize during
svn_swig_py_release_py_lock in
swig/python/libsvn_swig_py/swigutil_py.c.
(This means that we initialize APR multiple times on Linux.)

Perhaps we should remove the apr_initialize and apr_terminate calls
from proxy_apr.swg, and instead patch swigutil_py.c to initialize and
terminate APR on all platforms? (How do you suggest we do this?)

See excerpt from swigutil_py.c below:

void svn_swig_py_release_py_lock(void)
{
#ifdef ACQUIRE_PYTHON_LOCK
  PyThreadState *thread_state;

  if (_saved_thread_key == NULL) {

    /* This is ugly. We call svn_swig_py_release_py_lock before executing any
       subversion function. Thus it gets called before any call to
       apr_initialize in our script. This means we have to call
       apr_initialize ourselves, or otherwise we won't be able to
       create our pool. */
    apr_initialize();

    /* Obviously, creating a top-level pool for this is pretty stupid. */
    apr_pool_create(&_saved_thread_pool, NULL);
    apr_threadkey_private_create(&_saved_thread_key, NULL, _saved_thread_pool);
  }

  thread_state = PyEval_SaveThread();
  apr_threadkey_private_set(thread_state, _saved_thread_key);
#endif
}

--
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 30 17:48:23 2005

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