On 10/4/05, Max Bowsher <maxb@ukf.net> wrote:
> David James wrote:
> > On 10/4/05, Max Bowsher <maxb@ukf.net> wrote:
> >> David James wrote:
> >>> On 10/4/05, djames@tigris.org <djames@tigris.org> wrote:
> >>>> Author: djames
> >>>> Date: Tue Oct 4 09:52:26 2005
> >>>> New Revision: 16449
> >>>>
> >>>> Modified:
> >>>> trunk/build/generator/gen_make.py
> >>>>
> >>>> Log:
> >>>> Ensure that all python modules import libsvn._core before importing
> >>>> any other modules, so that the initialization code is run in the
> >>>> correct
> >>>> order (thus preventing segfaults). We can't implement this trick in
> >>>> SWIG,
> >>>> so we do it by postprocessing the SWIG output files.
> >>>>
> >>>> * build/generator/gen_make.py
> >>>> (Generator.write): Update generated *.py files to import libsvn._core
> >>>> first.
> ...
> >>> Here's a test case:
> >>> python -c "import svn.wc"
> >> That fix is _reeeaaaaly_ hacky :-(
> >>
> >> Also, why is it needed at all?
>
> > I hope that this fix is not necessary, or that we can find a different
> > way of implementing it. :)
> >
> >> The testcase completes successfully for me without this revision, plus, I
> >> manually examined the generated .py files and found that _core was being
> >> imported soon enough anyway without this fix.
>
> > Is it? On my machine, libsvn/wc.py starts like this:
> > # This file was created automatically by SWIG.
> > # Don't modify this file, modify the SWIG interface instead.
> > # This file is compatible with both classic and new-style classes.
> >
> > import _wc
> >
> > Oops! We imported _wc before importing _core. I'm not sure why
> > importing _wc before _core leads to crashes on my machine now -- it
> > used to work fine.
>
> Could you try using gdb to figure out where it crashes?
>
> It does not crash for me, nor would I expect it to, as no use of APR is made
> in the _wc initialization function.
>
> In an "import svn.wc" situation, APR will be initialized when the "import
> core" statement in libsvn.wc executes, which follows immediately (except for
> some pure python swig internal definitions) after the "import _wc".
I've figured out the problem: If we're using a threaded APR, and we
import libsvn._wc before importing libsvn._core, the
svn_swig_release_py_lock function will run before libsvn._core has had
a chance to initialize APR. Does this fix look reasonable?
[[[
Move apr_initialize calls into swigutil_py.c so that APR will be initialized
when svn_swig_py_release_lock is called.
* swig/core.i: Remove calls to apr_initialize and apr_terminate.
* swig/python/libsvn_swig_py/swigutil_py.c
(svn_swig_py_release_lock): Initialize APR, if it has not been initialized
yet. Initialize atexit(apr_terminate) exit handler.
]]]
Cheers,
David
--
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 Tue Oct 4 19:50:09 2005