You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Max Bowsher <ma...@ukf.net> on 2005/09/30 14:21:03 UTC

How do the Python bindings call apr_initialize() ?

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?


Max.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

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

Posted by Max Bowsher <ma...@ukf.net>.
David James wrote:
> On 9/30/05, Max Bowsher <ma...@ukf.net> wrote:
>> David James wrote:
>>> 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?)

Thanks for the clarification!

I suggest we call apr_initialize() from initialization function of 
libsvn._core - the same place we register the SubversionException type.

Max. 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

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

Posted by David James <ja...@gmail.com>.
On 9/30/05, Max Bowsher <ma...@ukf.net> wrote:
> David James wrote:
> > On 9/30/05, Max Bowsher <ma...@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


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

Posted by Max Bowsher <ma...@ukf.net>.
David James wrote:
> On 9/30/05, Max Bowsher <ma...@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.

I'm very confused as to why this affected Cygwin but not Linux.

Max.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

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

Posted by David James <ja...@gmail.com>.
On 9/30/05, Max Bowsher <ma...@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.

]]]


Cheers,

David

--
David James -- http://www.cs.toronto.edu/~james