Skip to content

Commit 2c3e7c9

Browse files
committed
api: Introduce new scheme for preserving ABI compatibility
This patch partially implements the new scheme for preserving ABI compatibility across minor (yearly) releases. "Major" or "first digit" releases, which only happen once every several years for us, are full ABI+API breaks. Previously, "minor" or "second digit" releases, which are annual, have fully incompatible ABIs, with separate namespaces to enforce it. Here, we are striving to allow our annual/minor releases to no longer break ABI, to make upgrading easier for downstream users. The basics are that once a symbol is introduced, it will forever live in the namespace of that release. Subsequent release years will have their own namespaces, but will either alias or duplicate the symbols. This is enabled by our recent (in the lead-up to 3.1) introduction of a split 2-part namespacing scheme. So 3.2 is the first release that has the potential to perserve compatibility with 3.1 in this way. In this PR, I do so just for libOpenImageIO_Util, as a proof of concept. It works! -- as measured by being able to have our automated ABI checker show 100% back compatibility with 3.1 for the utility library. But let's look this over and decide if we like it (it does involve some hoop jumping and extra care as we develop), and if we do, then in a second (or more) PR, I will bring this sauce to the rest of the main libOpenImageIO library. Signed-off-by: Larry Gritz <[email protected]>
1 parent 1c50410 commit 2c3e7c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+835
-495
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ jobs:
388388
simd: "avx2,f16c"
389389
skip_tests: 1
390390
# abi_check: v3.1.3.0
391-
abi_check: ae5dca7865c9956b43cc04dee00a65ad893e251e
391+
abi_check: 9bfcce725a3806a3f70c7e838d9d98d6d95c917a
392392
setenvs: export OIIO_CMAKE_FLAGS="-DOIIO_BUILD_TOOLS=0 -DOIIO_BUILD_TESTS=0 -DUSE_PYTHON=0"
393393
USE_OPENCV=0 USE_FFMPEG=0 USE_PYTHON=0 USE_FREETYPE=0
394394

src/include/OpenImageIO/argparse.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
#include <OpenImageIO/paramlist.h>
2121
#include <OpenImageIO/strutil.h>
2222

23+
// Define symbols that let client applications determine if newly added
24+
// features are supported.
25+
#define OIIO_ARGPARSE_SUPPORTS_BRIEFUSAGE 1
26+
#define OIIO_ARGPARSE_SUPPORTS_HUMAN_PARAMNAME 1
2327

24-
OIIO_NAMESPACE_BEGIN
2528

29+
OIIO_NAMESPACE_3_1_BEGIN
2630

2731
/////////////////////////////////////////////////////////////////////////////
2832
///
@@ -173,7 +177,7 @@ OIIO_NAMESPACE_BEGIN
173177

174178
class OIIO_UTIL_API ArgParse {
175179
public:
176-
class Arg; // Forward declarion of Arg
180+
class Arg; // Forward declaration of Arg
177181

178182
// ------------------------------------------------------------------
179183
/// @defgroup Setting up an ArgParse
@@ -782,11 +786,4 @@ class OIIO_UTIL_API ArgParse {
782786
void usage() const { print_help(); }
783787
};
784788

785-
786-
787-
// Define symbols that let client applications determine if newly added
788-
// features are supported.
789-
#define OIIO_ARGPARSE_SUPPORTS_BRIEFUSAGE 1
790-
#define OIIO_ARGPARSE_SUPPORTS_HUMAN_PARAMNAME 1
791-
792-
OIIO_NAMESPACE_END
789+
OIIO_NAMESPACE_3_1_END

src/include/OpenImageIO/benchmark.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#endif
2525

2626

27-
OIIO_NAMESPACE_BEGIN
27+
OIIO_NAMESPACE_3_1_BEGIN
2828

2929
/// DoNotOptimize(val) is a helper function for timing benchmarks that fools
3030
/// the compiler into thinking the the location 'val' is used and will not
@@ -310,6 +310,7 @@ class OIIO_UTIL_API Benchmarker {
310310

311311

312312

313+
313314
/// Helper template that runs a function (or functor) n times, using a
314315
/// Timer to benchmark the results, and returning the fastest trial. If
315316
/// 'range' is non-NULL, the range (max-min) of the various time trials
@@ -470,6 +471,24 @@ OIIO_FORCEINLINE void clobber_all_memory() { }
470471

471472
#endif
472473

474+
OIIO_UTIL_API std::ostream& operator<<(std::ostream& out,
475+
const Benchmarker& bench);
473476

477+
OIIO_NAMESPACE_3_1_END
474478

479+
480+
// Compatibility
481+
OIIO_NAMESPACE_BEGIN
482+
#ifndef OIIO_DOXYGEN
483+
using v3_1::Benchmarker;
484+
using v3_1::clobber;
485+
using v3_1::clobber_all_memory;
486+
using v3_1::DoNotOptimize;
487+
using v3_1::time_trial;
488+
using v3_1::timed_thread_wedge;
489+
using v3_1::operator<<;
490+
namespace pvt {
491+
using v3_1::pvt::use_char_ptr;
492+
}
493+
#endif
475494
OIIO_NAMESPACE_END

src/include/OpenImageIO/color.h

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#include <OpenImageIO/typedesc.h>
1313
#include <OpenImageIO/ustring.h>
1414

15+
// Preprocessor symbol to allow conditional compilation depending on
16+
// whether the ColorProcessor class is exposed (it was not prior to OIIO 1.9).
17+
#define OIIO_HAS_COLORPROCESSOR 1
1518

1619
//
1720
// Some general color management information materials to have handy:
@@ -23,7 +26,12 @@
2326
//
2427

2528

26-
OIIO_NAMESPACE_BEGIN
29+
// Preprocessor symbol to allow conditional compilation depending on
30+
// whether the ColorConfig returns ColorProcessor shared pointers or raw.
31+
#define OIIO_COLORCONFIG_USES_SHARED_PTR 1
32+
33+
34+
OIIO_NAMESPACE_3_1_BEGIN
2735

2836
/// The ColorProcessor encapsulates a baked color transformation, suitable for
2937
/// application to raw pixels, or ImageBuf(s). These are generated using
@@ -50,17 +58,9 @@ class OIIO_API ColorProcessor {
5058
}
5159
};
5260

53-
// Preprocessor symbol to allow conditional compilation depending on
54-
// whether the ColorProcessor class is exposed (it was not prior to OIIO 1.9).
55-
#define OIIO_HAS_COLORPROCESSOR 1
56-
57-
5861

59-
typedef std::shared_ptr<ColorProcessor> ColorProcessorHandle;
6062

61-
// Preprocessor symbol to allow conditional compilation depending on
62-
// whether the ColorConfig returns ColorProcessor shared pointers or raw.
63-
#define OIIO_COLORCONFIG_USES_SHARED_PTR 1
63+
using ColorProcessorHandle = std::shared_ptr<ColorProcessor>;
6464

6565

6666

@@ -445,7 +445,18 @@ class OIIO_API ColorConfig {
445445
Impl* getImpl() const { return m_impl.get(); }
446446
};
447447

448+
OIIO_NAMESPACE_3_1_END
449+
448450

451+
// Compatibility
452+
#ifndef OIIO_DOXYGEN
453+
OIIO_NAMESPACE_BEGIN
454+
using v3_1::ColorProcessorHandle;
455+
OIIO_NAMESPACE_END
456+
#endif
457+
458+
459+
OIIO_NAMESPACE_BEGIN
449460

450461
/// Utility -- convert sRGB value to linear transfer function, without
451462
/// any change in color primaries.

src/include/OpenImageIO/deepdata.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
OIIO_NAMESPACE_BEGIN
1414

15-
16-
struct TypeDesc;
1715
class ImageSpec;
1816

1917

src/include/OpenImageIO/errorhandler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <OpenImageIO/strutil.h>
1111

1212

13-
OIIO_NAMESPACE_BEGIN
13+
OIIO_NAMESPACE_3_1_BEGIN
1414

1515
/// ErrorHandler is a simple class that accepts error messages
1616
/// (classified as errors, severe errors, warnings, info, messages, or
@@ -136,4 +136,4 @@ class OIIO_UTIL_API ErrorHandler {
136136
int m_verbosity;
137137
};
138138

139-
OIIO_NAMESPACE_END
139+
OIIO_NAMESPACE_3_1_END

src/include/OpenImageIO/filesystem.h

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,29 @@
4444

4545

4646

47-
OIIO_NAMESPACE_BEGIN
48-
47+
OIIO_NAMESPACE_3_1_BEGIN
4948
#if OIIO_FILESYSTEM_USE_STDIO_FILEBUF
5049
// MingW uses GCC to build, but does not support having a wchar_t* passed as argument
5150
// of ifstream::open or ofstream::open. To properly support UTF-8 encoding on MingW we must
5251
// use the __gnu_cxx::stdio_filebuf GNU extension that can be used with _wfsopen and returned
5352
// into a istream which share the same API as ifsteam. The same reasoning holds for ofstream.
54-
typedef basic_ifstream<char> ifstream;
55-
typedef basic_ofstream<char> ofstream;
53+
using ifstream = basic_ifstream<char>;
54+
using ofstream = basic_ofstream<char>;
5655
#else
57-
typedef std::ifstream ifstream;
58-
typedef std::ofstream ofstream;
56+
using ifstream = std::ifstream;
57+
using ofstream = std::ofstream;
5958
#endif
59+
OIIO_NAMESPACE_3_1_END
60+
61+
// Compatibility
62+
OIIO_NAMESPACE_BEGIN
63+
using ifstream = v3_1::ifstream;
64+
using ofstream = v3_1::ofstream;
65+
OIIO_NAMESPACE_END
66+
67+
68+
69+
OIIO_NAMESPACE_3_1_BEGIN
6070

6171
/// @namespace Filesystem
6272
///
@@ -243,12 +253,12 @@ OIIO_UTIL_API std::string current_path ();
243253

244254
/// Version of std::ifstream.open that can handle UTF-8 paths
245255
///
246-
OIIO_UTIL_API void open (OIIO::ifstream &stream, string_view path,
256+
OIIO_UTIL_API void open (ifstream &stream, string_view path,
247257
std::ios_base::openmode mode = std::ios_base::in);
248258

249259
/// Version of std::ofstream.open that can handle UTF-8 paths
250260
///
251-
OIIO_UTIL_API void open (OIIO::ofstream &stream, string_view path,
261+
OIIO_UTIL_API void open (ofstream &stream, string_view path,
252262
std::ios_base::openmode mode = std::ios_base::out);
253263

254264
/// Version of C open() that can handle UTF-8 paths, returning an integer
@@ -584,4 +594,13 @@ class OIIO_UTIL_API IOMemReader : public IOProxy {
584594

585595
}; // namespace Filesystem
586596

597+
OIIO_NAMESPACE_3_1_END
598+
599+
// Compatibility
600+
#ifndef OIIO_DOXYGEN
601+
OIIO_NAMESPACE_BEGIN
602+
namespace Filesystem {
603+
using namespace OIIO::v3_1::Filesystem;
604+
}; // namespace Filesystem
587605
OIIO_NAMESPACE_END
606+
#endif

src/include/OpenImageIO/filter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <OpenImageIO/string_view.h>
1313

1414

15-
OIIO_NAMESPACE_BEGIN
15+
OIIO_NAMESPACE_3_1_BEGIN
1616

1717
/// Quick structure that describes a filter.
1818
///
@@ -156,4 +156,4 @@ class OIIO_UTIL_API Filter2D {
156156
};
157157

158158

159-
OIIO_NAMESPACE_END
159+
OIIO_NAMESPACE_3_1_END

src/include/OpenImageIO/function_view.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#include <OpenImageIO/platform.h>
4848

4949

50-
OIIO_NAMESPACE_BEGIN
50+
OIIO_NAMESPACE_3_1_BEGIN
5151

5252

5353
/// function_view<R(T...)> is a lightweight non-owning generic callable
@@ -105,4 +105,10 @@ template<typename Ret, typename... Params> class function_view<Ret(Params...)> {
105105
};
106106

107107

108+
OIIO_NAMESPACE_3_1_END
109+
110+
111+
// Compatibility
112+
OIIO_NAMESPACE_BEGIN
113+
using v3_1::function_view;
108114
OIIO_NAMESPACE_END

src/include/OpenImageIO/hash.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <OpenImageIO/span.h>
2828

2929

30-
OIIO_NAMESPACE_BEGIN
30+
OIIO_NAMESPACE_3_1_BEGIN
3131

3232
using std::hash;
3333
using std::unordered_map;
@@ -563,7 +563,7 @@ inline uint128_t Fingerprint128(const Str& s) {
563563
class CSHA1; // opaque forward declaration
564564

565565

566-
/// Class that encapsulates SHA-1 hashing, a crypticographic-strength
566+
/// Class that encapsulates SHA-1 hashing, a cryptographic-strength
567567
/// 160-bit hash function. It's not as fast as our other hashing
568568
/// methods, but has an extremely low chance of having collisions.
569569
class OIIO_API SHA1 {
@@ -616,4 +616,16 @@ class OIIO_API SHA1 {
616616
};
617617

618618

619+
OIIO_NAMESPACE_3_1_END
620+
621+
622+
// Compatibility
623+
OIIO_NAMESPACE_BEGIN
624+
// Replicate the hashing namespaces in v3_1:: inside OIIO::
625+
namespace fasthash { using namespace OIIO::v3_1::fasthash; }
626+
namespace xxhash { using namespace OIIO::v3_1::xxhash; }
627+
namespace bjhash { using namespace OIIO::v3_1::bjhash; }
628+
namespace murmur { using namespace OIIO::v3_1::murmur; }
629+
namespace farmhash { using namespace OIIO::v3_1::farmhash; }
630+
using v3_1::SHA1;
619631
OIIO_NAMESPACE_END

0 commit comments

Comments
 (0)