← Back to team overview

kicad-developers team mailing list archive

Re: PATCH: fix crash in netlist updater

 

Seth,

1. No, it's not needed. At first I didn't find Cast() in BOARD_ITEMS cpp
code so thought it's implemented in descendant classes only and added the
check as safeguard like it was done in DList. But now I found that Cast()
is in swig python extension for BOARD_ITEM so it will always be defined.
See amended patch attached.
2. Yes, it works and it was tested on py3 build. Self reference is passed
implicitly in python.

On Tue, Jun 4, 2019 at 5:24 AM Seth Hillbrand <seth@xxxxxxxxxxxxx> wrote:

> On 2019-06-04 03:09, Andrew Lutsenko wrote:
> > Hi Seth,
> > Another patch that fixes some bugs in scripting and restores previous
> > dlist behavior.
> >
> > Regards,
> > Andrew
>
> Thanks Andrew!  A couple questions:
> - Do we need to check the existence of Cast() for the BOARD_ITEMS?
> - Does the next() method work for python 3?  I had thought we needed to
> use the function like:
> item = it.next( it )
>
> Thanks again for addressing this.  Best-
> Seth
>
From 1059a80537b15ca3c3fe513f7cb0ae3908b6aa83 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     | 12 ++++++++++++
 pcbnew/swig/footprint.i |  3 ---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/pcbnew/swig/board.i b/pcbnew/swig/board.i
index ca6d7b119..c47e86670 100644
--- a/pcbnew/swig/board.i
+++ b/pcbnew/swig/board.i
@@ -106,6 +106,18 @@ 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.
+                yield item.Cast()
+    %}
+}
+
 %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