Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ plugin_sources = files(
)

libs = []
api_args = ['-DBSSHARED_API_BUILDING']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be behind a check for default_library != 'static'? Though I guess even that wouldn't cover all cases.
As far as I can see, the relevant cases are:

  • We're building a libbestsource.dll (vapoursynth plugin or not): We want to export the exception types.
  • We're building another executable or library that will dynamically link bestsource: We want to import the exception types.

The above two cases are covered by this code. However:

  • We're building a dynamic library that statically links bestsource: Here it depends on how that library calls bestsource. If it catches all of its exceptions and rethrows none of them, then the exception types don't need to be exported (though it probably doesn't hurt to export them either). If it doesn't catch all of its exception or rethrows some of them, the exception types do need to be reexported. But either way, only the exception types should be reexported, and none of bestsource's other API functions.

So, I think this current logic works, but only if BSSHARED_API_EXPORT is only applied to the exceptions and not to any of bestsource's other API functions. (Which I guess results in this comment having net zero information, but I wanted to bring this up for posterity and/or see if I missed something)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I only export the exceptions. In case it's important, I've gone ahead and added a gate against visibility in a static build.

p2p_args = []

if host_machine.cpu_family().startswith('x86')
Expand Down Expand Up @@ -71,6 +72,7 @@ endif
libbestsource = library('libbestsource', api_sources,
dependencies: deps,
install: true,
cpp_args: api_args,
link_args: link_args,
link_with: libs,
name_prefix: '',
Expand Down
24 changes: 22 additions & 2 deletions src/bsshared.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,33 @@
#include <functional>
#include <filesystem>

#if (defined(_WIN32) || defined(__CYGWIN__))
# define BSSHARED_API_EXPORT __declspec(dllexport)
# define BSSHARED_API_IMPORT __declspec(dllimport)
#elif defined(__OS2__)
# define BSSHARED_API_EXPORT __declspec(dllexport)
# define BSSHARED_API_IMPORT
#elif __GNUC__ >= 4
# define BSSHARED_API_EXPORT __attribute__((visibility("default")))
# define BSSHARED_API_IMPORT __attribute__((visibility("default")))
#else
# define BSSHARED_API_EXPORT
# define BSSHARED_API_IMPORT
#endif

#ifdef BSSHARED_API_BUILDING
# define BSSHARED_API BSSHARED_API_EXPORT
#else
# define BSSHARED_API BSSHARED_API_IMPORT
#endif

constexpr size_t HashSize = 8;

class BestSourceException : public std::runtime_error {
class BSSHARED_API BestSourceException : public std::runtime_error {
using std::runtime_error::runtime_error;
};

class BestSourceHWDecoderException : public BestSourceException {
class BSSHARED_API BestSourceHWDecoderException : public BestSourceException {
using BestSourceException::BestSourceException;
};

Expand Down
Loading