<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Just North of the Eyebrows</title>
	<atom:link href="http://iainbuclaw.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://iainbuclaw.wordpress.com</link>
	<description>The avant rantings of a developer and support analyst.</description>
	<lastBuildDate>Sun, 30 Jan 2011 23:51:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='iainbuclaw.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Just North of the Eyebrows</title>
		<link>http://iainbuclaw.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://iainbuclaw.wordpress.com/osd.xml" title="Just North of the Eyebrows" />
	<atom:link rel='hub' href='http://iainbuclaw.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Implementing Speed Counters in GDC</title>
		<link>http://iainbuclaw.wordpress.com/2010/09/18/implementing-speed-counters-in-gdc/</link>
		<comments>http://iainbuclaw.wordpress.com/2010/09/18/implementing-speed-counters-in-gdc/#comments</comments>
		<pubDate>Sat, 18 Sep 2010 16:51:58 +0000</pubDate>
		<dc:creator>ibuclaw</dc:creator>
				<category><![CDATA[d]]></category>
		<category><![CDATA[gdc]]></category>

		<guid isPermaLink="false">http://iainbuclaw.wordpress.com/?p=384</guid>
		<description><![CDATA[4 steps to timing just how long it takes for GDC to parse and generate code. Step 1: Add the timevar header and object into the GDC build. Include timevar.h in gcc/d/d-gcc-includes.h #include "ggc.h" #include "opts.h" #include "tm_p.h" /* Added timevar.h */ #include "timevar.h" Append timevar.o to the borrowed C objects in gcc/d/Make-lang.in D_BORROWED_C_OBJS += [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iainbuclaw.wordpress.com&amp;blog=9497112&amp;post=384&amp;subd=iainbuclaw&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>4 steps to timing just how long it takes for GDC to parse and generate code.</p>
<h3><strong>Step 1:</strong></h3>
<p>Add the timevar header and object into the GDC build.</p>
<p>Include timevar.h in gcc/d/d-gcc-includes.h</p>
<pre>#include "ggc.h"
#include "opts.h"
#include "tm_p.h"
 /* Added timevar.h */
#include "timevar.h"
</pre>
<p>Append timevar.o to the borrowed C objects in gcc/d/Make-lang.in</p>
<pre>D_BORROWED_C_OBJS += timevar.o
</pre>
<h3><strong>Step 2:</strong></h3>
<p>Define your own counters</p>
<p>Put your defined timevar macros in gcc/timevar.def<br />
Here&#8217;s what mine look like:</p>
<pre>/* GDC-Specific */
DEFTIMEVAR (TV_D_READ        , "Module::read")
DEFTIMEVAR (TV_D_PARSE       , "Module::parse")
DEFTIMEVAR (TV_D_IMPORTALL   , "Module::importAll")
DEFTIMEVAR (TV_D_SEMANTIC    , "Module::semantic")
DEFTIMEVAR (TV_D_SEMANTIC2   , "Module::semantic2")
DEFTIMEVAR (TV_D_SEMANTIC3   , "Module::semantic3")
DEFTIMEVAR (TV_D_GENOBJFILE  , "Module::genobjfile")
</pre>
<h3><strong>Step 3:</strong></h3>
<p>Add the counters to GDC</p>
<p>Add your push and pop functions anywhere in the code. timevar_push starts the timer, timevar_pop stops the timer.</p>
<p>As I&#8217;m interested in the top level only I&#8217;ve done mine in gcc/d/d-lang.cc<br />
There&#8217;s a lot here, so a diff view should give you the general idea of it.</p>
<pre>
--- a/gcc/d/d-lang.cc        2010-09-17 19:02:38.580306157 +0100
+++ b/gcc/d/d-lang.cc     2010-09-11 21:24:34.059001743 +0100
@@ -1044,6 +1044,7 @@
     //global.params.verbose = 1;

     // Read files
+    timevar_push (TV_D_READ);
 #if ! V2
     aw = AsyncRead::create(modules.dim);
     for (i = 0; i read(0);
     }
 #endif
+    timevar_pop (TV_D_READ);
     // Parse files
+    timevar_push (TV_D_PARSE);
     for (i = 0; i &lt; modules.dim; i++)
     {
        m = (Module *)modules.data[i];
@@ -1089,6 +1092,7 @@
            i--;
        }
     }
+    timevar_pop (TV_D_PARSE);
     if (global.errors)
        goto had_errors;

@@ -1116,6 +1120,7 @@

 #if ! V2
     // load all unconditional imports for better symbol resolving
+    timevar_push (TV_D_IMPORTALL);
     for (i = 0; i toChars());
        m-&gt;importAll(0);
     }
+    timevar_pop (TV_D_IMPORTALL);
     if (global.errors)
        goto had_errors;
 #endif

     // Do semantic analysis
+    timevar_push (TV_D_SEMANTIC);
     for (i = 0; i toChars());
        m-&gt;semantic();
     }
+    timevar_pop (TV_D_SEMANTIC);
     if (global.errors)
        goto had_errors;

@@ -1144,6 +1152,7 @@
 #endif

     // Do pass 2 semantic analysis
+    timevar_push (TV_D_SEMANTIC2);
     for (i = 0; i toChars());
        m-&gt;semantic2();
     }
+    timevar_pop (TV_D_SEMANTIC2);
     if (global.errors)
        goto had_errors;

     // Do pass 3 semantic analysis
+    timevar_push (TV_D_SEMANTIC3);
     for (i = 0; i toChars());
        m-&gt;semantic3();
     }
+    timevar_pop (TV_D_SEMANTIC3);
     if (global.errors)
        goto had_errors;

@@ -1233,6 +1245,7 @@
        json_generate(&amp;modules);
 #endif

+    timevar_push (TV_D_GENOBJFILE);
     for (i = 0; i gendocfile();
        }
     }
+    timevar_pop (TV_D_GENOBJFILE);

     // better to use input_location.xxx ?
     (*debug_hooks-&gt;end_source_file) (input_line);
</pre>
<h3><strong>Step 4:</strong></h3>
<p>Build GDC</p>
<pre>make</pre>
<p>Then compile your project with the DFLAG -ftime-report and post your results!</p>
<p>Here&#8217;s one I made earlier ( that&#8217;s not very tidy! :-)<br />
<a href="http://iainbuclaw.files.wordpress.com/2010/09/d2-time-report2.pdf">D2 Druntime/Phobos time report</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iainbuclaw.wordpress.com/384/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iainbuclaw.wordpress.com/384/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iainbuclaw.wordpress.com/384/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iainbuclaw.wordpress.com/384/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iainbuclaw.wordpress.com/384/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iainbuclaw.wordpress.com/384/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iainbuclaw.wordpress.com/384/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iainbuclaw.wordpress.com/384/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iainbuclaw.wordpress.com/384/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iainbuclaw.wordpress.com/384/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iainbuclaw.wordpress.com/384/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iainbuclaw.wordpress.com/384/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iainbuclaw.wordpress.com/384/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iainbuclaw.wordpress.com/384/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iainbuclaw.wordpress.com&amp;blog=9497112&amp;post=384&amp;subd=iainbuclaw&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iainbuclaw.wordpress.com/2010/09/18/implementing-speed-counters-in-gdc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/907f83bbb9b80bd8cf5e2f1a07c42e5e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ibuclaw</media:title>
		</media:content>
	</item>
		<item>
		<title>How to Embed Perl in your D program</title>
		<link>http://iainbuclaw.wordpress.com/2010/06/22/d-perlembed/</link>
		<comments>http://iainbuclaw.wordpress.com/2010/06/22/d-perlembed/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 13:48:36 +0000</pubDate>
		<dc:creator>ibuclaw</dc:creator>
				<category><![CDATA[d]]></category>
		<category><![CDATA[gdc]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://iainbuclaw.wordpress.com/?p=341</guid>
		<description><![CDATA[This post takes influence, and reference from perldoc&#8217;s perlembed page. Do you want to: Use D from Perl? Have a look at the Perl Inline API and write your own XS module. :) Use a Unix program from Perl? Read about back-quotes and about &#8220;system&#8221; and &#8220;exec&#8221; in perlfunc. Use Perl from Perl? Read about [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iainbuclaw.wordpress.com&amp;blog=9497112&amp;post=341&amp;subd=iainbuclaw&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post takes influence, and reference from perldoc&#8217;s <a href="http://search.cpan.org/dist/perl/pod/perlembed.pod">perlembed</a> page.</p>
<h3><strong>Do you want to:</strong></h3>
<h4><strong>Use D from Perl?</strong></h4>
<p style="padding-left:30px;">Have a look at the <a href="http://search.cpan.org/~sisyphus/Inline-0.46/">Perl Inline API</a> and write your own XS module. :)</p>
<h4><strong>Use a Unix program from Perl?</strong></h4>
<p style="padding-left:30px;">Read about back-quotes and about &#8220;system&#8221; and &#8220;exec&#8221; in <a href="http://search.cpan.org/~jesse/perl-5.12.1/pod/perlfunc.pod">perlfunc</a>.</p>
<h4><strong>Use Perl from Perl?</strong></h4>
<p style="padding-left:30px;">Read about &#8220;do&#8221;, &#8220;eval&#8221;, &#8220;require&#8221; and &#8220;use&#8221; in <a href="http://search.cpan.org/~jesse/perl-5.12.1/pod/perlfunc.pod">perlfunc</a>.</p>
<h4><strong>Use D from D?</strong></h4>
<p style="padding-left:30px;">Read about &#8220;mixin&#8221; in the <a href="http://www.digitalmars.com/d/1.0/mixin.html">D Language Reference</a> for compile-time interpretation.<br />
If you require run-time interpretation, rethink your design.</p>
<h4><strong>Use Perl from D?</strong></h4>
<p style="padding-left:30px;">Read on&#8230;</p>
<h3><strong>The D Perl Class Routine</strong></h3>
<p>This is made possible because Perl itself is written in C, the Perl library is the collection of compiled C programs, and D is binary compatible with C.</p>
<p>I&#8217;ll demonstrate this by showing a bastardized, non-portable version of miniperlmain.c containing the essentials of embedding. But re-written in D using a Class wrapper.</p>
<pre>
/*

  Perl/Interpreter.d

  Copyright (C) 2010 by Iain Buclaw

  You may distribute under the terms of either the GNU General Public
  License or the Artistic License. 

 */

module Perl.Interpreter;

/* For alloca, malloc, free */
private import std.c.stdlib;

/* flags in PL_exit_flags for nature of exit() */
enum
{
    EXIT_EXPECTED = 0x01,
    EXIT_DESTRUCT_END = 0x02, /* Run END in perl_destruct */
}

/* flags for Perl_call_* routines */
enum
{
    G_SCALAR = 0,
    G_ARRAY = 1,
    G_VOID = 128,  /* skip this bit when adding flags below */
    G_WANT = (128|1),
    G_DISCARD = 2,
    G_EVAL = 4,  /* Assume eval {} around subroutine call. */
    G_NOARGS = 8,  /* Don't construct a @_ array. */
    G_KEEPERR = 16,  /* Append errors to $@, don't overwrite it */
    G_NODEBUG = 32,  /* Disable debugging at toplevel.  */
    G_METHOD = 64,  /* Calling method. */
    G_FAKINGEVAL = 256,  /* Faking an eval context for call_sv or fold_constants */
}

extern (C)
{
    /* Perl Defines */
    struct interpreter {
        char broiled;
    }

    typedef interpreter PerlInterpreter;
    typedef void function(PerlInterpreter*) XSINIT_t;
    ubyte PL_exit_flags;

    /* Perl Prototypes */
    int (Perl_call_argv)(PerlInterpreter*, char *subname, int flags, char **argv);
    int (perl_destruct)(PerlInterpreter*);
    int (perl_parse)(PerlInterpreter*, XSINIT_t xsinit, int argc, char** argv, char** env);
    int (perl_run)(PerlInterpreter*);
    void (perl_construct)(PerlInterpreter*);
    void (perl_free)(PerlInterpreter*);
    void (Perl_sys_init3)(int* argc, char*** argv, char*** env);
    void (Perl_sys_term)();
    PerlInterpreter* (perl_alloc)();

    /* Unix System Environment */
    extern char** environ;
}

/* Copy a char[][] to a char** */
private void buildStringA(char[][] a, char** ap)
{
    foreach (s; a)
        *ap++ = (s ~ '&#092;&#048;').ptr;
    *ap = null;
}

/* Copy a char[] into a char* */
private void buildString(char[] a, char* ap)
{
    foreach (c; a)
        *ap++ = c;
    *ap = '&#092;&#048;';
}

/*** The Perl Interpreter Class ***/
class perlInterpreter
{
    int argc;
    char** argv;
    PerlInterpreter* my_perl;
    int parsestatus = 1;
    int exitstatus;

    this(ref char[][] args)
    {
        auto _argv = cast (char**)malloc ((char*).sizeof * (1 + args.length));
        buildStringA (args, _argv);
        argv = _argv;
        argc = args.length;
    }

    this(int _argc, char** _argv)
    {
        argc = _argc;
        argv = _argv;
    }

    ~this()
    {
        if (argv)
            free (argv);
    }

    void Construct()
    {
        if (!my_perl)
        {
            Perl_sys_init3 (&amp;argc, &amp;argv, &amp;environ);
            my_perl = perl_alloc();
            perl_construct (my_perl);
        }
    }

    void ExitFlags(uint flag)
    {
        PL_exit_flags |= flag;
    }

    void Parse()
    {
        if (my_perl)
            parsestatus = perl_parse (my_perl, null, argc, argv, null);
    }

    void Run()
    {
        if (my_perl &amp;&amp; !parsestatus)
            exitstatus = perl_run (my_perl);
    }

    void CallSub(char[] subname, int flags)
    {
        auto sub = cast (char*)alloca ((char).sizeof * (1 + subname.length));
        buildString (subname, sub);

        if (my_perl &amp;&amp; !parsestatus)
        {
            if (flags &amp; G_DISCARD)
                Perl_call_argv (my_perl, sub, flags, argv);
            else
                exitstatus = Perl_call_argv (my_perl, sub, flags, argv);
        }
    }

    void Destruct()
    {
        if (my_perl)
        {
            perl_destruct (my_perl);
            perl_free (my_perl);
            Perl_sys_term();
        }
    }
}
</pre>
<p>And to build the library, simply use your D compiler of choice.</p>
<pre>
gdc -c -O2 -frelease Perl/Interpreter.d
ar rcs libperld.a Interpreter.o
ranlib libperld.a
</pre>
<h3><strong>Adding a Perl interpreter to your D program</strong></h3>
<p>And I&#8217;ll demonstrate how you can use the class in D.</p>
<pre>
import Perl.Interpreter;

int main(char[][] args)
{
    perlInterpreter myPerl = new perlInterpreter (args);
    myPerl.Construct();
    myPerl.ExitFlags(EXIT_DESTRUCT_END);
    myPerl.Parse();
    myPerl.Run();
    myPerl.Destruct();
    return myPerl.exitstatus;
}
</pre>
<p>And build it with the linker option &#8216;-lperl&#8217; which requires libperl-dev to be installed on your system.</p>
<pre>
gdc -c -O2 -frelease dminiperl.d
gdc dminiperl.o -L. -lperld -lperl -o dminiperl
</pre>
<p>And after successful compilation, you&#8217;ll be able to use dminiperl just like Perl itself.</p>
<pre>
dminiperl myperlprog.pl
</pre>
<p>or</p>
<pre>
$ dminiperl
print "Pretty Good Perl \n";
print "10890 - 9801 is ", 10890 - 9801, "\n";
</pre>
<p>or</p>
<pre>
dminiperl -e 'printf("%x\n", 3735928559)'
</pre>
<h3><strong>Calling a Perl subroutine from your D program</strong></h3>
<p>To call individual Perl subroutines, Perl has four call_* functions to allow interface to. For this class though, I have only included call_argv() which takes a string argument.</p>
<pre>
import Perl.Interpreter;

void main(char[][] args)
{
    perlInterpreter myPerl = new perlInterpreter (args);
    myPerl.Construct();
    myPerl.ExitFlags(EXIT_DESTRUCT_END);
    myPerl.Parse();
    /* Skipping .Run() */
    myPerl.CallSub("showtime", G_DISCARD | G_NOARGS);
    myPerl.Destruct();
}
</pre>
<p>where showtime is a Perl subroutine that takes no arguments (that&#8217;s the G_NOARGS) and for which I&#8217;ll ignore the return value (that&#8217;s the G_DISCARD). Those flags, and others, are discussed in <a href="http://search.cpan.org/~jesse/perl-5.12.1/pod/perlcall.pod">perlcall</a>.</p>
<p>And to define the showtime subroutine in a file called showtime.pl:</p>
<pre>
print "I shan't be printed.";

sub showtime {
    print time,"\n";
}
</pre>
<p>And compile and run.</p>
<pre>
$ gdc -c -O2 -frelease showtime.d
$ gdc showtime.o -L. -lperld -lperl -o showtime
$ showtime showtime.pl
1277201943
</pre>
<p>yielding the number of seconds that elapsed between January 1, 1970 (the beginning of the Unix epoch), and the moment I began writing this sentence. :-)</p>
<h3><strong>Extending this D Class</strong></h3>
<p>For those who know perlembed well, this is just the icing of just what you can do. Sadly however, the more luxurious features, such as evaluating a Perl statement from your D program, require a little more complete D library, and a lot more time to write than I have to give in this particular essay.</p>
<p>If anyone wants to access any of the code / examples in this post from a source repository, or wish to collaborate in writing a complete Perl Library Interface for D. Just shout.</p>
<h3><strong>Moral?</strong></h3>
<p>You can sometimes write faster code in D, but you can always write code faster in Perl. Because you can use each from the other (with a little bit of work), combine them as you wish. :-)</p>
<p>Regards</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iainbuclaw.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iainbuclaw.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iainbuclaw.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iainbuclaw.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iainbuclaw.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iainbuclaw.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iainbuclaw.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iainbuclaw.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iainbuclaw.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iainbuclaw.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iainbuclaw.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iainbuclaw.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iainbuclaw.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iainbuclaw.wordpress.com/341/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iainbuclaw.wordpress.com&amp;blog=9497112&amp;post=341&amp;subd=iainbuclaw&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iainbuclaw.wordpress.com/2010/06/22/d-perlembed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/907f83bbb9b80bd8cf5e2f1a07c42e5e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ibuclaw</media:title>
		</media:content>
	</item>
		<item>
		<title>What&#8217;s Bugging GDC?</title>
		<link>http://iainbuclaw.wordpress.com/2010/05/23/whats-bugging-gdc/</link>
		<comments>http://iainbuclaw.wordpress.com/2010/05/23/whats-bugging-gdc/#comments</comments>
		<pubDate>Sun, 23 May 2010 12:39:45 +0000</pubDate>
		<dc:creator>ibuclaw</dc:creator>
				<category><![CDATA[d]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[gdc]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://iainbuclaw.wordpress.com/?p=276</guid>
		<description><![CDATA[Recently, I was asked the question: &#8220;Is gdc 4.3 really stable enough to be the default gdc?&#8220; As the gdc meta-package in Debian Squeeze and Ubuntu Lucid has been updated to now depend on gdc-4.3 instead of gdc-4.1. And by just playing around with D for a few days the kind fella who asked me [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iainbuclaw.wordpress.com&amp;blog=9497112&amp;post=276&amp;subd=iainbuclaw&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently, I was asked the question:</p>
<h3>&#8220;<em><strong>Is gdc 4.3 really stable enough to be the default gdc?</strong></em>&#8220;</h3>
<p>As the gdc meta-package in Debian Squeeze and Ubuntu Lucid has been updated to now depend on gdc-4.3 instead of gdc-4.1. And by just playing around with D for a few days the kind fella who asked me that discovered two bugs. So it seems to him that gdc-4.3 is far from being as mature as gdc-4.1 &#8230;</p>
<p>I decided to look into this by running <a href="http://www.dsource.org/projects/dstress">dstress</a> against the most recent build. For those of you who don&#8217;t know, dstress is a testing suite for D to ensure that the compiler correctly compiles (or in some cases, must not compile) a collection of about 7000+ files with 32 different compiler flag combinations without dying unintentionally, ie: via assertion or a segmentation fault.</p>
<p>From that huge list, I got a total of 10 internal compiler errors produced.</p>
<p>Here is a beautified list of internal errors that I got from the report. This first list consists of GDC back-end errors only, as they will be specific to GDC. Unlike the front-end errors, which will most likely be present in DMD and possibly LDC too.</p>
<p><strong>Update:</strong> Some good development has gone into GDC since writing this post, so I&#8217;m crossing off each issue as it gets resolved.</p>
<p>________________________________________________________________ </p>
<h2>Internal Compiler Error 1:</h2>
<p><strong>Code?</strong></p>
<pre>
public struct Color
{
    double red   = 0;
    double green = 0;
    double blue  = 0;

    static Color opCall()
    {
        Color instance;
        return instance;
    }
    Color opAdd(real right){ return Color(); }
    void opAddAssign(real right){ *this = *this + right; }
}
</pre>
<p><strong>Error?</strong></p>
<pre>
opAddAssign_A.d: In member function ‘opAddAssign’:
opAddAssign_A.d:13: internal compiler error: in decl_ultimate_origin, at dwarf2out.c:5139
</pre>
<p><strong>Reproducable?</strong><br />
Only via:</p>
<pre>
gdc -g -O3 -c opAddAssign_A.d
gdc -g -O2 -frelease -c opAddAssign_A.d
gdc -g -Os -frelease -c opAddAssign_A.d
gdmd -g -O -inline -c opAddAssign_A.d
gdmd -g -O -release -c opAddAssign_A.d
</pre>
<p><strong>Variants?</strong><br />
Not known.</p>
<p><strong>Workaround?</strong><br />
In all cases, include the compiler option &#8220;<em>-fno-inline</em>&#8221; to workaround the bug.</p>
<p><strong>Bug seen in gdc-4.1?</strong><br />
No.</p>
<p>________________________________________________________________</p>
<h2><del datetime="2010-08-23T22:51:20+00:00">Internal Compiler Error 2:</del></h2>
<p><strong><del datetime="2010-08-23T22:51:20+00:00">Code?</del></strong></p>
<pre>
template thunk(alias fn)
{
    static void thunk(int* arg)
    {
        fn(arg);
    }
}

int main()
{
    int x = 1;
    void inner(int* arg)
    {
        if(!(arg !is &amp;x))
            assert(0);
    }
    thunk!(inner)(&amp;x);
    return 0;
}
</pre>
<p><strong><del datetime="2010-08-23T22:51:20+00:00">Error?</del></strong></p>
<pre>
bug_tree_inline_1902_B.d: In function ‘thunk’:
bug_tree_inline_1902_B.d:5: internal compiler error: in estimate_num_insns_1, at tree-inline.c:2494
</pre>
<p><strong><del datetime="2010-08-23T22:51:20+00:00">Reproducable?</del></strong><br />
<del datetime="2010-08-23T22:51:20+00:00">Always.<br />
</del><br />
<strong><del datetime="2010-08-23T22:51:20+00:00">Variants?</del></strong><br />
<del datetime="2010-08-23T22:51:20+00:00">Seen also in compiler error 3 and 4, but not known just how related they are.<br />
</del><br />
<strong><del datetime="2010-08-23T22:51:20+00:00">Workaround?</del></strong><br />
<del datetime="2010-08-23T22:51:20+00:00">Using &#8220;void thunk&#8221; instead of &#8220;static void thunk&#8221;.<br />
</del><br />
<strong><del datetime="2010-08-23T22:51:20+00:00">Bug seen in gdc-4.1?</del></strong><br />
<del datetime="2010-08-23T22:51:20+00:00">Yes.<br />
</del><br />
________________________________________________________________</p>
<h2><del datetime="2010-08-23T22:51:20+00:00">Internal Compiler Error 3:</del></h2>
<p><strong><del datetime="2010-08-23T22:51:20+00:00">Code?</del></strong></p>
<pre>
int main()
{
    void foo() {}
    void function() bar = function void()
    {
        foo();
    };
    return 0;
}
</pre>
<p><strong><del datetime="2010-08-23T22:51:20+00:00">Error(s)?</del></strong></p>
<pre>
bug_e2ir_299_A.d: In function ‘__funcliteral1’:
bug_e2ir_299_A.d:6: internal compiler error: in estimate_num_insns_1, at tree-inline.c:2494
</pre>
<p><strong><del datetime="2010-08-23T22:51:20+00:00">Reproducable?</del></strong><br />
<del datetime="2010-08-23T22:51:20+00:00">Always.<br />
</del><br />
<strong><del datetime="2010-08-23T22:51:20+00:00">Variants?</del></strong><br />
<del datetime="2010-08-23T22:51:20+00:00">Seen also in compiler error 2 and 4, but not known just how related they are.<br />
</del><br />
<strong><del datetime="2010-08-23T22:51:20+00:00">Workaround?</del></strong><br />
<del datetime="2010-08-23T22:51:20+00:00">Is apparently not supposed to be compilable. (comes under nocompile).<br />
</del><br />
<strong><del datetime="2010-08-23T22:51:20+00:00">Bug seen in gdc-4.1?</del></strong><br />
<del datetime="2010-08-23T22:51:20+00:00">Yes.<br />
</del><br />
________________________________________________________________</p>
<h2>Internal Compiler Error 4:</h2>
<p><strong>Code?</strong></p>
<pre>
struct A (alias F)
{
    int f() { return F(); }
}

void main()
{
    int f() { return 0; }
    A!(f) a;
}
</pre>
<p><strong>Error?</strong></p>
<pre>
template_struct_01_A.d: In member function ‘f’:
template_struct_01_A.d:5: internal compiler error: in estimate_num_insns_1, at tree-inline.c:2494
</pre>
<p><strong>Reproducable?</strong><br />
Always.</p>
<p><strong>Variants?</strong><br />
Seen also in compiler error 2 and 3, but not known just how related they are.</p>
<p><strong>Workaround?</strong><br />
None.</p>
<p><strong>Bug seen in gdc-4.1?</strong><br />
Yes.</p>
<p>________________________________________________________________</p>
<h2><del datetime="2010-08-07T17:52:44+00:00">Internal Compiler Error 5:</del></h2>
<p><strong><del datetime="2010-08-07T17:52:44+00:00">Code?</del></strong></p>
<pre>
class Outer
{
    this()
    {
        Inner i = new Inner();
    }

    class Inner
    {
        Strct str;
    }
}

struct Strct
{
    int i;
}

int main()
{
    Outer o = new Outer();
    return 0;
}
</pre>
<p><strong><del datetime="2010-08-07T17:52:44+00:00">Error?</del></strong></p>
<pre>
forward_reference_17_A.d: In member function ‘_ctor’:
forward_reference_17_A.d:5: internal compiler error: Segmentation fault
</pre>
<p><strong><del datetime="2010-08-07T17:52:44+00:00">Reproducable?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00"><br />
Always<br />
</del><br />
<strong><del datetime="2010-08-07T17:52:44+00:00">Variants?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">Not known.<br />
</del><br />
<strong><del datetime="2010-08-07T17:52:44+00:00">Workaround?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">Declare the struct before the class.<br />
</del><br />
<strong><del datetime="2010-08-07T17:52:44+00:00">Bug seen in gdc-4.1?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">Yes<br />
</del><br />
________________________________________________________________</p>
<h2><del datetime="2010-08-07T17:59:47+00:00">Internal Compiler Error 6:</del></h2>
<p><strong><del datetime="2010-08-07T17:52:44+00:00">Code?</del></strong></p>
<pre>
bool nextis(void delegate() dgpositive = {})
{
    return true;
}

bool looping(lazy bool condition)
{
    return true;
}

int main()
{
    looping(nextis());
    return 0;
}
</pre>
<p><strong><del datetime="2010-08-07T17:52:44+00:00">Error?</del></strong></p>
<pre>
lazy_02_A.d: In member function ‘__dgliteral2’:
lazy_02_A.d:2: internal compiler error: in getFrameForSymbol, at d/d-codegen.cc:2541
</pre>
<p><strong><del datetime="2010-08-07T17:52:44+00:00">Reproducable?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">Always.<br />
</del><br />
<strong><del datetime="2010-08-07T17:52:44+00:00">Variants?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">Anything that uses the following as an argument.<br />
</del></p>
<pre>
void delegate() foo = {}
</pre>
<p><strong><del datetime="2010-08-07T17:52:44+00:00">Workaround?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">None.<br />
</del><br />
<strong><del datetime="2010-08-07T17:52:44+00:00">Bug seen in gdc-4.1?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">Yes.<br />
</del><br />
________________________________________________________________</p>
<h2><del datetime="2010-08-07T18:02:01+00:00">Internal Compiler Error 7:</del></h2>
<p><strong><del datetime="2010-08-07T17:52:44+00:00">Code?</del></strong></p>
<pre>
int status;

template T(alias a)
{
    int dummy;
}

class C
{
    mixin T!(
            () {
                status++;
            }
        ) mixed;
}

int main()
{
    C c = new C();
    c.mixed.a();
    if(status != 1)
    {
        assert(0);
    }
    return 0;
}
</pre>
<p><strong><del datetime="2010-08-07T17:52:44+00:00">Error?</del></strong></p>
<pre>
mixin_23_A.d:11: Error: delegate mixin_23_A.C.__dgliteral1 literals cannot be class members
cc1d: internal compiler error: Segmentation fault
</pre>
<p><strong><del datetime="2010-08-07T17:52:44+00:00">Reproducable?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">Always.<br />
</del><br />
<strong><del datetime="2010-08-07T17:52:44+00:00">Variants?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">Also seen when using:</del></p>
<pre>
mixin T!( delegate() { status++; } ) mixed;
</pre>
<p><del datetime="2010-08-07T17:52:44+00:00">And:</del></p>
<pre>
mixin T!( { status++; } ) mixed;
</pre>
<p><strong><del datetime="2010-08-07T17:52:44+00:00">Workaround?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">Using function() works around the problem, but probably not correct due to semantic differences.<br />
</del></p>
<pre>
mixin T!( function(){ status++; } ) mixed;
</pre>
<p><strong><del datetime="2010-08-07T17:52:44+00:00">Bug seen in gdc-4.1?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">No.<br />
</del><br />
________________________________________________________________</p>
<p><del datetime="2010-08-07T17:52:44+00:00">In this second list are DMD frontend compiler errors, they aren&#8217;t necessarily the fault of GDC&#8217;s, and they may well be present in LDC too.</p>
<p></del></p>
<h2><del datetime="2010-08-07T18:03:05+00:00">Internal Compiler Error 8:</del></h2>
<p><strong><del datetime="2010-08-07T17:52:44+00:00">Code?</del></strong></p>
<pre>
char[] testHelper(A ...)()
{
    char[] result;
    foreach(t; a)
    {
        result ~= "int " ~ t ~ ";\n";
    }
    return result;
}

int main()
{
    mixin( testHelper!( "hello", "world" )() );
    return 0;
}
</pre>
<p><strong><del datetime="2010-08-07T17:52:44+00:00">Error?</del></strong></p>
<pre>
cc1d: ../../src/gcc/d/dmd/template.c:811: MATCH TemplateDeclaration::deduceFunctionTemplateMatch(Loc, Objects*, Expression*, Expressions*, Objects*): Assertion `i dim' failed.
cc1d: internal compiler error: Aborted
</pre>
<p><strong><del datetime="2010-08-07T17:52:44+00:00">Reproducable?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">Always.<br />
</del><br />
<strong><del datetime="2010-08-07T17:52:44+00:00">Variants?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">Not known.<br />
</del><br />
<strong><del datetime="2010-08-07T17:52:44+00:00">Workaround?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">Code is not supposed to be compilable. (comes under nocompile).<br />
</del><br />
<strong><del datetime="2010-08-07T17:52:44+00:00">Bug seen in gdc-4.1?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">No.<br />
</del><br />
________________________________________________________________</p>
<h2><del datetime="2010-08-07T17:45:58+00:00">Internal Compiler Error 9:</del></h2>
<p><strong><del datetime="2010-08-07T17:52:44+00:00">Code?</del></strong></p>
<pre>
void[10] array;
</pre>
<p><strong><del datetime="2010-08-07T17:52:44+00:00">Error?</del></strong></p>
<pre>
Error: integral constant must be scalar type, not void
cc1d: ../../src/gcc/d/dmd/todt.c:85: dt_t* createTsarrayDt(dt_t*, Type*): Assertion `tsa-&gt;size(0) % eoa_size == 0' failed.
cc1d: internal compiler error: Aborted
</pre>
<p><strong><del datetime="2010-08-07T17:52:44+00:00">Reproducable?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">Always.<br />
</del><br />
<strong><del datetime="2010-08-07T17:52:44+00:00">Variants?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">Not known.<br />
</del><br />
<strong><del datetime="2010-08-07T17:52:44+00:00">Workaround?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">Code is not supposed to be compilable. (comes under nocompile).<br />
</del><br />
<strong><del datetime="2010-08-07T17:52:44+00:00">Bug seen in gdc-4.1?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">Yes.<br />
</del><br />
________________________________________________________________</p>
<h2><del datetime="2010-08-07T18:04:15+00:00">Internal Compiler Error 10:</del></h2>
<p><strong><del datetime="2010-08-07T17:52:44+00:00">Code?</del></strong></p>
<pre>
int main()
{
    auto arr = [4:"vier", 0:"null", 2:"zwei"];

    if(3 != arr.length)
    {
        assert(0);
    }

    char[][] master_e = ["vier", "null", "zwei"];
    int[] master_i = [4, 0, 2];

    foreach(index, element; arr)
    {
        bool found = false;
        foreach(pos, i; master_i)
        {
            if(index == i &amp;&amp; element == master_e[pos])
            {
                master_i = master_i[0 .. pos] ~ master_i[pos+1 .. $];
                master_e = master_e[0 .. pos] ~ master_e[pos+1 .. $];
                found = true;
                break;
            }
        }
        if(!found)
        {
            assert(0);
        }
    }
    if(master_i.length)
    {
        assert(0);
    }
    return 0;
}
</pre>
<p><strong><del datetime="2010-08-07T17:52:44+00:00">Error?</del></strong></p>
<pre>
associative_array_23_B.d:3: Error: cannot infer type from this array initializer
cc1d: ../../src/gcc/d/dmd/init.c:437: virtual Expression* ArrayInitializer::toExpression(): Assertion `j &lt; edim&#039; failed.
cc1d: internal compiler error: Aborted
</pre>
<p><strong><del datetime="2010-08-07T17:52:44+00:00">Reproducable?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">Always.<br />
</del><br />
<strong><del datetime="2010-08-07T17:52:44+00:00">Variants?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">Not known.<br />
</del><br />
<strong><del datetime="2010-08-07T17:52:44+00:00">Workaround?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">None.<br />
</del><br />
<strong><del datetime="2010-08-07T17:52:44+00:00">Bug seen in gdc-4.1?</del></strong><br />
<del datetime="2010-08-07T17:52:44+00:00">No.<br />
</del></p>
<p>________________________________________________________________</p>
<p>So, as far as the dstress testing goes, there are currently 4 regressions &#8211; 2 of which are not the fault of gdc &#8211; and 6 inherited bugs in gdc-4.3 when compared to gdc-4.1.</p>
<p>So, back to your original question, is gdc 4.3 really stable enough to be the default gdc? Thanks to your help in identifying two underlying problems in the Debianised version, yes, I believe it is!</p>
<p>Despite some outstanding quirks, and the odd ICE or two in this post that would be cool to plumb down and fix. I think we are heading in for a strong release &#8211; if and when the GDC upstream developers ever get round to it. In the meantime, I will continue maintaining the Debian and Ubuntu packages, and will love to hear more of your dedicated support and patience in testing.</p>
<p>Got any other show-stopping bugs? Please report! :-)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iainbuclaw.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iainbuclaw.wordpress.com/276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iainbuclaw.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iainbuclaw.wordpress.com/276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iainbuclaw.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iainbuclaw.wordpress.com/276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iainbuclaw.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iainbuclaw.wordpress.com/276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iainbuclaw.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iainbuclaw.wordpress.com/276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iainbuclaw.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iainbuclaw.wordpress.com/276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iainbuclaw.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iainbuclaw.wordpress.com/276/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iainbuclaw.wordpress.com&amp;blog=9497112&amp;post=276&amp;subd=iainbuclaw&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iainbuclaw.wordpress.com/2010/05/23/whats-bugging-gdc/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/907f83bbb9b80bd8cf5e2f1a07c42e5e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ibuclaw</media:title>
		</media:content>
	</item>
		<item>
		<title>Proof of Concept: Writing a Linux Kernel Module in D</title>
		<link>http://iainbuclaw.wordpress.com/2010/05/22/writing-a-linux-kernel-module-in-d/</link>
		<comments>http://iainbuclaw.wordpress.com/2010/05/22/writing-a-linux-kernel-module-in-d/#comments</comments>
		<pubDate>Sat, 22 May 2010 12:51:44 +0000</pubDate>
		<dc:creator>ibuclaw</dc:creator>
				<category><![CDATA[d]]></category>
		<category><![CDATA[gdc]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://iainbuclaw.wordpress.com/?p=223</guid>
		<description><![CDATA[I thought it best today to post this in a QA format just to ease you into it. Alright, what narcotics are you on? Seriously&#8230; I&#8217;d like to start this post with answering a few prejudiced questions before anyone asks. No, I&#8217;m not on narcotics. Yes, this can be done. No I don&#8217;t recommend it, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iainbuclaw.wordpress.com&amp;blog=9497112&amp;post=223&amp;subd=iainbuclaw&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I thought it best today to post this in a QA format just to ease you into it.</p>
<p><strong>Alright, what narcotics are you on? Seriously&#8230;</strong><br />
I&#8217;d like to start this post with answering a few prejudiced questions before anyone asks. No, I&#8217;m not on narcotics. Yes, this can be done. No I don&#8217;t recommend it, and no, I&#8217;m not that crazy, but I do have quite a bit of time on my hands.</p>
<p><strong>Why?</strong><br />
Try asking yourself, why not?</p>
<p><strong>D is a horrible language. It&#8217;s made more horrible by the fact that a lot of substandard programmers use it, to the point where it&#8217;s much much easier to generate total and utter crap with it. Quite frankly, even if the choice of C were to do *nothing* but keep the D programmers out, that in itself would be a huge reason to use C.</strong><br />
I think you are confusing D with <a href="http://thread.gmane.org/gmane.comp.version-control.git/57643/focus=57918">C++</a>. ;-)</p>
<p>Everyone happy? OK, I&#8217;ll continue then.</p>
<p><strong>You actually wrote a kernel module using only D?</strong><br />
OK. First I&#8217;d like to clarify, I am not using pure D here, but instead a utilising D&#8217;s capability of <a href="http://www.digitalmars.com/d/1.0/interfaceToC.html">Interfacing to C</a>. The glue itself is in C, and the interfacing code is wrapped in &#8220;extern (C)&#8221;, so the kernel can call the functions. But given the capability, you can mixin D with C.</p>
<p><strong>OK, so you&#8217;re faking it. Somehow I&#8217;ve lost interest in this.</strong><br />
Suit yourself, bet you don&#8217;t want to see the code either.</p>
<p><strong>Fine, so what does it look like?</strong><br />
Here is a hello world module.</p>
<p><em>hello.c</em>:</p>
<pre>
#include  /* Needed by all modules */
</pre>
<p><em>dinterface.d</em>:</p>
<pre>
extern (C):
int printk(char *s, ...);

int __gdc_personality_v0()
{
    // STUB: int __gdc_personality_v0() not implemented
    return 0;
}

int init_module()
{
    printk("Hello world!\n");
    return 0;
}

void cleanup_module()
{
    printk("Goodbye world!\n");
}
</pre>
<p><em>Makefile</em>:</p>
<pre>
# D compiler
DC := gdc
# D objects
DOBJS := dinterface.o

ifneq ($(MAKE_KBUILD),)
# kbuild part of makefile

obj-$(CONFIG_HELLO) := hello.o
hello-y += $(DOBJS)

else
# normal part of makefile

KERNELDIR := /lib/modules/$(shell uname -r)/build

all: $(DOBJS)
	$(MAKE) -C $(KERNELDIR) M=$(shell pwd) CONFIG_HELLO=m MAKE_KBUILD=1 modules

clean:
	$(MAKE) -C $(KERNELDIR) M=$(shell pwd) MAKE_KBUILD=1 clean

%.o: %.d
	$(DC) -c $&lt; -o $@

endif
</pre>
<p>Simply type</p>
<pre>
make
</pre>
<p>to build it, then to insert the module into the kernel</p>
<pre>
sudo insmod hello.ko
</pre>
<p>And you can see the hello world in &#8216;dmesg&#8217;</p>
<p><strong>That simple eh? OK, what is the catch Iain&#8230;</strong><br />
The catch? In order to use D&#8217;s most favoured features, such as arrays, you will have to port D&#8217;s runtime, typeinfo and exception handling routines (notice that __gdc_personality_v0 is just a dummy function), as they won&#8217;t be carried over in the linking of the module.</p>
<p><strong>Hmm&#8230; so have you implemented this?</strong><br />
As of writing, no, and I don&#8217;t intend to either. You can however look into <a href="http://github.com/xomboverlord/xomb">Xomb</a> for a minimal d runtime. But the feasibility of porting it is not really worth the hassle. Infact, more than likely you will never get it working full stop, and just end up segfaulting the kernel every time.</p>
<p><strong>OK, so what is the moral of this post then?</strong><br />
I&#8217;m wide awake, it&#8217;s Saturday. :)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iainbuclaw.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iainbuclaw.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iainbuclaw.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iainbuclaw.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iainbuclaw.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iainbuclaw.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iainbuclaw.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iainbuclaw.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iainbuclaw.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iainbuclaw.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iainbuclaw.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iainbuclaw.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iainbuclaw.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iainbuclaw.wordpress.com/223/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iainbuclaw.wordpress.com&amp;blog=9497112&amp;post=223&amp;subd=iainbuclaw&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iainbuclaw.wordpress.com/2010/05/22/writing-a-linux-kernel-module-in-d/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/907f83bbb9b80bd8cf5e2f1a07c42e5e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ibuclaw</media:title>
		</media:content>
	</item>
		<item>
		<title>Fixing your HAL application for Ubuntu 10.04</title>
		<link>http://iainbuclaw.wordpress.com/2010/04/20/fixing-your-hal-application-for-ubuntu-10-04/</link>
		<comments>http://iainbuclaw.wordpress.com/2010/04/20/fixing-your-hal-application-for-ubuntu-10-04/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 12:05:01 +0000</pubDate>
		<dc:creator>ibuclaw</dc:creator>
				<category><![CDATA[dbus]]></category>
		<category><![CDATA[hal]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://iainbuclaw.wordpress.com/?p=176</guid>
		<description><![CDATA[Ubuntu Lucid Lynx sports full removal of HAL from the boot process, making Ubuntu faster to boot and faster to resume from suspend. From a developer stance, all what has changed is that Ubuntu has switched over to D-BUS activation. So if a program tries to talk to HAL, but HAL is not running, it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iainbuclaw.wordpress.com&amp;blog=9497112&amp;post=176&amp;subd=iainbuclaw&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Ubuntu Lucid Lynx sports full removal of HAL from the boot process, making Ubuntu faster to boot and faster to resume from suspend.</p>
<p>From a developer stance, all what has changed is that Ubuntu has switched over to D-BUS activation. So if a program tries to talk to HAL, but HAL is not running, it triggers it&#8217;s startup.</p>
<p>If this isn&#8217;t the case when you try to start your application, then the most likely reason is that it is too cautious and checks if HAL is running before trying to connect to it. This is true in the case of lshal, where you probably wouldn&#8217;t want HAL starting if it wasn&#8217;t already running.</p>
<p>Such an example of this check would be as seen below (taken from pcmanfm).</p>
<pre>
/* try to initialize the HAL context */
if (!libhal_ctx_init (hal_context, &amp;error)
    goto failed;
</pre>
<p>What we do differently is simply dropping the check, letting the application connect to hal straight away, checking of course if that failed instead before returning true.</p>
<pre>
/* try to initialize the HAL context */
libhal_ctx_init (hal_context, &amp;error);
</pre>
<p>Happy debugging!</p>
<p>Regards</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iainbuclaw.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iainbuclaw.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iainbuclaw.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iainbuclaw.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iainbuclaw.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iainbuclaw.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iainbuclaw.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iainbuclaw.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iainbuclaw.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iainbuclaw.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iainbuclaw.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iainbuclaw.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iainbuclaw.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iainbuclaw.wordpress.com/176/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iainbuclaw.wordpress.com&amp;blog=9497112&amp;post=176&amp;subd=iainbuclaw&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iainbuclaw.wordpress.com/2010/04/20/fixing-your-hal-application-for-ubuntu-10-04/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/907f83bbb9b80bd8cf5e2f1a07c42e5e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ibuclaw</media:title>
		</media:content>
	</item>
		<item>
		<title>Debian kFreeBSD in QEMU-KVM</title>
		<link>http://iainbuclaw.wordpress.com/2010/04/15/debian-kfreebsd-in-qemu-kvm/</link>
		<comments>http://iainbuclaw.wordpress.com/2010/04/15/debian-kfreebsd-in-qemu-kvm/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 15:19:52 +0000</pubDate>
		<dc:creator>ibuclaw</dc:creator>
				<category><![CDATA[debian]]></category>
		<category><![CDATA[kfreebsd]]></category>
		<category><![CDATA[kvm]]></category>

		<guid isPermaLink="false">http://iainbuclaw.wordpress.com/?p=108</guid>
		<description><![CDATA[Debian GNU/kFreeBSD is a port that consists of GNU userland using the GNU C library on top of FreeBSD&#8216;s kernel, coupled with the regular Debian package set. Installing Assuming you don&#8217;t have KVM already installed, you&#8217;ll need to run: sudo apt-get install kvm Then check for the presence of /dev/kvm. If it doesn&#8217;t exist, check that virtualisation is turned [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iainbuclaw.wordpress.com&amp;blog=9497112&amp;post=108&amp;subd=iainbuclaw&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Debian GNU/kFreeBSD is a port that consists of <a href="http://www.gnu.org/">GNU userland</a> using the <a href="http://www.gnu.org/software/libc/">GNU C library</a> on top of <a href="http://www.freebsd.org/">FreeBSD</a>&#8216;s kernel, coupled with the regular <a href="http://packages.debian.org/">Debian package set</a>.</p>
<h2>Installing</h2>
<p>Assuming you don&#8217;t have KVM already installed, you&#8217;ll need to run:</p>
<p><span style="color:#008000;"><span style="font-style:normal;"><span style="color:#000000;"> </span></span></span></p>
<pre>
sudo apt-get install kvm
</pre>
<p>Then check for the presence of /dev/kvm. If it doesn&#8217;t exist, check that virtualisation is turned on in BIOS, else your system does not have the CPU extensions required to use KVM, so will fall back to using qemu instead.</p>
<p>You can get the installation media either from <a href="http://glibc-bsd.alioth.debian.org/install-cd">here</a> or grab the daily mini.iso at <a href="http://d-i.debian.org/daily-images/kfreebsd-i386/">this</a> location.</p>
<pre>
wget http://glibc-bsd.alioth.debian.org/install-cd/kfreebsd-i386/current/debian-20090729-kfreebsd-i386-install.iso
</pre>
<p>Create a hard drive image.</p>
<address><span style="color:#008000;"><span style="font-style:normal;"><span style="font-weight:bold;"><span style="font-weight:normal;"><span style="color:#000000;">
<pre>
kvm-img create -f qcow kfreebsd.img 10G
</pre>
<p></span></span></span></span></span></address>
<p>And get started.</p>
<pre>
kvm -drive file=kfreebsd.img,index=0,cache=writeback,media=disk -cdrom debian-20090729-kfreebsd-i386-install.iso
</pre>
<p><span style="font-weight:bold;">Note:</span> I use -drive instead of -hda because I find that it increases I/O performance of the guest system.</p>
<p>For installing Debian GNU/kFreeBSD and other useful information, refer to the <a href="http://glibc-bsd.alioth.debian.org/doc">install notes</a>.</p>
<p>You have two ways of running through the installer, Express or Custom, I chose &#8220;Express&#8221;. This brings you to a command-line partitioner, simply press &#8216;<span style="font-weight:bold;">a</span>&#8216; to create a slice across the whole hard drive, and &#8216;<span style="font-weight:bold;">q</span>&#8216; to finish.</p>
<p>Next is the BootMgr, in this program, press &#8216;<span style="font-weight:bold;">c</span>&#8216; to create a &#8216;<span style="font-weight:bold;">9500M</span>&#8216; filesystem to mount on &#8216;<span style="font-weight:bold;">/</span>&#8216;, followed by a the creation of a swap to fill the rest. Once done press &#8216;<span style="font-weight:bold;">q</span>&#8216; to finish.</p>
<p>Next, you&#8217;ll be asked what distribution you wish to install. I selected &#8216;<span style="font-weight:bold;">minimal</span>&#8216;, and if you plan to do a CD installation, I suggest the same too. Else with a Network installation, you could get away with what you want.</p>
<p>In the next menu, select the medium you wish to install off, either choose Network or CDROM here, then wait around to let the extraction finish. Then you&#8217;ll need to press &#8216;<span style="font-weight:bold;">Alt+F3</span>&#8216; to proceed with the installation, answering any questions you may be asked.</p>
<p>Once finished, you&#8217;ll be prompted to answer &#8216;No&#8217; to reboot. Don&#8217;t do this, instead answer &#8216;<span style="font-weight:bold;">Yes</span>&#8216; to return to the configuration menu, where you should set the Root Password first, then optionally configure anything else you may wish to. Once done, then exit the install and reboot into your new system.</p>
<h2>Configuring for Network</h2>
<p>Unfortunately, some of the defaults of the installation aren&#8217;t setup correctly for immediately usage.</p>
<p>First thing you&#8217;ll notice is no networking, so login to the root account and get that set.</p>
<pre>
nano /etc/network/interfaces
</pre>
<p>And put in the file</p>
<pre>
auto re0
iface re0 inet dhcp
</pre>
<p>Save, then restart networking</p>
<pre>
service networking restart
</pre>
<p>You can now update your system. Before you upgrade though, there is a nasty bug that prevents &#8216;rm&#8217; working properly on directories on the freebsd 7.x kernels, so we&#8217;ll need to put the coreutils package on hold.</p>
<pre>
echo coreutils hold | dpkg --set-selections
apt-get update
apt-get dist-upgrade
</pre>
<h2>Configuring for X</h2>
<p>Install Xorg.</p>
<pre>
apt-get install xorg
</pre>
<p>Now to address some issues.</p>
<p>Firstly, if you haven&#8217;t already noticed, during the installation of xorg, the package &#8216;hal&#8217; (as of writing) fails to install properly, leaving xorg in an unconfigured state.</p>
<p>Simply reboot the VM, login, and restart dbus.</p>
<pre>
service dbus restart
</pre>
<p>then run the installer again to finish the setup.</p>
<pre>
apt-get install -f
</pre>
<p>Secondly, xorg.conf needs to be setup correctly. To create a configuration file run:</p>
<pre>
X -configure
</pre>
<p>Allow about a 30-60 seconds for it to finish, then open the generated file for editing.</p>
<pre>
nano xorg.conf.new
</pre>
<p>Without going into too much detail, remove &#8216;Files&#8217; and &#8216;Modules&#8217; section, then edit the Sections outlined below as seen.</p>
<pre>
Section "InputDevice"
    Driver        "kbd"
[...]
Section "InputDevice"
    Driver        "mouse"
    Option        "Protocol" "SysMouse"
    Option        "Device" "/dev/sysmouse"
[...]
Section "Device"
    Driver        "vesa"
[...]
</pre>
<p><span style="font-weight:bold;">Note:</span> If you have support for kvm, you can get away with having Driver &#8220;cirrus&#8221; instead of &#8220;vesa&#8221; in your config file. Am not sure of the benefits either or though.</p>
<p>Once done, install the file in it&#8217;s proper location.</p>
<pre>
mv xorg.conf.new /etc/X11/xorg.conf
</pre>
<p>Lastly, you need to create the mouse and keyboard policies for hal, as without them, will unusable under X.</p>
<p>First is the keyboard policy</p>
<pre>
nano /etc/hal/fdi/policy/10-x11-input-kbd.fdi
</pre>
<p>And put into the file:</p>
<pre>
&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
&lt;deviceinfo version="0.2"&gt;
  &lt;device&gt;
    &lt;match key="/org/freedesktop/Hal/devices/computer:system.kernel.name" string="GNU/kFreeBSD"&gt;
      &lt;match key="info.capabilities" contains="input.keys"&gt;
        &lt;merge key="input.x11_driver" type="string"&gt;kbd&lt;/merge&gt;
      &lt;/match&gt;
    &lt;/match&gt;
  &lt;/device&gt;
&lt;/deviceinfo&gt;
</pre>
<p>Ditto for the mouse policy.</p>
<pre>
nano /etc/hal/fdi/policy/10-x11-input-mouse.fdi
</pre>
<p>And put into the file:</p>
<pre>
&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
&lt;deviceinfo version="0.2"&gt;
  &lt;device&gt;
    &lt;match key="/org/freedesktop/Hal/devices/computer:system.kernel.name" string="GNU/kFreeBSD"&gt;
      &lt;match key="info.capabilities" contains="input.mouse"&gt;
        &lt;merge key="input.x11_driver" type="string"&gt;mouse&lt;/merge&gt;
      &lt;/match&gt;
    &lt;/match&gt;
  &lt;/device&gt;
&lt;/deviceinfo&gt;
</pre>
<h2>Graphical Login</h2>
<p>Finally, install your favourite Window-Manager and Display-Manager. I chose xfce and gdm.</p>
<pre>
apt-get install xfce gdm
</pre>
<p>And reboot once more to be greeted by a graphical login screen.</p>
<p>As you can see, there is still alot of work to go into the port, a lot of work to setup correctly, and even then it is not guarenteed to work everytime. :)</p>
<p>However, hope you find a place for this fun Debian port when you get it stable + working.</p>
<p><img src="http://iainbuclaw.files.wordpress.com/2010/04/20100417121526800x600sc.png?w=630" alt="debian kfreebsd screenshot" /></p>
<p>Regards</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iainbuclaw.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iainbuclaw.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iainbuclaw.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iainbuclaw.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iainbuclaw.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iainbuclaw.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iainbuclaw.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iainbuclaw.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iainbuclaw.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iainbuclaw.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iainbuclaw.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iainbuclaw.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iainbuclaw.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iainbuclaw.wordpress.com/108/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iainbuclaw.wordpress.com&amp;blog=9497112&amp;post=108&amp;subd=iainbuclaw&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iainbuclaw.wordpress.com/2010/04/15/debian-kfreebsd-in-qemu-kvm/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/907f83bbb9b80bd8cf5e2f1a07c42e5e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ibuclaw</media:title>
		</media:content>

		<media:content url="http://iainbuclaw.files.wordpress.com/2010/04/20100417121526800x600sc.png" medium="image">
			<media:title type="html">debian kfreebsd screenshot</media:title>
		</media:content>
	</item>
		<item>
		<title>D-BUS Errors</title>
		<link>http://iainbuclaw.wordpress.com/2010/01/07/dbus-errors/</link>
		<comments>http://iainbuclaw.wordpress.com/2010/01/07/dbus-errors/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 17:54:30 +0000</pubDate>
		<dc:creator>ibuclaw</dc:creator>
				<category><![CDATA[dbus]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://iainbuclaw.wordpress.com/?p=71</guid>
		<description><![CDATA[Since I had a difficult time figuring it out &#8211; I just thought I might post a &#8220;be all, end all&#8221; answer here. There is a certain elusive DBus error that seems to occur in multiple applications, from Jockey to Bzr, to Ubuntu-One client. The bottom of the traceback will look like this: File "/var/lib/python-support/python2.5/dbus/bus.py", [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iainbuclaw.wordpress.com&amp;blog=9497112&amp;post=71&amp;subd=iainbuclaw&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Since I had a difficult time figuring it out &#8211; I just thought I might post a &#8220;be all, end all&#8221; answer here.</p>
<p>There is a certain elusive DBus error that seems to occur in multiple applications, from Jockey to Bzr, to Ubuntu-One client.</p>
<p>The bottom of the traceback will look like this:</p>
<pre>
File "/var/lib/python-support/python2.5/dbus/bus.py", line 244, in get_object
follow_name_owner_changes=follow_name_owner_changes)
File "/var/lib/python-support/python2.5/dbus/proxies.py", line 241, in __init__
self._named_service = conn.activate_name_owner(bus_name)
File "/var/lib/python-support/python2.5/dbus/bus.py", line 183, in activate_name_owner
self.start_service_by_name(bus_name)
File "/var/lib/python-support/python2.5/dbus/bus.py", line 281, in start_service_by_name
'su', (bus_name, flags)))
File "/var/lib/python-support/python2.5/dbus/connection.py", line 607, in call_blocking
message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.Spawn.ChildExited: Launch helper exited with unknown return code 1
</pre>
<p>To put this into english &#8211; this essentially means that your system&#8217;s configuration for that particular piece of software has made it corrupt. The simple fix is simply removing the system configuration &#8211; or purging and reinstalling the application if you use a package manager.</p>
<p>ie:</p>
<pre>
sudo apt-get purge jockey-gtk jockey-common
sudo apt-get install jockey-gtk jockey-common
</pre>
<p>And I am 90% certain that doing this will retify your problem in most cases.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iainbuclaw.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iainbuclaw.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iainbuclaw.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iainbuclaw.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iainbuclaw.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iainbuclaw.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iainbuclaw.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iainbuclaw.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iainbuclaw.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iainbuclaw.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iainbuclaw.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iainbuclaw.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iainbuclaw.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iainbuclaw.wordpress.com/71/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iainbuclaw.wordpress.com&amp;blog=9497112&amp;post=71&amp;subd=iainbuclaw&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iainbuclaw.wordpress.com/2010/01/07/dbus-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/907f83bbb9b80bd8cf5e2f1a07c42e5e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ibuclaw</media:title>
		</media:content>
	</item>
		<item>
		<title>HowTO: Setup Twin Graphics Cards</title>
		<link>http://iainbuclaw.wordpress.com/2009/09/29/howto-setup-twin-graphics-cards/</link>
		<comments>http://iainbuclaw.wordpress.com/2009/09/29/howto-setup-twin-graphics-cards/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 16:27:20 +0000</pubDate>
		<dc:creator>ibuclaw</dc:creator>
				<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://iainbuclaw.wordpress.com/?p=37</guid>
		<description><![CDATA[Some people I have been supporting use twin view with two NViDIA graphics cards. While this is perfectly fine, you may run into problems if your xorg.conf file is setup to handle only one card. Such a setup will look like this when you go to edit the xorg.conf file. Section "Device" Identifier "Device0" Driver [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iainbuclaw.wordpress.com&amp;blog=9497112&amp;post=37&amp;subd=iainbuclaw&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Some people I have been supporting use twin view with two NViDIA graphics cards. While this is perfectly fine, you may run into problems if your xorg.conf file is setup to handle only one card.</p>
<p>Such a setup will look like this when you go to edit the xorg.conf file.</p>
<pre>
Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
EndSection
</pre>
<p>To work around the issue, it is best advised to remove the secondary card from the computer, boot up and acquire the output of the following.</p>
<pre>
lspci | grep VGA
</pre>
<p>and you should see something like this:</p>
<pre>
04:00.0 VGA compatible controller: nVidia Corporation GeForce 9800 GX2
</pre>
<p>Make a note of the Bus ID of the card (<strong>04:00.0</strong>) , and edit the xorg.conf file.</p>
<pre>
sudo nano /etc/X11/xorg.conf
</pre>
<p>Scroll to the Device section and add the Bus ID to the conf file, except remove all leading zeros, replace the period with a colon, and add &#8216;PCI&#8217; as a prefix.<br />
So, our example of <strong>04:00.0</strong> becomes:</p>
<pre>
Section "Device"
    BUSID          "PCI:4:0:0"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
EndSection
</pre>
<p>After doing this, save the file, then shutdown the workstation and reinsert the second GFX card back into the machine.</p>
<p>Regards</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iainbuclaw.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iainbuclaw.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iainbuclaw.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iainbuclaw.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iainbuclaw.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iainbuclaw.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iainbuclaw.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iainbuclaw.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iainbuclaw.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iainbuclaw.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iainbuclaw.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iainbuclaw.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iainbuclaw.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iainbuclaw.wordpress.com/37/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iainbuclaw.wordpress.com&amp;blog=9497112&amp;post=37&amp;subd=iainbuclaw&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iainbuclaw.wordpress.com/2009/09/29/howto-setup-twin-graphics-cards/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/907f83bbb9b80bd8cf5e2f1a07c42e5e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ibuclaw</media:title>
		</media:content>
	</item>
		<item>
		<title>HowTO: Manually Compile NViDIA Drivers in Ubuntu</title>
		<link>http://iainbuclaw.wordpress.com/2009/09/29/howto-manually-compile-nvidia-drivers-in-ubuntu/</link>
		<comments>http://iainbuclaw.wordpress.com/2009/09/29/howto-manually-compile-nvidia-drivers-in-ubuntu/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 16:21:26 +0000</pubDate>
		<dc:creator>ibuclaw</dc:creator>
				<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://iainbuclaw.wordpress.com/?p=34</guid>
		<description><![CDATA[This is the shortened &#8220;in a nutshell&#8221; version of my guide here. So, here goes: Backup your current configuration. sudo cp /etc/X11/xorg.conf /etc/X11/xorg.xonf.original Install all build dependencies. sudo apt-get install build-essential pkg-config linux-headers-$(uname -r) Remove all traces of the Ubuntu version of NViDIA on your system sudo aptitude purge $(dpkg -l &#124; grep nvidia &#124; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iainbuclaw.wordpress.com&amp;blog=9497112&amp;post=34&amp;subd=iainbuclaw&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is the shortened &#8220;in a nutshell&#8221; version of my guide <a href="http://ubuntuforums.org/showthread.php?t=1125400" target="_blank">here</a>.</p>
<p>So, here goes:</p>
<p>Backup your current configuration.</p>
<pre>
sudo cp /etc/X11/xorg.conf /etc/X11/xorg.xonf.original
</pre>
<p>Install all build dependencies.</p>
<pre>
sudo apt-get install build-essential pkg-config linux-headers-$(uname -r)
</pre>
<p>Remove all traces of the Ubuntu version of NViDIA on your system</p>
<pre>
sudo aptitude purge $(dpkg -l | grep nvidia | awk '{print $2}')
</pre>
<p>Download the driver from the  nvidia download site.</p>
<p>For 32bit systems using the 185 Driver:</p>
<pre>
wget ftp://download.nvidia.com/XFree86/Linux-x86/185.18.36/NVIDIA-Linux-x86-185.18.36-pkg0.run -O NVIDIA-Linux-185.18.pkg.run
</pre>
<p>For 64bit systems using the 185 Driver:</p>
<pre>
wget ftp://download.nvidia.com/XFree86/Linux-x86_64/185.18.36/NVIDIA-Linux-x86_64-185.18.36-pkg0.run -O NVIDIA-Linux-185.18.pkg.run
</pre>
<p>If you use a legacy card that is not supported by the 185 driver, you can download the right one accordingly <a href="ftp://download.nvidia.com/XFree86/Linux-x86" target="_blank">here for 32bit</a> or <a href="ftp://download.nvidia.com/XFree86/Linux-x86_64" target="_blank">here for 64bit</a>.</p>
<p>Install the installer into the /usr/src directory and create an easy link to it.</p>
<pre>
sudo install NVIDIA-Linux-185.18.pkg.run /usr/src
sudo ln -fs /usr/src/NVIDIA-Linux-185.18.pkg.run /usr/src/nvidia-driver
</pre>
<p>Save and close all work, then kill X.</p>
<pre>
sudo service gdm stop
</pre>
<p>Login to a VT, and run the installer.</p>
<pre>
sudo sh /usr/src/nvidia-driver
</pre>
<p>Once the installer finishes, restore the backed up xorg.conf</p>
<pre>
sudo cp /etc/X11/xorg.conf.original /etc/X11/xorg.conf
</pre>
<p>And restore X.</p>
<pre>
sudo service gdm start
</pre>
<p>Congratulations, you now are running on your own manually compiled drivers.</p>
<p>One caveat with this that you must recompile every time there is a kernel update. For a guide on how to automate this procedure, <a href="http://ubuntuforums.org/showthread.php?t=835573" target="_blank">see here</a>.</p>
<p>To upgrade from your manually compiled the 185 drivers to the latest 190 beta, you would run through the current procedure.</p>
<p>Download</p>
<pre>
wget ftp://download.nvidia.com/XFree86/Linux-x86/190.32/NVIDIA-Linux-x86-190.32-pkg0.run -O NVIDIA-Linux-190.32.pkg.run
</pre>
<p>Install into the /usr/src directory, and <strong>override</strong> your existing symlink</p>
<pre>
sudo install NVIDIA-Linux-190.32.pkg.run /usr/src
sudo ln -fs /usr/src/NVIDIA-Linux-190.32.pkg.run /usr/src/nvidia-driver
</pre>
<p>Save and close all work, then kill X.</p>
<pre>
sudo service gdm stop
</pre>
<p>Uninstall NViDIA, to ensure a smooth transition.</p>
<pre>
sudo nvidia-uninstall
</pre>
<p>Run the installer as per previous method.</p>
<pre>
sudo sh /usr/src/nvidia-driver
</pre>
<p>And restore X.</p>
<pre>
sudo service gdm start
</pre>
<p>simple, eh?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iainbuclaw.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iainbuclaw.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iainbuclaw.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iainbuclaw.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iainbuclaw.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iainbuclaw.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iainbuclaw.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iainbuclaw.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iainbuclaw.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iainbuclaw.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iainbuclaw.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iainbuclaw.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iainbuclaw.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iainbuclaw.wordpress.com/34/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iainbuclaw.wordpress.com&amp;blog=9497112&amp;post=34&amp;subd=iainbuclaw&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iainbuclaw.wordpress.com/2009/09/29/howto-manually-compile-nvidia-drivers-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/907f83bbb9b80bd8cf5e2f1a07c42e5e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ibuclaw</media:title>
		</media:content>
	</item>
		<item>
		<title>HowTO: Fix Laptop Battery not Detected in LXDE Applet</title>
		<link>http://iainbuclaw.wordpress.com/2009/09/15/howto-fix-laptop-battery-not-detected-in-lxde-applet/</link>
		<comments>http://iainbuclaw.wordpress.com/2009/09/15/howto-fix-laptop-battery-not-detected-in-lxde-applet/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 19:43:50 +0000</pubDate>
		<dc:creator>ibuclaw</dc:creator>
				<category><![CDATA[battery]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://iainbuclaw.wordpress.com/?p=25</guid>
		<description><![CDATA[Although it is really the fault of the application having a certain location hard coded into them, one way to workaround a problem with the battery not being detected by the battery applet. First though, to confirm that this fix applies to you, run the following: ls /proc/acpi/battery If you get something other than CMB0 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iainbuclaw.wordpress.com&amp;blog=9497112&amp;post=25&amp;subd=iainbuclaw&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Although it is really the fault of the application having a certain location hard coded into them, one way to workaround a problem with the battery not being detected by the battery applet.</p>
<p>First though, to confirm that this fix applies to you, run the following:</p>
<pre>
ls /proc/acpi/battery
</pre>
<p>If you get something other than <strong>CMB0</strong> in the output, this fix may not apply to you.</p>
<p>First thing we need to do is install the iasl compiler/decompiler</p>
<pre>
sudo apt-get install iasl
</pre>
<p>Then obtain a copy of your motherboard&#8217;s dsdt</p>
<pre>
sudo cat /proc/acpi/dsdt &gt; dsdt.dat
</pre>
<p>Decompile the dsdt</p>
<pre>
iasl -d dsdt.dat
</pre>
<p>Then change all instances of CMB0 with BAT0 using sed</p>
<pre>
sed -i 's/CMB0/BAT0/g' dsdt.ds
</pre>
<p>and finally compile the dsdt again</p>
<pre>
iasl -tc dsdt.dsl
</pre>
<p>You may receive errors/warnings when compiling. If your system runs just fine, you can safely ignore these, else you may want to look into fixing them, as a buggy dsdt can mean that you are unable to suspend/hibernate.</p>
<p>To implement the new dsdt into your system, run the following:</p>
<pre>
sudo cp dsdt.aml /etc/initramfs-tools/DSDT.aml
sudo update-initramfs -u all
</pre>
<p>and then just reboot.</p>
<p>To test that dsdt is working, run the following:</p>
<pre>
ls /proc/acpi/battery
</pre>
<p>and you will now see <strong>BAT0</strong> in the output.</p>
<p><span style="color:#ff0000;">Note: The Kernel Devs will no longer use the patch to enable custom DSDTs for all releases after Karmic. Jaunty will be the last release that this works on.<br />
</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iainbuclaw.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iainbuclaw.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iainbuclaw.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iainbuclaw.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iainbuclaw.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iainbuclaw.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iainbuclaw.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iainbuclaw.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iainbuclaw.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iainbuclaw.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iainbuclaw.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iainbuclaw.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iainbuclaw.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iainbuclaw.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iainbuclaw.wordpress.com&amp;blog=9497112&amp;post=25&amp;subd=iainbuclaw&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iainbuclaw.wordpress.com/2009/09/15/howto-fix-laptop-battery-not-detected-in-lxde-applet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/907f83bbb9b80bd8cf5e2f1a07c42e5e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ibuclaw</media:title>
		</media:content>
	</item>
	</channel>
</rss>
