On Fri, May 11, 2012 at 7:03 AM, Martin Braun <martin.br...@kit.edu> wrote:
> In the current state of gr-howto (which is also used in gr_modtool), the
> SWIG stuff is done pretty intelligently by using the header files as
> .i-files, which means there is no need to write a SWIG header for every
> block.
>
> One advantage of this was the possibility to add stuff in the .i-file
> which weren't in the .h-file; specifically, exception specifiers.
>
> Example (from gr-specest, specest_welch.i):
> <snip>
> GR_SWIG_BLOCK_MAGIC(specest,welch);
>
> specest_welch_sptr
> specest_make_welch(unsigned fft_len, int overlap, int ma_len, bool fft_shift, 
> const std::vector<float> &window)
>        throw(std::invalid_argument);
>
> // And so on .
> </snip>
>
> If I don't declare the exception specifier, I can't catch the exception
> in Python. If I simply include specest_welch.h in specest_swig.i, I need
> to add the specifiers in the C++-code, which is not very popular (and I
> think not future-compatible, and gcc doesn't handle that well).
>
> Here's my question: is there a cool way to have SWIG know about the
> exceptions without having to write a .i-file for every block that uses
> exceptions? Can I 'tag' the source code in a way that gcc doesn't care,
> but SWIG does?
>
> Thanks for any nice ideas!
>
> MB

Marin,

With the restructuring of the code and implementation style in the
up-coming version 3.7, we are moving in the same direction of just
including .h files in the component's main swig .i file. For a very
large majority of cases, there is no need for extra code in the .i
file, so this reduces duplication and simplifies a lot.

For those cases where a developer needs to add SWIG-specific things to
an interface file, you can always edit it by hand and include
everything required to make it work. I'm not practiced enough in SWIG
to know this off the top of my head, but I should think that you could
just include the header file and overwrite a specific case as needed.

On the other hand, I thought all standard exceptions were passed
properly through SWIG to Python already. I was under the impression
that if you're header file declares that it throws, then you can catch
it in Python. If that's not the case, then we should try to figure out
an easy way to handle that.

Tom

_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to