From f29c5f45f8af33532ec768bae6c826e700139d62 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Mon, 4 Aug 2014 23:45:59 +0900 Subject: [PATCH 1/4] Workaround for 64-bit MP4 atoms. --- ConfigureChecks.cmake | 51 +++++++++++++++++++++++------------------- config.h.cmake | 3 +++ taglib/mp4/mp4atom.cpp | 14 +++++++++--- 3 files changed, 42 insertions(+), 26 deletions(-) diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index bd7c5658..cae533e3 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -20,6 +20,11 @@ if(NOT ${SIZEOF_INT} EQUAL 4) MESSAGE(FATAL_ERROR "TagLib requires that int is 32-bit wide.") endif() +check_type_size("long" SIZEOF_LONG) +if(${SIZEOF_LONG} EQUAL 8) + set(LONG_IS_INT64 1) +endif() + check_type_size("long long" SIZEOF_LONGLONG) if(NOT ${SIZEOF_LONGLONG} EQUAL 8) MESSAGE(FATAL_ERROR "TagLib requires that long long is 64-bit wide.") @@ -66,65 +71,65 @@ endif() check_cxx_source_compiles(" #include - int main() { + int main() { std::atomic x; x.fetch_add(1); x.fetch_sub(1); - return 0; + return 0; } " HAVE_STD_ATOMIC) if(NOT HAVE_STD_ATOMIC) check_cxx_source_compiles(" #include - int main() { + int main() { boost::atomic x(1); x.fetch_add(1); x.fetch_sub(1); - return 0; + return 0; } " HAVE_BOOST_ATOMIC) if(NOT HAVE_BOOST_ATOMIC) check_cxx_source_compiles(" - int main() { + int main() { volatile int x; __sync_add_and_fetch(&x, 1); int y = __sync_sub_and_fetch(&x, 1); - return 0; + return 0; } " HAVE_GCC_ATOMIC) if(NOT HAVE_GCC_ATOMIC) check_cxx_source_compiles(" #include - int main() { + int main() { volatile int32_t x; OSAtomicIncrement32Barrier(&x); int32_t y = OSAtomicDecrement32Barrier(&x); - return 0; + return 0; } " HAVE_MAC_ATOMIC) if(NOT HAVE_MAC_ATOMIC) check_cxx_source_compiles(" #include - int main() { + int main() { volatile LONG x; InterlockedIncrement(&x); LONG y = InterlockedDecrement(&x); - return 0; + return 0; } " HAVE_WIN_ATOMIC) if(NOT HAVE_WIN_ATOMIC) check_cxx_source_compiles(" #include - int main() { + int main() { volatile int x; __sync_add_and_fetch(&x, 1); int y = __sync_sub_and_fetch(&x, 1); - return 0; + return 0; } " HAVE_IA64_ATOMIC) endif() @@ -135,26 +140,26 @@ endif() # Determine which kind of byte swap functions your compiler supports. -# GCC's __builtin_bswap* should be checked individually +# GCC's __builtin_bswap* should be checked individually # because some of them can be missing depends on the GCC version. check_cxx_source_compiles(" int main() { __builtin_bswap16(0); - return 0; + return 0; } " HAVE_GCC_BYTESWAP_16) check_cxx_source_compiles(" int main() { __builtin_bswap32(0); - return 0; + return 0; } " HAVE_GCC_BYTESWAP_32) check_cxx_source_compiles(" int main() { __builtin_bswap64(0); - return 0; + return 0; } " HAVE_GCC_BYTESWAP_64) @@ -165,7 +170,7 @@ if(NOT HAVE_GCC_BYTESWAP_16 OR NOT HAVE_GCC_BYTESWAP_32 OR NOT HAVE_GCC_BYTESWAP __bswap_16(0); __bswap_32(0); __bswap_64(0); - return 0; + return 0; } " HAVE_GLIBC_BYTESWAP) @@ -176,7 +181,7 @@ if(NOT HAVE_GCC_BYTESWAP_16 OR NOT HAVE_GCC_BYTESWAP_32 OR NOT HAVE_GCC_BYTESWAP _byteswap_ushort(0); _byteswap_ulong(0); _byteswap_uint64(0); - return 0; + return 0; } " HAVE_MSC_BYTESWAP) @@ -187,7 +192,7 @@ if(NOT HAVE_GCC_BYTESWAP_16 OR NOT HAVE_GCC_BYTESWAP_32 OR NOT HAVE_GCC_BYTESWAP OSSwapInt16(0); OSSwapInt32(0); OSSwapInt64(0); - return 0; + return 0; } " HAVE_MAC_BYTESWAP) @@ -198,7 +203,7 @@ if(NOT HAVE_GCC_BYTESWAP_16 OR NOT HAVE_GCC_BYTESWAP_32 OR NOT HAVE_GCC_BYTESWAP swap16(0); swap32(0); swap64(0); - return 0; + return 0; } " HAVE_OPENBSD_BYTESWAP) endif() @@ -224,9 +229,9 @@ endif() check_cxx_source_compiles(" #include - int main() { - std::codecvt_utf8_utf16 x; - return 0; + int main() { + std::codecvt_utf8_utf16 x; + return 0; } " HAVE_STD_CODECVT) diff --git a/config.h.cmake b/config.h.cmake index 07abffa6..abecfbfb 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -8,6 +8,9 @@ /* 1 if little-endian, 2 if big-endian. */ #cmakedefine FLOAT_BYTEORDER ${FLOAT_BYTEORDER} +/* Defined if long is 64-bit wide */ +#cmakedefine LONG_IS_INT64 ${LONG_IS_INT64} + /* Defined if your compiler supports some byte swap functions */ #cmakedefine HAVE_GCC_BYTESWAP_16 1 #cmakedefine HAVE_GCC_BYTESWAP_32 1 diff --git a/taglib/mp4/mp4atom.cpp b/taglib/mp4/mp4atom.cpp index 7b87a479..5a304e3f 100644 --- a/taglib/mp4/mp4atom.cpp +++ b/taglib/mp4/mp4atom.cpp @@ -23,6 +23,10 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include "mp4atom.h" @@ -50,9 +54,12 @@ MP4::Atom::Atom(File *file) length = header.toUInt(); - if (length == 1) { + if(length == 1) { const long long longLength = file->readBlock(8).toLongLong(); - if (longLength >= 8 && longLength <= 0xFFFFFFFF) { +#ifdef LONG_IS_INT64 + length = longLength; +#else + if(longLength <= 0xFFFFFFFF) { // The atom has a 64-bit length, but it's actually a 32-bit value length = (long)longLength; } @@ -62,8 +69,9 @@ MP4::Atom::Atom(File *file) file->seek(0, File::End); return; } +#endif } - if (length < 8) { + if(length < 8) { debug("MP4: Invalid atom size"); length = 0; file->seek(0, File::End); From dfbaee4103384954abe712029498054ce29d5d7c Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Tue, 5 Aug 2014 13:52:29 +0900 Subject: [PATCH 2/4] Removed an ambiguous cast from FileNameHandle to FileName. --- taglib/toolkit/tfilestream.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/taglib/toolkit/tfilestream.cpp b/taglib/toolkit/tfilestream.cpp index 93078ae9..0195302a 100644 --- a/taglib/toolkit/tfilestream.cpp +++ b/taglib/toolkit/tfilestream.cpp @@ -85,10 +85,14 @@ namespace #else // _WIN32 - struct FileNameHandle : public std::string + class FileNameHandle { - FileNameHandle(FileName name) : std::string(name) {} - operator FileName () const { return c_str(); } + private: + std::string name; + + public: + FileNameHandle(FileName n) : name(n) {} + FileName toFileName() const { return name.c_str(); } }; typedef FILE* FileHandle; @@ -122,12 +126,10 @@ namespace class FileStream::FileStreamPrivate { public: - FileStreamPrivate(const FileName &fileName) - : file(InvalidFileHandle) - , name(fileName) - , readOnly(true) - { - } + FileStreamPrivate(const FileName &fileName) : + file(InvalidFileHandle), + name(fileName), + readOnly(true) {} FileHandle file; FileNameHandle name; @@ -138,8 +140,8 @@ public: // public members //////////////////////////////////////////////////////////////////////////////// -FileStream::FileStream(FileName fileName, bool openReadOnly) - : d(new FileStreamPrivate(fileName)) +FileStream::FileStream(FileName fileName, bool openReadOnly) : + d(new FileStreamPrivate(fileName)) { // First try with read / write mode, if that fails, fall back to read only. @@ -156,7 +158,7 @@ FileStream::FileStream(FileName fileName, bool openReadOnly) # ifdef _WIN32 debug("Could not open file " + fileName.toString()); # else - debug("Could not open file " + String(static_cast(d->name))); + debug("Could not open file " + String(d->name.toFileName())); # endif } } @@ -171,7 +173,11 @@ FileStream::~FileStream() FileName FileStream::name() const { +# ifdef _WIN32 return d->name; +# else + return d->name.toFileName(); +# endif } ByteVector FileStream::readBlock(ulong length) From 0e6d8617ae38ded8bb9c5d030c4e90a5a5838e5f Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sat, 23 Aug 2014 00:01:11 +0900 Subject: [PATCH 3/4] Revert "Removed an ambiguous cast from FileNameHandle to FileName." This reverts commit 9af7601baee66ed8fa7cac01b5dc272dd2544ee5. --- taglib/toolkit/tfilestream.cpp | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/taglib/toolkit/tfilestream.cpp b/taglib/toolkit/tfilestream.cpp index 0195302a..93078ae9 100644 --- a/taglib/toolkit/tfilestream.cpp +++ b/taglib/toolkit/tfilestream.cpp @@ -85,14 +85,10 @@ namespace #else // _WIN32 - class FileNameHandle + struct FileNameHandle : public std::string { - private: - std::string name; - - public: - FileNameHandle(FileName n) : name(n) {} - FileName toFileName() const { return name.c_str(); } + FileNameHandle(FileName name) : std::string(name) {} + operator FileName () const { return c_str(); } }; typedef FILE* FileHandle; @@ -126,10 +122,12 @@ namespace class FileStream::FileStreamPrivate { public: - FileStreamPrivate(const FileName &fileName) : - file(InvalidFileHandle), - name(fileName), - readOnly(true) {} + FileStreamPrivate(const FileName &fileName) + : file(InvalidFileHandle) + , name(fileName) + , readOnly(true) + { + } FileHandle file; FileNameHandle name; @@ -140,8 +138,8 @@ public: // public members //////////////////////////////////////////////////////////////////////////////// -FileStream::FileStream(FileName fileName, bool openReadOnly) : - d(new FileStreamPrivate(fileName)) +FileStream::FileStream(FileName fileName, bool openReadOnly) + : d(new FileStreamPrivate(fileName)) { // First try with read / write mode, if that fails, fall back to read only. @@ -158,7 +156,7 @@ FileStream::FileStream(FileName fileName, bool openReadOnly) : # ifdef _WIN32 debug("Could not open file " + fileName.toString()); # else - debug("Could not open file " + String(d->name.toFileName())); + debug("Could not open file " + String(static_cast(d->name))); # endif } } @@ -173,11 +171,7 @@ FileStream::~FileStream() FileName FileStream::name() const { -# ifdef _WIN32 return d->name; -# else - return d->name.toFileName(); -# endif } ByteVector FileStream::readBlock(ulong length) From 0731bc7b2e2b532b8dec588313aca73d83ed4955 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Tue, 9 Dec 2014 08:55:46 +0900 Subject: [PATCH 4/4] Remove CMake check for sizeof(long). --- ConfigureChecks.cmake | 5 ----- config.h.cmake | 3 --- taglib/mp4/mp4atom.cpp | 15 ++++++++------- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index cae533e3..99cc1de5 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -20,11 +20,6 @@ if(NOT ${SIZEOF_INT} EQUAL 4) MESSAGE(FATAL_ERROR "TagLib requires that int is 32-bit wide.") endif() -check_type_size("long" SIZEOF_LONG) -if(${SIZEOF_LONG} EQUAL 8) - set(LONG_IS_INT64 1) -endif() - check_type_size("long long" SIZEOF_LONGLONG) if(NOT ${SIZEOF_LONGLONG} EQUAL 8) MESSAGE(FATAL_ERROR "TagLib requires that long long is 64-bit wide.") diff --git a/config.h.cmake b/config.h.cmake index abecfbfb..07abffa6 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -8,9 +8,6 @@ /* 1 if little-endian, 2 if big-endian. */ #cmakedefine FLOAT_BYTEORDER ${FLOAT_BYTEORDER} -/* Defined if long is 64-bit wide */ -#cmakedefine LONG_IS_INT64 ${LONG_IS_INT64} - /* Defined if your compiler supports some byte swap functions */ #cmakedefine HAVE_GCC_BYTESWAP_16 1 #cmakedefine HAVE_GCC_BYTESWAP_32 1 diff --git a/taglib/mp4/mp4atom.cpp b/taglib/mp4/mp4atom.cpp index 5a304e3f..b12f9459 100644 --- a/taglib/mp4/mp4atom.cpp +++ b/taglib/mp4/mp4atom.cpp @@ -56,20 +56,21 @@ MP4::Atom::Atom(File *file) if(length == 1) { const long long longLength = file->readBlock(8).toLongLong(); -#ifdef LONG_IS_INT64 - length = longLength; -#else - if(longLength <= 0xFFFFFFFF) { - // The atom has a 64-bit length, but it's actually a 32-bit value - length = (long)longLength; + if(sizeof(long) == sizeof(long long)) { + length = longLength; } else { + if(longLength <= 0xFFFFFFFF) { + // The atom has a 64-bit length, but it's actually a 32-bit value + length = (long)longLength; + } + else { debug("MP4: 64-bit atoms are not supported"); length = 0; file->seek(0, File::End); return; + } } -#endif } if(length < 8) { debug("MP4: Invalid atom size");