From cc9d3486b2a30297b0a636f7514101227c9b5343 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Thu, 2 Apr 2020 20:29:00 +0200 Subject: [PATCH] project: Fix Linux support by fixing errors and warnings With this, GCC 8 and above should now be able to compile the project both in obs-studio and as a standalone install. Some features are currently still not fully supported and require extra work, but the majority of things are supported and work out of the box. Exact feature parity can be looked up here on the wiki: https://github.com/Xaymar/obs-StreamFX/wiki/Platform-Feature-Parity Related: #119 #98 #30 --- cmake/module.cpp.in | 6 +- source/common.hpp | 14 +- source/encoders/ffmpeg-encoder.cpp | 19 +-- source/encoders/handlers/debug_handler.hpp | 2 + source/encoders/handlers/handler.hpp | 3 + .../encoders/handlers/nvenc_h264_handler.hpp | 3 + .../encoders/handlers/nvenc_hevc_handler.hpp | 3 + .../encoders/handlers/prores_aw_handler.hpp | 3 + source/ffmpeg/hwapi/base.hpp | 4 + source/ffmpeg/hwapi/d3d11.cpp | 11 +- source/ffmpeg/hwapi/d3d11.hpp | 1 + source/gfx/shader/gfx-shader-param.cpp | 2 +- source/nvidia/cuda/nvidia-cuda-context.cpp | 2 +- source/nvidia/cuda/nvidia-cuda.hpp | 1 + source/obs/gs/gs-effect-parameter.cpp | 10 +- source/obs/gs/gs-effect-pass.cpp | 9 ++ source/obs/gs/gs-effect-technique.cpp | 9 ++ source/obs/gs/gs-effect.cpp | 11 -- source/obs/gs/gs-indexbuffer.cpp | 10 -- source/obs/gs/gs-mipmapper.cpp | 12 -- source/obs/gs/gs-rendertarget.cpp | 11 -- source/obs/gs/gs-texture.cpp | 11 -- source/obs/gs/gs-vertexbuffer.cpp | 10 -- source/obs/obs-tools.cpp | 10 -- source/sources/source-mirror.cpp | 2 - source/utility.hpp | 145 ++---------------- 26 files changed, 91 insertions(+), 233 deletions(-) diff --git a/cmake/module.cpp.in b/cmake/module.cpp.in index 754e011..44bd688 100644 --- a/cmake/module.cpp.in +++ b/cmake/module.cpp.in @@ -8,9 +8,9 @@ #pragma warning(pop) #endif -OBS_DECLARE_MODULE(); -OBS_MODULE_AUTHOR("@PROJECT_AUTHORS@"); -OBS_MODULE_USE_DEFAULT_LOCALE("@PROJECT_NAME@", "en-US"); +OBS_DECLARE_MODULE() +OBS_MODULE_AUTHOR("@PROJECT_AUTHORS@") +OBS_MODULE_USE_DEFAULT_LOCALE("@PROJECT_NAME@", "en-US") MODULE_EXPORT const char* obs_module_name() { diff --git a/source/common.hpp b/source/common.hpp index c1a3325..e6ab835 100644 --- a/source/common.hpp +++ b/source/common.hpp @@ -41,10 +41,10 @@ // Common Plugin includes #include "strings.hpp" +#include "version.hpp" #include "util-profiler.hpp" #include "util-threadpool.hpp" #include "utility.hpp" -#include "version.hpp" // Common OBS includes extern "C" { @@ -53,15 +53,23 @@ extern "C" { #pragma warning(disable : 4201) #endif #include + +#include #include #include #include #include #include -#include + #include -#include + +#include #include +#include +#include +#include + +#include #ifdef _MSC_VER #pragma warning(pop) #endif diff --git a/source/encoders/ffmpeg-encoder.cpp b/source/encoders/ffmpeg-encoder.cpp index d930420..dfb993a 100644 --- a/source/encoders/ffmpeg-encoder.cpp +++ b/source/encoders/ffmpeg-encoder.cpp @@ -20,6 +20,7 @@ // SOFTWARE. #include "ffmpeg-encoder.hpp" +#include "strings.hpp" #include #include "codecs/hevc.hpp" #include "ffmpeg/tools.hpp" @@ -27,13 +28,11 @@ #include "handlers/nvenc_h264_handler.hpp" #include "handlers/nvenc_hevc_handler.hpp" #include "handlers/prores_aw_handler.hpp" +#include "obs/gs/gs-helper.hpp" #include "plugin.hpp" -#include "strings.hpp" #include "utility.hpp" extern "C" { -#include -#include #pragma warning(push) #pragma warning(disable : 4244) #include @@ -41,6 +40,7 @@ extern "C" { #include #include #include +#include #pragma warning(pop) } @@ -782,7 +782,7 @@ ffmpeg_instance::ffmpeg_instance(obs_data_t* settings, obs_encoder_t* encoder, b } #ifdef WIN32 - auto gctx = util::obs_graphics(); + auto gctx = gs::context(); if (gs_get_device_type() == GS_DEVICE_DIRECT3D_11) { _hwapi = std::make_shared<::ffmpeg::hwapi::d3d11>(); } @@ -815,7 +815,7 @@ ffmpeg_instance::ffmpeg_instance(obs_data_t* settings, obs_encoder_t* encoder, b update(settings); // Initialize Encoder - auto gctx = util::obs_graphics(); + auto gctx = gs::context(); int res = avcodec_open2(_context, _codec, NULL); if (res < 0) { std::stringstream sstr; @@ -827,7 +827,7 @@ ffmpeg_instance::ffmpeg_instance(obs_data_t* settings, obs_encoder_t* encoder, b ffmpeg_instance::~ffmpeg_instance() { - auto gctx = util::obs_graphics(); + auto gctx = gs::context(); if (_context) { // Flush encoders that require it. if ((_codec->capabilities & AV_CODEC_CAP_DELAY) != 0) { @@ -938,7 +938,8 @@ bool ffmpeg_instance::update(obs_data_t* settings) if (_handler) { LOG_INFO("[%s] Initializing...", _codec->name); LOG_INFO("[%s] FFmpeg:", _codec->name); - LOG_INFO("[%s] Custom Settings: %s", _codec->name, obs_data_get_string(settings, KEY_FFMPEG_CUSTOMSETTINGS)); + LOG_INFO("[%s] Custom Settings: %s", _codec->name, + obs_data_get_string(settings, KEY_FFMPEG_CUSTOMSETTINGS)); LOG_INFO("[%s] Standard Compliance: %s", _codec->name, ::ffmpeg::tools::get_std_compliance_name(_context->strict_std_compliance)); LOG_INFO("[%s] Threading: %s (with %i threads)", _codec->name, @@ -1115,7 +1116,7 @@ int ffmpeg_instance::receive_packet(bool* received_packet, struct encoder_packet av_packet_unref(&_current_packet); { - auto gctx = util::obs_graphics(); + auto gctx = gs::context(); res = avcodec_receive_packet(_context, &_current_packet); } if (res != 0) { @@ -1181,7 +1182,7 @@ int ffmpeg_instance::send_frame(std::shared_ptr const frame) { int res = 0; { - auto gctx = util::obs_graphics(); + auto gctx = gs::context(); res = avcodec_send_frame(_context, frame.get()); } if (res == 0) { diff --git a/source/encoders/handlers/debug_handler.hpp b/source/encoders/handlers/debug_handler.hpp index 5599678..7cc3ef8 100644 --- a/source/encoders/handlers/debug_handler.hpp +++ b/source/encoders/handlers/debug_handler.hpp @@ -25,6 +25,8 @@ namespace encoder::ffmpeg::handler { class debug_handler : public handler { public: + virtual ~debug_handler(){}; + virtual void get_defaults(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context, bool hw_encode) override; diff --git a/source/encoders/handlers/handler.hpp b/source/encoders/handlers/handler.hpp index c2292e2..1df49f4 100644 --- a/source/encoders/handlers/handler.hpp +++ b/source/encoders/handlers/handler.hpp @@ -37,6 +37,9 @@ namespace encoder::ffmpeg { namespace handler { class handler { + public: + virtual ~handler(){}; + public /*factory*/: virtual void adjust_encoder_info(ffmpeg_factory* factory, ffmpeg_info* main, ffmpeg_info* fallback); diff --git a/source/encoders/handlers/nvenc_h264_handler.hpp b/source/encoders/handlers/nvenc_h264_handler.hpp index 64cf066..94eb837 100644 --- a/source/encoders/handlers/nvenc_h264_handler.hpp +++ b/source/encoders/handlers/nvenc_h264_handler.hpp @@ -31,6 +31,9 @@ extern "C" { namespace encoder::ffmpeg::handler { class nvenc_h264_handler : public handler { + public: + virtual ~nvenc_h264_handler(){}; + public /*factory*/: virtual void adjust_encoder_info(ffmpeg_factory* factory, ffmpeg_info* main, ffmpeg_info* fallback); diff --git a/source/encoders/handlers/nvenc_hevc_handler.hpp b/source/encoders/handlers/nvenc_hevc_handler.hpp index 25f10b1..5da093d 100644 --- a/source/encoders/handlers/nvenc_hevc_handler.hpp +++ b/source/encoders/handlers/nvenc_hevc_handler.hpp @@ -31,6 +31,9 @@ extern "C" { namespace encoder::ffmpeg::handler { class nvenc_hevc_handler : public handler { + public: + virtual ~nvenc_hevc_handler(){}; + public /*factory*/: virtual void adjust_encoder_info(ffmpeg_factory* factory, ffmpeg_info* main, ffmpeg_info* fallback); diff --git a/source/encoders/handlers/prores_aw_handler.hpp b/source/encoders/handlers/prores_aw_handler.hpp index 38c214c..59264c0 100644 --- a/source/encoders/handlers/prores_aw_handler.hpp +++ b/source/encoders/handlers/prores_aw_handler.hpp @@ -31,6 +31,9 @@ extern "C" { namespace encoder::ffmpeg::handler { class prores_aw_handler : public handler { + public: + virtual ~prores_aw_handler(){}; + public: virtual void override_colorformat(AVPixelFormat& target_format, obs_data_t* settings, const AVCodec* codec, AVCodecContext* context) override; diff --git a/source/ffmpeg/hwapi/base.hpp b/source/ffmpeg/hwapi/base.hpp index 674e3dd..5df8bce 100644 --- a/source/ffmpeg/hwapi/base.hpp +++ b/source/ffmpeg/hwapi/base.hpp @@ -44,6 +44,8 @@ namespace ffmpeg::hwapi { class instance { public: + virtual ~instance(){}; + virtual AVBufferRef* create_device_context() = 0; virtual std::shared_ptr allocate_frame(AVBufferRef* frames) = 0; @@ -57,6 +59,8 @@ namespace ffmpeg::hwapi { class base { public: + virtual ~base(){}; + virtual std::list enumerate_adapters() = 0; virtual std::shared_ptr create(hwapi::device target) = 0; diff --git a/source/ffmpeg/hwapi/d3d11.cpp b/source/ffmpeg/hwapi/d3d11.cpp index d89fe56..18d35e1 100644 --- a/source/ffmpeg/hwapi/d3d11.cpp +++ b/source/ffmpeg/hwapi/d3d11.cpp @@ -24,6 +24,7 @@ #include "d3d11.hpp" #include #include +#include "obs/gs/gs-helper.hpp" #include "utility.hpp" extern "C" { @@ -33,9 +34,7 @@ extern "C" { #pragma warning(disable : 4244) #pragma warning(disable : 4365) #pragma warning(disable : 4986) -#include #include -#include #pragma warning(pop) } @@ -138,7 +137,7 @@ std::shared_ptr d3d11::create(device target) std::shared_ptr d3d11::create_from_obs() { - auto gctx = util::obs_graphics(); + auto gctx = gs::context(); if (GS_DEVICE_DIRECT3D_11 != gs_get_device_type()) { throw std::runtime_error("OBS Device is not a D3D11 Device."); @@ -190,7 +189,7 @@ AVBufferRef* d3d11_instance::create_device_context() std::shared_ptr d3d11_instance::allocate_frame(AVBufferRef* frames) { - auto gctx = util::obs_graphics(); + auto gctx = gs::context(); auto frame = std::shared_ptr(av_frame_alloc(), [](AVFrame* frame) { av_frame_unref(frame); @@ -207,7 +206,7 @@ std::shared_ptr d3d11_instance::allocate_frame(AVBufferRef* frames) void d3d11_instance::copy_from_obs(AVBufferRef*, uint32_t handle, uint64_t lock_key, uint64_t* next_lock_key, std::shared_ptr frame) { - auto gctx = util::obs_graphics(); + auto gctx = gs::context(); ATL::CComPtr mutex; ATL::CComPtr input; @@ -246,7 +245,7 @@ void d3d11_instance::copy_from_obs(AVBufferRef*, uint32_t handle, uint64_t lock_ std::shared_ptr d3d11_instance::avframe_from_obs(AVBufferRef* frames, uint32_t handle, uint64_t lock_key, uint64_t* next_lock_key) { - auto gctx = util::obs_graphics(); + auto gctx = gs::context(); auto frame = this->allocate_frame(frames); this->copy_from_obs(frames, handle, lock_key, next_lock_key, frame); diff --git a/source/ffmpeg/hwapi/d3d11.hpp b/source/ffmpeg/hwapi/d3d11.hpp index 84903da..73a0882 100644 --- a/source/ffmpeg/hwapi/d3d11.hpp +++ b/source/ffmpeg/hwapi/d3d11.hpp @@ -31,6 +31,7 @@ extern "C++" { #pragma warning(disable : 4777) #pragma warning(disable : 4986) #pragma warning(disable : 5039) +#pragma warning(disable : 5204) #include #include #include diff --git a/source/gfx/shader/gfx-shader-param.cpp b/source/gfx/shader/gfx-shader-param.cpp index 87b59c8..44f73a2 100644 --- a/source/gfx/shader/gfx-shader-param.cpp +++ b/source/gfx/shader/gfx-shader-param.cpp @@ -164,7 +164,7 @@ gfx::shader::parameter::parameter(gs::effect_parameter param, std::string key_pr if (ov > 0) _size = ov; } - _size = std::clamp(_size, 1ull, 32ull); + _size = std::clamp(_size, size_t{1}, size_t{32}); } void gfx::shader::parameter::defaults(obs_data_t* settings) {} diff --git a/source/nvidia/cuda/nvidia-cuda-context.cpp b/source/nvidia/cuda/nvidia-cuda-context.cpp index e593087..749354f 100644 --- a/source/nvidia/cuda/nvidia-cuda-context.cpp +++ b/source/nvidia/cuda/nvidia-cuda-context.cpp @@ -23,7 +23,7 @@ #ifdef WIN32 #ifdef _MSC_VER #pragma warning(push) -#pragma warning(disable: 4191 4365 4777 5039) +#pragma warning(disable: 4191 4365 4777 5039 5204) #endif #include #ifdef _MSC_VER diff --git a/source/nvidia/cuda/nvidia-cuda.hpp b/source/nvidia/cuda/nvidia-cuda.hpp index fb6acdc..ba5f046 100644 --- a/source/nvidia/cuda/nvidia-cuda.hpp +++ b/source/nvidia/cuda/nvidia-cuda.hpp @@ -25,6 +25,7 @@ #ifdef WIN32 #pragma warning(push) #pragma warning(disable : 4365) +#pragma warning(disable : 5204) #include #include #pragma warning(pop) diff --git a/source/obs/gs/gs-effect-parameter.cpp b/source/obs/gs/gs-effect-parameter.cpp index f402bf1..b4d4699 100644 --- a/source/obs/gs/gs-effect-parameter.cpp +++ b/source/obs/gs/gs-effect-parameter.cpp @@ -22,8 +22,16 @@ #include #include "gs-effect-pass.hpp" +extern "C" { +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4201) +#endif #include -#include +#ifdef _MSC_VER +#pragma warning(pop) +#endif +} gs::effect_parameter::effect_parameter() : _effect_parent(nullptr), _pass_parent(nullptr), _param_parent(nullptr) { diff --git a/source/obs/gs/gs-effect-pass.cpp b/source/obs/gs/gs-effect-pass.cpp index db2215f..9a42d4a 100644 --- a/source/obs/gs/gs-effect-pass.cpp +++ b/source/obs/gs/gs-effect-pass.cpp @@ -20,7 +20,16 @@ #include "gs-effect-pass.hpp" #include +extern "C" { +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4201) +#endif #include +#ifdef _MSC_VER +#pragma warning(pop) +#endif +} gs::effect_pass::effect_pass(gs_epass_t* pass, std::shared_ptr* parent) : _parent(parent) { diff --git a/source/obs/gs/gs-effect-technique.cpp b/source/obs/gs/gs-effect-technique.cpp index 8921c89..d5792e4 100644 --- a/source/obs/gs/gs-effect-technique.cpp +++ b/source/obs/gs/gs-effect-technique.cpp @@ -21,7 +21,16 @@ #include #include +extern "C" { +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4201) +#endif #include +#ifdef _MSC_VER +#pragma warning(pop) +#endif +} gs::effect_technique::effect_technique(gs_technique_t* technique, std::shared_ptr* parent) : _parent(parent) diff --git a/source/obs/gs/gs-effect.cpp b/source/obs/gs/gs-effect.cpp index b7e5acd..044da21 100644 --- a/source/obs/gs/gs-effect.cpp +++ b/source/obs/gs/gs-effect.cpp @@ -23,17 +23,6 @@ #include #include "obs/gs/gs-helper.hpp" -// OBS -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4201) -#endif -#include -#include -#ifdef _MSC_VER -#pragma warning(pop) -#endif - #define MAX_EFFECT_SIZE 32 * 1024 * 1024 static std::string load_file_as_code(std::filesystem::path file) diff --git a/source/obs/gs/gs-indexbuffer.cpp b/source/obs/gs/gs-indexbuffer.cpp index dcc4b97..62b493a 100644 --- a/source/obs/gs/gs-indexbuffer.cpp +++ b/source/obs/gs/gs-indexbuffer.cpp @@ -22,16 +22,6 @@ #include "gs-limits.hpp" #include "obs/gs/gs-helper.hpp" -// OBS -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4201) -#endif -#include -#ifdef _MSC_VER -#pragma warning(pop) -#endif - gs::index_buffer::index_buffer(uint32_t maximumVertices) { this->reserve(maximumVertices); diff --git a/source/obs/gs/gs-mipmapper.cpp b/source/obs/gs/gs-mipmapper.cpp index dda6125..515967b 100644 --- a/source/obs/gs/gs-mipmapper.cpp +++ b/source/obs/gs/gs-mipmapper.cpp @@ -22,18 +22,6 @@ #include "obs/gs/gs-helper.hpp" #include "plugin.hpp" -// OBS -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4201) -#endif -#include -#include -#include -#ifdef _MSC_VER -#pragma warning(pop) -#endif - #if defined(WIN32) || defined(WIN64) #ifdef _MSC_VER #pragma warning(push) diff --git a/source/obs/gs/gs-rendertarget.cpp b/source/obs/gs/gs-rendertarget.cpp index 0f5576f..1b4ba67 100644 --- a/source/obs/gs/gs-rendertarget.cpp +++ b/source/obs/gs/gs-rendertarget.cpp @@ -21,17 +21,6 @@ #include #include "obs/gs/gs-helper.hpp" -// OBS -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4201) -#endif -#include -#include -#ifdef _MSC_VER -#pragma warning(pop) -#endif - gs::rendertarget::~rendertarget() { auto gctx = gs::context(); diff --git a/source/obs/gs/gs-texture.cpp b/source/obs/gs/gs-texture.cpp index 400d57d..cab2caf 100644 --- a/source/obs/gs/gs-texture.cpp +++ b/source/obs/gs/gs-texture.cpp @@ -24,17 +24,6 @@ #include "obs/gs/gs-helper.hpp" #include "util-math.hpp" -// OBS -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4201) -#endif -#include -#include -#ifdef _MSC_VER -#pragma warning(pop) -#endif - static uint32_t decode_flags(gs::texture::flags texture_flags) { uint32_t flags = 0; diff --git a/source/obs/gs/gs-vertexbuffer.cpp b/source/obs/gs/gs-vertexbuffer.cpp index 113009c..f44f2e7 100644 --- a/source/obs/gs/gs-vertexbuffer.cpp +++ b/source/obs/gs/gs-vertexbuffer.cpp @@ -22,16 +22,6 @@ #include "obs/gs/gs-helper.hpp" #include "utility.hpp" -// OBS -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4201) -#endif -#include -#ifdef _MSC_VER -#pragma warning(pop) -#endif - void gs::vertex_buffer::initialize(size_t capacity, size_t layers) { if (capacity > MAXIMUM_VERTICES) { diff --git a/source/obs/obs-tools.cpp b/source/obs/obs-tools.cpp index 5676db9..909588d 100644 --- a/source/obs/obs-tools.cpp +++ b/source/obs/obs-tools.cpp @@ -22,16 +22,6 @@ #include #include "plugin.hpp" -// OBS -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4201) -#endif -#include -#ifdef _MSC_VER -#pragma warning(pop) -#endif - struct scs_searchdata { obs_source_t* source; bool found = false; diff --git a/source/sources/source-mirror.cpp b/source/sources/source-mirror.cpp index dcbdbbc..0d149d7 100644 --- a/source/sources/source-mirror.cpp +++ b/source/sources/source-mirror.cpp @@ -35,9 +35,7 @@ #pragma warning(push) #pragma warning(disable : 4201) #endif -#include #include -#include #ifdef _MSC_VER #pragma warning(pop) #endif diff --git a/source/utility.hpp b/source/utility.hpp index 89cd774..b7c3ade 100644 --- a/source/utility.hpp +++ b/source/utility.hpp @@ -18,18 +18,20 @@ */ #pragma once -#include "common.hpp" +#include +#include +#include +#include extern "C" { #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4201) #endif +#include #include #include #include -#include -#include #ifdef _MSC_VER #pragma warning(pop) #endif @@ -94,17 +96,6 @@ namespace util { return obs_get_version() < MAKE_SEMANTIC_VERSION(24, 0, 0); } - struct obs_graphics { - obs_graphics() - { - obs_enter_graphics(); - } - ~obs_graphics() - { - obs_leave_graphics(); - } - }; - obs_property_t* obs_properties_add_tristate(obs_properties_t* props, const char* name, const char* desc); inline bool is_tristate_enabled(int64_t tristate) @@ -122,25 +113,6 @@ namespace util { return tristate == -1; } - typedef union { - uint32_t color; - struct { - uint8_t r; - uint8_t g; - uint8_t b; - uint8_t a; - }; - } rgba32; - typedef union { - uint32_t color; - struct { - uint8_t a; - uint8_t r; - uint8_t g; - uint8_t b; - }; - } argb32; - struct vec2a : public vec2 { // 16-byte Aligned version of vec2 static void* operator new(size_t count); @@ -171,16 +143,6 @@ namespace util { static void operator delete[](void* p); }; - inline size_t GetNearestPowerOfTwoAbove(size_t v) - { - return 1ull << size_t(ceil(log10(double(v)) / log10(2.0))); - } - - inline size_t GetNearestPowerOfTwoBelow(size_t v) - { - return 1ull << size_t(floor(log10(double(v)) / log10(2.0))); - } - std::pair size_from_string(std::string text, bool allowSquare = true); namespace math { @@ -216,14 +178,14 @@ namespace util { { \ return is_power_of_two_loop(v); \ } - P_IS_POWER_OF_TWO_AS_LOOP(int8_t); - P_IS_POWER_OF_TWO_AS_LOOP(uint8_t); - P_IS_POWER_OF_TWO_AS_LOOP(int16_t); - P_IS_POWER_OF_TWO_AS_LOOP(uint16_t); - P_IS_POWER_OF_TWO_AS_LOOP(int32_t); - P_IS_POWER_OF_TWO_AS_LOOP(uint32_t); - P_IS_POWER_OF_TWO_AS_LOOP(int64_t); - P_IS_POWER_OF_TWO_AS_LOOP(uint64_t); + P_IS_POWER_OF_TWO_AS_LOOP(int8_t) + P_IS_POWER_OF_TWO_AS_LOOP(uint8_t) + P_IS_POWER_OF_TWO_AS_LOOP(int16_t) + P_IS_POWER_OF_TWO_AS_LOOP(uint16_t) + P_IS_POWER_OF_TWO_AS_LOOP(int32_t) + P_IS_POWER_OF_TWO_AS_LOOP(uint32_t) + P_IS_POWER_OF_TWO_AS_LOOP(int64_t) + P_IS_POWER_OF_TWO_AS_LOOP(uint64_t) #undef P_IS_POWER_OF_TWO_AS_LOOP #pragma pop_macro("P_IS_POWER_OF_TWO_AS_LOOP") @@ -315,85 +277,4 @@ namespace util { } void* malloc_aligned(size_t align, size_t size); void free_aligned(void* mem); - - template - class AlignmentAllocator { - public: - typedef T value_type; - typedef size_t size_type; -#ifdef __clang__ - typedef ptrdiff_t difference_type; -#else - typedef std::ptrdiff_t difference_type; -#endif - - typedef T* pointer; - typedef const T* const_pointer; - - typedef T& reference; - typedef const T& const_reference; - - public: - inline AlignmentAllocator() {} - - template - inline AlignmentAllocator(const AlignmentAllocator&) - {} - - inline ~AlignmentAllocator() {} - - inline pointer adress(reference r) - { - return &r; - } - - inline const_pointer adress(const_reference r) const - { - return &r; - } - - inline pointer allocate(size_type n) - { - return (pointer)malloc_aligned(n * sizeof(value_type), N); - } - - inline void deallocate(pointer p, size_type) - { - free_aligned(p); - } - - inline void construct(pointer p, const value_type& wert) - { - new (p) value_type(wert); - } - - inline void destroy(pointer p) - { - p->~value_type(); - p; - } - - inline size_type max_size() const - { - return size_type(-1) / sizeof(value_type); - } - - template - struct rebind { - typedef AlignmentAllocator other; - }; - - bool operator!=(const AlignmentAllocator& other) const - { - return !(*this == other); - } - - // Returns true if and only if storage allocated from *this - // can be deallocated from other, and vice versa. - // Always returns true for stateless allocators. - bool operator==(const AlignmentAllocator&) const - { - return true; - } - }; } // namespace util