Re: [Kicad-developers] Python scripting build broken on windows.

2018-12-12 Thread Wayne Stambaugh
On 12/12/2018 2:27 AM, jp charras wrote:
> 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 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)
> 

I think you can also use "%ignore GetNewConfig;" in the appropriate swig
file.  The documentation for %ignore can be found here
http://swig.org/Doc3.0/SWIG.html#SWIG_rename_ignore.  I would prefer
this method if possible to keep our headers clean from as many
#ifdef/#endif blocks as possible.

___
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


Re: [Kicad-developers] Python scripting build broken on windows.

2018-12-11 Thread jp charras
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 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 GetNewConfig( const wxString& aProgName )
 {
 wxFileName configname;
@@ -256,7 +258,7 @@ std::unique_ptr GetNewConfig( const wxString& 
aProgName )
 
 return std::make_unique( 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 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


Re: [Kicad-developers] Python scripting build broken on windows.

2018-12-11 Thread Maciej Suminski
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



signature.asc
Description: OpenPGP digital signature
___
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


Re: [Kicad-developers] Python scripting build broken on windows.

2018-12-11 Thread Wayne Stambaugh
On 12/11/2018 1:14 PM, Seth Hillbrand wrote:
> Am 2018-12-11 12:05, schrieb Seth Hillbrand:
>> Am 2018-12-11 11:46, schrieb Wayne Stambaugh:
>>> One of the last couple of patches this morning broke the python
>>> scripting build on windows.  I'm getting the following error (and yes I
>>> deleted pcbnew_wrap in an attempt to fix the issue):
>>
>> Same on linux.  I had to back out
>> a9efbf47161f7ab6619f099d6b4eb3671451
>>
> 
> Hi Orson-
> 
> I temporarily reverted the commit to get the compiles working again.
> 
> -S

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.

[1]:
http://www.swig.org/Doc3.0/SWIGDocumentation.html#CPlusPlus11_general_purpose_smart_pointers
[2]:
http://www.howtobuildsoftware.com/index.php/how-do/b0RN/python-c-swig-how-to-handle-unique-ptrs-with-swig

___
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


Re: [Kicad-developers] Python scripting build broken on windows.

2018-12-11 Thread Seth Hillbrand

Am 2018-12-11 12:05, schrieb Seth Hillbrand:

Am 2018-12-11 11:46, schrieb Wayne Stambaugh:

One of the last couple of patches this morning broke the python
scripting build on windows.  I'm getting the following error (and yes 
I

deleted pcbnew_wrap in an attempt to fix the issue):


Same on linux.  I had to back out 
a9efbf47161f7ab6619f099d6b4eb3671451




Hi Orson-

I temporarily reverted the commit to get the compiles working again.

-S

___
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


Re: [Kicad-developers] Python scripting build broken on windows.

2018-12-11 Thread Seth Hillbrand

Am 2018-12-11 11:46, schrieb Wayne Stambaugh:

One of the last couple of patches this morning broke the python
scripting build on windows.  I'm getting the following error (and yes I
deleted pcbnew_wrap in an attempt to fix the issue):


Same on linux.  I had to back out 
a9efbf47161f7ab6619f099d6b4eb3671451


-S

___
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