Commit a9ab308e authored by Davis King's avatar Davis King

I just fixed some warnings and compiler errors you get if you try to compile dlib

with the newest version of mingw.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403111
parent f4678b8f
......@@ -752,6 +752,61 @@ namespace dlib
template <typename T, typename A0, typename A1, typename A2, typename A3, typename A4>
funct_wrap5<T,A0,A1,A2,A3,A4> wrap_function(T (&f)(A0, A1, A2, A3, A4)) { return funct_wrap5<T,A0,A1,A2,A3,A4>(f); }
// ----------------------------------------------------------------------------------------
template <unsigned long bSIZE>
class stack_based_memory_block : noncopyable
{
/*!
WHAT THIS OBJECT REPRESENTS
This object is a simple container for a block of memory
of bSIZE bytes. This memory block is located on the stack
and properly aligned to hold any kind of object.
!*/
public:
static const unsigned long size = bSIZE;
stack_based_memory_block(): data(mem.data) {}
void* get () { return data; }
/*!
ensures
- returns a pointer to the block of memory contained in this object
!*/
const void* get () const { return data; }
/*!
ensures
- returns a pointer to the block of memory contained in this object
!*/
private:
union mem_block
{
// All of this garbage is to make sure this union is properly aligned
// (a union is always aligned such that everything in it would be properly
// aligned. So the assumption here is that one of these objects has
// a large enough alignment requirement to satisfy any object this
// block of memory might be cast into).
void* void_ptr;
int integer;
struct {
void (stack_based_memory_block::*callback)();
stack_based_memory_block* o;
} stuff;
long double more_stuff;
char data[size];
} mem;
// The reason for having this variable is that doing it this way avoids
// warnings from gcc about violations of strict-aliasing rules.
void* const data;
};
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_ALGs_
......
......@@ -196,13 +196,13 @@ namespace dlib
}
template <unsigned long mem_size>
void safe_clone(char (&buf)[mem_size])
void safe_clone(stack_based_memory_block<mem_size>& buf)
{
// This is here just to validate the assumption that our block of memory we have made
// in bf_memory.data is the right size to store the data for this object. If you
// in bf_memory is the right size to store the data for this object. If you
// get a compiler error on this line then email me :)
COMPILE_TIME_ASSERT(sizeof(bound_function_helper_T) <= mem_size);
clone(buf);
clone(buf.get());
}
void clone (void* ptr) const
......@@ -227,11 +227,11 @@ namespace dlib
public:
bound_function_pointer_kernel_1 (
) { bf_null_type().safe_clone(bf_memory.data); }
) { bf_null_type().safe_clone(bf_memory); }
bound_function_pointer_kernel_1 (
const bound_function_pointer_kernel_1& item
) { item.bf()->clone(bf_memory.data); }
) { item.bf()->clone(bf_memory.get()); }
~bound_function_pointer_kernel_1()
{ destroy_bf_memory(); }
......@@ -259,12 +259,12 @@ namespace dlib
// destory the stuff in item
item.destroy_bf_memory();
// copy *this into item
bf()->clone(item.bf_memory.data);
bf()->clone(item.bf_memory.get());
// destory the stuff in this
destroy_bf_memory();
// copy temp into *this
temp.bf()->clone(bf_memory.data);
temp.bf()->clone(bf_memory.get());
}
void operator() (
......@@ -300,7 +300,7 @@ namespace dlib
bf_helper_type temp;
temp.fp = &function_object;
temp.safe_clone(bf_memory.data);
temp.safe_clone(bf_memory);
}
template <typename F, typename A1 >
......@@ -320,7 +320,7 @@ namespace dlib
temp.arg1 = &arg1;
temp.fp = &function_object;
temp.safe_clone(bf_memory.data);
temp.safe_clone(bf_memory);
}
template <typename F, typename A1, typename A2 >
......@@ -342,7 +342,7 @@ namespace dlib
temp.arg2 = &arg2;
temp.fp = &function_object;
temp.safe_clone(bf_memory.data);
temp.safe_clone(bf_memory);
}
template <typename F, typename A1, typename A2, typename A3 >
......@@ -366,7 +366,7 @@ namespace dlib
temp.arg3 = &arg3;
temp.fp = &function_object;
temp.safe_clone(bf_memory.data);
temp.safe_clone(bf_memory);
}
template <typename F, typename A1, typename A2, typename A3, typename A4>
......@@ -392,7 +392,7 @@ namespace dlib
temp.arg4 = &arg4;
temp.fp = &function_object;
temp.safe_clone(bf_memory.data);
temp.safe_clone(bf_memory);
}
// -------------------------------------------
......@@ -412,7 +412,7 @@ namespace dlib
bf_helper_type temp;
temp.mfp.set(object,funct);
temp.safe_clone(bf_memory.data);
temp.safe_clone(bf_memory);
}
template <typename T >
......@@ -428,7 +428,7 @@ namespace dlib
bf_helper_type temp;
temp.mfp.set(object,funct);
temp.safe_clone(bf_memory.data);
temp.safe_clone(bf_memory);
}
// -------------------------------------------
......@@ -448,7 +448,7 @@ namespace dlib
temp.arg1 = &arg1;
temp.mfp.set(object,funct);
temp.safe_clone(bf_memory.data);
temp.safe_clone(bf_memory);
}
template <typename T, typename T1, typename A1 >
......@@ -466,7 +466,7 @@ namespace dlib
temp.arg1 = &arg1;
temp.mfp.set(object,funct);
temp.safe_clone(bf_memory.data);
temp.safe_clone(bf_memory);
}
// ----------------
......@@ -489,7 +489,7 @@ namespace dlib
temp.arg2 = &arg2;
temp.mfp.set(object,funct);
temp.safe_clone(bf_memory.data);
temp.safe_clone(bf_memory);
}
template <typename T, typename T1, typename A1,
......@@ -510,7 +510,7 @@ namespace dlib
temp.arg2 = &arg2;
temp.mfp.set(object,funct);
temp.safe_clone(bf_memory.data);
temp.safe_clone(bf_memory);
}
// ----------------
......@@ -536,7 +536,7 @@ namespace dlib
temp.arg3 = &arg3;
temp.mfp.set(object,funct);
temp.safe_clone(bf_memory.data);
temp.safe_clone(bf_memory);
}
template <typename T, typename T1, typename A1,
......@@ -560,7 +560,7 @@ namespace dlib
temp.arg3 = &arg3;
temp.mfp.set(object,funct);
temp.safe_clone(bf_memory.data);
temp.safe_clone(bf_memory);
}
// ----------------
......@@ -589,7 +589,7 @@ namespace dlib
temp.arg4 = &arg4;
temp.mfp.set(object,funct);
temp.safe_clone(bf_memory.data);
temp.safe_clone(bf_memory);
}
template <typename T, typename T1, typename A1,
......@@ -616,7 +616,7 @@ namespace dlib
temp.arg4 = &arg4;
temp.mfp.set(object,funct);
temp.safe_clone(bf_memory.data);
temp.safe_clone(bf_memory);
}
// -------------------------------------------
......@@ -634,7 +634,7 @@ namespace dlib
bf_helper_type temp;
temp.fp = funct;
temp.safe_clone(bf_memory.data);
temp.safe_clone(bf_memory);
}
template <typename T1, typename A1>
......@@ -651,7 +651,7 @@ namespace dlib
temp.arg1 = &arg1;
temp.fp = funct;
temp.safe_clone(bf_memory.data);
temp.safe_clone(bf_memory);
}
template <typename T1, typename A1,
......@@ -671,7 +671,7 @@ namespace dlib
temp.arg2 = &arg2;
temp.fp = funct;
temp.safe_clone(bf_memory.data);
temp.safe_clone(bf_memory);
}
template <typename T1, typename A1,
......@@ -694,7 +694,7 @@ namespace dlib
temp.arg3 = &arg3;
temp.fp = funct;
temp.safe_clone(bf_memory.data);
temp.safe_clone(bf_memory);
}
template <typename T1, typename A1,
......@@ -720,28 +720,14 @@ namespace dlib
temp.arg4 = &arg4;
temp.fp = funct;
temp.safe_clone(bf_memory.data);
temp.safe_clone(bf_memory);
}
// -------------------------------------------
private:
union data_block_type
{
// All of this garbage is to make sure this union is properly aligned
// (a union is always aligned such that everything in it would be properly
// aligned. So the assumption here is that one of these things big good
// alignment to satisfy mp_null_impl objects (or other objects like it).
void* void_ptr;
long double dtemp;
struct {
void (bfp1_helpers::bound_function_helper_base_base::*callback)();
bfp1_helpers::bound_function_helper_base_base* o;
} stuff;
char data[sizeof(bf_null_type)];
} bf_memory;
stack_based_memory_block<sizeof(bf_null_type)> bf_memory;
void destroy_bf_memory (
)
......@@ -752,10 +738,10 @@ namespace dlib
}
bfp1_helpers::bound_function_helper_base_base* bf ()
{ void* ptr = bf_memory.data; return static_cast<bfp1_helpers::bound_function_helper_base_base*>(ptr); }
{ return static_cast<bfp1_helpers::bound_function_helper_base_base*>(bf_memory.get()); }
const bfp1_helpers::bound_function_helper_base_base* bf () const
{ const void* ptr = bf_memory.data; return static_cast<const bfp1_helpers::bound_function_helper_base_base*>(ptr); }
{ return static_cast<const bfp1_helpers::bound_function_helper_base_base*>(bf_memory.get()); }
};
......
......@@ -6,6 +6,7 @@
#include "../algs.h"
#include <iostream>
#include <streambuf>
#include <cstdio>
#include "compress_stream_kernel_abstract.h"
namespace dlib
......
......@@ -78,13 +78,13 @@ namespace dlib
mp_impl_T(void* ptr, mfp_pointer_type cb) : mp_impl(ptr,cb) {}
template <unsigned long mem_size>
void safe_clone(char (&buf)[mem_size])
void safe_clone(stack_based_memory_block<mem_size>& buf)
{
// This is here just to validate the assumption that our block of memory we have made
// in mp_memory.data is the right size to store the data for this object. If you
// in mp_memory is the right size to store the data for this object. If you
// get a compiler error on this line then email me :)
COMPILE_TIME_ASSERT(sizeof(mp_impl_T) <= mem_size);
clone(buf);
clone(buf.get());
}
void clone (void* ptr) const { new(ptr) mp_impl_T(this->o,this->callback); }
......@@ -111,10 +111,10 @@ namespace dlib
mfp_kernel_1_base_class (
const mfp_kernel_1_base_class& item
) { item.mp()->clone(mp_memory.data); }
) { item.mp()->clone(mp_memory.get()); }
mfp_kernel_1_base_class (
) { mp_null_impl().safe_clone(mp_memory.data); }
) { mp_null_impl().safe_clone(mp_memory); }
bool operator == (
const mfp_kernel_1_base_class& item
......@@ -154,31 +154,17 @@ namespace dlib
// destory the stuff in item
item.destroy_mp_memory();
// copy *this into item
mp()->clone(item.mp_memory.data);
mp()->clone(item.mp_memory.get());
// destory the stuff in this
destroy_mp_memory();
// copy temp into *this
temp.mp()->clone(mp_memory.data);
temp.mp()->clone(mp_memory.get());
}
protected:
// make a block of memory big enough to hold a mp_null object.
union data_block_type
{
// All of this garbage is to make sure this union is properly aligned
// (a union is always aligned such that everything in it would be properly
// aligned. So the assumption here is that one of these things big good
// alignment to satisfy mp_null_impl objects (or other objects like it).
void* void_ptr;
struct {
void (mp_base_base::*callback)();
mp_base_base* o;
} stuff;
char data[sizeof(mp_null_impl)];
} mp_memory;
stack_based_memory_block<sizeof(mp_null_impl)> mp_memory;
void destroy_mp_memory (
)
......@@ -188,8 +174,8 @@ namespace dlib
mp()->~mp_base_base();
}
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); }
mp_base_base* mp () { return static_cast<mp_base_base*>(mp_memory.get()); }
const mp_base_base* mp () const { return static_cast<const mp_base_base*>(mp_memory.get()); }
};
......@@ -230,16 +216,16 @@ namespace dlib
typedef void param3_type;
typedef void param4_type;
void operator() () const { static_cast<const mp_base*>((const void*)mp_memory.data)->call(); }
void operator() () const { static_cast<const mp_base*>(mp_memory.get())->call(); }
// the reason for putting disable_if on this function is that it avoids an overload
// resolution bug in visual studio.
template <typename T> typename disable_if<is_const_type<T>,void>::type
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
{ destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).safe_clone(mp_memory.data); }
{ destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).safe_clone(mp_memory); }
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
{ destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).safe_clone(mp_memory.data); }
{ destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).safe_clone(mp_memory); }
};
......@@ -282,16 +268,16 @@ namespace dlib
typedef void param3_type;
typedef void param4_type;
void operator() (PARAM1 p1) const { static_cast<const mp_base*>((const void*)mp_memory.data)->call(p1); }
void operator() (PARAM1 p1) const { static_cast<const mp_base*>(mp_memory.get())->call(p1); }
// the reason for putting disable_if on this function is that it avoids an overload
// resolution bug in visual studio.
template <typename T> typename disable_if<is_const_type<T>,void>::type
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
{ destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).safe_clone(mp_memory.data); }
{ destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).safe_clone(mp_memory); }
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
{ destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).safe_clone(mp_memory.data); }
{ destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).safe_clone(mp_memory); }
};
......@@ -335,16 +321,16 @@ namespace dlib
typedef void param3_type;
typedef void param4_type;
void operator() (PARAM1 p1, PARAM2 p2) const { static_cast<const mp_base*>((const void*)mp_memory.data)->call(p1,p2); }
void operator() (PARAM1 p1, PARAM2 p2) const { static_cast<const mp_base*>(mp_memory.get())->call(p1,p2); }
// the reason for putting disable_if on this function is that it avoids an overload
// resolution bug in visual studio.
template <typename T> typename disable_if<is_const_type<T>,void>::type
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
{ destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).safe_clone(mp_memory.data); }
{ destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).safe_clone(mp_memory); }
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
{ destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).safe_clone(mp_memory.data); }
{ destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).safe_clone(mp_memory); }
};
......@@ -389,16 +375,16 @@ namespace dlib
typedef PARAM3 param3_type;
typedef void param4_type;
void operator() (PARAM1 p1, PARAM2 p2, PARAM3 p3) const { static_cast<const mp_base*>((const void*)mp_memory.data)->call(p1,p2,p3); }
void operator() (PARAM1 p1, PARAM2 p2, PARAM3 p3) const { static_cast<const mp_base*>(mp_memory.get())->call(p1,p2,p3); }
// the reason for putting disable_if on this function is that it avoids an overload
// resolution bug in visual studio.
template <typename T> typename disable_if<is_const_type<T>,void>::type
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
{ destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).safe_clone(mp_memory.data); }
{ destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).safe_clone(mp_memory); }
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
{ destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).safe_clone(mp_memory.data); }
{ destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).safe_clone(mp_memory); }
};
......@@ -445,16 +431,16 @@ namespace dlib
typedef PARAM4 param4_type;
void operator() (PARAM1 p1, PARAM2 p2, PARAM3 p3, PARAM4 p4) const
{ static_cast<const mp_base*>((const void*)mp_memory.data)->call(p1,p2,p3,p4); }
{ static_cast<const mp_base*>(mp_memory.get())->call(p1,p2,p3,p4); }
// the reason for putting disable_if on this function is that it avoids an overload
// resolution bug in visual studio.
template <typename T> typename disable_if<is_const_type<T>,void>::type
set(T& object, typename mp_impl<T>::mfp_pointer_type cb)
{ destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).safe_clone(mp_memory.data); }
{ destroy_mp_memory(); mp_impl_T<mp_impl<T> >(&object,cb).safe_clone(mp_memory); }
template <typename T> void set(const T& object, typename mp_impl_const<T>::mfp_pointer_type cb)
{ destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).safe_clone(mp_memory.data); }
{ destroy_mp_memory(); mp_impl_T<mp_impl_const<T> >((void*)&object,cb).safe_clone(mp_memory); }
};
......
......@@ -204,7 +204,7 @@ namespace dlib
// don't declare this if we are using mingw because it apparently doesn't
// support iostreams with wchar_t?
#ifndef __MINGW32__
#if !(defined(__MINGW32__) && (__GNUC__ < 4))
template <
typename T
>
......
......@@ -11,6 +11,7 @@
namespace dlib
{
// ----------------------------------------------------------------------------------------
template <
......@@ -31,7 +32,7 @@ namespace dlib
CONVENTION
- is_empty() == (type_identity == 0)
- contains<T>() == (type_identity == get_id<T>())
- mem.data == the block of memory on the stack which is
- mem.get() == the block of memory on the stack which is
where objects in the union are stored
!*/
......@@ -48,26 +49,10 @@ namespace dlib
sizeof(T9)>::value,
sizeof(T10)>::value;
union mem_block
{
// All of this garbage is to make sure this union is properly aligned
// (a union is always aligned such that everything in it would be properly
// aligned. So the assumption here is that one of these objects has
// a large enough alignment requirement to satisfy any object this
// type_safe_union might contain).
void* void_ptr;
struct {
void (type_safe_union::*callback)();
type_safe_union* o;
} stuff;
long double more_stuff;
char data[max_size];
};
stack_based_memory_block<max_size> mem;
int type_identity;
mem_block mem;
struct destruct_helper
{
......@@ -120,7 +105,7 @@ namespace dlib
if (type_identity != get_id<T>())
{
destruct();
new((void*)mem.data) T();
new(mem.get()) T();
type_identity = get_id<T>();
}
}
......@@ -316,7 +301,7 @@ namespace dlib
}
}
template <typename T> T& get() { construct<T>(); return *reinterpret_cast<T*>(mem.data); }
template <typename T> T& get() { construct<T>(); return *reinterpret_cast<T*>(mem.get()); }
};
......
......@@ -8,6 +8,7 @@
#include "xml_parser_kernel_interfaces.h"
#include "xml_parser_kernel_abstract.h"
#include "../algs.h"
#include <cstdio>
namespace dlib
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment