mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
Made sure the destructor for mp_base_base gets called before anyone clones
data into the mp_base_base's memory space. --HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402624
This commit is contained in:
parent
7cefb1e5db
commit
805365a154
@ -117,7 +117,7 @@ namespace dlib
|
|||||||
) { mfp_kernel_1_base_class(item).swap(*this); return *this; }
|
) { mfp_kernel_1_base_class(item).swap(*this); return *this; }
|
||||||
|
|
||||||
~mfp_kernel_1_base_class (
|
~mfp_kernel_1_base_class (
|
||||||
) { mp()->~mp_base_base(); }
|
) { destroy_mp_memory(); }
|
||||||
|
|
||||||
void clear(
|
void clear(
|
||||||
) { mfp_kernel_1_base_class().swap(*this); }
|
) { mfp_kernel_1_base_class().swap(*this); }
|
||||||
@ -138,8 +138,14 @@ namespace dlib
|
|||||||
{
|
{
|
||||||
// make a temp copy of item
|
// make a temp copy of item
|
||||||
mfp_kernel_1_base_class temp(item);
|
mfp_kernel_1_base_class temp(item);
|
||||||
|
|
||||||
|
// destory the stuff in item
|
||||||
|
item.destroy_mp_memory();
|
||||||
// copy *this into item
|
// copy *this into item
|
||||||
mp()->clone(item.mp_memory.data);
|
mp()->clone(item.mp_memory.data);
|
||||||
|
|
||||||
|
// destory the stuff in this
|
||||||
|
destroy_mp_memory();
|
||||||
// copy temp into *this
|
// copy temp into *this
|
||||||
temp.mp()->clone(mp_memory.data);
|
temp.mp()->clone(mp_memory.data);
|
||||||
}
|
}
|
||||||
@ -162,6 +168,14 @@ namespace dlib
|
|||||||
char data[sizeof(mp_null_impl)];
|
char data[sizeof(mp_null_impl)];
|
||||||
} mp_memory;
|
} mp_memory;
|
||||||
|
|
||||||
|
void destroy_mp_memory (
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Honestly this probably doesn't even do anything but I'm putting
|
||||||
|
// it here just for good measure.
|
||||||
|
mp()->~mp_base_base();
|
||||||
|
}
|
||||||
|
|
||||||
mp_base_base* mp () { void* ptr = mp_memory.data; return static_cast<mp_base_base*>(ptr); }
|
mp_base_base* mp () { void* ptr = mp_memory.data; return static_cast<mp_base_base*>(ptr); }
|
||||||
const mp_base_base* mp () const { const void* ptr = mp_memory.data; return static_cast<const mp_base_base*>(ptr); }
|
const mp_base_base* mp () const { const void* ptr = mp_memory.data; return static_cast<const mp_base_base*>(ptr); }
|
||||||
|
|
||||||
@ -217,10 +231,10 @@ namespace dlib
|
|||||||
// resolution bug in visual studio.
|
// resolution bug in visual studio.
|
||||||
template <typename T> typename disable_if<is_const_type<T>,void>::type
|
template <typename T> typename disable_if<is_const_type<T>,void>::type
|
||||||
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
|
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
|
||||||
{ mp_impl_T<mp_impl<T> >(&object,cb).clone(mp_memory.data); }
|
{ destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).clone(mp_memory.data); }
|
||||||
|
|
||||||
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
|
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
|
||||||
{ mp_impl_T<mp_impl_const<T> >((void*)&object,cb).clone(mp_memory.data); }
|
{ destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).clone(mp_memory.data); }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -276,10 +290,10 @@ namespace dlib
|
|||||||
// resolution bug in visual studio.
|
// resolution bug in visual studio.
|
||||||
template <typename T> typename disable_if<is_const_type<T>,void>::type
|
template <typename T> typename disable_if<is_const_type<T>,void>::type
|
||||||
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
|
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
|
||||||
{ mp_impl_T<mp_impl<T> >(&object,cb).clone(mp_memory.data); }
|
{ destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).clone(mp_memory.data); }
|
||||||
|
|
||||||
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
|
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
|
||||||
{ mp_impl_T<mp_impl_const<T> >((void*)&object,cb).clone(mp_memory.data); }
|
{ destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).clone(mp_memory.data); }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -336,10 +350,10 @@ namespace dlib
|
|||||||
// resolution bug in visual studio.
|
// resolution bug in visual studio.
|
||||||
template <typename T> typename disable_if<is_const_type<T>,void>::type
|
template <typename T> typename disable_if<is_const_type<T>,void>::type
|
||||||
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
|
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
|
||||||
{ mp_impl_T<mp_impl<T> >(&object,cb).clone(mp_memory.data); }
|
{ destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).clone(mp_memory.data); }
|
||||||
|
|
||||||
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
|
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
|
||||||
{ mp_impl_T<mp_impl_const<T> >((void*)&object,cb).clone(mp_memory.data); }
|
{ destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).clone(mp_memory.data); }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -397,10 +411,10 @@ namespace dlib
|
|||||||
// resolution bug in visual studio.
|
// resolution bug in visual studio.
|
||||||
template <typename T> typename disable_if<is_const_type<T>,void>::type
|
template <typename T> typename disable_if<is_const_type<T>,void>::type
|
||||||
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
|
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
|
||||||
{ mp_impl_T<mp_impl<T> >(&object,cb).clone(mp_memory.data); }
|
{ destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).clone(mp_memory.data); }
|
||||||
|
|
||||||
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
|
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
|
||||||
{ mp_impl_T<mp_impl_const<T> >((void*)&object,cb).clone(mp_memory.data); }
|
{ destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).clone(mp_memory.data); }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -460,10 +474,10 @@ namespace dlib
|
|||||||
// resolution bug in visual studio.
|
// resolution bug in visual studio.
|
||||||
template <typename T> typename disable_if<is_const_type<T>,void>::type
|
template <typename T> typename disable_if<is_const_type<T>,void>::type
|
||||||
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
|
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
|
||||||
{ mp_impl_T<mp_impl<T> >(&object,cb).clone(mp_memory.data); }
|
{ destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).clone(mp_memory.data); }
|
||||||
|
|
||||||
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
|
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
|
||||||
{ mp_impl_T<mp_impl_const<T> >((void*)&object,cb).clone(mp_memory.data); }
|
{ destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).clone(mp_memory.data); }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user