<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Engwar &#187; swig</title>
	<atom:link href="http://engwar.com/tags/swig/feed" rel="self" type="application/rss+xml" />
	<link>http://engwar.com</link>
	<description>Chintana Wilamuna&#039;s weblog</description>
	<lastBuildDate>Wed, 30 Nov 2011 13:28:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>SWIG binary string caveat</title>
		<link>http://engwar.com/post/31?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=swig-binary-string-caveat</link>
		<comments>http://engwar.com/post/31#comments</comments>
		<pubDate>Wed, 23 Apr 2008 23:18:37 +0000</pubDate>
		<dc:creator>Chintana</dc:creator>
				<category><![CDATA[mtom]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[swig]]></category>
		<category><![CDATA[wsf/perl]]></category>

		<guid isPermaLink="false">http://engwar.com/post/31</guid>
		<description><![CDATA[If you have been working with Web services you might have heard the term MTOM. I was getting MTOM support to work on WSF/Perl and the image that was not getting saved properly. Only the first few bytes was written &#8230; <a href="http://engwar.com/post/31">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you have been working with Web services you might have heard the term <a href="http://en.wikipedia.org/wiki/MTOM">MTOM</a>.  I was getting MTOM support to work on <a href="http://wso2.org/projects/wsf/perl">WSF/Perl</a> and the image that was not getting saved properly.  Only the first few bytes was written to the file.  The magic numbers that were getting saved was enough for the file command to say it&#8217;s a JPEG image.  From the C layer it was reading image data to a character pointer and returning it to the scripting language.</p>
<p>The C function reading the image had a <code>char *</code> return type.  The code that was generated by SWIG was returning the pointer after running it through the following function,</p>
<pre lang="c">
SWIG_FromCharPtr(const char *cptr)
{
  return SWIG_FromCharPtrAndSize(cptr, (cptr ? strlen(cptr) : 0));
}
</pre>
<p>The rough English translation of the above is, &#8220;you&#8217;re screwed&#8221;.  Why?  The <code>strlen</code> doesn&#8217;t particularly like to go through binary strings.  It&#8217;ll choke and die when it see a null byte.  So, only the content before the null byte was returned.</p>
<p>The solution was to create a string using the API provided by the particular scripting language.  For Perl it&#8217;s <code>newSVpv</code> and for Ruby it&#8217;s <code>rb_str_new</code>.  Wrapped the functions inside an ifdef (thanks to the nice SWIG&lt;lang&gt; defines) and all is set for MTOM!</p>
]]></content:encoded>
			<wfw:commentRss>http://engwar.com/post/31/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Scripting language bindings</title>
		<link>http://engwar.com/post/20?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=scripting-language-bindings</link>
		<comments>http://engwar.com/post/20#comments</comments>
		<pubDate>Thu, 03 Jan 2008 08:53:08 +0000</pubDate>
		<dc:creator>Chintana</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[swig]]></category>
		<category><![CDATA[webservices]]></category>

		<guid isPermaLink="false">http://engwar.com/post/20</guid>
		<description><![CDATA[Besides having the ability to provide a high level and a more developer friendly API, making a scripting language binding to an existing C library could make the testing of the library a less painful process. Initially I was under &#8230; <a href="http://engwar.com/post/20">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Besides having the ability to provide a high level and a more developer friendly API, making a scripting language binding to an existing C library could make the testing of the library a less painful process.  Initially I was under the impression that exposing low level C functions to the scripting language will make it flexible so that you could build a high level module in that scripting language encapsulating those low level functions.  True.  But the big downside when you have, say, 3 different language bindings for your C library all exposing low level functions is, a) you need to spend a lot of time writing the module in the respective scripting language b) too much overhead when it comes to debugging.  If you find a subtle bug which you have overlooked in the Ruby binding, now you need to change the same thing on your Python and Perl bindings as well.</p>
<p>This was a real issue that we came across developing the Ruby and Perl bindings for the <a href="http://wso2.org/projects/wsf/c">WSF/C</a> framework.  Also having the Python binding in sight.  We use <a href="http://www.swig.org/">SWIG</a> to generate language bindings.  Having learned the price you have to pay exposing the lowest level functions, I&#8217;m gonna look into refactoring the existing code limiting the stuff that&#8217;s exposed to the scripting language to a minimum.  So, code that goes into the module which need to be written in the respective scripting language is very small.</p>
<p>At the end of the day it&#8217;s about making you feel sooo comfortable when you program in your favourite scripting language, exposing your services with the doublew ess death star goodness with a few lines which will call the C library for maximum performance which will then give the result back to your favourite scripting language scripting language.  It&#8217;s a deadly game out there <img src='http://engwar.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />   Yes, you can breathe now.</p>
]]></content:encoded>
			<wfw:commentRss>http://engwar.com/post/20/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

