<?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>deffbeff &#187; Programming</title>
	<atom:link href="http://www.deffbeff.com/blog/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.deffbeff.com/blog</link>
	<description>Mostly software</description>
	<lastBuildDate>Thu, 03 Dec 2009 23:00:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>underscore t reserved!</title>
		<link>http://www.deffbeff.com/blog/2009/12/underscore-t-reserved/</link>
		<comments>http://www.deffbeff.com/blog/2009/12/underscore-t-reserved/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 22:59:35 +0000</pubDate>
		<dc:creator>Matthew Gilbert</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Posix]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Posix C++ Programming NamingConventions]]></category>

		<guid isPermaLink="false">http://www.deffbeff.com/blog/2009/12/underscore-t-reserved/</guid>
		<description><![CDATA[Through a recent stackoverflow question I learned that Posix reserves any identifier ending in “_t”. News to me! I really liked naming my classes starting with a lowercase letter and ending in an “_t”. This permits code like: class list_t { }; ... int main(int argc, char *argv[]) { list_t list; } This pretty much [...]]]></description>
			<content:encoded><![CDATA[<p>Through a recent stackoverflow question I learned that Posix reserves any identifier ending in “_t”. News to me! I really liked naming my classes starting with a lowercase letter and ending in an “_t”. This permits code like: </p>
<pre>     class list_t { };
     ...
     int
     main(int argc, char *argv[])
     {
          list_t list;
     }</pre>
</p>
<p>This pretty much forces me to start any type in the global namespace with a capitol letter (not my preference). To keep things consistent, that means all my classes/structs will now start with a capitol letter. See <a href="http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_02.html">here</a> for the posix rules.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.deffbeff.com/blog/2009/12/underscore-t-reserved/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building Qt with OpenSSL support using the Windows SDK</title>
		<link>http://www.deffbeff.com/blog/2009/08/building-qt-with-openssl-support-using-the-windows-sdk/</link>
		<comments>http://www.deffbeff.com/blog/2009/08/building-qt-with-openssl-support-using-the-windows-sdk/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 19:50:11 +0000</pubDate>
		<dc:creator>Matthew Gilbert</dc:creator>
				<category><![CDATA[OpenSSL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Qt]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[SDK]]></category>

		<guid isPermaLink="false">http://www.deffbeff.com/blog/?p=53</guid>
		<description><![CDATA[Install perl (needed for building OpenSSL). Follow OpenSSL instructions to build and install (README.W32 or README.W64, use the masm target). I installed OpenSSL into the same prefix that I’m using for Qt. Copy the Qt mkspeks directory to the Qt prefix directory. Run configure, something like: ./configure -release -no-qt3support -prefix C:\qt\4.5.2 -qt-libjpeg -qt-libpng -openssl -I [...]]]></description>
			<content:encoded><![CDATA[<ol>
<li>Install perl (needed for building OpenSSL). </li>
<li>Follow OpenSSL instructions to build and install (README.W32 or README.W64, use the masm target). I installed OpenSSL into the same prefix that I’m using for Qt. </li>
<li>Copy the Qt mkspeks directory to the Qt prefix directory. </li>
<li>Run configure, something like:      <br /><font size="2" face="Droid Sans Mono">./configure -release -no-qt3support -prefix C:\qt\4.5.2 -qt-libjpeg -qt-libpng -openssl -I c:\qt\4.5.2\include -L c:\qt\4.5.2\bin</font>
<p><font size="2">(based on instructions from </font><a href="http://wiki.secondlife.com/wiki/QtWebkitWin32BuildInstructions"></a><a href="http://wiki.secondlife.com/wiki/QtWebkitWin32BuildInstructions"><font size="2">http://wiki.secondlife.com/wiki/QtWebkitWin32BuildInstructions</font></a></a><font size="2">)</font></p>
</li>
<li>nmake &amp;&amp; nmake install </li>
</ol>
<p><font size="2"></font></p>
]]></content:encoded>
			<wfw:commentRss>http://www.deffbeff.com/blog/2009/08/building-qt-with-openssl-support-using-the-windows-sdk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Pygments with docutils</title>
		<link>http://www.deffbeff.com/blog/2009/06/using-pygments-with-docutils/</link>
		<comments>http://www.deffbeff.com/blog/2009/06/using-pygments-with-docutils/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 21:56:03 +0000</pubDate>
		<dc:creator>Matthew Gilbert</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[reStructuredText]]></category>
		<category><![CDATA[docutils]]></category>
		<category><![CDATA[pygments]]></category>

		<guid isPermaLink="false">http://www.deffbeff.com/blog/?p=46</guid>
		<description><![CDATA[Pygments has a very short tutorial for integrating itself with docutils here: http://pygments.org/docs/rstdirective/. However, that was not enough info to get me started using Pygments with rst2html.py. Here are the missing steps: Copy the Pygments supplied rst-directive.py to your docutils installation. Something like: cp Pygments/external/rst-directive.py \ .../site-packages/docutils/parsers/rst/directives/rst_directive.py Notice that rst-directive.py became rst_directive.py (dash changed to [...]]]></description>
			<content:encoded><![CDATA[<p>Pygments has a very short tutorial for integrating itself with docutils here: <a href="http://pygments.org/docs/rstdirective/">http://pygments.org/docs/rstdirective/</a>. However, that was not enough info to get me started using Pygments with rst2html.py. Here are the missing steps:</p>
<ol>
<li>Copy the Pygments supplied rst-directive.py to your docutils installation. Something like:
<pre>cp Pygments/external/rst-directive.py \
 .../site-packages/docutils/parsers/rst/directives/rst_directive.py</pre>
<p>Notice that rst-directive.py became rst_directive.py (dash changed to underscore). </li>
<li>Modify rst_directive.py in the docutils directives directory to set INLINESTYLES = True and add a style option to the formatter. Something like:
<pre># Set to True if you want inline CSS styles instead of classes
INLINESTYLES = True

from pygments.formatters import HtmlFormatter

# The default formatter
DEFAULT = HtmlFormatter(noclasses=INLINESTYLES, style='trac')</pre>
</li>
<li>Modify rst2html.py to import the Pygments directive. I added the following line:
<pre>from docutils.parsers.rst.directives import rst_directive</pre>
</li>
</ol>
<p>That’s it. Now I can use the ..sourcecode directive in my rst documents. For example:</p>
<pre>.. sourcecode:: c++
	int
	main(int argc, char *argv[])
	{
	}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.deffbeff.com/blog/2009/06/using-pygments-with-docutils/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preparing for jEdit plugin development</title>
		<link>http://www.deffbeff.com/blog/2009/02/preparing-for-jedit-plugin-development/</link>
		<comments>http://www.deffbeff.com/blog/2009/02/preparing-for-jedit-plugin-development/#comments</comments>
		<pubDate>Sun, 08 Feb 2009 16:57:49 +0000</pubDate>
		<dc:creator>Matthew Gilbert</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Editor]]></category>
		<category><![CDATA[jEdit]]></category>

		<guid isPermaLink="false">http://www.deffbeff.com/blog/?p=32</guid>
		<description><![CDATA[When I started using jEdit it took me a while to figure out how to begin building and developing jEdit and its plugins. I don&#8217;t know of a well documented tutorial, so I&#8217;m documenting the way I get started here. I typically develop on Windows, but most steps equally apply on Linux. I strongly recommend [...]]]></description>
			<content:encoded><![CDATA[<p>When I started using jEdit it took me a while to figure out how to begin building and developing jEdit and its plugins. I don&#8217;t know of a well documented tutorial, so I&#8217;m documenting the way I get started here. I typically develop on Windows, but most steps equally apply on Linux. I strongly recommend using jEdit trunk, it is very stable and is required for the latest and greatest plugins.</p>
<ol>
<li>Install subversion </li>
<li>Install the Sun Java JDK. Unfortunately, the completely free IcedTea JDK isn&#8217;t up to running jEdit. </li>
<li>Download Apache ant and put the bin directory in your path. </li>
<li>You&#8217;ll need xsltproc and docbook to build the jEdit documentation. Download the docbook xsl scripts from <a href="http://sourceforge.net/project/showfiles.php?group_id=21935&amp;package_id=16608&amp;release_id=603854/">http://sourceforge.net/project/showfiles.php?group_id=21935&amp;package_id=16608&amp;release_id=603854</a> and unpack somewhere (I unpack into c:\workspace\docbook, this path is needed later in step 7). The above links to version 1.74. The most recent version can be found from <a href="http://wiki.docbook.org/topic/DocBookXslStylesheets">http://wiki.docbook.org/topic/DocBookXslStylesheets</a>. </li>
<li>Download xsltproc. I downloaded a binary from <a href="http://xmlsoft.org/XSLT/downloads.html">http://xmlsoft.org/XSLT/downloads.html</a>. On Windows, you&#8217;ll also need iconv.dll, zlib1.dll, libxslt.dll, libxml2.dll, and libexslt.dll to run xsltproc.exe. Put the exe and dll&#8217;s in your path. </li>
<li>Check-out jEdit from svn:
<pre>svn co https://jedit.svn.sourceforge.net/svnroot/jedit/jEdit/trunk jEdit</pre>
</li>
<li>Create jEdit&#8217;s build.properties from the build.properties.sample file:
<pre>cd jEdit
cp build.properties.sample build.properties</pre>
<p>Edit the build.properties file to point to your xslt installation. The following are the lines I add (the path to docbook.xsl should match the directory in step 4):</p>
<pre>xsltproc.executable=C:\\workspace\\bin\\xsltproc.exe
docbook.xsl=C:\\workspace\\docbook\\docbook-xsl-1.74.0
docbook.catalog=C:\\workspace\\docbook\\docbook-xsl-1.74.0\\catalog.xml</pre>
</li>
<li>Now build jEdit, run:
<pre>ant
ant userdocs</pre>
<p>This builds jedit.jar and the userdocs in the build directory (a normal jEdit prints numerous warnings that can be ignored). You can run this jEdit with something like:</p>
<pre>javaw.exe -Xmx1024M -Dswing.aatext=true -Dawt.useSystemAAFontSettings=lcd -Dsun.java2d.d3d=false -jar build\jedit.jar</pre>
</li>
<li>If the above was successful, you should now have a .jedit settings directory in your home directory. We can now setup the necessities for building a plugin. Go to your settings directory and check-out jEdit&#8217;s build-support.
<pre>cd ~/.jedit/jars
svn co <a href="https://jedit.svn.sourceforge.net/svnroot/jedit/build-support/trunk">https://jedit.svn.sourceforge.net/svnroot/jedit/build-support/trunk</a> build-support</pre>
</li>
<li>Now copy the build-support build.properties sample and edit for your installation (should still be in ~/.jedit/jars).
<pre>cp build-support\build.properties.sample build.properties</pre>
<p>Edit build.properties to set the jEdit install directory (I don&#8217;t change anything else). On my system, that line looks like this:</p>
<pre>jedit.install.dir=c:\\workspace\\jedit\\jEdit\\build</pre>
</li>
<li>Finally, check-out a plugin to build and build it.
<pre>svn co https://jedit.svn.sourceforge.net/svnroot/jedit/plugins/VoxSpell/trunk VoxSpell
cd VoxSpell
ant</pre>
<p>This should build VoxSpell and place the jar file in your settings directory plugin-jars directory. The next time you start jEdit it will find the jar file and load the plugin. </p>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.deffbeff.com/blog/2009/02/preparing-for-jedit-plugin-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multithreading and fork()</title>
		<link>http://www.deffbeff.com/blog/2009/01/multithreading-and-fork/</link>
		<comments>http://www.deffbeff.com/blog/2009/01/multithreading-and-fork/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 18:48:33 +0000</pubDate>
		<dc:creator>Matthew Gilbert</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[multiprocess]]></category>
		<category><![CDATA[multithreaded]]></category>

		<guid isPermaLink="false">http://www.deffbeff.com/blog/?p=12</guid>
		<description><![CDATA[Prevent hangs in multi-threaded/multi-process code by minimizing code that runs in the child process after a fork.]]></description>
			<content:encoded><![CDATA[<p>I recently wrote a tool in C++ that would run a large number of tasks in the background, parse the results, and print simple pass/fail information for each task. I used the tool as an opportunity to start using boost::threads which resembles the upcoming C++0x threading support. The multithreaded portion of the code was very simple, all contained in my own <a href="http://en.wikipedia.org/wiki/Future_(programming)">futures</a> class.</p>
<p>Everything ran well, except occasionally a test would time-out. I figured this was a problem with how I was setting up the stdin/stdout pipes to the subtask (each thread would fork() to run the sub-task and use a timed poll() to wait for results). On Friday, I finally sat down to figure out what was causing the test hangs.</p>
<p>Turns out it had nothing to do with sub-task input and output. Each thread is responsible for one subtask. The thread creates the necessary pipes, performs some other book keeping, and then forks. The child process then transforms a vector of command line arguments to an argv[] style array, sets up stdin/stdout with dup2, and calls execvp.</p>
<p>To debug, I modified the parent to print the hung pid which I would attach to using gdb. Every time I attached, the child process was stuck in the same place: waiting on a mutex used by the std::string implementation.</p>
<p>The child process doesn’t use any threading functions, and all of its parameters are passed on the stack. However, I didn’t consider that most of libstdc++ is thread safe (I can’t find a reference that specifies exactly what is and isn’t thread safe in glibc/libstdc++). Each time the process forked, it risked forking while the underlying std::string memory mutex was being held by another thread. As documented in the pthread_atfork man page, those mutexes are not useable after the fork, and must be re-initialized with pthread_mutex_init in the child process. This caused the child process to hang indefinitely waiting on a mutex that would be released only in the parent’s process space.</p>
<p>The solution was to move the std::string processing before the fork. That left only dup2 calls and the execvp after the fork. Result: no more hangs!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.deffbeff.com/blog/2009/01/multithreading-and-fork/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Embedded manifests in Windows 7</title>
		<link>http://www.deffbeff.com/blog/2009/01/embedded-manifests-in-windows-7/</link>
		<comments>http://www.deffbeff.com/blog/2009/01/embedded-manifests-in-windows-7/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 17:01:58 +0000</pubDate>
		<dc:creator>Matthew Gilbert</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[manifests]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[windows7]]></category>

		<guid isPermaLink="false">http://www.deffbeff.com/blog/?p=8</guid>
		<description><![CDATA[Getting "invalid windows image" when trying to use mt.exe on Windows 7? The likely cause is an issue with embedding a manifest resource before an existing resource section is present. This is documented in section 5.3.6 of the Windows 7 SDK release notes.]]></description>
			<content:encoded><![CDATA[<p>I recently took advantage of the Windows7 beta and think it’s a great upgrade over Vista. However, anything I compiled with the Windows SDK resulted in a binary that was reported to be an invalid windows image. Turns out the issue is documented in the SDK release notes (section 5.3.6). A resource section is required (even an empty resource) before you can embed a manifest resource.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.deffbeff.com/blog/2009/01/embedded-manifests-in-windows-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
