kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #34580
Re: Deletion in plugins causing trouble
-
To:
kicad-developers@xxxxxxxxxxxxxxxxxxx
-
From:
Wayne Stambaugh <stambaughw@xxxxxxxxx>
-
Date:
Fri, 2 Mar 2018 08:45:08 -0500
-
In-reply-to:
<CAH3vBSQsdKpPL=mSAVAY8PNQeggwT3NBQ_K7t8eNuDfUE=J3Lg@mail.gmail.com>
-
User-agent:
Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0
Miles,
I wish I had a answer for your but you are probably on your own here
unless the developer who implemented this steps in and helps. I don't
have the time to figure it out right now. Maybe someone else can help
you or maybe you could become the resident python expert and maintain
this. ;)
Cheers,
Wayne
On 2/28/2018 11:12 AM, miles mccoo wrote:
>
>
>
> So I'm plugin-ifying my python scripts (the mechanism is awesome). One
> of the plugins deletes some stuff and that is causing trouble.
>
>
>
> I'm not sure how to fix the root cause. Hence this mail.
>
>
>
> The plugin just deletes Edge.Cuts[1]:
> for d in board.GetDrawings():
> if (d.GetLayerName() == 'Edge.Cuts'):
> board.Remove(d)
>
>
>
> in board_item_container.i, I see this (with stuff deleted):
> %rename(RemoveNative) BOARD_ITEM_CONTAINER::Remove;
> def Remove(self,item):
> self.RemoveNative(item)
> item.thisown=1
>
>
> Setting thisown tells, python "you own it". Delete it when you're done.
> Which it does.
>
>
> The problem this causes is that the plugin mechanism saves a list of all
> objects before running the plugin and then checks if any of them has a
> null list after (ie is it still in the design).
>
> Since the object has been deleted by python, the plugin stuff gets confused.
>
>
> *So, the question is how to fix this?*
>
>
> It appears that the plugin infrastructure will delete for you (that's
> what I'm guessing), so the thisown setting shouldn't be done.
>
>
> On the other hand, if running code from within a standalone script (ie
> from regular python shell), now thisown'ing it would yield a memory leak.
>
>
>
> Perhaps the plugin stuff should have some sort of flag indicating
> "you're in a plugin". Then the thisown setting could be conditional.
>
>
> But I'm just a spectator. *I'm happy to put in the time to fix this but
> need guidance on what approach to take.*
>
>
> Miles
>
>
>
> [1] full plugin text
> import pcbnew
>
> class RemoveBoundaryPlugin(pcbnew.ActionPlugin):
> def defaults(self):
> self.name <http://self.name> = "Remove boundary"
> self.category = "A descriptive category name"
> self.description = "This plugin reads a dxf file and converts it
> to a zone"
>
> def Run(self):
> board = pcbnew.GetBoard()
>
> for d in board.GetDrawings():
> print("{}".format(str(d)))
> #print("on layer {} {} {}".format(d.GetLayerName(),
> # str(d.GetStart()),
> # str(d.GetEnd())))
> if (d.GetLayerName() == 'Edge.Cuts'):
> board.Remove(d)
>
> RemoveBoundaryPlugin().register()
>
>
>
> _______________________________________________
> 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
>
References