<?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>Ctrl-C &#187; Blog</title>
	<atom:link href="http://ctrl-c.us/blog/archives/category/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://ctrl-c.us/blog</link>
	<description>a friendly interruption</description>
	<lastBuildDate>Fri, 28 May 2010 11:49:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Minority Rights Are Not Predicated on the Readiness of the Majority</title>
		<link>http://ctrl-c.us/blog/archives/875</link>
		<comments>http://ctrl-c.us/blog/archives/875#comments</comments>
		<pubDate>Fri, 28 May 2010 11:45:32 +0000</pubDate>
		<dc:creator>Caleb Spare</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Politics]]></category>
		<category><![CDATA[Rants]]></category>
		<category><![CDATA[don't ask don't tell]]></category>
		<category><![CDATA[lgbt rights]]></category>

		<guid isPermaLink="false">http://ctrl-c.us/blog/?p=875</guid>
		<description><![CDATA[Here in the US there has been some good news on the gay rights front recently: the House of Representatives voted to repeal the military&#8217;s &#8220;don&#8217;t ask, don&#8217;t tell&#8221; policy under which openly gay service members are discharged and which has been in place for the better part of two decades. Now it&#8217;s going to [...]]]></description>
			<content:encoded><![CDATA[<p>Here in the US there has been some good news on the gay rights front recently: the House of Representatives voted to repeal the military&#8217;s &#8220;don&#8217;t ask, don&#8217;t tell&#8221; policy under which openly gay service members are discharged and which has been in place for the better part of two decades. Now it&#8217;s going to the Senate, where apparently things could get tough, but if all goes well we may see real policy change within the next year or so. <a href="http://www.chron.com/disp/story.mpl/ap/top/all/7026085.html">Here is a Houston Chronicle article</a> about it.</p>
<p>It should not come as a surprise that almost across the board, Republicans oppose this policy change. From the article:</p>
<blockquote><p>Republicans, who voted overwhelmingly against it, cited statements by some military leaders that they need more time to study how a change in the law could affect the lives and readiness of service members.</p></blockquote>
<p>Here&#8217;s what I haven&#8217;t heard anyone say in response to this: why do we care what the brass thinks about the &#8220;readiness&#8221; of service members to have out gays serving with them? How does that take precedence over eliminating blatant discrimination in military policy? Some things are <strong>more important</strong> than appeasing some homophobic bigots in the military.</p>
<p>The case against repealing &#8220;don&#8217;t ask, don&#8217;t tell&#8221; is usually put this way (to quote John McCain):</p>
<blockquote><p>I think it&#8217;s really going to be very harmful to the morale and effectiveness of our military.</p></blockquote>
<p>The interesting part is that this argument is not new. As is pointed out by House Majority Leader Steny Hoyer in the article, the objection about &#8220;morale&#8221; is the same that was made by the people who opposed racial integration in the military 60 years ago. This was a cowardly and disingenuous argument then, and it remains so today.</p>
<p><span id="more-875"></span></p>
<p>The argument is cowardly because it implies that it is asking too much of the men and women in the military to serve honorably regardless of the sexual orientation of the people with whom they work. There are no evidence that the military will encounter huge problems when they abandon &#8220;don&#8217;t ask, don&#8217;t tell.&#8221; On the other hand, there are examples to show that letting gays serve is not a problem; <a href="http://www.ynetnews.com/articles/0,7340,L-3362505,00.html">one is the IDF</a>. It is a sad coincidence that Israel abolished the last of their restrictions on gays in the military in 1993, the same year that &#8220;don&#8217;t ask, don&#8217;t tell&#8221; was adopted.</p>
<p>The argument is disingenuous because it&#8217;s really a more politically correct way of expressing an ugly, bigoted sentiment. In 1948, when Members of Congress suggested that allowing people of different races to serve together in the military would undermine morale, I contend that this primarily sprung not from a concern about tensions in the armed forces, but from the strong racist tendencies of the day. Politicians couldn&#8217;t come out and say that they just didn&#8217;t want blacks serving alongside whites, so they had to frame it in anxiety for the effects on morale. The same thing is happening with respect to gays in the military today, and when the Republicans trot out this flimsy assertion it is the same shiny wrapping on the same rotten core.</p>
<p>(Somewhat related aside.) A long time ago, it was Mormon doctrine that the mark God made on Cain was, to quote Brigham Young, &#8220;the flat nose and black skin.&#8221; Henceforth Cain&#8217;s descendants were cursed with this mark, and people who are born this way are so cursed because they were less valiant in the pre-existence. This was why blacks were prohibited from the priesthood in the LDS church (in which essentially all the males become priests). In 1978, the leaders of the LDS church said that they had received a revelation that all worthy males could be ordained, regardless of race. (Presumably, this was almost as humorous as God revealing that polygamy should no longer be practiced in 1890, just when the outside pressure on Utah was the strongest.) Nowadays the conventional Mormon explanation for the denial of the priesthood to blacks is that the white members of the church weren&#8217;t ready for it.  Sound familiar?</p>
<p>In all these instances, the real anti-minority sentiment has been hidden by a veneer of concern for the feelings of the majority. This is invalid. Blacks and gays don&#8217;t get their rights when the majority stop feeling squeamish. They are born equal, and the majority don&#8217;t grow to accept that until they are forced to confront it.</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-c.us/blog/archives/875/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gmail: Please Bold the Hidden Labels Button when there are Unread Messages</title>
		<link>http://ctrl-c.us/blog/archives/643</link>
		<comments>http://ctrl-c.us/blog/archives/643#comments</comments>
		<pubDate>Tue, 21 Jul 2009 18:41:56 +0000</pubDate>
		<dc:creator>Caleb Spare</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[gmail labels]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">http://ctrl-c.us/blog/?p=643</guid>
		<description><![CDATA[I love Gmail. It does everything I could possibly want an email client (web or desktop) to do. All of my non-junk email accounts are Gmail or are forwarded to Gmail accounts. That said, occasionally something occurs to me that would make my Gmail experience a little bit better. Sometimes these crop up as Labs [...]]]></description>
			<content:encoded><![CDATA[<p>I love Gmail. It does everything I could possibly want an email client (web or desktop) to do. All of my non-junk email accounts are Gmail or are forwarded to Gmail accounts. That said, occasionally something occurs to me that would make my Gmail experience a little bit better. Sometimes these crop up as Labs features, which I think is great, and is part of why I enjoy using Gmail so much.<br />
<span id="more-643"></span></p>
<div id="attachment_644" class="wp-caption alignright" style="width: 191px"><img class="size-full wp-image-644 " src="http://ctrl-c.us/blog/wp-content/uploads/2009/07/gmail-hidden-labels.jpg" alt="What if this were bold?" width="181" height="488" /><p class="wp-caption-text">What if this were bold?</p></div>
<p>There was a fairly recent change to Gmail, where infrequently used labels could be hidden. It lets you keep your important labels in the left sidebar, and if you have 10 more hidden labels you click a little button that says &#8220;10 more&#8221; to show a menu with all of these labels. Chats, Sent Mail, Drafts, Starred, All Mail, Spam, and Trash also behave like normal labels for this purpose. This is a nice feature, in my opinion. I usually don&#8217;t care about how many spam messages I have, so I can tuck it away from my normal view. More importantly, I use a lot of filters (50 or 60) to organize incoming mail under labels (I have 32 at the moment), but  most of these only occasionally receive mail and it&#8217;s nice to have them hidden too.</p>
<p>When a label has unread messages in, it turns bold. For me, this used to mean that to see if I had any new mail, I looked both at the top of the inbox and scanned the labels for a bold one. Now, to see if any of my hidden labels have new messages, I have to click the button to show these labels. The fix, in my opinion, is to turn the &#8220;25 more&#8221; text bold when hidden labels have unread messages (see picture). I know it&#8217;s small, but this would save compulsive email checkers like myself a fair amount of annoyance. (Yes, I&#8217;m aware that I can just move all my labels out of this menu, but I like this feature too much to stop using it because of this.)</p>
<p>A small caveat here is that if you move the Spam label into this menu, you will always have unread messages (unless you don&#8217;t get spam, or mark it as read). Spam could be ignored for the purposes of bolding the button, but this might be considered unexpected behavior. Regardless, I&#8217;m sure the smart people on the Gmail team could figure something out.</p>
<p>I couldn&#8217;t find anyone else talking about this. This may be due to poor Googling on my part, or perhaps nobody else really cares. Hopefully other people have thought about it and we can get the attention of somebody at Google.</p>
<p><strong>Edit:</strong> I found another person&#8217;s idea for a solution to this problem <a href="http://www.google.com/support/forum/p/gmail/thread?tid=1e61cf53d192cc1d&amp;hl=en">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-c.us/blog/archives/643/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ctrl-C is Back</title>
		<link>http://ctrl-c.us/blog/archives/351</link>
		<comments>http://ctrl-c.us/blog/archives/351#comments</comments>
		<pubDate>Sat, 13 Jun 2009 08:34:06 +0000</pubDate>
		<dc:creator>Caleb Spare</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://ctrl-c.us/blog/?p=351</guid>
		<description><![CDATA[My (indirect) host, fsckvps.com, was pretty messed up by hackers using a HyperVM exploit. Fortunately, the server I use seemed to be OK, but the DNS servers were down and due to one thing and another I wasn&#8217;t able to set up alternate nameservers until just now. I&#8217;m using free service from afraid.org. It seems [...]]]></description>
			<content:encoded><![CDATA[<p>My (indirect) host, <a href="http://fsckvps.com">fsckvps.com</a>, was pretty messed up by hackers using a HyperVM exploit. Fortunately, the server I use seemed to be OK, but the DNS servers were down and due to one thing and another I wasn&#8217;t able to set up alternate nameservers until just now. I&#8217;m using free service from <a href="http://freedns.afraid.org/">afraid.org</a>. It seems kind of slow, but it&#8217;s definitely better than nothing. Anyone know of any alternatives? Is it possible to roll my own?</p>
<p>There is a slight improvement; <a href="http://www.ctrl-c.us/">http://www.ctrl-c.us/</a> now redirects to <a href="http://ctrl-c.us/">http://ctrl-c.us/</a> :-)</p>
<p>OK, it&#8217;s now way past my bedtime. I&#8217;m getting up in just a few hours to go on another epic hike. Pictures to follow.</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-c.us/blog/archives/351/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interfacing C and Python 3 using SWIG</title>
		<link>http://ctrl-c.us/blog/archives/99</link>
		<comments>http://ctrl-c.us/blog/archives/99#comments</comments>
		<pubDate>Mon, 27 Apr 2009 09:06:17 +0000</pubDate>
		<dc:creator>Caleb Spare</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[python 3]]></category>
		<category><![CDATA[swig]]></category>

		<guid isPermaLink="false">http://ctrl-c.us/?p=99</guid>
		<description><![CDATA[I like Python, and I use it for almost all of my personal projects and whenever I can get away with it in school. Sometimes, however, (rarely, these days) you&#8217;re looking for raw speed. Python, alas, is not the fastest kid on the block, and at these times you might have to turn to a [...]]]></description>
			<content:encoded><![CDATA[<p>I like Python, and I use it for almost all of my personal projects and whenever I can get away with it in school. Sometimes, however, (rarely, these days) you&#8217;re looking for raw speed. Python, alas, is not the fastest kid on the block, and at these times you might have to turn to a different language to give you the necessary speed. (Another option you might consider first is <a title="Psyco" href="http://psyco.sourceforge.net/" target="_blank">Psyco</a>.) In these situations it is often the case that only particular operations or functions really have to be fast. Even if you want to write the whole piece of software in C, you might like to use Python to write the front end. There are a lot of different ways to do this, but my favorite is <a title="Simplified Wrapper and Interface Generator" href="http://www.swig.org/" target="_blank">SWIG</a>, because it&#8217;s easy and I&#8217;m lazy.</p>
<p><span id="more-99"></span>SWIG is a great tool that supports a host of high-level languages; I&#8217;ve only ever used it with Python. At the other end, you get your choice of C and C++—crappy languages aren&#8217;t really my thing, so this tutorial will be about C. I&#8217;m going to use Python 3 because all the cool kids live on the bleeding edge. This requires SWIG 1.3.37 or better; if you&#8217;re on Ubuntu like me, you&#8217;re going to have to go grab it from the website and compile it yourself (I&#8217;m using 1.3.39). Also, remember that you need the header files for python installed (python3-dev on Ubuntu). If you&#8217;re too lazy to copy-paste, you can download the files <a href='http://ctrl-c.us/wordpress/wp-content/uploads/2009/04/swig_intro.tar.gz'>here</a>.</p>
<p>We&#8217;ll start out with the obligatory hello world program just to test that SWIG is set up correctly. First make a C function that prints the text and name it <code>hello.c</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include&lt;stdio.h&gt;</span>
&nbsp;
<span style="color: #993333;">void</span> hello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Hello, World!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now we&#8217;ll get SWIG to generate a wrapper for us so that we can call it in Python. Make a file called hello.i and put this in it (my code highlighting isn&#8217;t feeling very confident about SWIG files, sorry):</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">%</span>module hello
<span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">void</span> hello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">%</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>This file is the interface file, and it tells SWIG what functions and data structures are going to be shared between C and Python. Now we&#8217;ll have SWIG process the interface file to make a wrapper for a python module:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ swig <span style="color: #660033;">-python</span> hello.i</pre></div></div>

<p>This should generate two files: <code>hello.py</code> and <code>hello_wrap.c</code>. Compile the C files:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-fPIC</span> hello_wrap.c hello.c -I<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>include<span style="color: #000000; font-weight: bold;">/</span>python3.0 -I<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>python3.0</pre></div></div>

<p>Make sure that the direcotories are correct. Unfortunately, gcc generates a warning when I compile, which is bothersome as I&#8217;m a <code>-Werror</code> kind of guy. The <code>-fPIC</code> flag is necessary, because we&#8217;re making a shared library the python module is going to use:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ld</span> <span style="color: #660033;">-shared</span> hello.o hello_wrap.o <span style="color: #660033;">-o</span> _hello.so</pre></div></div>

<p>If that works, you are ready to fire up Python and try it. At a Python3 prompt:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">from</span> hello <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> hello<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
Hello, World<span style="color: #66cc66;">!</span></pre></div></div>

<p>Easy, right? Now I&#8217;ll show you some of the features that I most frequently use. First, we&#8217;ll pass some data through by wrapping a C function to multiply integers. Make a file called <code>swig_intro.h</code>, and put in the following declaration:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include&lt;stdlib.h&gt;</span>
<span style="color: #339933;">#include&lt;stdio.h&gt;</span>
&nbsp;
<span style="color: #993333;">int</span> mult<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> a<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Then in <code>swig_intro.c</code> we can write</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &quot;swig_intro.h&quot;</span>
&nbsp;
<span style="color: #993333;">int</span> mult<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> a<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> b<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> a <span style="color: #339933;">*</span> b<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Finally, the interface file, <code>swig_intro.i</code>, will look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">%</span>module swig_intro
<span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>
    <span style="color: #339933;">#include &quot;swig_intro.h&quot;</span>
<span style="color: #339933;">%</span><span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> mult<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> a<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>To make things easier, let&#8217;s write a makefile for this little project:</p>

<div class="wp_syntax"><div class="code"><pre class="make" style="font-family:monospace;">TARGET     <span style="color: #004400;">=</span> swig_intro
CC         <span style="color: #004400;">=</span> gcc
CFLAGS     <span style="color: #004400;">=</span> <span style="color: #004400;">-</span>g <span style="color: #004400;">-</span>fPIC <span style="color: #004400;">-</span>Wall <span style="color: #004400;">-</span>Wextra
HEADERS    <span style="color: #004400;">=</span> swig_intro<span style="color: #004400;">.</span>h
SRCS       <span style="color: #004400;">=</span> swig_intro<span style="color: #004400;">.</span>c
INCLUDES   <span style="color: #004400;">=</span>
INTERFACE  <span style="color: #004400;">=</span> swig_intro<span style="color: #004400;">.</span>i
SWIG       <span style="color: #004400;">=</span> swig
&nbsp;
LDSHARED   <span style="color: #004400;">=</span> ld
CSHARED    <span style="color: #004400;">=</span> <span style="color: #004400;">-</span>shared
&nbsp;
OBJS       <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span>SRCS<span style="color: #004400;">:.</span>c<span style="color: #004400;">=.</span>o<span style="color: #004400;">&#41;</span>
&nbsp;
IWRAP      <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span>INTERFACE<span style="color: #004400;">:.</span>i<span style="color: #004400;">=</span>_wrap<span style="color: #004400;">.</span>i<span style="color: #004400;">&#41;</span>
ISRCS      <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span>IWRAP<span style="color: #004400;">:.</span>i<span style="color: #004400;">=.</span>c<span style="color: #004400;">&#41;</span>
IOBJS      <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span>IWRAP<span style="color: #004400;">:.</span>i<span style="color: #004400;">=.</span>o<span style="color: #004400;">&#41;</span>
&nbsp;
PYTHON_INCLUDE<span style="color: #004400;">=</span> <span style="color: #004400;">-</span>I<span style="color: #004400;">/</span>usr<span style="color: #004400;">/</span><span style="color: #666622; font-weight: bold;">include</span><span style="color: #004400;">/</span>python3<span style="color: #004400;">.</span>0 <span style="color: #004400;">-</span>I<span style="color: #004400;">/</span>usr<span style="color: #004400;">/</span>lib<span style="color: #004400;">/</span>python3<span style="color: #004400;">.</span>0
PYTHON_SO     <span style="color: #004400;">=</span> <span style="color: #004400;">.</span>so
&nbsp;
all<span style="color: #004400;">:</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SRCS</span><span style="color: #004400;">&#41;</span>
	<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SWIG</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>python <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">INTERFACE</span><span style="color: #004400;">&#41;</span>
	<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CC</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>c <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CCSHARED</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CFLAGS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">ISRCS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">HEADERS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SRCS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">INCLUDES</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">PYTHON_INCLUDE</span><span style="color: #004400;">&#41;</span>
	<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LDSHARED</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CSHARED</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">OBJS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">IOBJS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>o _<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">TARGET</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">PYTHON_SO</span><span style="color: #004400;">&#41;</span>
&nbsp;
clean<span style="color: #004400;">:</span>
	rm <span style="color: #004400;">-</span>f <span style="color: #004400;">*</span>_wrap<span style="color: #004400;">*</span> <span style="color: #004400;">*</span>~ <span style="color: #004400;">.</span>~<span style="color: #004400;">*</span> <span style="color: #004400;">*.</span>pyc
	rm <span style="color: #004400;">-</span>f <span style="color: #004400;">*.</span>o <span style="color: #004400;">*.</span>so <span style="color: #004400;">*.</span>so</pre></div></div>

<p>If that works, you can launch a Python3 shell (from now on I&#8217;ll assume you do the import first):</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">from</span> swig_intro <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> mult<span style="color: black;">&#40;</span>-<span style="color: #ff4500;">10</span>, <span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>
-<span style="color: #ff4500;">50</span></pre></div></div>

<p>Behind the scenes, SWIG uses something called typemaps to specify how each type is from Python to C and vice versa. In many cases, such as this, we don&#8217;t need to worry about that at all, because SWIG has default typemaps for all the fundamental datatypes. For example, you might wonder what SWIG does with a C struct. Go ahead and add this definition to the header file and the interface file:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span> Person <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>first_name<span style="color: #339933;">;</span>
    <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>last_name<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> birth_year<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> Person<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> print_person<span style="color: #009900;">&#40;</span>Person <span style="color: #339933;">*</span>p<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>and put the following function into the <code>.c</code> file:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> print_person<span style="color: #009900;">&#40;</span>Person <span style="color: #339933;">*</span>p<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>p<span style="color: #339933;">-&gt;</span>first_name <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>p<span style="color: #339933;">-&gt;</span>last_name<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;The person is not properly defined.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%s %s was born in %d.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> p<span style="color: #339933;">-&gt;</span>first_name<span style="color: #339933;">,</span> p<span style="color: #339933;">-&gt;</span>last_name<span style="color: #339933;">,</span> p<span style="color: #339933;">-&gt;</span>birth_year<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now recompile and try this:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> p = Person<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> p.<span style="color: black;">first_name</span> = <span style="color: #483d8b;">&quot;Paul&quot;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> p.<span style="color: black;">last_name</span> = <span style="color: #483d8b;">&quot;Black&quot;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> p.<span style="color: black;">birth_year</span> = <span style="color: #ff4500;">1977</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> print_person<span style="color: black;">&#40;</span>p<span style="color: black;">&#41;</span>
Paul Black was born <span style="color: #ff7700;font-weight:bold;">in</span> 1977.</pre></div></div>

<p>As you can see, the the struct Person was wrapped in a very simple Python class with the three public data fields <code>first_name</code>, <code>last_name</code>, and <code>birth_year</code>.</p>
<p>Next, let&#8217;s see how to use typemaps ourselves to pass a more complex structure from Python to C. We&#8217;re going to make a (rather contrived) C function that will return the product of a list of integers. We&#8217;ll do this by turning a Python list into a C struct that specifies an int array and a size. Add the following code to the header and interface files:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">struct</span> IntList <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> size<span style="color: #339933;">;</span>
    <span style="color: #993333;">long</span> <span style="color: #339933;">*</span>list<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> IntList<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span> product<span style="color: #009900;">&#40;</span>IntList <span style="color: #339933;">*</span>l<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In the <code>.c</code> file, add the function:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> product<span style="color: #009900;">&#40;</span>IntList <span style="color: #339933;">*</span>l<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>l<span style="color: #339933;">-&gt;</span>size <span style="color: #339933;">&lt;=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #993333;">int</span> ret_val <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i size<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        ret_val <span style="color: #339933;">*=</span> l<span style="color: #339933;">-&gt;</span>list<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> ret_val<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now we need to define the typemap in the <code>.i</code> file. This isn&#8217;t too difficult; we just make use of several functions from the Python C API:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">%</span>typemap<span style="color: #009900;">&#40;</span>in<span style="color: #009900;">&#41;</span> IntList <span style="color: #339933;">*</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>PyList_Check<span style="color: #009900;">&#40;</span>$input<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        PyErr_SetString<span style="color: #009900;">&#40;</span>PyExc_TypeError<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Not a list.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #993333;">int</span> size <span style="color: #339933;">=</span> PyList_Size<span style="color: #009900;">&#40;</span>$input<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #0000dd;">1</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>IntList <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>IntList<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">long</span> <span style="color: #339933;">*</span>list <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #0000dd;">1</span><span style="color: #339933;">-&gt;</span>list <span style="color: #339933;">=</span> list<span style="color: #339933;">;</span>
    $<span style="color: #0000dd;">1</span><span style="color: #339933;">-&gt;</span>size <span style="color: #339933;">=</span> size<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> size<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        PyObject <span style="color: #339933;">*</span>item <span style="color: #339933;">=</span> PyList_GetItem<span style="color: #009900;">&#40;</span>$input<span style="color: #339933;">,</span> i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>PyInt_Check<span style="color: #009900;">&#40;</span>item<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            PyErr_SetString<span style="color: #009900;">&#40;</span>PyExc_TypeError<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;List item is not an integer.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            free<span style="color: #009900;">&#40;</span>list<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            free<span style="color: #009900;">&#40;</span>$<span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        list<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> PyInt_AsLong<span style="color: #009900;">&#40;</span>item<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">%</span>typemap<span style="color: #009900;">&#40;</span>freearg<span style="color: #009900;">&#41;</span> IntList <span style="color: #339933;">*</span> <span style="color: #009900;">&#123;</span>
    free<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>IntList <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>$<span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>list<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    free<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>IntList <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>$<span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This also illustrates how to tell SWIG to free your objects and how to handle errors. Now we can see it in action:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">from</span> swig_intro <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> product<span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>
Traceback <span style="color: black;">&#40;</span>most recent call last<span style="color: black;">&#41;</span>:
  File <span style="color: #483d8b;">&quot;&lt;stdin&gt;&quot;</span>, line <span style="color: #ff4500;">1</span>, <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #66cc66;">&lt;</span>module<span style="color: #66cc66;">&gt;</span>
<span style="color: #008000;">TypeError</span>: Not a <span style="color: #008000;">list</span>.
<span style="color: #66cc66;">&gt;&gt;&gt;</span> product<span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;five&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
Traceback <span style="color: black;">&#40;</span>most recent call last<span style="color: black;">&#41;</span>:
  File <span style="color: #483d8b;">&quot;&lt;stdin&gt;&quot;</span>, line <span style="color: #ff4500;">1</span>, <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #66cc66;">&lt;</span>module<span style="color: #66cc66;">&gt;</span>
<span style="color: #008000;">TypeError</span>: List item <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #ff7700;font-weight:bold;">not</span> an integer.
<span style="color: #66cc66;">&gt;&gt;&gt;</span> product<span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">7</span>,<span style="color: #ff4500;">9</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
<span style="color: #ff4500;">945</span></pre></div></div>

<p>As you would expect, transferring data the other way is similar. For an example, let&#8217;s make a function that takes a list and returns a dictionary mapping the list elements to their squares. Add these definitions to the header and interface files:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">struct</span> IntMap <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> size<span style="color: #339933;">;</span>
    <span style="color: #993333;">long</span> <span style="color: #339933;">*</span>list1<span style="color: #339933;">;</span>
    <span style="color: #993333;">long</span> <span style="color: #339933;">*</span>list2<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> IntMap<span style="color: #339933;">;</span>
&nbsp;
IntMap <span style="color: #339933;">*</span>square<span style="color: #009900;">&#40;</span>IntList <span style="color: #339933;">*</span>l<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The actual C function will take a pointer to an <code>IntList</code> and return a pointer to an <code>IntMap</code>, allocating space for a second list as needed. The conversion to a <code>dict</code> will be specified with an out typemap. In the <code>.c</code> file:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">IntMap <span style="color: #339933;">*</span>square<span style="color: #009900;">&#40;</span>IntList <span style="color: #339933;">*</span>l<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    IntMap <span style="color: #339933;">*</span>ret_map <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>IntMap <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>IntMap<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    ret_map<span style="color: #339933;">-&gt;</span>size <span style="color: #339933;">=</span> l<span style="color: #339933;">-&gt;</span>size<span style="color: #339933;">;</span>
    ret_map<span style="color: #339933;">-&gt;</span>list1 <span style="color: #339933;">=</span> l<span style="color: #339933;">-&gt;</span>list<span style="color: #339933;">;</span>
    ret_map<span style="color: #339933;">-&gt;</span>list2 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> l<span style="color: #339933;">-&gt;</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i size<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        ret_map<span style="color: #339933;">-&gt;</span>list2<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> l<span style="color: #339933;">-&gt;</span>list<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> l<span style="color: #339933;">-&gt;</span>list<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> ret_map<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Add the typemap to the <code>.i</code> file:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">%</span>typemap<span style="color: #009900;">&#40;</span>out<span style="color: #009900;">&#41;</span> IntMap <span style="color: #339933;">*</span> <span style="color: #009900;">&#123;</span>
    $result <span style="color: #339933;">=</span> PyDict_New<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i size<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        PyObject <span style="color: #339933;">*</span>key <span style="color: #339933;">=</span> PyInt_FromLong<span style="color: #009900;">&#40;</span>$<span style="color: #0000dd;">1</span><span style="color: #339933;">-&gt;</span>list1<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        PyObject <span style="color: #339933;">*</span>val <span style="color: #339933;">=</span> PyInt_FromLong<span style="color: #009900;">&#40;</span>$<span style="color: #0000dd;">1</span><span style="color: #339933;">-&gt;</span>list2<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        PyDict_SetItem<span style="color: #009900;">&#40;</span>$result<span style="color: #339933;">,</span> key<span style="color: #339933;">,</span> val<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">%</span>typemap<span style="color: #009900;">&#40;</span>freearg<span style="color: #009900;">&#41;</span> IntMap <span style="color: #339933;">*</span> <span style="color: #009900;">&#123;</span>
    free<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>IntMap <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>$<span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>list2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    free<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>IntMap <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>$<span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And we&#8217;re done!</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> square<span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>,-<span style="color: #ff4500;">12</span>,<span style="color: #ff4500;">60000</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
<span style="color: black;">&#123;</span><span style="color: #ff4500;">60000</span>: <span style="color: #ff4500;">3600000000</span>, <span style="color: #ff4500;">1</span>: <span style="color: #ff4500;">1</span>, -<span style="color: #ff4500;">12</span>: <span style="color: #ff4500;">144</span><span style="color: black;">&#125;</span></pre></div></div>

<p>I&#8217;ve only shown some of the more useful capabilities of SWIG that I find myself using a lot. For more information, consult the official <a href="http://www.swig.org/Doc1.3/Python.html">SWIG docs</a>. Unfortunately, they&#8217;re not entirely complete, so it is sometime easier to get answers by just browsing the built-in SWIG interface files to see how the typemaps work.</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-c.us/blog/archives/99/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>64-bit Flash Player!</title>
		<link>http://ctrl-c.us/blog/archives/92</link>
		<comments>http://ctrl-c.us/blog/archives/92#comments</comments>
		<pubDate>Mon, 17 Nov 2008 06:47:39 +0000</pubDate>
		<dc:creator>Caleb Spare</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://ctrl-c.us/?p=92</guid>
		<description><![CDATA[Today Adobe is releasing an alpha version of a 64-bit Flash player for Linux. I cannot explain how happy this makes me. I have been dealing with shitty 32-bit Flash players running on 32-bit emulation in 64-bit browsers in Linux for about the past five years, and it has caused me nothing but endless annoyance [...]]]></description>
			<content:encoded><![CDATA[<p>Today <a title="Press release" href="http://news.cnet.com/8301-1001_3-10097931-92.html" target="_blank">Adobe is releasing an alpha version of a 64-bit Flash player for Linux</a>. I cannot explain how happy this makes me. I have been dealing with shitty 32-bit Flash players running on 32-bit emulation in 64-bit browsers in Linux for about the past five years, and it has caused me nothing but endless annoyance and frustration. Half the time I have to refresh a page a few times because Flash keeps dying, and even when it manages to play it&#8217;s a complete coin toss as to whether there will be sound. With my current setup I basically have to close Amarok to play a Flash video if I want to hear sound. Adobe is years late to the party with this one, but better late than never, right?</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-c.us/blog/archives/92/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Seven Document Formats Worse than Scribd</title>
		<link>http://ctrl-c.us/blog/archives/83</link>
		<comments>http://ctrl-c.us/blog/archives/83#comments</comments>
		<pubDate>Fri, 31 Oct 2008 07:05:13 +0000</pubDate>
		<dc:creator>Caleb Spare</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://ctrl-c.us/?p=83</guid>
		<description><![CDATA[The other day while searching for some LaTeX information I came across this page on Scribd, and I was reminded once again how much I loathe this website. If you aren&#8217;t familiar with it, Scribd is a site which hosts various books, articles, and other documents. For reasons that are an impenetrable mystery to me, [...]]]></description>
			<content:encoded><![CDATA[<p>The other day while searching for some LaTeX information I came across <a title="Latex symbols reference on Scribd" href="http://www.scribd.com/doc/2287516/latex-symbols-reference" target="_blank">this page</a> on <a title="Scribd" href="http://www.scribd.com/" target="_blank">Scribd</a>, and I was reminded once again how much I loathe this website. If you aren&#8217;t familiar with it, Scribd is a site which hosts various books, articles, and other documents. For reasons that are an impenetrable mystery to me, these people have decided that the way to bring together potentially many different formats of print media is to turn them all into shockwave flash. As in, this beautifully typeset LaTeX document, compiled to PDF, was turned into a scrollable flash…thing. Combine this with the rather sorry state of flash on Linux, and you get just about my least favorite website on the entire intertubes. Just getting it in a Google search makes me almost as mad as getting a link to <a title="Experts Exchange" href="http://www.experts-exchange.com/" target="_blank">Experts Exchange</a>.</p>
<p>So, to keep my blood pressure down, I put things into perspective for myself by making a list of seven document formats Scribd <em>could </em>have chosen to use, but didn&#8217;t.</p>
<p><span id="more-83"></span></p>
<ol>
<li>Upon request, print the document out and mail it to the users, preferably from a distribution center somewhere in Africa.</li>
<li>Put each word from the document in a Web 2.0-esque cloud visualization where the size of each tag reflects the relative frequency of the word&#8217;s occurrence.</li>
<li>Save the document as a series of images. Upload these to Facebook. When a user requests the document, tag the user in all of those pictures so that he/she can view them.</li>
<li>Offer RealPlayer streaming videos of somebody slowly scrolling through the document.</li>
<li>Record someone reading the document, set it to soothing piano music with a psychedelic visualization, and submit it to YouTube in a series of 10-minute segments.</li>
<li>Ask the user for his/her phone number. Split the document into 140-byte chunks and send them sequentially as SMS messages.</li>
<li>Write out the document in 1:1000 scale on the ground using large rocks. Then provide links to the appropriate Google Map coordinates.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-c.us/blog/archives/83/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Why Tim Burton&#8217;s &#8216;Alice in Wonderland&#8217; Will Be Epic</title>
		<link>http://ctrl-c.us/blog/archives/75</link>
		<comments>http://ctrl-c.us/blog/archives/75#comments</comments>
		<pubDate>Thu, 16 Oct 2008 06:42:44 +0000</pubDate>
		<dc:creator>Caleb Spare</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Movies]]></category>

		<guid isPermaLink="false">http://ctrl-c.us/?p=75</guid>
		<description><![CDATA[I just finished reading this interview with Tim Burton about his upcoming film Alice in Wonderland, and I am really excited. I knew that this film was in the works, but I had somehow missed the fact that Johnny Depp is playing the Mad Hatter. With these two together, I cannot possibly imagine this film [...]]]></description>
			<content:encoded><![CDATA[<p>I just finished reading <a title="LA Times Tim Burton interview" href="http://latimesblogs.latimes.com/herocomplex/2008/10/tim-burton-talk.html" target="_blank">this interview</a> with Tim Burton about his upcoming film <a title="IMDB page for Alice in Wonderland" href="http://www.imdb.com/title/tt1014759/" target="_blank">Alice in Wonderland</a>, and I am really excited. I knew that this film was in the works, but I had somehow missed the fact that Johnny Depp is playing the Mad Hatter. With these two together, I cannot possibly imagine this film not kicking serious ass.</p>
<p><span id="more-75"></span></p>
<p>The reason I&#8217;m so pumped about the Burton/Depp combination is primarily based on the great work they did with <a title="IMDB page for Charlie and the Chocolate Factory" href="http://www.imdb.com/title/tt0367594/" target="_blank">Charlie and the Chocolate Factory</a>. To fully explain how much I like this movie, a bit of background is in order. As a child, I absolutely adored Roald Dahl. I read and re-read almost every children&#8217;s book and short story he had written (my favorite was definitely James and the Giant Peach). My parents were not completely comfortable with this, and in general I would imagine that a lot of adults would find most of Roald Dahl&#8217;s children&#8217;s literature at least somewhat disturbing. This is for the same reason that it resonates so very well with kids: it portrays the world as an unfair, messed-up place, and a lot of the adults are downright despicable people. His stories generally involve children who are completely unsheltered from the cruelty of life. There is a definite touch of cruel humor to almost all of Dahl&#8217;s work and, as a child, I loved it.</p>
<p>When I eventually watched the first film adaptation of Charlie and the Chocolate Factory (<a title="IMDB page for Willy Wonka &amp; the Chocolate Factory" href="http://www.imdb.com/title/tt0067992/" target="_blank">the one that&#8217;s not actually titled &#8216;Charlie and the Chocolate Factory&#8217;</a>), I was thoroughly disappointed. It told a wonderful, magical tale with a happy ending, a nice, pro-family moral, and catchy music. But it didn&#8217;t convey the real spirit of Roald Dahl. It just wasn&#8217;t there. When Burton&#8217;s adaptation came out, I was expecting it to be the same, only weirder. In fact, I didn&#8217;t even watch it until one night when I was really bored more than a year after its release. When I did see it, though, I was completely floored. It was exactly spot-on to the image of Charlie and the Chocolate Factory that I&#8217;d had in my mind all those years. It was like a piece of my childhood had suddenly been restored. Burton&#8217;s touch for dark humor made the movie an absolute masterpiece. Johnny Depp, who I wasn&#8217;t all that familiar with at the time, was a flawless pick for Willy Wonka. He fully realized the erratic, unforgiving, and wildly eccentric character given to us by Dahl so many years ago. After watching it, I realized that the 2005 movie is better than its 1971 counterpart by every standard I could think of (and I&#8217;m including the music; Danny Elfman&#8217;s score is compelling and impeccable).</p>
<p>The slightly odd thing is that I&#8217;ve found very few people who share my view. I find that most people who have seen both of the film adaptations for Charlie and the Chocolate Factory prefer the older one. I&#8217;m not quite sure why this is; I think that one reason is that a lot of people were more familiar with the film than the book as children, and thus didn&#8217;t identify with Burton&#8217;s version like I did.</p>
<p>This was supposed to be about Alice in Wonderland, though. Let me explain why this movie is going to rock: <strong>every quality of Roald Dahl&#8217;s Charlie that Burton and Depp did so well is even more core to Alice in Wonderland</strong>. This book is so much more bizarre, more unpredictable, more whimsical. It feels scarier and twists the reader&#8217;s expectations more. It is dark, capricious, and infinitely original. Drugs were definitely involved. Johnny Depp and Tim Burton aren&#8217;t just going to do it well, they are the best people in Hollywood right now to turn Lewis Carroll&#8217;s masterpiece into pure awesome on the silver screen. I can&#8217;t wait.</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-c.us/blog/archives/75/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Howto: Dual Monitors with Ubuntu and NVidia</title>
		<link>http://ctrl-c.us/blog/archives/54</link>
		<comments>http://ctrl-c.us/blog/archives/54#comments</comments>
		<pubDate>Mon, 29 Sep 2008 07:26:29 +0000</pubDate>
		<dc:creator>Caleb Spare</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://ctrl-c.us/?p=54</guid>
		<description><![CDATA[Pursuant to my previous post on using dual monitors in Linux, I decided to post a some information that would have definitely appreciated having a long time ago. This specifically covers how get two monitors working in a reasonable fashion in Ubuntu and Xubuntu, but I originally figured it out in Gentoo (and it applies [...]]]></description>
			<content:encoded><![CDATA[<p>Pursuant to my previous post on using dual monitors in Linux, I decided to post a some information that would have definitely appreciated having a long time ago. This specifically covers how get two monitors working in a reasonable fashion in Ubuntu and Xubuntu, but I originally figured it out in Gentoo (and it applies to other distros).</p>
<p><span id="more-54"></span></p>
<ol>
<li>Make sure that you&#8217;re using the proprietary nvidia driver and that you have nvidia settings installed:

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">sudo apt-get install nvidia-settings</pre></div></div>

</li>
<li>Open up nvidia-settings (under System -&gt; Administration in Ubuntu and System in Xubuntu).</li>
<li>Under &#8220;X Server Display Configuration&#8221;, you need to set each monitor to have the correct resolution. Also specify the layout you want, and change the configuration to TwinView. Finally, set the position of <strong>both</strong> to &#8220;Absolute&#8221;.</li>
<li>Now hit &#8220;Save to X Configuration File&#8221;. Save this to your home directory (i.e. change the path to <code>~/xorg.conf</code>).</li>
<li>(Optional.) If you want to get rid of the NVidia splash screen every time X restarts, open the <code>xorg.conf</code> file in the editor of your choice and make sure that the line

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Option   &quot;NoLogo&quot; &quot;True&quot;</pre></div></div>

<p>appears under each &#8220;Device&#8221; section.</li>
<li>Move the file to the proper directory (you need root access):

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">sudo mv ~/xorg.conf /etc/X11/</pre></div></div>

</li>
<li>Restart the X server. The easiest way to do this is to log out and log back in.</li>
<li>Now the Xinerama info should be getting sent properly. In Ubuntu you can tell that this is the case if you are able to place your panel on just one screen instead of both of them (drag it around a bit). Unfortunately, Gnome doesn&#8217;t let you set separate desktop backgrounds, so if you want something different on each screen you&#8217;ll need to make an image the width of both screens added together and paste the two pictures in (you can do this easily in the Gimp). In Xubuntu, when you open up the properties for your panel, you&#8217;ll be able to choose the monitor on which it should appear. Additionally, Xfce allows you to set separate desktop backgrounds.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-c.us/blog/archives/54/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Yet Another Wordpress User</title>
		<link>http://ctrl-c.us/blog/archives/48</link>
		<comments>http://ctrl-c.us/blog/archives/48#comments</comments>
		<pubDate>Mon, 22 Sep 2008 08:55:10 +0000</pubDate>
		<dc:creator>Caleb Spare</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://ctrl-c.us/?p=48</guid>
		<description><![CDATA[After dealing with spam again tonight and facing the prospect of reworking my captcha and adding user registration, I completely gave up on the whole site-from-scratch thing and have replaced it with the Wordpress site you&#8217;re looking at now. I found this process to be very simple and straightforward, and I especially liked all the [...]]]></description>
			<content:encoded><![CDATA[<p>After dealing with spam again tonight and facing the prospect of reworking my captcha and adding user registration, I completely gave up on the whole site-from-scratch thing and have replaced it with the Wordpress site you&#8217;re looking at now. I found this process to be very simple and straightforward, and I especially liked all the import options (in my case, I got the articles from my old RSS feed). After spending about an hour changing settings, adding plugins, and tweaking CSS, I think that I&#8217;ll be able to live with it.</p>
<p><span id="more-48"></span></p>
<p>Unfortunately I was too lazy to rescue comments, so they&#8217;re all gone. We&#8217;ll have to see how commenting goes; right now I have to approve comments except by registered users, so at least the spam won&#8217;t be showing up on the site (just my inbox).</p>
<p>A couple of thoughts about Wordpress:</p>
<ul>
<li>My favorite part is definitely the admin experience. The admin pages have a beautiful layout with a very nice color scheme, rounded corners, and AJAX-y goodness. The admin panel is also very powerful and extremely intuitive; all in all, I love it.</li>
<li>I think that the weakest part of Wordpress is actually the themes. I spent a ton of time trying to find one I liked and eventually settled for a moderately okay one. People who write Wordpress themes need to be introduced to two important concepts: (a) It is not an efficient use of space to only use the middle fifth of the monitor (see <a href="http://wordpress.org/extend/themes/mini-blog" target="_blank">this crap-tacular example</a>), and (b) An 10pt serif font is awful for a blog. People have big monitors these days, and <a href="http://www.webdesignfromscratch.com/readability.cfm" target="_blank">readability</a> is important.</li>
</ul>
<p>Alright, I have to go to bed right now. I have been working on this instead of school work, which unfortunately leaves me with a register allocator to finish writing by the end of the day tomorrow :(</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-c.us/blog/archives/48/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>In Defense of Sarah Palin (Sort of)</title>
		<link>http://ctrl-c.us/blog/archives/8</link>
		<comments>http://ctrl-c.us/blog/archives/8#comments</comments>
		<pubDate>Tue, 09 Sep 2008 06:31:30 +0000</pubDate>
		<dc:creator>Caleb Spare</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Politics]]></category>

		<guid isPermaLink="false">http://ctrl-c.us/index.php?page=articles&amp;article=in_defense_of_sarah_</guid>
		<description><![CDATA[For the past six months or so, the presidential election hasn&#8217;t ceased to provide me with story after story that I find deeply disturbing or upsetting. I&#8217;ve been particularly struck by the absolute about-face McCain has made from his independent stances in the past. With his acquisition of Sarah Palin as a running-mate, I&#8217;ve become [...]]]></description>
			<content:encoded><![CDATA[<p>For the past six months or so, the presidential election hasn&#8217;t ceased to provide me with story after story that I find deeply disturbing or upsetting. I&#8217;ve been particularly struck by the absolute about-face McCain has made from his independent stances in the past. With his acquisition of Sarah Palin as a running-mate, I&#8217;ve become certain that the awful, crippled monstrosity that is the US election system has done the unimaginable and provided us with a ticket even <em>more</em> harmful to our nation then the drooling sack of ineptitude currently occupying the White House. I&#8217;ve thought of at least a dozen blog posts that I haven&#8217;t had the time to write concerning this dismal state of affairs in the last few weeks alone.</p>
<p><span id="more-8"></span></p>
<p>I saw something today, though, that was the proverbial last straw. It may be surprising, but what upset me was actually an <em>attack</em> on Palin. I read it in <a href="http://www.huffingtonpost.com/2008/09/08/how-to-understand-sarah-p_n_124801.html">this Huffington Post article</a>. Under the heading <strong>On Abortion</strong>, the author explains Palin&#8217;s (quaint, yet terrifying) views on abortion. She doesn&#8217;t believe in abortions even for rape victims, AND, writes Mr. Walls, (you can practically hear a scandalized whisper) she makes no exceptions, even for her OWN DAUGHTER.</p>
<p>It&#8217;s not just Mr. Walls and the Huffington Post, though. I&#8217;ve seen this played as some sort of trump card by many liberal blog sites and in many of the political stories I&#8217;ve read. In only the past few days I&#8217;ve seen at least five references to this fact.</p>
<p>It&#8217;s certainly true that this is Mrs. Palin&#8217;s position. She stated this in a response to a question during a debate in the 2006 gubernatorial race. It&#8217;s clearly on the record, and I feel confident that she would still back that statement completely.</p>
<p>Guess what? It doesn&#8217;t matter. It&#8217;s completely irrelevant.</p>
<p>It doesn&#8217;t mean anything if she opposes her own daughter getting an abortion if she were a rape victim if that&#8217;s her official political stance. It&#8217;s not draconian. It&#8217;s called having integrity.</p>
<p>In fact, I take issue with the person who asks such a question. There is absolutely nothing of political relevance that can be gleaned from her answer that couldn&#8217;t have been revealed by asking a question such as &#8220;Do you think that a teenager who has been raped should be permitted to get an abortion?&#8221;. The only difference in these questions is in the emotionality and sentimental weight they place upon her response.</p>
<p>This is a problem because emotion and sentiment are precisely what this country&#8217;s election system needs less of right now. We have reached a point where logic and level-headed reasoning plays almost no role in voters&#8217; decisions, and each time non-issues like this one are paraded around it adds to the problem.</p>
<p>Interestingly, this is certainly not the first time this kind of thing has reared its ugly head in our elections. In 1988 Dukakis lost 7 precious poll points in a single night following a debate in which he was asked if he would support the death penalty for a person who raped and murdered his wife. His response? No. He wouldn&#8217;t support the death penalty in this case because he&#8217;d always been an opponent of the death penalty. This was an utterly useless question, yet it was one that probably cost Dukakis the presidency. All subsequent presidential nominees by the major parties have supported the death penalty in at least some cases.</p>
<p>What can we do about it? Don&#8217;t propogate irrelevant stories like this. Focus on the issues. Don&#8217;t vote without having logical reasons for your choice.</p>
<p>In the end, I hope Palin keeps sticking to her guns. When politicians are honest and give us straight talk (think McCain, but 10 years ago), we don&#8217;t have to analyze the nuances of their speeches and engage in endless political punditry. They&#8217;ll tell us what we need to know about them, we&#8217;ll be able to compare that to our own ideas, and then we&#8217;ll make informed decisions.</p>
<p>Like not voting for a right-wing nut job.</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-c.us/blog/archives/8/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
