discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] Compiling SWIG python bindings with -builtin opti


From: Daniele Nicolodi
Subject: Re: [Discuss-gnuradio] Compiling SWIG python bindings with -builtin option
Date: Tue, 28 Oct 2014 12:15:14 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.2.0

On 28/10/14 11:54, Martin Braun wrote:
> On 10/28/2014 12:58 AM, Daniele Nicolodi wrote:
>> This is to inform you that I'm giving up trying to transition the swig
>> bindings to generate builtin classes. I may revisit this decision if
>> I'll get encouraging answers from swig developers on the swig mailing
>> lists, but I believe this is very unlikely.
>>
>> While the changes to the interface definition files are nominally
>> extremely small, I'm hitting bugs in swig that make the exercise
>> extremely painful and I fear impossible without patching swig itself.
>> I also fear that no matter what I can do, the binding egenrated are
>> going to stay sub-optimal due to intrinsic limitations of swig.
>>
>> I prefer to spent my spare time doing something more rewarding that
>> fighting an under documented, inconsistent, and buggy system.
> 
> Thanks for trying. Can't blame you for being fed up with SWIG.

It is not that I'm fed up, it is simply that SWIG cannot do what I would
like it to do. To help others that may venture down the same route, I
think the decision has to be better circumstanced.

The first road block I encountered is the fact that there is a bug in
SWIG that prevents to mix the -builtin (to enable the generation of
nicer python builtin objects instead of the usual abomination) and the
-keyword parameter (to enable calling the generated methods with keyword
arguments) when wrapping std::vector template instances. The generated
C++ simply does not compile.

Part of the problem comes from the fact that the C++ code SWIG generates
to wrap std::vector uses overloaded methods, and SWIG refuses to enable
keywords arguments for those. From there things are very brittle and
breaks in numerous ways.

By accident I found out that keyword arguments can be enabled and
disabled for specific classes (this is AFAIK undocumented), therefore
the problem could be in principle be circumvented adding some additional
SWIG directives to the interface description files.

The second road block is related to the first: the make() method of many
GNURadio blocks is an overloaded method, and for those SWIG refuses to
enable keywords arguments. For some reason keywords arguments work
anyway when bindings are generated without the -builtin option, but do
not work with it. Looking at the generated C++ code, it seems that
keywords arguments are enabled in some layers of the wrapping code, but
disabled where it matters.

A solution would be to give up the use of keyword arguments to method
calls, but I think this would be loosing a nice feature, just for a
limitation of a stupid tool.

While fixing SWIG is probably non trivial but possible, I don't think
that requiring a very recent SWIG would be accepted by the maintainers.
Therefore I decided to give up, the advantages are not worth fighting.

I prefer investing some times to experiment with the idea of generating
Cython wrappers and drop SWIG completely.

Cheers,
Daniele




reply via email to

[Prev in Thread] Current Thread [Next in Thread]