Tuesday, December 14, 2010

SWIG and fstream

I have a love/hate relationship with swig.
I have had some success wrapping C and C++ libraries so they can be called from python. The real plus with swig is that is not invasive to existing code, with a little work you can usually create good wrappers without having to change underlying code.
However, when it fails it can be hard to spot why. I've found that looking at the C++ wrapper code that swig produces can help a lot, but still there can be a lot of thrashing around.
My latest battle was with fstream. I had a method that need a C++ stream to read from and I wanted to open a specific file, so I needed fstream. Unfortunately, I had no joy wrapping the fstream header file. Some googling suggested that C++ streams are one area where swig struggles.
In the end, my solution was to just create a function that takes a filename and returns an istream:
%inline %{
istream & open_stream(const char *filename) {
istream *infile = new ifstream(filename);
return *infile;
istream & open_stream(const char *filename);
Armed with this I can open files and get the istream objects I need to pass into methods that read streams.
I'd be interested to hear of any better solutions.

Wednesday, December 1, 2010

Wikileaks: most startling revelation

The dump of diplomatic cables from wikileaks has provided some interesting insight into diplomatic communications. So far I've not really heard anything earth shattering.

The most surprising thing I've heard is that 2.5 million US citizens had access to all this data. Now if I was one of the diplomats involved I'd be more than a little miffed that what I considered confidential conversations were being dessiminated so widely.

This piece explains some of Assange's motivations in publishing this material. I had originally thought he was just interested in exposing illegal and immoral behaviour in governments, but his motivations are much wider than that, hence the dump of data rather than publication, allowing others to mine the data.

Whilst nothing I've heard so far seems to threaten security seriously (although some of the revelations re: Saudi Arabia might have potential to increass tension in the Middle East). My guess is that most of the data just confirms stuff that people already suspected. In many cases, it actually might increase trust between nations, since they now have confirmation of what they have up to now only suspected.

However, it is going to be hard for diplomats to be so candid in the light of these revelations. The US can actually help heal this damage by accepting that the wide internal dissemination of this information was itself a breach of trust.

Meanwhile, there are some pretty scary ideas about how to deal with the perpertrators of the leaks.

Update: this piece in the Guardian sums up what I was trying to say above.