← Back to team overview

kicad-developers team mailing list archive

Re: Regression Testing

 

On Wed, May 01, 2013 at 04:09:58PM -0500, Dick Hollenbeck wrote:
> On 05/01/2013 11:27 AM, Lorenzo Marcantonio wrote:
> > On Wed, May 01, 2013 at 05:38:48PM +0200, Miguel Angel Ajo wrote:
> >> If the object is obtained via GetBoard() , it won't be deleted by python
> >> because he doesn't own it.
> > 
> > Yes but *nothing* prevents C++ to delete an object which is 'held' (not
> > created) by python (that's the reason for python being best extended: it
> > like to manage objects itself). AFAIK at the moment all the object are
> > created and delete from the C++ side only so python has objects
> > disappearing under its feet.
> 
> 
> Can you back this up please with either an example or a web reference.

Do the thing I suggested. board = GetBoard() in the python console, file
new, use the board reference. I found it in the hard way during plotting
tests.

> BTW, Java <-> C/C++ does not behave this way.  The term "object" should probably clarified
> before we go too much further.  Both python and java languages use handles a.k.a.
> references, so you have a layer of indirection to protect against "bad things" from happening.

SWIG proxies are doing that (the 'wrap' things) but they are not
sufficiently smart (and neither they could since an object don't know
that it have proxies pointing to it, so it couldn't notificate them even
if it wanted to).

> When you "delete an object" in C++ this merely triggers some activity at the holder of the
> true end object.

Exactly. The true end object is in C++, however, delete do its
destruction thing and free memory and the python proxy is left with an
invalid pointer.

I've tried to look in the swig manual but it only talks about avoiding
Python deleting objects, not the other way around. Deleting from python
is 'safe' since it has an ownership flag.

In fact it's more of a C++ side problem not to delete an object when
someone else is using it, that's one of the main reason for segfaults
(in my experience). It's simply that the whole pcbnew assume that's the
only one accessing its own object (it's a reasonable assumption if you
don't have some kind of garbage collector... how would you know when to
delete otherwise?)

BTW I'm curious: how does jni know when an object is destroyed without
special programming from the object side?

-- 
Lorenzo Marcantonio
Logos Srl


Follow ups

References