← Back to team overview

kicad-developers team mailing list archive

Re: Scripting on Windows Fix


On Mar 10, 2013 4:52 PM, "Brian Sidebotham" <brian.sidebotham@xxxxxxxxx>
> Hi Guys,
> I have "fixed" the final issue with python scripting on Windows. I've
attached a patch which fixes the sigsegv problem I see on Windows.
> I'd like to discuss it so that I can fully understand why this fixes the
issue, or if this is simply a kludge that's putting a plaster on a bone
> The issue boiled down to the following code in
> /* Time to call the callback */
>     arglist = Py_BuildValue( "(i)", aPage );
>     result = CallMethod( "GetParameterPageName", arglist );
>     Py_DECREF( arglist );
> There was a SIGSEGV in Py_DECREF( arglist ). In Py_DECREF() the code was
breaking in tupledealloc() (in Objects/tupleobject.c).
> The specific issue was in the macro Py_TRASHCAN_SAFE_BEGIN(op) where
PyThreadState_GET() returns NULL.

It looks like that null is unexpected.  I thought we were seeing a thread
context fetch function returning null earlier also, during dll
initialization.  Might be same underlying problem.

Dllmain () function as I recall, was calling a thread context function and
coming up dry.

See if they are related by common data or variable name of a saved value.

Is this "thread local storage" failing?

The next line would SIGSEV.
> The PY_BLOCK_THREADS( ) and PY_UNBLOCK_THREADS( ) macro's surrounding the
python calls appear to fix the thread state issue.
> I haven't had a chance to look into wxPyBeginBlockThreads() yet to see
what's going on.
> The trouble is that I don't really understand what is going on. I could
do with someone versed in python extensions explaining the use of the GIL
and the PY_BLOCK_THREADS and PY_UNBLOCK_THREADS macros for me so I can
understand some more.
> I've also attached a quick image of the footprint wizard working okay. It
generates footprints successfully with this patch in place. So at least
that's something positive! :D
> I'm interested to understand what is wrong here. Why does Linux (and
presumably MAC) work okay without doing this?
> Perhaps the Windows build is broken in some other way that shouldn't be
fixed like this?
> At least there is progress.
> Best Regards, Brian.
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp