more safer memcpy use
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5813 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
beb0eebd14
commit
90c7eeb3ee
1 changed files with 11 additions and 8 deletions
|
|
@ -24,22 +24,25 @@
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
#ifdef SWIG_UNNAMED_USE_MEMCPY
|
#ifdef SWIG_UNNAMED_USE_MEMCPY
|
||||||
// "dangerous" assigment, but for enums it should work.
|
// safe assigment, for enums it should work.
|
||||||
// it is dangerous because you could get a bad value,
|
#define swig_assign_unnamed(eval, val) \
|
||||||
// but it is safer than "*(T*)(void*)&x = t;", which
|
if(sizeof(eval) == sizeof(val)) \
|
||||||
// could produce a seg. fault.
|
memcpy(&(eval), &(val), sizeof(eval)); \
|
||||||
#define swig_assign_unnamed(eval, val) memcpy(&(eval),&(val), sizeof(eval))
|
else \
|
||||||
|
printf("unnamed member assigment not supported\n")
|
||||||
#else
|
#else
|
||||||
// much much safer choice :)
|
// much much safer choice :)
|
||||||
#define swig_assign_unnamed(eval, val) printf("unnamed member assigment not supported\n")
|
#define swig_assign_unnamed(eval, val) \
|
||||||
|
printf("unnamed member assigment not supported\n")
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else /*** we have a 'good' compiler ***/
|
||||||
|
// This is much safer, but some old compiler could not like it
|
||||||
template <class T, class V>
|
template <class T, class V>
|
||||||
inline
|
inline
|
||||||
void swig_assign_unnamed(T& eval, const V& val)
|
void swig_assign_unnamed(T& eval, const V& val)
|
||||||
{
|
{
|
||||||
// it 'should' be: eval = static_cast<T>(val);
|
// it 'should' be: eval = static_cast<T>(val);
|
||||||
// but just in case we found a very very old compiler
|
// but just in case we found an old compiler
|
||||||
eval = (T)val;
|
eval = (T)val;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue