<?xml version="1.0"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:bgn="http://blogreen.org" xmlns:res="http://blogreen.org/TR/Resources" bgn:template-name="rss" version="2.0"><channel><title>Mono</title><link>http://romain.blogreen.org/categories/mono/</link><description>An open source, cross-platform, implementation of C# and the CLR.</description><link xmlns="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://romain.blogreen.org/categories/mono/rss-full.xml"/><item><title>The state of Mono 2.6 on FreeBSD</title><description><![CDATA[<p xmlns="http://www.w3.org/1999/xhtml">Long time no post... Well, I an writing a serie of articles about <a href="http://en.wikipedia.org/wiki/Near_Field_Communication">NFC</a> and it takes me a lot of time, not mentioning I still do many other things in parallel.  If you are interested in this area, stay tuned ;-)</p><p xmlns="http://www.w3.org/1999/xhtml">So apart NFC, what's new with <a href="http://www.mono-project.com">Mono</a> on <a href="http://www.FreeBSD.org">FreeBSD</a>?  First, you wight have seen that <a href="http://www.mono-project.com/Release_Notes_Mono_2.6">mono 2.6 has been released</a> for a while and is still not available in FreeBSD ports.  The main reasons are:</p><ul xmlns="http://www.w3.org/1999/xhtml">
<li><a href="https://bugzilla.novell.com/show_bug.cgi?id=528830">a thread concurrency problem</a> which is still not solved but <a href="http://code.google.com/p/bsd-sharp/source/browse/trunk/lang/mono/files/patch-mono_metadata_appdomain.c">an ugly workaround</a> have been found;</li>
<li>a bug (well, a weird implementation) of the new <a href="http://www.mono-project.com/Soft_Debugger">built-in soft-mode debugger</a> that makes it totally useless on amd64.  A workaround have been found and in the meantime, the code has been updated upstream and will be part of mono-2.6.2 which will probably be released at the end of the month;</li>
<li>the <a href="http://www.mono-project.com/Moonlight">moonlight</a> tools (e.g. the <tt>smcs.exe</tt> compiler) are still part of mono (read <em>the code source is in <tt>mono-2.6.tar.bz2</tt></em>) but installed by moonlight (read <em>the Makefiles with install targets are in <tt>moonlight-2.0.tar.bz2</tt></em>).  This leads to some juggling which is in progress (read: I can build and install it on my system, Firefox segfaults when I browse a website with Silverlight contents, and configure fails in Tinderbox because it cannot find bison, which is however installed according to the logs).</li>
</ul><p xmlns="http://www.w3.org/1999/xhtml">I will not mention here the <tt>mono-basic-2.6.tar.bz2</tt> source tarball that exists besides the <tt>moonlight-2.0.tar.bz2</tt> tarball in the <a href="http://ftp.novell.com/pub/mono/sources/moon/2.0/"><tt>moon</tt>(light) source directory</a> and the <tt>mono-basic-2.6.tar.bz2</tt> source tarball in  the <a href="http://ftp.novell.com/pub/mono/sources/mono-basic/"><tt>mono-basic</tt> directory</a> having different dates &amp; checksums… Lot of fun to come I guess.</p><p xmlns="http://www.w3.org/1999/xhtml">Once these various problems have been fixed, you can expect mono-2.6 to reach the ports, promptly followed by the last version of the MonoDevelop IDE which is quite lovely.</p><p xmlns="http://www.w3.org/1999/xhtml">Last but not least, <a href="http://www.freebsd.org/news/newsflash.html#event20100126:01">I am now a ports committer</a> and <a href="http://blog.xbsd.org/2010/01/26/new-ports-committer-romain-tartiere">flz@ is my mentor</a>.</p>]]></description><link>http://romain.blogreen.org/blog/2010/02/the-state-of-mono-26-on-freebsd/</link><category>FreeBSD</category><category>Mono</category><guid isPermaLink="true">http://romain.blogreen.org/blog/2010/02/the-state-of-mono-26-on-freebsd/</guid><pubDate>Tue, 16 Feb 2010 15:57:00 GMT</pubDate></item><item><title>Unbreaking Mono on FreeBSD 6.4</title><description><![CDATA[<p xmlns="http://www.w3.org/1999/xhtml">A few days ago <a href="http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/140916">ports/140916: lang/mono (2.4.2.3) installation fails</a> was opened. The reported problem had already been reported a few time but with insufficient feedback so far and I was not able to diagnose the problem, not mentioning providing a fix. But this time, the reporter could spot that the problem was happening for him only with FreeBSD-6.4.  I did the test on a fresh FreeBSD-6.4 install and could trigger the error:</p><pre xmlns="http://www.w3.org/1999/xhtml">arthur# portsnap fetch
[...]
arthur# portsnap extract
[...]
arthur# cd /usr/ports/lang/mono
arthur# make -V PKGNAME
mono-2.4.2.3_1
arthur# make
[...]
if test -w ../mcs; then :; else chmod -R +w ../mcs; fi
cd ../mcs &amp;&amp; gmake NO_DIR_CHECK=1 PROFILES='net_1_1 net_2_0 net_3_5 net_2_1' CC='cc' all-profiles
gmake[3]: Entering directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs'
gmake profile-do--net_1_1--all profile-do--net_2_0--all profile-do--net_3_5--all profile-do--net_2_1--all
gmake[4]: Entering directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs'
gmake PROFILE=basic all
gmake[5]: Entering directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs'
gmake[6]: *** [build/deps/basic-profile-check.exe] Error 1
gmake[6]: Entering directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs'
*** The compiler 'false' doesn't appear to be usable.
*** Trying the 'monolite' directory.
gmake[7]: Entering directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs'
gmake[8]: *** [build/deps/basic-profile-check.exe] Error 138
gmake[8]: Entering directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs'
*** The contents of your 'monolite' directory may be out-of-date
*** You may want to try 'make get-monolite-latest'
gmake[8]: *** [do-profile-check-monolite] Error 1
gmake[8]: Leaving directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs'
gmake[7]: *** [do-profile-check] Error 2
gmake[7]: Leaving directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs'
gmake[6]: *** [do-profile-check-monolite] Error 2
gmake[6]: Leaving directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs'
gmake[5]: *** [do-profile-check] Error 2
gmake[5]: Leaving directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs'
gmake[4]: *** [profile-do--basic--all] Error 2
gmake[4]: Leaving directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs'
gmake[3]: *** [profiles-do--all] Error 2
gmake[3]: Leaving directory `/usr/ports/lang/mono/work/mono-2.4.2.3/mcs'
gmake[2]: *** [all-local] Error 2
gmake[2]: Leaving directory `/usr/ports/lang/mono/work/mono-2.4.2.3/runtime'
gmake[1]: *** [all-recursive] Error 1
gmake[1]: Leaving directory `/usr/ports/lang/mono/work/mono-2.4.2.3'
gmake: *** [all] Error 2
*** Error code 1

Stop in /usr/ports/lang/mono.
*** Error code 1

Stop in /usr/ports/lang/mono.</pre><p xmlns="http://www.w3.org/1999/xhtml">A first look leads us on a wrong way (lane?): <em>*** The compiler 'false' doesn't appear to be usable</em>. This message is actually <strong>not</strong> an error message: the mono C# compiler (<tt>mcs(1)</tt>) is written in C# so some bootstrapping may be required if no version of mono is present on the system.  The mono port adds <tt>EXTERNAL_MCS=false</tt> to <tt>MAKE_ARGS</tt> so that the mono port will be build exactly the same way regardless of an available <tt>mcs(1)</tt> in the path.</p><p xmlns="http://www.w3.org/1999/xhtml">Hopefully, I tested on an old machine and could see that <q>something was running for a couple seconds before failing</q>. Ctrl+T in <tt>tcsh(1)</tt> told me more:</p><pre xmlns="http://www.w3.org/1999/xhtml">load: 0.08  cmd: mono 10910 [ksesigwait] 0.13u 0.10s 0% 24492k
load: 0.08  cmd: mono 10910 [ksesigwait] 0.13u 0.10s 0% 24964k</pre><p xmlns="http://www.w3.org/1999/xhtml">The good news is that some <q>mono</q> application is running. But wait, what is this <em>ksesigwait</em> state? A first look at the <a href="http://fxr.watson.org/">FreeBSD Kernel Cross Reference</a> reveals that this state is defined in <tt>kern/kern_kse.c</tt>; the man page is <tt><a href="http://www.FreeBSD.org/cgi/man.cgi?query=kse&amp;manpath=FreeBSD+6.4-RELEASE">kse(2)</a></tt>; <a href="http://en.wikipedia.org/wiki/Kernel_Scheduled_Entities">Wikipedia states</a> <em>KSEs were mandatory at introduction; made optional at kernel build time in the 7.0 release and removed from the 8.0 release with a compatibility library</em>.</p><p xmlns="http://www.w3.org/1999/xhtml">The second good news is that a 22MB <tt>mono.core</tt> file is written in the mcs directory.</p><pre xmlns="http://www.w3.org/1999/xhtml">arthur# gdb -q /usr/ports/lang/mono/work/mono-2.4.2.3/mono/mini/mono mono.core
Core was generated by `mono'.
Program terminated with signal 10, Bus error.
Reading symbols from /usr/local/lib/libgthread-2.0.so.0...done.
Loaded symbols for /usr/local/lib/libgthread-2.0.so.0
Reading symbols from /usr/local/lib/libglib-2.0.so.0...done.
Loaded symbols for /usr/local/lib/libglib-2.0.so.0
Reading symbols from /usr/local/lib/libintl.so.8...done.
Loaded symbols for /usr/local/lib/libintl.so.8
Reading symbols from /usr/local/lib/libiconv.so.3...done.
Loaded symbols for /usr/local/lib/libiconv.so.3
Reading symbols from /usr/local/lib/libpcre.so.0...done.
Loaded symbols for /usr/local/lib/libpcre.so.0
Reading symbols from /lib/libm.so.4...done.
Loaded symbols for /lib/libm.so.4
Reading symbols from /lib/libpthread.so.2...done.
Loaded symbols for /lib/libpthread.so.2
Reading symbols from /lib/libc.so.6...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /libexec/ld-elf.so.1...done.
Loaded symbols for /libexec/ld-elf.so.1
#0  0x2856bf2a in signalcontext () from /lib/libc.so.6
[New Thread 0x8319c00 (sleeping)]
[New Thread 0x8319800 (sleeping)]
[New Thread 0x8319600 (LWP 100098)]
[New Thread 0x82fd000 (runnable)]
[New LWP 100058]
(gdb) thread apply all bt

Thread 5 (LWP 100058):
#0  0x2856bf2a in signalcontext () from /lib/libc.so.6
#1  0x28527fc4 in pthread_mutexattr_init () from /lib/libpthread.so.2
#2  0x28303480 in ?? ()

Thread 4 (Thread 0x82fd000 (runnable)):
#0  0x285eb0ac in __vfprintf () from /lib/libc.so.6
#1  0x2855ff90 in vasprintf () from /lib/libc.so.6
[...]
#33814 0x081464b8 in mono_runtime_invoke (method=0x82fd81c, obj=0x0, params=0xbfbfe510, exc=0x0) at object.c:2401
#33815 0x0814785b in mono_runtime_exec_main (method=0x82fd81c, args=0x28657f60, exc=0x0) at object.c:3301
#33816 0x0814736c in mono_runtime_run_main (method=0x82fd81c, argc=2, argv=0xbfbfe74c, exc=0x0) at object.c:3089
#33817 0x080cdf7d in mono_jit_exec (domain=0x28653ee0, assembly=0x833c880, argc=3, argv=0xbfbfe748) at driver.c:924
#33818 0x080ce0e8 in main_thread_handler (user_data=0xbfbfe690) at driver.c:972
#33819 0x080cfc3a in mono_main (argc=6, argv=0xbfbfe73c) at driver.c:1647
#33820 0x08058f90 in main (argc=6, argv=0xbfbfe73c) at main.c:34

Thread 3 (Thread 0x8319600 (LWP 100098)):
#0  0x2852f5f3 in pthread_testcancel () from /lib/libpthread.so.2
#1  0x28527fc4 in pthread_mutexattr_init () from /lib/libpthread.so.2
#2  0x28303480 in ?? ()

Thread 2 (Thread 0x8319800 (sleeping)):
#0  0x28528097 in pthread_mutexattr_init () from /lib/libpthread.so.2
#1  0x28521ade in _nanosleep () from /lib/libpthread.so.2
#2  0x28521c42 in nanosleep () from /lib/libpthread.so.2
#3  0x081e32ca in collection_thread (unused=0x0) at collection.c:34
#4  0x28520449 in pthread_create () from /lib/libpthread.so.2
#5  0x285deecb in _ctx_start () from /lib/libc.so.6

Thread 1 (Thread 0x8319c00 (sleeping)):
#0  0x28528097 in pthread_mutexattr_init () from /lib/libpthread.so.2
#1  0x2852822b in pthread_mutexattr_init () from /lib/libpthread.so.2
#2  0x2852c839 in _pthread_cond_wait () from /lib/libpthread.so.2
#3  0x2852cd82 in pthread_cond_wait () from /lib/libpthread.so.2
#4  0x081e86d8 in _wapi_handle_timedwait_signal_handle (handle=0x1d05, timeout=0x0, alertable=0, poll=0) at handles.c:1605
#5  0x081e846e in _wapi_handle_wait_signal_handle (handle=0x1d05, alertable=0) at handles.c:1548
#6  0x08205f2e in WaitForSingleObjectEx (handle=0x1d05, timeout=4294967295, alertable=0) at wait.c:205
#7  0x081608a0 in finalizer_thread (unused=0x0) at gc.c:1061
#8  0x081806f0 in start_wrapper (data=0x8326380) at threads.c:623
#9  0x08200367 in thread_start_routine (args=0x832c230) at threads.c:286
#10 0x08223adf in GC_start_routine (arg=0x2865aec0) at pthread_support.c:1382
#11 0x28520449 in pthread_create () from /lib/libpthread.so.2
#12 0x285deecb in _ctx_start () from /lib/libc.so.6
#0  0x2852f5f3 in pthread_testcancel () from /lib/libpthread.so.2</pre><p xmlns="http://www.w3.org/1999/xhtml">Yes, you read it well, the thread 4 backtrace is 33820 frame long! Looks like we have a stack overflow... Since the problem occurs on FreeBSD 6 (where KSE is <em>enabled</em> by default) and not on FreeBSD 7 (where KSE is <em>disabled</em> by default) nor FreeBSD 8 (No KSE at all), it is likely to be related to the thread implementation.</p><p xmlns="http://www.w3.org/1999/xhtml">Let's launched one more time <tt>gmake(1)</tt> and hit Ctrl+Z to suspend all when mono was filling-in it's stack in order to have some hints about the exact command being executed. Reducing it to a simple test is trivial, e.g.:</p><pre xmlns="http://www.w3.org/1999/xhtml">arthur# pwd
/usr/ports/lang/mono/work/mono-2.4.2.3/mcs
arthur# env MONO_PATH="$PWD/class/lib/monolite" ../mono/mini/mono --config ../runtime/etc/mono/config ./class/lib/monolite/mcs.exe
Bus error (core dumped)
arthur# </pre><p xmlns="http://www.w3.org/1999/xhtml">Now we know what is being run. Let's get some info about this binary file:</p><pre xmlns="http://www.w3.org/1999/xhtml">arthur# ldd ../mono/mini/mono
../mono/mini/mono:
	libgthread-2.0.so.0 =&gt; /usr/local/lib/libgthread-2.0.so.0 (0x28304000)
	libglib-2.0.so.0 =&gt; /usr/local/lib/libglib-2.0.so.0 (0x28309000)
	libintl.so.8 =&gt; /usr/local/lib/libintl.so.8 (0x283c9000)
	libiconv.so.3 =&gt; /usr/local/lib/libiconv.so.3 (0x283d2000)
	libpcre.so.0 =&gt; /usr/local/lib/libpcre.so.0 (0x284c7000)
	libm.so.4 =&gt; /lib/libm.so.4 (0x284fc000)
	libpthread.so.2 =&gt; /lib/libpthread.so.2 (0x28512000)
	libc.so.6 =&gt; /lib/libc.so.6 (0x28537000)</pre><p xmlns="http://www.w3.org/1999/xhtml"><tt>pthread(3)</tt> list all thread libraries available on the system:</p><ul xmlns="http://www.w3.org/1999/xhtml">
<li>POSIX Threads Library (libpthread, -lpthread)</li>
<li>1:1 Threading Library (libthr, -lthr)</li>
<li>Reentrant C Library (libc_r, -lc_r)</li>
</ul><p xmlns="http://www.w3.org/1999/xhtml">On my FreeBSD 8.0-STABLE machine, <tt>ldd(1)</tt> reports (mono-2.6 instead of 2.4):</p><pre xmlns="http://www.w3.org/1999/xhtml">marvin# ldd `which mono`
/usr/local/bin/mono:
	libgthread-2.0.so.0 =&gt; /usr/local/lib/libgthread-2.0.so.0 (0x8008b4000)
	libglib-2.0.so.0 =&gt; /usr/local/lib/libglib-2.0.so.0 (0x8009b8000)
	libicui18n.so.38 =&gt; /usr/local/lib/libicui18n.so.38 (0x800b74000)
	libintl.so.8 =&gt; /usr/local/lib/libintl.so.8 (0x800dca000)
	libiconv.so.3 =&gt; /usr/local/lib/libiconv.so.3 (0x800ed3000)
	libpcre.so.0 =&gt; /usr/local/lib/libpcre.so.0 (0x8010cd000)
	libm.so.5 =&gt; /lib/libm.so.5 (0x8011fd000)
	libthr.so.3 =&gt; /lib/libthr.so.3 (0x80131c000)
	libc.so.7 =&gt; /lib/libc.so.7 (0x801434000)
	libicuuc.so.38 =&gt; /usr/local/lib/libicuuc.so.38 (0x80166e000)
	libicudata.so.38 =&gt; /usr/local/lib/libicudata.so.38 (0x80189f000)
	libstdc++.so.6 =&gt; /usr/lib/libstdc++.so.6 (0x80248e000)
	libgcc_s.so.1 =&gt; /lib/libgcc_s.so.1 (0x802699000)</pre><p xmlns="http://www.w3.org/1999/xhtml">So let's try to use <em>libthr</em> on FreeBSD 6. This can be achieved using <tt>libmap.conf(5)</tt>: instead of <tt>/lib/libpthread.so(.2)</tt> we want to use <tt>/usr/lib/libthr.so(.2)</tt>:</p><pre xmlns="http://www.w3.org/1999/xhtml">arthur# cat &gt;&gt; /etc/libmap.conf &lt;&lt; EOT
libpthread.so.2  libthr.so.2
libpthread.so    libthr.so
EOT</pre><p xmlns="http://www.w3.org/1999/xhtml">then...</p><pre xmlns="http://www.w3.org/1999/xhtml">arthur# make
[...]
arthur# make tests
[...]
363 test(s) passed. 0 test(s) did not pass.
[...]
arthur# echo $?
0</pre><p xmlns="http://www.w3.org/1999/xhtml">\o/</p>]]></description><link>http://romain.blogreen.org/blog/2009/12/unbreaking-mono-on-freebsd-64/</link><category>FreeBSD</category><category>Mono</category><guid isPermaLink="true">http://romain.blogreen.org/blog/2009/12/unbreaking-mono-on-freebsd-64/</guid><pubDate>Wed, 23 Dec 2009 02:29:00 GMT</pubDate></item><item><title>Banshee: Like Frankenstein! It rips!</title><description><![CDATA[<p xmlns="http://www.w3.org/1999/xhtml">A while ago (I mean when it landed in the FreeBSD ports tree), <a href="http://banshee-project.org/">Banshee</a> reacted when a music CD-ROM was in a CD-Drive: it crashed. Well, not so cool in fact, you had to double-check it was empty before launching the player...</p><p xmlns="http://www.w3.org/1999/xhtml">More recently, I was happy to find out that it was not the case anymore: Banshee was simply unable to detect the CD-ROM anymore. Still not so cool: you were still unable to listen to an audio CD, not mentioning ripping it.</p><p xmlns="http://www.w3.org/1999/xhtml">For some reason I cannot really figure out (I have spent quite some time in fixing Banshee for FreeBSD and giving it some love), I took a look at this problem.</p><p xmlns="http://www.w3.org/1999/xhtml">Obviously, the first rusty part of the chain of tools involved with audio CD was <a href="http://musicbrainz.org/">MusicBrainz</a> and more precisely <a href="http://musicbrainz.org/doc/MusicbrainzSharp">musicbrainz-sharp</a> (a client library for .NET / Mono). FreeBSD having it's own <tt>ioctl</tt>s for managing CD drives, and musicbrainz-sharp having 3 concrete classes for managing such devices called <tt>DiscLinux</tt>, <tt>DiscWin32</tt> and <tt>DiscWin32NT</tt>, a piece was definitively missing. With a great deal of inspiration, it was called <tt>DiscFreeBSD</tt> and provides bindings for almost everything referenced in <tt>sys/cdio.h</tt>. When instanced, this class reads the CD in the drive and computes an ID used to fetch information about the audio CD from the Internet.</p><p xmlns="http://www.w3.org/1999/xhtml">Unfortunately, I could not test the library on a system one which it is supposed to work (read GNU/Linux) so I asked a friend of mine, Baptiste (Yes! <a href="http://bapt.name/">It works!</a>) [edit: 2009-11-10:12:04 he just told me he has a <em>a-bit-better</em> website where he is <a href="http://blog.bapt.name/">playing now...</a>], to tell me how it goes and to help me make the library behave the same on GNU/Linux and FreeBSD. We quickly had some good results:</p><p xmlns="http://www.w3.org/1999/xhtml" class="figure"><a href="http://romain.blogreen.org/files/banshee-list-tracks.png"><img src="http://romain.blogreen.org/files/banshee-list-tracks-thumb.png" alt="Banshee listing an audio CD tracks"/></a><br/>
Yay! Tracks from <em>Sopor Aeternus</em>' album <em>Les fleurs du Mal</em> are being listed!</p><p xmlns="http://www.w3.org/1999/xhtml">Unfortunately, it was not possible to listen to the CD nor rip it... Not so cool once more.</p><p xmlns="http://www.w3.org/1999/xhtml">And here takes place the magic of GStreamer!</p><pre xmlns="http://www.w3.org/1999/xhtml">cd /usr/ports/audio/gstreamer-plugins-cdparanoia &amp;&amp; make install</pre><p xmlns="http://www.w3.org/1999/xhtml">Now, Banshee can play and RIP audio CDs with a single mouse clic!</p><p xmlns="http://www.w3.org/1999/xhtml" class="figure"><a href="http://romain.blogreen.org/files/banshee-play-cd.png"><img src="http://romain.blogreen.org/files/banshee-play-cd-thumb.png" alt="Banshee playing an audio CD"/></a><br/>
Playing <em>Cinema  Strange</em>'s <em>The Astonished Eyes Of Evening</em>...</p><p xmlns="http://www.w3.org/1999/xhtml" class="figure"><a href="http://romain.blogreen.org/files/banshee-ripping.png"><img src="http://romain.blogreen.org/files/banshee-ripping-thumb.png" alt="Banshee ripping an audio CD"/></a><br/>
And ripping it (progress in the bottom left corner)...</p><p xmlns="http://www.w3.org/1999/xhtml">All this will be soon in your ports tree!</p><p xmlns="http://www.w3.org/1999/xhtml">For those who can't wait, patches for musicbrainz-shap are in the project's trac: <a href="http://bugs.musicbrainz.org/ticket/5490">Add support for FreeBSD in MusicBrainzSharp</a>.</p>]]></description><link>http://romain.blogreen.org/blog/2009/11/banshee-like-frankenstein-it-rips/</link><category>FreeBSD</category><category>Mono</category><guid isPermaLink="true">http://romain.blogreen.org/blog/2009/11/banshee-like-frankenstein-it-rips/</guid><pubDate>Tue, 10 Nov 2009 02:03:00 GMT</pubDate></item><item><title>Packing structures with Mono or how to fix alignment problems for P/Invoke</title><description><![CDATA[<p xmlns="http://www.w3.org/1999/xhtml">This is basically a[nother] note for myself.</p><p xmlns="http://www.w3.org/1999/xhtml">I have just spent a while wondering why the size of some data structures in C# was wrong while writing bindings to the CD-ROM control features of the FreeBSD libc.</p><p xmlns="http://www.w3.org/1999/xhtml">Considering the following code snippet:</p><pre xmlns="http://www.w3.org/1999/xhtml" class="sh_csharp">struct msf {
	public byte unused;
	public byte minute;
	public byte second;
	public byte frame;
};
[StructLayout (LayoutKind.Explicit)]
struct msf_lba {
	[FieldOffset (0)] public msf msf;
	[FieldOffset (0)] public int lba;
	[MarshalAs (UnmanagedType.ByValArray, SizeConst = 4)]
	[FieldOffset (0)] public byte [] addr;
};
struct cd_toc_entry {
	byte unused1;
	public byte control_addr_type;
	public byte track;
	byte unused2;
	public msf_lba addr;
};
struct cd_sub_channel_media_catalog {
	public byte data_format;
	public int mc_valid;
	[MarshalAs (UnmanagedType.ByValArray, SizeConst = 15)]
	public byte [] mc_number;
};</pre><p xmlns="http://www.w3.org/1999/xhtml">We can compute the size of each structure (<a href="http://msdn.microsoft.com/en-us/library/eahchzkf.aspx">MSDN page about types size</a>):</p><dl xmlns="http://www.w3.org/1999/xhtml">
<dt>msf</dt>
<dd>A <tt>msf</tt> structure contains 4 members each of 1 <tt>byte</tt> long so the whole structure is 4 bytes;</dd>
<dt>msf_lba</dt>
<dd>This is not more than the union of a <tt>msf</tt> structure (4 bytes), an <tt>int</tt> (4 bytes) and an array of 4 <tt>byte</tt> (4 bytes), so it's 4 bytes long too;</dd>
<dt>cd_toc_entry</dt>
<dd>A <tt>cd_toc_entry</tt> structure is composed of an unused <tt>byte</tt> (1 byte), 2 data <tt>byte</tt> (1 byte + 1 byte), another unused <tt>byte</tt> (1 byte) and a <tt>msf_lba</tt> structure (4 bytes) so it is 1 + 1 + 1 + 1 + 4 = 8 bytes long;</dd>
<dt>cd_sub_channel_media_catalog</dt>
<dd>A <tt>cd_sub_channel_media_catalog</tt> structure starts with 1 <tt>byte</tt> (1 byte), followed by an <tt>int</tt> (4 bytes), and an array of 15 <tt>byte</tt> (15 bytes). The whole structure is therefore 1 + 4 + 15 = 20 bytes long.</dd>
</dl><p xmlns="http://www.w3.org/1999/xhtml">These results can be checked using <a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.sizeof.aspx"><tt>Marshal.SizeOf</tt></a>:</p><pre xmlns="http://www.w3.org/1999/xhtml">Marshal.SizeOf (typeof (msf)) = 4
Marshal.SizeOf (typeof (msf_lba)) = 4
Marshal.SizeOf (typeof (cd_toc_entry)) = 8
Marshal.SizeOf (typeof (cd_sub_channel_media_catalog)) = 24</pre><p xmlns="http://www.w3.org/1999/xhtml">So the <tt>cd_sub_channel_media_catalog</tt> structure it 4 bytes long more that expected.  This really sounds like alignment problems in C. A quick search on the <a href="http://www.mono-project.com/Interop_with_Native_Libraries">Interop with Native Libraries</a> page on Novell's wiki does not give any info about such a problem. Switching the two first fields order fix the size (but of course breaks the workability) so it is definitively an alignment problem that takes place here.</p><p xmlns="http://www.w3.org/1999/xhtml">After some search, I could find the <a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.structlayoutattribute.pack.aspx">StructLayoutAttribute.Pack Field</a> (actually I could not find this piece of information using the MSDN search engine, I had to search on the web similar problems and find <a href="http://stackoverflow.com/questions/1258987/c-p-invoke-structure-alignment">this one with a reference to <q>Pack</q></a> to find this page in the Microsoft .NET documentation).</p><p xmlns="http://www.w3.org/1999/xhtml">Finally, the solution is to write this:</p><pre xmlns="http://www.w3.org/1999/xhtml" class="sh_csharp">[StructLayout (LayoutKind.Sequential, Pack = 1)]
struct cd_sub_channel_media_catalog {
	public byte data_format;
	public int mc_valid;
	[MarshalAs (UnmanagedType.ByValArray, SizeConst = 15)]
	public byte [] mc_number;
};</pre><p xmlns="http://www.w3.org/1999/xhtml">The <a href="http://musicbrainz.org/doc/MusicbrainzSharp">MusicBrainzSharp</a> port to FreeBSD can go on!</p>]]></description><link>http://romain.blogreen.org/blog/2009/11/packing-structures-with-mono-or-how-to-fix-alignment-problems-for-pinvoke/</link><category>FreeBSD</category><category>Mono</category><guid isPermaLink="true">http://romain.blogreen.org/blog/2009/11/packing-structures-with-mono-or-how-to-fix-alignment-problems-for-pinvoke/</guid><pubDate>Mon, 09 Nov 2009 13:39:00 GMT</pubDate></item><item><title>LINQ, PostgreSQL and Mono</title><description><![CDATA[<p xmlns="http://www.w3.org/1999/xhtml"><a href="http://en.wikipedia.org/wiki/Language_Integrated_Query">LINQ</a> to DB is planned for <a href="http://www.mono-project.com/Roadmap">mono-2.6</a>, however I wanted to access data from a <a href="http://www.postgresql.org/">PostgreSQL</a> database, without spending much time playing with <a href="http://npgsql.projects.postgresql.org/">Npgsql</a>, and using the stable version of mono: 2.4.2.3.</p><p xmlns="http://www.w3.org/1999/xhtml">Here comes <a href="http://linq.to/db">DbLinq</a>, which aims to provide <q>linq to SQL</q> for many DataBase systems. While this project is still considered experimental to some extends by its developers, I wanted to give it a try. Since it way quite a PITA, here are the details for building using DbLinq with mono.</p><h3 xmlns="http://www.w3.org/1999/xhtml">Get DbLinq from the Subversion repository</h3><p xmlns="http://www.w3.org/1999/xhtml">The latest stable release is quite old, and the project page warns <em>we recommend using the latest SVN HEAD</em>, so checkout the code from the google code repository:</p><pre xmlns="http://www.w3.org/1999/xhtml">svn checkout http://dblinq2007.googlecode.com/svn/trunk/ dblinq2007</pre><p xmlns="http://www.w3.org/1999/xhtml">Open the solution in MonoDevelop (or your favourite editor) and edit each project options so that assemblies are signed with the <code>DbLinq.snk</code> key.</p><p xmlns="http://www.w3.org/1999/xhtml">You can then compile all needed assemblies and the <em>DbMetal</em> utility.</p><h3 xmlns="http://www.w3.org/1999/xhtml">Get the System.Data.Linq.dll assembly</h3><p xmlns="http://www.w3.org/1999/xhtml">This assembly is not yet in the stable mono releases. You can compile it from the mono trunk:</p><pre xmlns="http://www.w3.org/1999/xhtml">svn checkout http://anonsvn.mono-project.com/source/trunk/mcs
cd mcs &amp;&amp; ./configure &amp;&amp; gmake</pre><p xmlns="http://www.w3.org/1999/xhtml">The assembly for the 2.0 profile is then available as <code>class/lib/net_2_0/System.Data.Linq.dll</code>.</p><h3 xmlns="http://www.w3.org/1999/xhtml">Start you project</h3><p xmlns="http://www.w3.org/1999/xhtml">Create a new project as usual and add any required references. For example, my project use PostgreSQL so I added the following assemblies:</p><ul xmlns="http://www.w3.org/1999/xhtml">
  <li>DbLinq.dll</li>
  <li>DbLinq.PostgreSQL.dll</li>
  <li>Npgsql.dll</li>
  <li>System.Data.dll</li>
  <li>System.Data.Linq.dll</li>
</ul><h3 xmlns="http://www.w3.org/1999/xhtml">Generate classes to access your DataBase</h3><p xmlns="http://www.w3.org/1999/xhtml">The <em>DbMetal</em> utility generate classes from a DataBase schema. Before using it, ensure that <code>DbMetal.exe.config</code> exists in the <code>DbMetal.exe</code> directory and if not, copy it from <code>DbMetal/App.config</code>. You can then use the utility to generate your code:</p><pre xmlns="http://www.w3.org/1999/xhtml">mono DbMetal.exe /conn:"server=localhost;user id=user;\
   password=password; database=db" /provider=PostgreSQL \
   /code:db.cs /pluralize</pre><p xmlns="http://www.w3.org/1999/xhtml">Add the generated <code>db.cs</code> to your project and start coding:</p><pre xmlns="http://www.w3.org/1999/xhtml" class="sh_csharp">using System;
using Npgsql;

class MainClass
{
	public static void Main(string[] args)
	{
		string connStr = "server=localhost;user id=user; password=password; database=db";
		NpgsqlConnection conn = new NpgsqlConnection(connStr);

		using (Db db = new Db(conn))
		{
			foreach (Employees e in db.Employees)
			Console.WriteLine(e.Name);
		}
	}
}</pre>]]></description><link>http://romain.blogreen.org/blog/2009/07/linq-postgresql-and-mono/</link><category>FreeBSD</category><category>Mono</category><guid isPermaLink="true">http://romain.blogreen.org/blog/2009/07/linq-postgresql-and-mono/</guid><pubDate>Tue, 28 Jul 2009 22:16:00 GMT</pubDate></item><item><title>Mono on FreeBSD</title><description><![CDATA[<p xmlns="http://www.w3.org/1999/xhtml"><a href="http://www.mono-project.com">Mono</a> <a href="http://www.mono-project.com/Release_Notes_Mono_2.4.2">2.4.2</a> has just been committed to the <a href="http://www.FreeBSD.org/">FreeBSD</a> <a href="http://freshports.org/">ports tree</a>, after being available for a few days in the <a href="http://code.google.com/p/bsd-sharp/">BSD#</a> <a href="http://code.google.com/p/bsd-sharp/source/checkout">repository</a>.</p><p xmlns="http://www.w3.org/1999/xhtml">The <tt>lang/mono</tt> port still has many patches to make mono build and run on FreeBSD, but still should change with mono-2.6: the mono trunk can now be build <em>vanilla</em> on FreeBSD.</p><p xmlns="http://www.w3.org/1999/xhtml">So, what's coming next? Well, I have been working on splitting the <tt>deskutils/gnome-do-plugins</tt> in order to cut down a bit the <strong>*HUGE*</strong> amount of dependencies for building and running all plugins. Working on this proved that <tt>devel/monodevelop</tt> is somewhat ready to be committed in the FreeBSD ports tree, so expect at least these two packages to be available in the ports collection soon!</p><p xmlns="http://www.w3.org/1999/xhtml">To finish, I want to thanks <a href="http://blog.xbsd.org/">Florent Thoumie</a> (flz@) for taking care of my Mono PR.</p>]]></description><link>http://romain.blogreen.org/blog/2009/07/mono-on-freebsd/</link><category>FreeBSD</category><category>Mono</category><guid isPermaLink="true">http://romain.blogreen.org/blog/2009/07/mono-on-freebsd/</guid><pubDate>Mon, 06 Jul 2009 09:43:00 GMT</pubDate></item><item><title>Meta-note-taking with Tomboy</title><description><![CDATA[<p xmlns="http://www.w3.org/1999/xhtml">Just wrote a <a href="http://projects.gnome.org/tomboy/">Tomboy</a> add-in allowing the user to keep notes in Tomboy notes. The idea? If just like me you rely a lot on short tags such as <em>TODO</em> or <em>FIXME</em>, you find it convenient to have the editor highlight them. It is exactly what the add-in has been designed for.</p><p xmlns="http://www.w3.org/1999/xhtml">Mandatory screenshot:</p><p xmlns="http://www.w3.org/1999/xhtml" class="figure">
<img src="/images/tomboy-todo.png" alt="tomboy-todo screenshot"/><br/>
Editing notes with <em>FIXME</em>s and <em>TODO</em>s.
</p><p xmlns="http://www.w3.org/1999/xhtml">For more info and downloads, have a look to the <a href="http://romain.blogreen.org/projects/tomboy-todo/">Tomboy-Todo project</a>'s page.</p>]]></description><link>http://romain.blogreen.org/blog/2009/01/meta-note-taking-with-tomboy/</link><category>FreeBSD</category><category>Mono</category><guid isPermaLink="true">http://romain.blogreen.org/blog/2009/01/meta-note-taking-with-tomboy/</guid><pubDate>Sun, 25 Jan 2009 15:55:00 GMT</pubDate></item><item><title>BSD#: Mono on FreeBSD</title><description><![CDATA[<p xmlns="http://www.w3.org/1999/xhtml">A few weeks ago, I joined the <a href="http://code.google.com/p/bsd-sharp/">BSD#</a> project which aim to maintain <a href="http://www.mono-project.org">Mono</a> (an open source implementation of the <a href="http://msdn.microsoft.com/en-us/netframework/default.aspx">Microsoft .NET framework</a>) on <a href="http://www.FreeBSD.org">FreeBSD</a>. It was the occasion for giving <a href="http://svk.bestpractical.com/view/HomePage"><tt>svk</tt></a> a try.</p><p xmlns="http://www.w3.org/1999/xhtml"><tt>svk</tt> is a decentralised version control system based on <a href="http://subversion.tigris.org">Subversion</a>. It acts as a staging area between the repository and your local copy, making synchronisations and merges easy.</p><h2 xmlns="http://www.w3.org/1999/xhtml">Preparing repositories</h2><p xmlns="http://www.w3.org/1999/xhtml">A tricky thing with mono is that it is likely to blow-up in your face each time you change the framework version. Hence, I decided to build ports with different mono versions to see which one is the best for production use.</p><p xmlns="http://www.w3.org/1999/xhtml">In order to work with different versions of mono, I created as many working copies of the ports tree as needed. This was achieved this way:</p><pre xmlns="http://www.w3.org/1999/xhtml">$ svk mirror http://bsd-sharp.googlecode.com/svn/trunk //mirror/bsd-sharp
$ svk sync -a
$ svk copy //mirror/bsd-sharp //local/bsd-sharp
$ svk checkout //local/bsd-sharp bsd-sharp-latest
$ svk checkout //local/bsd-sharp bsd-sharp-mono-126</pre><p xmlns="http://www.w3.org/1999/xhtml">The <code>bsd-sharp-latest</code> directory will contain the latest mono version available (1.9.1 at the time of writing), while the <code>bsd-sharp-mono-126</code> directory will hold mono at version 1.2.6.</p><h2 xmlns="http://www.w3.org/1999/xhtml">Setting-up a Tinderbox</h2><p xmlns="http://www.w3.org/1999/xhtml">I already mentioned the <a href="http://tinderbox.marcuscom.com/">tinderbox</a> package building system. I will not detail here the complete setup of a tinderbox, please refer to the <tt>README</tt> file provided in the tarball for detailed instructions.</p><h3 xmlns="http://www.w3.org/1999/xhtml">Creating Ports Trees</h3><p xmlns="http://www.w3.org/1999/xhtml">The first ports tree to create is an <em>official</em> ports tree, in sync with FreeBSD ports:</p><pre xmlns="http://www.w3.org/1999/xhtml"># cd ${pb}/scripts
# ./tc createPortsTree -p FreeBSD -d "FreeBSD ports tree" \
  -w http://www.freebsd.org/cgi/cvsweb.cgi/ports/</pre><p xmlns="http://www.w3.org/1999/xhtml">Each BSD# ports tree is then created using an <em>user</em> (i.e. <em>custom</em>) update script that merge local copies of the BSD# repository in the FreeBSD ports tree:</p><pre xmlns="http://www.w3.org/1999/xhtml"># cd ${pb}/scripts
# mkdir ../portstrees/BSD-sharp-latest
# ln -s <a href="http://romain.blogreen.org/files/BSD-sharp-update.sh">/home/romain/BSD-sharp-update.sh</a> ../portstrees/BSD-sharp-latest/update.sh
# ./tc createPortsTree -p BSD-sharp-latest -u USER</pre><h3 xmlns="http://www.w3.org/1999/xhtml"><acronym title="Dont Repeat Yourself">DRY</acronym> with Hooks</h3><p xmlns="http://www.w3.org/1999/xhtml">The main problem with this setup is that all ports that do not depends on mono will still be compiled for each build and therefore we will lose a lot of time compiling the same software packages.</p><p xmlns="http://www.w3.org/1999/xhtml">This can however be avoided using a post-port-build hook that copy successfully created packages of software pieces not depending on mono to other builds' package directory and update those ports status in the data-store:</p><pre xmlns="http://www.w3.org/1999/xhtml"># cd ${pb}/scripts
# ./tc updateHookCmd -h postPortBuild -c <a href="http://romain.blogreen.org/files/postPortBuild">/home/romain/postPortBuild</a></pre><h2 xmlns="http://www.w3.org/1999/xhtml">Tinderbuild</h2><p xmlns="http://www.w3.org/1999/xhtml">The environment is ready! You can start playing:</p><pre xmlns="http://www.w3.org/1999/xhtml"># cd ${pb}/scripts
# ./tinderd</pre><p xmlns="http://www.w3.org/1999/xhtml">The tinderbox I setup is IPv6 only accessible at <a href="http://eddy.sigabrt.org">http://eddy.sigabrt.org</a> (Not always up).</p>]]></description><link>http://romain.blogreen.org/blog/2008/08/bsd-mono-on-freebsd/</link><category>FreeBSD</category><category>Mono</category><guid isPermaLink="true">http://romain.blogreen.org/blog/2008/08/bsd-mono-on-freebsd/</guid><pubDate>Sat, 02 Aug 2008 08:15:00 GMT</pubDate></item></channel></rss>

