<story><title>Curl is C</title><url>https://daniel.haxx.se/blog/2017/03/27/curl-is-c/</url></story><parent_chain><item><author>KuiN</author><text>&amp;gt; generate C code.&lt;p&gt;Programmatically generating C code not without problems. How can you prove that the C you&amp;#x27;re generating is free from problems solved by the safer language? Cloudbleed came from computer generated C code: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;blog.cloudflare.com&amp;#x2F;incident-report-on-memory-leak-caused-by-cloudflare-parser-bug&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;blog.cloudflare.com&amp;#x2F;incident-report-on-memory-leak-c...&lt;/a&gt;.</text></item><item><author>rwmj</author><text>While this doesn&amp;#x27;t so much apply to libcurl (but see below), there is a third alternative to &amp;quot;write everything in C&amp;quot; or &amp;quot;write everything in &amp;lt;some other safer language&amp;gt;&amp;quot;.  That is: &lt;i&gt;use a safer language to generate C code&lt;/i&gt;.&lt;p&gt;End users, even those compiling from source, will still only need a C compiler.  Only developers need to install the safer language (even Curl developers must install valgrind to run the full tests).&lt;p&gt;Where can you use generated code?&lt;p&gt;- For non-C language bindings (this could apply to the Curl project, but libcurl is a bit unusual in that it doesn&amp;#x27;t include other bindings, they are supplied by third parties).&lt;p&gt;- To describe the API and generate header files, function prototypes, and wrappers.&lt;p&gt;- To enforce type checking on API parameters (eg. all the CURL_EASY_... options could be described in the generator and then that can be turned into some kind of type checking code).&lt;p&gt;- Any other time you want a single source of truth in your codebase.&lt;p&gt;We use a generator (written in OCaml, generating mostly C) successfully in two projects: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;libguestfs&amp;#x2F;libguestfs&amp;#x2F;tree&amp;#x2F;master&amp;#x2F;generator&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;libguestfs&amp;#x2F;libguestfs&amp;#x2F;tree&amp;#x2F;master&amp;#x2F;generat...&lt;/a&gt; &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;libguestfs&amp;#x2F;hivex&amp;#x2F;tree&amp;#x2F;master&amp;#x2F;generator&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;libguestfs&amp;#x2F;hivex&amp;#x2F;tree&amp;#x2F;master&amp;#x2F;generator&lt;/a&gt;</text></item></parent_chain><comment><author>patrec</author><text>No, it didn&amp;#x27;t.&lt;p&gt;See quote from the author of Ragel in the comments:&lt;p&gt;&lt;i&gt;There is no mistake in ragel generated code. What happened was that you turned on EOF actions without appropriate testing. The original author most certainly never intended for that. He&amp;#x2F;She would have known it would require extensive testing. Legacy code needs to be tested heavily after changes. It should have been left alone.&lt;p&gt;PLEASE PLEASE PLEASE take some time to ensure the media doesn&amp;#x27;t print things like this. It&amp;#x27;s going to destroy me. You guys have most certainly benefitted from my hard work over the years. Please don&amp;#x27;t kill my reputation!&lt;/i&gt;</text></comment>
<story><title>Curl is C</title><url>https://daniel.haxx.se/blog/2017/03/27/curl-is-c/</url></story><parent_chain><item><author>KuiN</author><text>&amp;gt; generate C code.&lt;p&gt;Programmatically generating C code not without problems. How can you prove that the C you&amp;#x27;re generating is free from problems solved by the safer language? Cloudbleed came from computer generated C code: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;blog.cloudflare.com&amp;#x2F;incident-report-on-memory-leak-caused-by-cloudflare-parser-bug&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;blog.cloudflare.com&amp;#x2F;incident-report-on-memory-leak-c...&lt;/a&gt;.</text></item><item><author>rwmj</author><text>While this doesn&amp;#x27;t so much apply to libcurl (but see below), there is a third alternative to &amp;quot;write everything in C&amp;quot; or &amp;quot;write everything in &amp;lt;some other safer language&amp;gt;&amp;quot;.  That is: &lt;i&gt;use a safer language to generate C code&lt;/i&gt;.&lt;p&gt;End users, even those compiling from source, will still only need a C compiler.  Only developers need to install the safer language (even Curl developers must install valgrind to run the full tests).&lt;p&gt;Where can you use generated code?&lt;p&gt;- For non-C language bindings (this could apply to the Curl project, but libcurl is a bit unusual in that it doesn&amp;#x27;t include other bindings, they are supplied by third parties).&lt;p&gt;- To describe the API and generate header files, function prototypes, and wrappers.&lt;p&gt;- To enforce type checking on API parameters (eg. all the CURL_EASY_... options could be described in the generator and then that can be turned into some kind of type checking code).&lt;p&gt;- Any other time you want a single source of truth in your codebase.&lt;p&gt;We use a generator (written in OCaml, generating mostly C) successfully in two projects: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;libguestfs&amp;#x2F;libguestfs&amp;#x2F;tree&amp;#x2F;master&amp;#x2F;generator&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;libguestfs&amp;#x2F;libguestfs&amp;#x2F;tree&amp;#x2F;master&amp;#x2F;generat...&lt;/a&gt; &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;libguestfs&amp;#x2F;hivex&amp;#x2F;tree&amp;#x2F;master&amp;#x2F;generator&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;libguestfs&amp;#x2F;hivex&amp;#x2F;tree&amp;#x2F;master&amp;#x2F;generator&lt;/a&gt;</text></item></parent_chain><comment><author>patrec</author><text>More generally, I don&amp;#x27;t understand this argument. Assuming you can trust the C compiler (big if, but at least some validated (large subset of) C compilers exist; see CompCert), I don&amp;#x27;t get why this would be worse then generating machine code in a safe language.</text></comment>