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.




Managing Autonomous Data Warehouse Using oci-curl Every now and then we get questions about how to create and manage an Autonomous Data Warehouse (ADW) instance using REST APIs. ADW is an Oracle Cloud...
PHP curl problem – error if you use a variab... I'm having a very strange curl issue within php. When I pass in a URL as a variable, the request will return a 400 error saying "Bad Request - missing...
CLion之C++框架篇-优化开源框架,引入curl,实现get方式获取资源(四)... cmake_minimum_required(VERSION 3.11.2)project(work)message(STATUS "start load boost ========================================") # BOOST ...
一文解剖ubuntu,curl,openssl更新根证书的细节... 在 《apt,curl,openssl之间的那点事》 和 《yum,curl,nss之间的那点事》 这两篇文章中,介绍了以下几个主题: 在 CentOS、Ubuntu 操作系统中,Curl 分别使用 OpenSSL、NSS 密码学库。 在 CentOS、Ubuntu 操作系统中...
Rust 翻译计划——网络编程 curl 库 (上) 本文目录: 简介 快速通道 翻译--curl库 easy模块 multi模块 1. 简介 虽然这个系列是属于Rust使用库翻译计划的系列之一,但是由于该库官网提供的使用文档几乎等于没有,所以本文实际上是简单翻译一...