Skip to content

Commit acf0985

Browse files
committed
allow blind C++ windows RC structures
1 parent 47af0c5 commit acf0985

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

include/mir/rcarray.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ struct mir_rcarray
2525

2626
T* _payload = nullptr;
2727
using U = typename std::remove_all_extents<T>::type;
28-
static constexpr void (*destr)(U&) = std::is_destructible<T>::value ? &mir::Destructor<U>::destroy : nullptr;
29-
static constexpr mir::type_info_g<U> typeInfoT = {destr, sizeof(T)};
3028

3129
void _cpp_copy_constructor(const mir_rcarray& rhs) noexcept;
3230
mir_rcarray& _cpp_assign(const mir_rcarray& rhs) noexcept;
@@ -38,7 +36,7 @@ struct mir_rcarray
3836
{
3937
if (length == 0)
4038
return;
41-
auto context = mir_rc_create((const mir_type_info*)&typeInfoT, length, nullptr, false, deallocate);
39+
auto context = mir_rc_create(mir::typeInfoT_<U>(), length, nullptr, false, deallocate);
4240
if (context == nullptr)
4341
throw std::bad_alloc();
4442
_payload = (T*)(context + 1);

include/mir/rcptr.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ namespace mir
7272

7373
// template<class = typename std::enable_if<std::is_destructible<T>::value>::type>
7474

75+
template<class U>
76+
static const mir_type_info* typeInfoT_()
77+
{
78+
static constexpr void (*destr)(U&) = std::is_destructible<U>::value ? &Destructor<U>::destroy : nullptr;
79+
static constexpr type_info_g<U> value = {destr, sizeof(U)};
80+
return (const mir_type_info*)&value;
81+
}
7582
}
7683

7784
// Does not support allocators for now
@@ -83,8 +90,6 @@ struct mir_rcptr
8390
T* _payload = nullptr;
8491
mir_rc_context* _context = nullptr;
8592
using U = typename std::remove_all_extents<T>::type;
86-
static constexpr void (*destr)(U&) = std::is_destructible<T>::value ? &mir::Destructor<U>::destroy : nullptr;
87-
static constexpr mir::type_info_g<U> typeInfoT = {destr, sizeof(T)};
8893

8994
public:
9095

@@ -114,7 +119,7 @@ struct mir_rcptr
114119
using U = typename std::remove_const<T>::type;
115120
static_assert( std::is_constructible<U, Args...>::value, "Can't construct object in mir_rcptr constructor" );
116121
mir_rcptr ret;
117-
ret._context = mir_rc_create((const mir_type_info*)&typeInfoT, 1);
122+
ret._context = mir_rc_create(mir::typeInfoT_<U>(), 1);
118123
if (ret._context == nullptr)
119124
throw std::bad_alloc();
120125
ret._payload = (T*)(ret._context + 1);

include/mir/slim_rcptr.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ struct mir_slim_rcptr
1212

1313
T* _payload = nullptr;
1414
using U = typename std::remove_all_extents<T>::type;
15-
static constexpr void (*destr)(U&) = std::is_destructible<T>::value ? &mir::Destructor<U>::destroy : nullptr;
16-
static constexpr mir::type_info_g<U> typeInfoT = {destr, sizeof(T)};
1715

1816
public:
1917

@@ -49,7 +47,7 @@ struct mir_slim_rcptr
4947
using U = typename std::remove_const<T>::type;
5048
static_assert( std::is_constructible<U, Args...>::value, "Can't construct object in mir_slim_rcptr constructor" );
5149
mir_slim_rcptr ret;
52-
auto context = mir_rc_create((const mir_type_info*)&typeInfoT, 1);
50+
auto context = mir_rc_create(mir::typeInfoT_<U>(), 1);
5351
if (context == nullptr)
5452
throw std::bad_alloc();
5553
ret._payload = (T*)(context + 1);

0 commit comments

Comments
 (0)