<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>lighty's life: Project Glib: it compiles ... mostly</title>
    <link>http://blog.lighttpd.net/articles/2008/02/19/project-glib-it-compiles-mostly</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Project Glib: it compiles ... mostly</title>
      <description>&lt;p&gt;Part of my ongoing, hidden effort to port lighttpd to glib I can now at least say: it compiles.&lt;/p&gt;


	&lt;p&gt;Well, mostly. The core does compile and &lt;i&gt;mod_staticfile&lt;/i&gt; is also mostly done. Mostly, as I don&amp;#8217;t have decided on how to handle the config-file handling yet.&lt;/p&gt;
&lt;p&gt;So, what has been done so far:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;i&gt;buffer.c&lt;/i&gt; and &lt;i&gt;buffer.h&lt;/i&gt; are gone and are replaced by &lt;i&gt;GString&lt;/i&gt;&lt;/li&gt;
		&lt;li&gt;&lt;i&gt;array.c&lt;/i&gt; is gone and is replace by &lt;i&gt;GHashTable&lt;/i&gt; or &lt;i&gt;GPtrArray&lt;/i&gt;&lt;/li&gt;
		&lt;li&gt;&lt;i&gt;array.h&lt;/i&gt; will vanish when the &lt;i&gt;data_&amp;#8230;c&lt;/i&gt; goes away&lt;/li&gt;
		&lt;li&gt;&lt;i&gt;log.c&lt;/i&gt; is now a wrapper around &lt;i&gt;g_log_&amp;#8230;&lt;/i&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;As you see this is ripping out the basic data-structures and replaces them by a glib look-alike.&lt;/p&gt;


	&lt;p&gt;This isn&amp;#8217;t just a drop-in replacement as the structures use other field-names and sometimes have a slightly different meaning.&lt;/p&gt;


	&lt;p&gt;One example is GString vs. buffer:&lt;/p&gt;


&lt;pre&gt;
buffer {
  char *ptr;
  size_t used;
  size_t size;
};

GString {
  char *str;
  size_t len;
  size_t allocated_len;
};
&lt;/pre&gt;

	&lt;p&gt;While &lt;i&gt;str&lt;/i&gt; and &lt;i&gt;ptr&lt;/i&gt;, and &lt;i&gt;allocated_len&lt;/i&gt; and &lt;i&gt;size&lt;/i&gt; match, &lt;i&gt;used&lt;/i&gt; and &lt;i&gt;len&lt;/i&gt; differ by one byte (&lt;i&gt;used&lt;/i&gt; includes the &lt;i&gt;&lt;span class="caps"&gt;NUL&lt;/span&gt;&lt;/i&gt;-byte, &lt;i&gt;len&lt;/i&gt; doesn&amp;#8217;t).&lt;/p&gt;


	&lt;p&gt;One side-effect of this boring work is seeing the code-size shrinking, piece by piece.&lt;/p&gt;


	&lt;p&gt;Seeing old, sometimes dirty code vanish is another nice side-effect. Like the &lt;i&gt;log_error_write()&lt;/i&gt; call &amp;#8230; man &amp;#8230;&lt;/p&gt;</description>
      <pubDate>Tue, 19 Feb 2008 17:14:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:8e6b7444-2eb1-4564-9806-febdf9ce196d</guid>
      <author>jan</author>
      <link>http://blog.lighttpd.net/articles/2008/02/19/project-glib-it-compiles-mostly</link>
      <category>lighttpd</category>
      <trackback:ping>http://blog.lighttpd.net/articles/trackback/4908</trackback:ping>
    </item>
    <item>
      <title>"Project Glib: it compiles ... mostly" by Henrik Holst</title>
      <description>That is true, but only if your one malloc() was for an insane amount of pages. Of course one can turn of the overcommit quite easily, but I think that you would be caught by bugs in quite a few applications then.

I think that the reason behind glib2's use of abort() is that if you receive NULL from malloc() you have a 99% chance that the heap is corrupted and you better abort your process. The situation that Tom described where lighty would be terminated when handling to many simultaneous connections is one situation where NULL would practically never ever be returned by malloc() due to the overcommit in linux.</description>
      <pubDate>Thu, 13 Mar 2008 16:51:36 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:2de099ab-d0d8-4b24-9878-c27f3daada0f</guid>
      <link>http://blog.lighttpd.net/articles/2008/02/19/project-glib-it-compiles-mostly#comment-5384</link>
    </item>
    <item>
      <title>"Project Glib: it compiles ... mostly" by Timo Savola</title>
      <description>Henrik: Actually memory allocation on Linux can fail if you try to allocate too much over the top (see linux/Documentation/vm/overcommit-accounting).
</description>
      <pubDate>Thu, 13 Mar 2008 15:37:59 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:9bc7a6a7-f675-48b7-88ab-13499c57e7e0</guid>
      <link>http://blog.lighttpd.net/articles/2008/02/19/project-glib-it-compiles-mostly#comment-5383</link>
    </item>
    <item>
      <title>"Project Glib: it compiles ... mostly" by Henrik Holst</title>
      <description>Tom: Memory allocation in Linux does not return NULL on out-of-memory, libc will only return NULL if it detected a corrupted heap.

Linux will only perform the allocation itself when you actually use the memory so there is no way to tell you on malloc() time that you are out of memory, so calling abort() on failed allocation is the only sane way to do it so glib2 performs correct. </description>
      <pubDate>Thu, 13 Mar 2008 09:52:58 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:840ca716-4009-47b2-a66f-a704320f07aa</guid>
      <link>http://blog.lighttpd.net/articles/2008/02/19/project-glib-it-compiles-mostly#comment-5381</link>
    </item>
    <item>
      <title>"Project Glib: it compiles ... mostly" by Jason</title>
      <description>jan,

Can you provide some insight on why the move the glib?v

Thanks.</description>
      <pubDate>Wed, 12 Mar 2008 15:49:05 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:60c2b262-8c03-46d1-a1ef-e440065bab9f</guid>
      <link>http://blog.lighttpd.net/articles/2008/02/19/project-glib-it-compiles-mostly#comment-5376</link>
    </item>
    <item>
      <title>"Project Glib: it compiles ... mostly" by Marco</title>
      <description>Yeah, that's great work. Keep on. Never had any problems with lightty and it's serving plenty of gigabytes a day for months.</description>
      <pubDate>Tue, 11 Mar 2008 23:49:15 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:1b888024-5239-4dcf-8b23-fbd9bb60fb18</guid>
      <link>http://blog.lighttpd.net/articles/2008/02/19/project-glib-it-compiles-mostly#comment-5372</link>
    </item>
    <item>
      <title>"Project Glib: it compiles ... mostly" by Reed A. Cartwright</title>
      <description>re: &lt;a href="mailto:tom@dbservice.com" rel="nofollow"&gt;tom@dbservice.com&lt;/a&gt;

Well there is a g_try_malloc, that will return NULL if the memory allocation fails and does not abort.</description>
      <pubDate>Fri, 29 Feb 2008 07:09:27 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:36f00201-bd97-46c2-a23f-8816a8eef8d2</guid>
      <link>http://blog.lighttpd.net/articles/2008/02/19/project-glib-it-compiles-mostly#comment-5118</link>
    </item>
    <item>
      <title>"Project Glib: it compiles ... mostly" by Anders</title>
      <description>That's great, I've been using GLib myself in my own app and it makes C a lot nicer to work with!</description>
      <pubDate>Thu, 28 Feb 2008 15:10:59 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:14542af4-5637-470b-9851-6400c5eabffe</guid>
      <link>http://blog.lighttpd.net/articles/2008/02/19/project-glib-it-compiles-mostly#comment-5096</link>
    </item>
    <item>
      <title>"Project Glib: it compiles ... mostly" by lu_zero</title>
      <description>Having too many clients to be serviced shouldn't cause the whole server to close, but just to reject newer connections...</description>
      <pubDate>Thu, 28 Feb 2008 08:32:42 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:75960393-ea9c-4629-a2d2-a7746a64ce52</guid>
      <link>http://blog.lighttpd.net/articles/2008/02/19/project-glib-it-compiles-mostly#comment-5089</link>
    </item>
    <item>
      <title>"Project Glib: it compiles ... mostly" by jasper</title>
      <description>tom: Why o' why do you have a "24/7" web server that has so little memory that memory allocation fails? You would have to both be completely out of physical RAM, and also have no swap left.</description>
      <pubDate>Wed, 27 Feb 2008 23:56:36 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:d709907d-dca6-4fe6-8f01-21694b0b63d1</guid>
      <link>http://blog.lighttpd.net/articles/2008/02/19/project-glib-it-compiles-mostly#comment-5078</link>
    </item>
    <item>
      <title>"Project Glib: it compiles ... mostly" by tom@dbservice.com</title>
      <description>Why o' why glib? Don't you know that glib abort()s when memory allocation fails? That's really bad for a webserver that's supposed to run 24/7</description>
      <pubDate>Tue, 26 Feb 2008 10:44:57 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:329055ff-504d-4e4f-b740-24d1b6ebf06d</guid>
      <link>http://blog.lighttpd.net/articles/2008/02/19/project-glib-it-compiles-mostly#comment-5039</link>
    </item>
    <item>
      <title>"Project Glib: it compiles ... mostly" by lu_zero</title>
      <description>I'm currently using part of your design and currently part of your nice syntax parser in feng (a small rtsp streaming server), since it is already using glib I was about to start converting some stuff the way you already did ^^. Thank you 

</description>
      <pubDate>Sat, 23 Feb 2008 12:07:02 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:a814f3d2-0ef4-41e0-aa03-738b6012cb5a</guid>
      <link>http://blog.lighttpd.net/articles/2008/02/19/project-glib-it-compiles-mostly#comment-4949</link>
    </item>
    <item>
      <title>"Project Glib: it compiles ... mostly" by Jan (the other one)</title>
      <description>Yeah and camelcase instead looks nicer than lower case :) In a few years we have IDEs, which provice AI refactoring. Just describe your wishes and the IDE does the boring work for you :) Have you done some performance benchmarks yet? I'm excited to see the results :) Great work!</description>
      <pubDate>Wed, 20 Feb 2008 17:56:43 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:f18827e8-4f0e-4bc6-a593-bb618ae71036</guid>
      <link>http://blog.lighttpd.net/articles/2008/02/19/project-glib-it-compiles-mostly#comment-4914</link>
    </item>
  </channel>
</rss>
