Swig madness

Hi Guys,

I am trying to create a rational_sync_block class in an out of tree
module, which is both an interpolator and decimator with a rational
data rate. So I just wrote the class, almost exactly like how
sync_interpolator is written. Then when I want to use this new base
class in a derived real block named xxx_block in my out of tree
module, then everything compiles, but the swig generation fails with
an error message that xxx_block cannot be allocated because it is
abstract type has an virtual work function. When I change the base
type back to sync_interpolator, then swig is happy. I do not
understand what is so special about gr::sync_interpolator, and why I
cannot reproduce the sync_interpolator in a way that makes swig happy.
Any ideas?

Miklos

Miklos,

Have you imported all of the gnuradio files into the swig .i file that
you
are using within your OOT module? I recently went through this, and I
had
to include a gnuradio header into my swig .i file as shown below; I’m
not
entirely sure what the two include declarations are for, but I needed
both
to work.

%{
#include “gnuradio/digital/constellation.h”
#include “”
%}
%include “gnuradio/digital/constellation.h”
%include “”

Also, make sure you include the appropriate .so file of any gnuradio
object
you are using into the CMakeList.txt file, otherwise you may get a
runtime
error as it cannot find the object you are referencing within gnuradio.

Michael B.

Hi Michael,

Unfortunately, the problem is not always reproducible with a simple
“cmake …/ && make clean && make”, I have to remove the build
directory completely. I have tried all combinations, and now I seem to
have something that seem to work. The problem is that I need a

rational_sync_block(void) {} // allows pure virtual interface
sub-classes

constructor in order to declare interface classes in my include
directory. These interface classes are inheriting from
rational_sync_block with virtual inheritance. So when SWIG is scanning
the header files, then it decides that it is going to create a wrapper
around the empty constructor (and I do not know why it does this). But
you cannot instantiate this interface class, you have to use make
which will create the proper implementation. Anyhow, the solution was
to conditionally create a different class definition for swig like
below. If I do not do this special case, then the error is there.
Also, it is not clear what and how to set up my swig .i file, but some
combination seems to work now.

#ifdef SWIG_VERSION

class rational_sync_block : public gr::sync_block
{
protected:
rational_sync_block(const std::string &name,
gr::io_signature::sptr input_signature, gr::io_signature::sptr
output_signature,
unsigned int interpolation, unsigned int decimation);
};

#else

class rational_sync_block: public gr::sync_block
{
private:
unsigned int d_interpolation;
unsigned int d_decimation;

protected:
rational_sync_block(void) {} // allows pure virtual interface
sub-classes
rational_sync_block(const std::string &name,
gr::io_signature::sptr input_signature, gr::io_signature::sptr
output_signature,
unsigned int interpolation, unsigned int decimation);

public:
unsigned int interpolation() const { return d_interpolation; }
unsigned int decimation() const { return d_interpolation; }

void set_interpolation(unsigned int interpolation, unsigned int
decimation);

int fixed_rate_ninput_to_noutput(int ninput);
int fixed_rate_noutput_to_ninput(int noutput);

void forecast(int noutput_items, gr_vector_int
&ninput_items_required);

// derived classes should override work
int general_work(int noutput_items, gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items, gr_vector_void_star
&output_items);
};

#endif

Miklos