← Back to team overview

kicad-developers team mailing list archive

Re: PATCH: fix crash in netlist updater

 

Hi Seth,
Another patch that fixes some bugs in scripting and restores previous dlist
behavior.

Regards,
Andrew

On Sat, Jun 1, 2019 at 10:06 PM Andrew Lutsenko <anlutsenko@xxxxxxxxx>
wrote:

> On further digging I believe reason for that is that we no longer use the
> extended iterator that is in dlist.i
> There is some logic there to auto cast objects to proper class by calling
> Cast(). I tried this in scripting console and
> it works:
>
> c = d[0].Cast()
> c
> <pcbnew.DRAWSEGMENT; proxy of <Swig Object of type 'DRAWSEGMENT *' at
> 0x7fa121ffca80> >
> c.GetShape()
> 0
>
> It would be good to add same wrapper for deque. I can look into it a bit
> later if nobody beats me to it.
>
> On Sat, Jun 1, 2019 at 9:55 PM Andrew Lutsenko <anlutsenko@xxxxxxxxx>
> wrote:
>
>> On a related note, python api to get drawings (and probably everything
>> else that is now in deque) is broken.
>> board.GetDrawings() returns
>> <pcbnew.DRAWINGS; proxy of <Swig Object of type 'std::deque< BOARD_ITEM *
>> > *' at 0x7fa121ffc930> >
>> and it's items don't have some methods for some reason
>>
>> b = pcbnew.GetBoard()
>> d = b.GetDrawings()
>> d[0].GetClass()
>> 'DRAWSEGMENT'
>> d[0].GetShape()
>> Traceback (most recent call last):
>>   File "<input>", line 1, in <module>
>>   File "/usr/local/lib/python3.6/dist-packages/pcbnew.py", line 8393, in
>> <lambda>
>>     __getattr__ = lambda self, name: _swig_getattr(self, BOARD_ITEM, name)
>>   File "/usr/local/lib/python3.6/dist-packages/pcbnew.py", line 83, in
>> _swig_getattr
>>     raise AttributeError("'%s' object has no attribute '%s'" %
>> (class_type.__name__, name))
>> AttributeError: 'BOARD_ITEM' object has no attribute 'GetShape'
>>
>>
>>
>> On Sat, Jun 1, 2019 at 9:49 PM Seth Hillbrand <seth@xxxxxxxxxxxxx> wrote:
>>
>>>
>>> Thanks Andrew!  Good catch.
>>>
>>> -Seth
>>>
>>> On 2019-06-01 21:40, Andrew Lutsenko wrote:
>>> > Hi Seth,
>>> >
>>> > I tried to pull netlist into completely empty board today and got a
>>> > crash that I tracked down to
>>> > this commit
>>> >
>>> https://github.com/KiCad/kicad-source-mirror/commit/d1877d7c1b531dee2f4e35304a1d6b33a34c5fff
>>> >
>>> > Simple fix for this particular problem is in attached patch but I
>>> > didn't go through all the changes in that commit. It seems in a few
>>> > places there are unchecked Modules().front() calls. Maybe they should
>>> > be changed to GetFirstModule().
>>> >
>>> > Regards,
>>> > Andrew
>>>
>>
From 6582cdbd8c0d0f67f2d5eb8286a8fbc439cf52ef Mon Sep 17 00:00:00 2001
From: qu1ck <anlutsenko@xxxxxxxxx>
Date: Mon, 3 Jun 2019 23:49:58 -0700
Subject: [PATCH] Pcbnew scripting fixes

* Remove infinite recursion calls in footprint.i
* Extend DRAWINGS deque iterator to auto cast contained BOARD_ITEMS,
similar to what dlist implementation did.
---
 pcbnew/swig/board.i     | 16 ++++++++++++++++
 pcbnew/swig/footprint.i |  3 ---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/pcbnew/swig/board.i b/pcbnew/swig/board.i
index ca6d7b119..682aadd3f 100644
--- a/pcbnew/swig/board.i
+++ b/pcbnew/swig/board.i
@@ -106,6 +106,22 @@ HANDLE_EXCEPTIONS(BOARD::TracksInNetBetweenPoints)
 #include <class_board.h>
 %}
 
+%extend std::deque<BOARD_ITEM *>
+{
+    %pythoncode
+    %{
+        def __iter__(self):
+            it = self.iterator()
+            while True:
+                item = it.next()  # throws StopIteration when iterator reached the end.
+                cast_attr = getattr(item, 'Cast', None)
+                if callable(cast_attr):
+                    yield item.Cast()
+                else:
+                    yield item
+    %}
+}
+
 %extend BOARD
 {
     // BOARD_ITEM_CONTAINER's interface functions will be implemented by SWIG
diff --git a/pcbnew/swig/footprint.i b/pcbnew/swig/footprint.i
index 2c3108b17..15b5214aa 100644
--- a/pcbnew/swig/footprint.i
+++ b/pcbnew/swig/footprint.i
@@ -50,9 +50,6 @@
     %pythoncode
     %{
 
-    def Pads(self):            return self.Pads()
-    def GraphicalItems(self):  return self.GraphicalItems()
-
     #def SaveToLibrary(self,filename):
     #  return SaveModuleToLibrary(filename,self)
 
-- 
2.22.0.rc1.311.g5d7573a151-goog


Follow ups

References