summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarseny.kapoulkine@gmail.com <arseny.kapoulkine@gmail.com@99668b35-9821-0410-8761-19e4c4f06640>2012-03-20 07:07:01 +0000
committerarseny.kapoulkine@gmail.com <arseny.kapoulkine@gmail.com@99668b35-9821-0410-8761-19e4c4f06640>2012-03-20 07:07:01 +0000
commit5e8e325d856b52d44452155f456ac4182908c958 (patch)
tree279f4506c2c68fa2c5fbe51ac1f1a643a7f5c0b5
parent3a282e2f0b21ec01626e76fa94ef0579b5326f8d (diff)
Fixed strict aliasing violation warning in output buffer conversion via union. Fixed BlackBerry NDK -O3 compilation in header-only wchar mode.
git-svn-id: http://pugixml.googlecode.com/svn/trunk@869 99668b35-9821-0410-8761-19e4c4f06640
-rw-r--r--src/pugiconfig.hpp4
-rw-r--r--src/pugixml.cpp33
2 files changed, 22 insertions, 15 deletions
diff --git a/src/pugiconfig.hpp b/src/pugiconfig.hpp
index 465fd21..cd9bc63 100644
--- a/src/pugiconfig.hpp
+++ b/src/pugiconfig.hpp
@@ -33,8 +33,8 @@
// In absence of PUGIXML_CLASS/PUGIXML_FUNCTION definitions PUGIXML_API is used instead
// Uncomment this to switch to header-only version
-// #define PUGIXML_HEADER_ONLY
-// #include "pugixml.cpp"
+#define PUGIXML_HEADER_ONLY
+#include "pugixml.cpp"
// Tune these constants to adjust memory-related behavior
// #define PUGIXML_MEMORY_PAGE_SIZE 32768
diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index 2c0efa4..a323d32 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -2685,12 +2685,12 @@ PUGI__NS_BEGIN
return (sizeof(wchar_t) == 2 && static_cast<unsigned int>(static_cast<uint16_t>(data[length - 1]) - 0xD800) < 0x400) ? length - 1 : length;
}
- PUGI__FN size_t convert_buffer(void* result, const char_t* data, size_t length, xml_encoding encoding)
+ PUGI__FN size_t convert_buffer(char_t* r_char, uint8_t* r_u8, uint16_t* r_u16, uint32_t* r_u32, const char_t* data, size_t length, xml_encoding encoding)
{
// only endian-swapping is required
if (need_endian_swap_utf(encoding, get_wchar_encoding()))
{
- convert_wchar_endian_swap(reinterpret_cast<char_t*>(result), data, length);
+ convert_wchar_endian_swap(r_char, data, length);
return length * sizeof(char_t);
}
@@ -2698,7 +2698,7 @@ PUGI__NS_BEGIN
// convert to utf8
if (encoding == encoding_utf8)
{
- uint8_t* dest = reinterpret_cast<uint8_t*>(result);
+ uint8_t* dest = r_u8;
uint8_t* end = utf_decoder<utf8_writer>::decode_wchar_block(data, length, dest);
return static_cast<size_t>(end - dest);
@@ -2707,7 +2707,7 @@ PUGI__NS_BEGIN
// convert to utf16
if (encoding == encoding_utf16_be || encoding == encoding_utf16_le)
{
- uint16_t* dest = reinterpret_cast<uint16_t*>(result);
+ uint16_t* dest = r_u16;
// convert to native utf16
uint16_t* end = utf_decoder<utf16_writer>::decode_wchar_block(data, length, dest);
@@ -2723,7 +2723,7 @@ PUGI__NS_BEGIN
// convert to utf32
if (encoding == encoding_utf32_be || encoding == encoding_utf32_le)
{
- uint32_t* dest = reinterpret_cast<uint32_t*>(result);
+ uint32_t* dest = r_u32;
// convert to native utf32
uint32_t* end = utf_decoder<utf32_writer>::decode_wchar_block(data, length, dest);
@@ -2739,7 +2739,7 @@ PUGI__NS_BEGIN
// convert to latin1
if (encoding == encoding_latin1)
{
- uint8_t* dest = reinterpret_cast<uint8_t*>(result);
+ uint8_t* dest = r_u8;
uint8_t* end = utf_decoder<latin1_writer>::decode_wchar_block(data, length, dest);
return static_cast<size_t>(end - dest);
@@ -2765,11 +2765,11 @@ PUGI__NS_BEGIN
return length;
}
- PUGI__FN size_t convert_buffer(void* result, const char_t* data, size_t length, xml_encoding encoding)
+ PUGI__FN size_t convert_buffer(char_t* /* r_char */, uint8_t* r_u8, uint16_t* r_u16, uint32_t* r_u32, const char_t* data, size_t length, xml_encoding encoding)
{
if (encoding == encoding_utf16_be || encoding == encoding_utf16_le)
{
- uint16_t* dest = reinterpret_cast<uint16_t*>(result);
+ uint16_t* dest = r_u16;
// convert to native utf16
uint16_t* end = utf_decoder<utf16_writer>::decode_utf8_block(reinterpret_cast<const uint8_t*>(data), length, dest);
@@ -2784,7 +2784,7 @@ PUGI__NS_BEGIN
if (encoding == encoding_utf32_be || encoding == encoding_utf32_le)
{
- uint32_t* dest = reinterpret_cast<uint32_t*>(result);
+ uint32_t* dest = r_u32;
// convert to native utf32
uint32_t* end = utf_decoder<utf32_writer>::decode_utf8_block(reinterpret_cast<const uint8_t*>(data), length, dest);
@@ -2799,7 +2799,7 @@ PUGI__NS_BEGIN
if (encoding == encoding_latin1)
{
- uint8_t* dest = reinterpret_cast<uint8_t*>(result);
+ uint8_t* dest = r_u8;
uint8_t* end = utf_decoder<latin1_writer>::decode_utf8_block(reinterpret_cast<const uint8_t*>(data), length, dest);
return static_cast<size_t>(end - dest);
@@ -2842,11 +2842,11 @@ PUGI__NS_BEGIN
else
{
// convert chunk
- size_t result = convert_buffer(scratch, data, size, encoding);
+ size_t result = convert_buffer(scratch.data_char, scratch.data_u8, scratch.data_u16, scratch.data_u32, data, size, encoding);
assert(result <= sizeof(scratch));
// write data
- writer.write(scratch, result);
+ writer.write(scratch.data_u8, result);
}
}
@@ -2975,7 +2975,14 @@ PUGI__NS_BEGIN
};
char_t buffer[bufcapacity];
- char scratch[4 * bufcapacity];
+
+ union
+ {
+ uint8_t data_u8[4 * bufcapacity];
+ uint16_t data_u16[2 * bufcapacity];
+ uint32_t data_u32[bufcapacity];
+ char_t data_char[bufcapacity];
+ } scratch;
xml_writer& writer;
size_t bufsize;