Le 11/12/2018 à 20:38, Maciej Suminski a écrit :
> Hi Wayne, Seth,
> 
> On 12/11/18 7:51 PM, Wayne Stambaugh wrote:
> [...]
>> FYI, swig does not support unique_ptr or weak_ptr yet[1].  If you change
>> any code in pcbnew that gets swigged using these pointer templates, the
>> python scripting will fail to build.  If you want to use unique_ptr, you
>> will have to create a swig wrapper for it[2].  SWIG does support
>> shared_ptr so that may be an option.
> 
> Sorry for the build errors and thanks for the quick reaction. I have
> seen unique_ptrs all over the KiCad code, so it has never occurred to me
> that they need a special treatment for SWIG. I will find another
> scripting-friendly way to fix the memory leaks.
> 
> Cheers,
> Orson

Hi Orson,

The issue is due to this method:
std::unique_ptr<wxConfigBase> GetNewConfig( const wxString& aProgName )
that cannot be mapped by SWIG, because it returns a unique_ptr.

This method is not really useful for python scripting.
So the easy way is just to do not map it in pcbnew.py

The attached basic patch show hos to do that.

(There are many other examples in Kicad code that use this trick)

-- 
Jean-Pierre CHARRAS
 common/common.cpp | 6 ++++--
 include/common.h  | 2 ++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/common/common.cpp b/common/common.cpp
index d3c6bef89..a5b8a4c52 100644
--- a/common/common.cpp
+++ b/common/common.cpp
@@ -247,7 +247,9 @@ double RoundTo0( double x, double precision )
     return (double) ix / precision;
 }
 
-
+#ifndef SWIG
+// SWIG cannot map std::unique_ptr<> in Python. So because this method is not 
usefull in Python
+// just discard it.
 std::unique_ptr<wxConfigBase> GetNewConfig( const wxString& aProgName )
 {
     wxFileName configname;
@@ -256,7 +258,7 @@ std::unique_ptr<wxConfigBase> GetNewConfig( const wxString& 
aProgName )
 
     return std::make_unique<wxConfig>( wxT( "" ), wxT( "" ), 
configname.GetFullPath() );
 }
-
+#endif
 
 wxString GetKicadConfigPath()
 {
diff --git a/include/common.h b/include/common.h
index 62410d367..4491433d7 100644
--- a/include/common.h
+++ b/include/common.h
@@ -311,7 +311,9 @@ const wxString PrePendPath( const wxString& aEnvVar, const 
wxString& aPriorityPa
  * @return A pointer to a new wxConfigBase derived object is returned.  The 
caller is in charge
  *  of deleting it.
  */
+#ifndef SWIG
 std::unique_ptr<wxConfigBase> GetNewConfig( const wxString& aProgName );
+#endif
 
 /**
  * Return the user configuration path used to store KiCad's configuration 
files.
_______________________________________________
Mailing list: https://launchpad.net/~kicad-developers
Post to     : kicad-developers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~kicad-developers
More help   : https://help.launchpad.net/ListHelp

Reply via email to