target-independent libcurl headers

综合技术 2017-06-15

We write libcurl to be very portable. It can be built and run on virtually every operating system with an CPU architecture that is at least 32 bit, from some of the most legacy Unixes from the early 90s to the most recent updates to all the popular systems, including the widespread mobile platforms.

Type sizes on different archs

In the early 2000s we added support to libcurl for “large files” (back in the days when that support wasn’t always present in your operating systems) and large variable types (beyond 32 bits) to work for applications and libcurl alike, and to work the same way for libcurl-using applications independently on which platform you’d compile the code on.

We started out using compiler/system defines to figure out for example the size of the native “off_t” type to know if it was 32 bit or 64 bit. That turned out to be problematic as users accidentally ended up in situations where the library considered a type to be one size and the application considered it to be another, leading to unexpected behaviors at best or downright crashes and misery.

Determine at lib build-time

The fix to that run-time size-of-variables confusion was to generate a fixed “outcome” at build-time that would then be used by both the library and applications so that they could never again disagree on this. The obvious downside here was that we had to generate this target specific information into public headers for the library (known as curl/curlbuild.h). We didn’t like doing it this way, but this approach was a better situation than before as it caused less headaches for users.

Now we instead created problems for system packagers who wanted to provide a set of curl headers and allow users to build for example either a 32 bit build or a 64 bit build of their application – so they had to generate two sets of curl headers. Or having the headers on a shared file system to be used by many different systems. Inconvenient. But as this solution didn’t hurt too many people, was a cumbersome problem to fix and yet possible to work around, it remained in the curl project since August 7, 2008 ( commit 14240e9e109fe6af1 ).

Determine at app build-time

In March 2017 ( commit 9506d01ee5 ) we introduced a new take on this problem. A new header that checks systems defines and determines all the necessary information at the time the application is compiled instead of at the time libcurl is compiled. We call it curl/system.h.

The goal was to replace the generated curlbuild.h header, but since it would cause serious problems if this new header would get any different results (like variable type sizes) than the old header, it was a risky move. We needed extra seat-belts for this.

We therefor added the new header next to the old header in parallel, and introduced a test case in the curl test suite that verifies the output from the two systems and make sure that they agree, and had them present in the curl source tree, coexisting. The curl/system.h file of course without being used for anything real, but tested by everyone who runs the test suite – to make sure it isn’t awful.

We think the new header file has now proven itself worthy. We have not gotten any recent reports on problems with test 1541. It is time to cut out the old header system and launch the new!

Starting in release curl 7.55.0, due to be released on August 9, 2017, the header files will finally again be truly platform agnostic. It took us nine years but we finally did it! The bulk of the change is made in this commit .

Just another detail in the machinery.

danielhaxxse

责编内容by:danielhaxxse (源链)。感谢您的支持!

您可能感兴趣的

libcurl 简单事例 curl 是利用 URL 语法在命令行方式下工作的开源文件传输工具。它被广泛应用在 Unix、多种 Linux 发行版中,并且有 DOS 和 Win32、Win64 下的移植版本。 libcurl 主要功能就是用不同的协议连接和沟通不同的服务器,也就是相当封装了的 sock。 在基于L...
The curl bus factor bus factor: the minimum number of team members that have to suddenly disappear from a project before the project stalls due to lack of knowledgeable ...
issue #79: OpenSnitch, VXLAN, GCC, 4.11 kernel, RE... Welcome to cron.weekly issue #79 for Sunday, May 7th, 2017. There’s a new Linux kernel out, some heavy networking guides on VXLAN and BGP &am...
CLion之C++框架篇-优化开源框架,引入curl,实现get方式获取资源(四)... cmake_minimum_required(VERSION 3.11.2)project(work)message(STATUS "start load boost ========================================") # BOOST ...
RabbitMQ – Get messages from a queue using t... I am trying to get a few messages from a queue using the HTTP API of rabbitmq. I am following the documentation in here I have no vhost confi...