语义版本控制:小改动还是大改动?(第二部分) [英] Semantic versioning: minor or major change? (second part)

查看:60
本文介绍了语义版本控制:小改动还是大改动?(第二部分)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前段时间我问过是否将字段添加到struct 需要根据语义版本控制对版本字符串进行主要或次要更改.少数参与者倾向于提出重大改变.

Some time ago I had asked whether adding fields to a struct of a shared library would require a major or a minor change in the version string according to semantic versioning. The few participants where inclined to suggest a major change.

几个月过去了,我还没有向我的 struct 添加任何字段.但现在可能是做这件事的合适时机.

Months have passed and I have not added any fields to my struct yet. But now it might be the right time for doing it.

然而与此同时,我也一直在思考这会如何破坏用我的库的以前版本编译的程序的二进制兼容性,老实说,就我所想的那样,我还没有发现任何可能的二进制兼容性情况休息.

However in the meanwhile I have also been thinking about how this could break binary compatibility with programs compiled with previous versions of my library, and honestly, for as much as I have thought, I have not found any possible scenario where binary compatibility breaks.

新的字段被添加到结构的末尾,使用我的库的人通常不会自己分配这个struct,而是接收一个指向它的指针作为回调的参数功能.这就是我的库对它所做的一切,用户永远不需要使用这个 struct 来调用库.

The new fields are added to the end of the structure, and who uses my library normally does not allocate this struct him-/herself, but receives a pointer to it as an argument of a callback function. This is all my library does with it, the user never needs to call the library back using this struct.

当旧程序使用新版本的库运行时,可能的情况有两种:

The possible scenarios are two when an old program runs with the new version of the library:

  1. 在正常情况下(即旧程序收到一个指向这个struct的指针并读取它需要的字段),我的库将从现在开始发送一个指向更大的struct,但老程序不知道,也不关心.
  2. 如果旧程序出于某种未知原因分配了这个 struct ,它仍然会分配一个较小的结构(这是程序在编译时确实知道的),但是我的库不知道它也不关心它,因为它永远不需要从用户那里接收这个 struct,它只将它作为一个指针发送.
  1. Under normal circumstances (i.e., the old program receives a pointer to this struct and reads the fields it needs), my library will send from now on a pointer to a bigger struct, but the old program does not know it and doesn't care.
  2. If the old program, for some unknown reasons, allocates this struct for its own sake, it will still allocate a smaller structure (that's what the program knew when it was compiled indeed), but my library doesn't know it and doesn't care, since it never needs to receive this struct back from the user, it only sends it as a pointer.

在之前的讨论中,有人也从Linux 程序库 HOWTO — §3.6.不兼容的库:

In the previous discussion someone had also posted this quotation from Linux Program Library HOWTO — §3.6. Incompatible Libraries:

当库的新版本与旧版本二进制不兼容时,soname 需要更改.在 C 中,库不再与二进制兼容有四个基本原因:

When a new version of a library is binary-incompatible with the old one the soname needs to change. In C, there are four basic reasons that a library would cease to be binary compatible:

  1. 函数的行为发生变化,使其不再符合其原始规范,

  1. The behavior of a function changes so that it no longer meets its original specification,

导出的数据项发生变化(例外:在结构的末尾添加可选项是可以的,只要这些结构仅在库内分配).

Exported data items change (exception: adding optional items to the ends of structures is okay, as long as those structures are only allocated within the library).

删除了导出的函数.

导出函数的接口发生变化.

The interface of an exported function changes.

案例号.2 似乎在谈论不透明的结构.我的 struct 不是不透明的,但是情况很相似.但真正的重点是,正如我所说的,我还没有找到一种在此更改后会破坏二进制兼容性的场景.

The case no. 2 seems to talk about opaque structures. My struct is not opaque, but the situation is very similar. But the real point is that, as I said, I have not been able to find one single scenario where binary compatibility will be broken after this change.

所以问题还是一样:这是次要的还是主要的版本变化?

So the question remains the same: Is this a a minor or a major version change?

推荐答案

我能看到的唯一问题是,如果用户做了一些依赖于你的结构大小的事情,然后在没有代码的情况下重新编译程序时会出现意想不到的结果正在更新.最有可能受到影响的是非二进制发行版,如 Gentoo 或 Yocto 构建链.

The only issue I can see is if the user does something that relies on the size of your structure and then unexpected results occur when the program is recompiled without the code being updated. Most likely to be affected would be a non-binary distribution like Gentoo or maybe a Yocto build chain.

例如,如果用户将这些结构的数组的内容写入一个文件,该文件希望在程序下次运行时读取.如果程序针对库的新版本重新编译,如果它不知道版本之间的变化,就会出现问题.如果存在不使用 sizeof 等不良做法,则可能会出现另一个问题.

For example, if the user were to write the contents of an array of these structures to a file that it expects to read next time the program runs. If the program gets recompiled against the new version of the library, there will be issues if it is not aware of the change between versions. Another issue may occur if bad practices like not using sizeof are present.

这篇关于语义版本控制:小改动还是大改动?(第二部分)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆