clang cant compile the handle_raii class because it thinks INVALID_HANDLE_VALUE is not a constexpr

Make a standalone class for it instead of inheriting generic_raii
This commit is contained in:
Kovid Goyal 2023-01-26 19:27:36 +05:30
parent 2d386d87da
commit 69656be428
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -59,11 +59,36 @@ class scoped_com_initializer { // {{{
#define INITIALIZE_COM_IN_FUNCTION scoped_com_initializer com; if (!com) return com.set_python_error(); #define INITIALIZE_COM_IN_FUNCTION scoped_com_initializer com; if (!com) return com.set_python_error();
static inline void co_task_mem_free(void* m) { CoTaskMemFree(m); } static inline void co_task_mem_free(void* m) { CoTaskMemFree(m); }
typedef generic_raii<wchar_t*, co_task_mem_free, static_cast<wchar_t*>(NULL)> com_wchar_raii; typedef generic_raii<wchar_t*, co_task_mem_free> com_wchar_raii;
static inline void handle_destructor(HANDLE p) { CloseHandle(p); }
typedef generic_raii<HANDLE, handle_destructor, INVALID_HANDLE_VALUE> handle_raii;
static inline void mapping_destructor(void *p) { UnmapViewOfFile(p); } static inline void mapping_destructor(void *p) { UnmapViewOfFile(p); }
typedef generic_raii<void*, mapping_destructor, static_cast<void*>(NULL)> mapping_raii; typedef generic_raii<void*, mapping_destructor> mapping_raii;
class handle_raii {
private:
handle_raii( const handle_raii & ) noexcept;
handle_raii & operator=( const handle_raii & ) noexcept ;
protected:
HANDLE handle;
public:
explicit handle_raii(HANDLE h = INVALID_HANDLE_VALUE) noexcept : handle(h) {}
~handle_raii() noexcept { release(); }
void release() noexcept {
if (handle != INVALID_HANDLE_VALUE) {
HANDLE temp = handle;
handle = INVALID_HANDLE_VALUE;
CloseHandle(temp);
}
}
HANDLE ptr() noexcept { return handle; }
HANDLE detach() noexcept { HANDLE ans = handle; handle = INVALID_HANDLE_VALUE; return ans; }
void attach(HANDLE val) noexcept { release(); handle = val; }
explicit operator bool() const noexcept { return handle != INVALID_HANDLE_VALUE; }
};
struct prop_variant : PROPVARIANT { struct prop_variant : PROPVARIANT {
prop_variant(VARTYPE vt=VT_EMPTY) noexcept : PROPVARIANT{} { PropVariantInit(this); this->vt = vt; } prop_variant(VARTYPE vt=VT_EMPTY) noexcept : PROPVARIANT{} { PropVariantInit(this); this->vt = vt; }