I'm using the gr-modtool that is now included with gnuradio to add a block to an existing module that was created with an earlier version of gr-modtool.py. The swig.i file originally looks like:
%include "gnuradio.i"
%include "testmod_swig_doc.i"
{
#include "testmod_testblock.h"
}
GR_SWIG_BLOCK_MAGIC(testmod,testblock);
%include "testmod_testblock.h"
After adding my new block the swig.i looks like:
%include "gnuradio.i"
%include "testmod_swig_doc.i"
{
#include "testmod_testblock.h"
#include "testmod_testblock2.h"
}
GR_SWIG_BLOCK_MAGIC(testmod,testblock);
%include "testmod_testblock.h"
%include "testmod_testblock2.h"
GR_SWIG_BLOCK_MAGIC(testmod, testblock2);
I can build and install the module just fine but when I got to execute a flowgraph with testblock2 in it I get these errors:
Traceback (most recent call last):
File "/home/user/top_block.py", line 52, in <module>
tb = top_block()
File "/home/user/top_block.py", line 34, in __init__
self.testmod_testblock2_0 = testmod.testblock2()
AttributeError: 'module' object has no attribute 'testblock2'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 64, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python2.7/dist-packages/apport/__init__.py", line 4, in <module>
from apport.report import Report
File "/usr/lib/python2.7/dist-packages/apport/report.py", line 28, in <module>
import problem_report
File "/usr/lib/python2.7/dist-packages/problem_report.py", line 14, in <module>
import zlib, base64, time, sys, gzip, struct, os
File "/usr/lib/python2.7/gzip.py", line 10, in <module>
import io
File "/usr/lib/python2.7/io.py", line 51, in <module>
import _io
TypeError: type '_io._IOBase' participates in gc and is a base type but has inappropriate tp_free slot
Original exception was:
Traceback (most recent call last):
File "/home/user/top_block.py", line 52, in <module>
tb = top_block()
File "/home/user/top_block.py", line 34, in __init__
self.testmod_testblock2_0 = testmod.testblock2()
AttributeError: 'module' object has no attribute 'testblock2'
Simply reversing the order of the last two lines (ie. GR_SWIG_BLOCK_MAGIC comes BEFORE %include) fixes this and allows it to run correctly. This isn't very intuitive from the error and it would be great if gr-modtool could be updated to correct this.