1.2.2版本策略
为了控制APR接口的稳定,APR制定了严格的版本变化策略。
1.2.2.1PATCH版本策略
在前表中我们看到,PATCH的变化并不影响版本的源代码和二进制级别的兼容性,包括向前和向后兼容,因此,我们很容易看出,PATCH版本变化通常意味着对版本的修修补补,即BUG的修复。这些工作通常被局限于函数内部的修改,或者是API函数内部,或者是APR内部static函数的变化。任何对API的增加、修改、删除都是不允许的。
1.2.2.1次版本号策略
任何新函数,新变量以及新常量的引入以及任何现有函数的废除都将可能导致次版本号的变化:
1)、新函数的引入
An application coded against an older minor release will still have all of its functions available with their original signatures. Once an application begins to use a new function, however, they will be unable to work against older minor versions.
It is tempting to say that introducing new functions might create incompatibility across minor releases. If an application takes advantage of an API that was introduced in version 2.3 of a library, then it is not going to work against version 2.2. However, we have stated that an any application built against version 2.2 will continue to work for all 2.x releases. Thus, an application that states "requires 2.3 or later" is perfectly acceptable -- the user or administrator simply upgrades the installed library to 2.3. This is a safe operation and will not break any other application that was using the 2.2 library.
In other words, yes an incompatibility arises by mandating that a specific version needs to be installed. But in practice, this will not be a problem since upgrading to newer versions is always safe.
2)、新常量的引入
Similar to functions, all of the original (old) constants will be available to an application. An application can then choose to use new constants to pick up new semantics and features.
3)、函数替换
This gets a bit trickier. The original function must remain available at the link-level so that an application compiled against a minor version will continue to work with later minor versions. Further, if an application is designed to work with an earlier minor version, then we don't want to suddenly change the requirements for that application. This means that the headers cannot silently map an old function into a newer function, as that would turn an application, say, based on 1.2 into an application requiring the 1.4 or later release.
This means that functions cannot truly be replaced. The new, alternate function can be made available in the header and applications can choose to use it (and become dependent upon the minor release where the function appears).
It is possible to design a set of headers where a macro will always refer to the "latest" function available. Of course, if an application chooses to use this macro, then the resulting compiled-binary will be dependent upon whatever version it was compiled against. This strategy adds the new functionality for applications, yet retains the necessary source and binary compatibility for applications designed or built against previous minor releases.
Constants (enumerated values and preprocessor macros) are not allowed to change since an older application will still be using them. Similarly, function signatures at the link-level may not change, so that support for older, compiled applications is maintained.
4)、函数作废
随着APR的升级,APR中的一些API可能将作废,不再使用,但是这些API并不能从APR库中移除。因为一旦API被移除,向后兼容性将被破坏。因此我们能够做的仅仅是宣布其作废。
If you deprecate a function in APR, please mark it as such in the function documentation, using the doxygen "\deprecated" tag. Deprecated functions can only be removed in major releases.
A deprecated function should remain available through the original header. The function prototype should remain in the same header, or if moved to a "deprecated functions" header, then the alternate header should be included by the original header. This requirement is to ensure that source compatibility is retained.
Finally, if you are deprecating a function so that you can change the name of the function, please use the method described above under "Replacing functions", so that projects which use APR can retain binary compatibility.
Note that all deprecated functions will be removed at the next major version bump.
1.2.2.3主版本号策略
下面的任何一种变化都将可能导致主版本号的变化:
1)、常量的移除或者更改
2)、函数移除或者作为
3)、fold together macro-ized function replacements
1.2.3版本检查
由于APR严格的版本控制策略,使得应用程序在使用APR库之前必须能够检测使用的APR库的版本号。APR允许在编译以及使用APR的时候检测它的版本号。
1.2.3.1 编译时版本检查
Libraries should make their version number available as compile-time constants. For example:
#define FOO_MAJOR_VERSION 1
#define FOO_MINOR_VERSION 4
#define FOO_PATCH_VERSION 0
The above symbols are the minimum required for this specification.
An application that desires, at compile-time, to decide on whether and how to use a particular library feature needs to only check two values: the major and the minor version. Since, by definition, there are no API changes across patch versions, that symbol can be safely ignored. Note that any kind of a check for a minimum version will then pin that application to at least that version. The application's installation mechanism should then ensure that that minimal version has been installed (for example, using RPM dependency checks).
If the feature changes across minor versions are source compatible, but are (say) simply different choices of values to pass into the library, then an application can support a wider variety of installed libraries if it avoids compile-time checks.
1.2.3.2 执行时版本检查
A library meeting this specification should support a way for an application to determine the library's version at run-time. This will usually be emboded as a simple function which returns the MAJOR, MINOR, and PATCH triplet in some form.
Run-time checks are preferable in all cases. This type of check enables an application to run against a wider variety of minor releases of a library (the application is "less coupled" to a particular library release). Of course, if an application requires a function that was introduced in a later, minor release, then the application will require that, at least, that release is installed on the target system.
Run-time checks are particurly important if the application is trying to determine if the library has a particular bug that may need to be worked around, but has been fixed in a later release. If the bug is fixed in a patch release, then the only avenue for an application is to perform a runtime check. This is because an application cannot require a specific patch level of the library to be installed -- those libraries are perfectly forward and backwards compatible, and the administrator is free to choose any patch release, knowing that all applications will continue to function properly. If the bug was fixed in a minor release, then it is possible to use a compile-time check, but that would create a tighter coupling to the library.
1.2.3.3 版本API
与前面的版本规则定义一致,APR中定义了数据结构apr_version_t来描述版本规则:
typedef struct {
int major; /**< major number */
int minor; /**< minor number */
int patch; /**< patch number */
int is_dev; /**< is development (1 or 0) */
} apr_version_t;
major是当前APR版本的主版本号,minor则是次版本号,patch对应的则是APR的补丁号。es_dev则描述了当前APR库的状态:开发版还是发行版,分别对应1和0。
一旦定义了apr_version_t结构,APR就将使用它作为基本的版本控制单位。APR中提供了函数apr_version和apr_version_string分别设置和返回APR的版本。
APR_DECLARE(void) apr_version(apr_version_t *pvsn)
{
pvsn->major = APR_MAJOR_VERSION;
pvsn->minor = APR_MINOR_VERSION;
pvsn->patch = APR_PATCH_VERSION;
#ifdef APR_IS_DEV_VERSION
pvsn->is_dev = 1;
#else
pvsn->is_dev = 0;
#endif
}
apr_version函数仅仅就是设置apr_version_t结构中的各个成员。对于每一个APR版本,APR都会将当前的版本号分别用三个常量定义在version.h中,比如,如果版本号是2.2.0,则常量定义应该如下:
#define APR_MAJOR_VERSION 2
#define APR_MINOR_VERSION 2
#define APR_PATCH_VERSION 0
apr_version_string函数仅仅是返回APR_VERSION_STRING宏,该宏定义为:
#define APR_VERSION_STRING \
APR_STRINGIFY(APR_MAJOR_VERSION) "." \
APR_STRINGIFY(APR_MINOR_VERSION) "." \
APR_STRINGIFY(APR_PATCH_VERSION) \
APR_IS_DEV_STRING
APR_STRINGIFY用于将给定的数值转换为字符串,因此APR_VERSION_STRING宏就是无非将APR_MAJOR_VERSION,APR_MINOR_VERSION,APR_PATCH_VERSION分别转换为字符串,再用"."连接起来,最后的形式应该为“2.2.0”。
尽管一般情况下,APR的版本号是“x.x.x”的格式,不过在Window的资源文件.rc中通常是“x,x,x”格式,因此APR中也提供了APR_VERSION_STRING_CSV来提供这种格式的版本号:
#define APR_VERSION_STRING_CSV APR_MAJOR_VERSION ##, \
##APR_MINOR_VERSION ##, \
##APR_PATCH_VERSION
##宏用于将变量与特定字符进行连接形成新的字符串。在后面的部分,我们会不断看到它的用法。
在一些情况下,应用程序需要使用的APR版本达到一定的版本号,为此,APR中提供了APR_VERSION_AT_LEAST宏用以检测给定的APR库是否达到给定的版本要求:
#define APR_VERSION_AT_LEAST(major,minor,patch) \
(((major) < APR_MAJOR_VERSION) \
|| ((major) == APR_MAJOR_VERSION && (minor) < APR_MINOR_VERSION) \
|| ((major) == APR_MAJOR_VERSION && (minor) == APR_MINOR_VERSION && (patch) <= APR_PATCH_VERSION))
如果我们希望当前使用的APR库的版本不的低于”1.2.0”,那么我们就使用使用APR_VERSION_AT_LEAST(1,2,0)对当前的APR库版本进行检查。