From fdb8a6b0650f216ee1e31ab3562e2bc6a9648c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Lalinsk=C3=BD?= Date: Thu, 20 Jun 2013 15:07:25 +0200 Subject: [PATCH 1/2] Reintroduce HAVE_CONFIG_H so that TagLib can be built without CMake --- CMakeLists.txt | 1 + bindings/c/tag_c.cpp | 1 - taglib/asf/asfproperties.cpp | 1 - taglib/asf/asftag.cpp | 1 - taglib/fileref.cpp | 2 -- taglib/mp4/mp4properties.cpp | 1 - taglib/mp4/mp4tag.cpp | 1 - taglib/mpeg/id3v2/id3v2frame.cpp | 5 +++-- taglib/mpeg/id3v2/id3v2framefactory.cpp | 6 ++++-- taglib/mpeg/id3v2/id3v2tag.cpp | 4 ++++ taglib/toolkit/tbytevector.cpp | 4 +++- taglib/toolkit/tdebug.cpp | 4 +++- taglib/toolkit/trefcounter.cpp | 5 ++++- taglib/toolkit/tstring.cpp | 4 +++- tests/test_id3v2.cpp | 5 ++++- tests/utils.h | 4 +++- 16 files changed, 32 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 91e1901d..f410e098 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ option(BUILD_EXAMPLES "Build the examples" OFF) option(NO_ITUNES_HACKS "Disable workarounds for iTunes bugs" OFF) +add_definitions(-DHAVE_CONFIG_H) set(TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests/") ## the following are directories where stuff will be installed to diff --git a/bindings/c/tag_c.cpp b/bindings/c/tag_c.cpp index 5b739d6f..2ae8c7dd 100644 --- a/bindings/c/tag_c.cpp +++ b/bindings/c/tag_c.cpp @@ -19,7 +19,6 @@ * USA * ***************************************************************************/ -#include "taglib_config.h" #include #include #include diff --git a/taglib/asf/asfproperties.cpp b/taglib/asf/asfproperties.cpp index 638baf6e..b82c131a 100644 --- a/taglib/asf/asfproperties.cpp +++ b/taglib/asf/asfproperties.cpp @@ -23,7 +23,6 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#include "taglib_config.h" #include #include #include "asfproperties.h" diff --git a/taglib/asf/asftag.cpp b/taglib/asf/asftag.cpp index 0767817f..c07abe94 100644 --- a/taglib/asf/asftag.cpp +++ b/taglib/asf/asftag.cpp @@ -23,7 +23,6 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#include "taglib_config.h" #include #include "asftag.h" diff --git a/taglib/fileref.cpp b/taglib/fileref.cpp index d13a2837..4403a5fb 100644 --- a/taglib/fileref.cpp +++ b/taglib/fileref.cpp @@ -27,8 +27,6 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#include "taglib_config.h" - #include #include #include diff --git a/taglib/mp4/mp4properties.cpp b/taglib/mp4/mp4properties.cpp index d704b452..058cc61c 100644 --- a/taglib/mp4/mp4properties.cpp +++ b/taglib/mp4/mp4properties.cpp @@ -23,7 +23,6 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#include "taglib_config.h" #include #include #include "mp4file.h" diff --git a/taglib/mp4/mp4tag.cpp b/taglib/mp4/mp4tag.cpp index 1edeace7..bbe3301d 100644 --- a/taglib/mp4/mp4tag.cpp +++ b/taglib/mp4/mp4tag.cpp @@ -23,7 +23,6 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#include "taglib_config.h" #include #include #include diff --git a/taglib/mpeg/id3v2/id3v2frame.cpp b/taglib/mpeg/id3v2/id3v2frame.cpp index 424ac2d2..c5c5585d 100644 --- a/taglib/mpeg/id3v2/id3v2frame.cpp +++ b/taglib/mpeg/id3v2/id3v2frame.cpp @@ -23,8 +23,9 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#include "config.h" -#include "taglib_config.h" +#ifdef HAVE_CONFIG_H +#include +#endif #if HAVE_ZLIB #include diff --git a/taglib/mpeg/id3v2/id3v2framefactory.cpp b/taglib/mpeg/id3v2/id3v2framefactory.cpp index 3138f90a..3371ca7d 100644 --- a/taglib/mpeg/id3v2/id3v2framefactory.cpp +++ b/taglib/mpeg/id3v2/id3v2framefactory.cpp @@ -23,8 +23,10 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#include "config.h" -#include "taglib_config.h" +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include "id3v2framefactory.h" diff --git a/taglib/mpeg/id3v2/id3v2tag.cpp b/taglib/mpeg/id3v2/id3v2tag.cpp index a1b169e1..57637a36 100644 --- a/taglib/mpeg/id3v2/id3v2tag.cpp +++ b/taglib/mpeg/id3v2/id3v2tag.cpp @@ -23,6 +23,10 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include "id3v2tag.h" diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index 631acc87..63bce4cc 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -23,7 +23,9 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#include "config.h" +#ifdef HAVE_CONFIG_H +#include +#endif #include #include diff --git a/taglib/toolkit/tdebug.cpp b/taglib/toolkit/tdebug.cpp index 65c51efe..71350af7 100644 --- a/taglib/toolkit/tdebug.cpp +++ b/taglib/toolkit/tdebug.cpp @@ -23,7 +23,9 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#include "config.h" +#ifdef HAVE_CONFIG_H +#include +#endif #include "tdebug.h" #include "tstring.h" diff --git a/taglib/toolkit/trefcounter.cpp b/taglib/toolkit/trefcounter.cpp index 327d7245..71f3c2f2 100644 --- a/taglib/toolkit/trefcounter.cpp +++ b/taglib/toolkit/trefcounter.cpp @@ -23,7 +23,10 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#include "config.h" +#ifdef HAVE_CONFIG_H +#include +#endif + #include "trefcounter.h" #if defined(HAVE_STD_ATOMIC) diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index 7b4d2040..8fcbb2de 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -25,7 +25,9 @@ // This class assumes that std::basic_string has a contiguous and null-terminated buffer. -#include "config.h" +#ifdef HAVE_CONFIG_H +#include +#endif #include "tstring.h" #include "tdebug.h" diff --git a/tests/test_id3v2.cpp b/tests/test_id3v2.cpp index 42d0f138..9f5ffe01 100644 --- a/tests/test_id3v2.cpp +++ b/tests/test_id3v2.cpp @@ -1,6 +1,9 @@ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include -#include // so evil :( #define protected public #include diff --git a/tests/utils.h b/tests/utils.h index a2d997eb..00cef628 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -1,4 +1,6 @@ -#include "config.h" +#ifdef HAVE_CONFIG_H +#include +#endif #ifdef _WIN32 #include From 5051010835df7c31d03e170fa07eebae2fad5873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Lalinsk=C3=BD?= Date: Thu, 20 Jun 2013 15:22:06 +0200 Subject: [PATCH 2/2] Move byteSwap to a (private) shared include file, rather than having the same code in tstring.cpp and tbytevector.cpp --- taglib/toolkit/tbytevector.cpp | 123 +-------------------------- taglib/toolkit/tstring.cpp | 39 +-------- taglib/toolkit/tutils.h | 151 +++++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+), 158 deletions(-) create mode 100644 taglib/toolkit/tutils.h diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index 63bce4cc..0ea7517c 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -31,19 +31,10 @@ #include #include -#if defined(HAVE_MSC_BYTESWAP) -# include -#elif defined(HAVE_GLIBC_BYTESWAP) -# include -#elif defined(HAVE_MAC_BYTESWAP) -# include -#elif defined(HAVE_OPENBSD_BYTESWAP) -# include -#endif - #include #include #include "trefcounter.h" +#include "tutils.h" #include "tbytevector.h" @@ -190,114 +181,6 @@ int findVector( return -1; } -template -T byteSwap(T x) -{ - // There should be all counterparts of to*() and from*() overloads for integral types. - debug("byteSwap() -- Non specialized version should not be called"); - return 0; -} - -template <> -ushort byteSwap(ushort x) -{ -#if defined(HAVE_GCC_BYTESWAP_16) - - return __builtin_bswap16(x); - -#elif defined(HAVE_MSC_BYTESWAP) - - return _byteswap_ushort(x); - -#elif defined(HAVE_GLIBC_BYTESWAP) - - return __bswap_16(x); - -#elif defined(HAVE_MAC_BYTESWAP) - - return OSSwapInt16(x); - -#elif defined(HAVE_OPENBSD_BYTESWAP) - - return swap16(x); - -#else - - return ((x >> 8) & 0xff) | ((x & 0xff) << 8); - -#endif -} - -template <> -uint byteSwap(uint x) -{ -#if defined(HAVE_GCC_BYTESWAP_32) - - return __builtin_bswap32(x); - -#elif defined(HAVE_MSC_BYTESWAP) - - return _byteswap_ulong(x); - -#elif defined(HAVE_GLIBC_BYTESWAP) - - return __bswap_32(x); - -#elif defined(HAVE_MAC_BYTESWAP) - - return OSSwapInt32(x); - -#elif defined(HAVE_OPENBSD_BYTESWAP) - - return swap32(x); - -#else - - return ((x & 0xff000000u) >> 24) - | ((x & 0x00ff0000u) >> 8) - | ((x & 0x0000ff00u) << 8) - | ((x & 0x000000ffu) << 24); - -#endif -} - -template <> -ulonglong byteSwap(ulonglong x) -{ -#if defined(HAVE_GCC_BYTESWAP_64) - - return __builtin_bswap64(x); - -#elif defined(HAVE_MSC_BYTESWAP) - - return _byteswap_uint64(x); - -#elif defined(HAVE_GLIBC_BYTESWAP) - - return __bswap_64(x); - -#elif defined(HAVE_MAC_BYTESWAP) - - return OSSwapInt64(x); - -#elif defined(HAVE_OPENBSD_BYTESWAP) - - return swap64(x); - -#else - - return ((x & 0xff00000000000000ull) >> 56) - | ((x & 0x00ff000000000000ull) >> 40) - | ((x & 0x0000ff0000000000ull) >> 24) - | ((x & 0x000000ff00000000ull) >> 8) - | ((x & 0x00000000ff000000ull) << 8) - | ((x & 0x0000000000ff0000ull) << 24) - | ((x & 0x000000000000ff00ull) << 40) - | ((x & 0x00000000000000ffull) << 56); - -#endif -} - template T toNumber(const ByteVector &v, size_t offset, size_t length, bool mostSignificantByteFirst) { @@ -333,7 +216,7 @@ T toNumber(const ByteVector &v, size_t offset, bool mostSignificantByteFirst) const bool swap != mostSignificantByteFirst; #endif if(swap) - return byteSwap(tmp); + return byteSwap(tmp); else return tmp; } @@ -349,7 +232,7 @@ ByteVector fromNumber(T value, bool mostSignificantByteFirst) const bool swap != mostSignificantByteFirst; #endif if(swap) - value = byteSwap(value); + value = byteSwap(value); return ByteVector(reinterpret_cast(&value), size); } diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index 8fcbb2de..d28855b8 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -33,21 +33,12 @@ #include "tdebug.h" #include "tstringlist.h" #include "trefcounter.h" +#include "tutils.h" #include #include #include -#if defined(HAVE_MSC_BYTESWAP) -# include -#elif defined(HAVE_GLIBC_BYTESWAP) -# include -#elif defined(HAVE_MAC_BYTESWAP) -# include -#elif defined(HAVE_OPENBSD_BYTESWAP) -# include -#endif - #ifdef HAVE_STD_CODECVT # include #else @@ -56,34 +47,6 @@ namespace { - inline TagLib::ushort byteSwap(TagLib::ushort x) - { -#if defined(HAVE_GCC_BYTESWAP_16) - - return __builtin_bswap16(x); - -#elif defined(HAVE_MSC_BYTESWAP) - - return _byteswap_ushort(x); - -#elif defined(HAVE_GLIBC_BYTESWAP) - - return __bswap_16(x); - -#elif defined(HAVE_MAC_BYTESWAP) - - return OSSwapInt16(x); - -#elif defined(HAVE_OPENBSD_BYTESWAP) - - return swap16(x); - -#else - - return ((x >> 8) & 0xff) | ((x & 0xff) << 8); - -#endif - } inline unsigned short combine(unsigned char c1, unsigned char c2) { diff --git a/taglib/toolkit/tutils.h b/taglib/toolkit/tutils.h new file mode 100644 index 00000000..73c35716 --- /dev/null +++ b/taglib/toolkit/tutils.h @@ -0,0 +1,151 @@ +/*************************************************************************** + copyright : (C) 2013 by Tsuda Kageyu + email : tsuda.kageyu@gmail.com + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + +#ifndef TAGLIB_TUTILS_H +#define TAGLIB_TUTILS_H + +// THIS FILE IS NOT A PART OF THE TAGLIB API + +#ifndef DO_NOT_DOCUMENT // tell Doxygen not to document this header + +#ifdef HAVE_CONFIG_H +#include +#endif + +#if defined(HAVE_MSC_BYTESWAP) +# include +#elif defined(HAVE_GLIBC_BYTESWAP) +# include +#elif defined(HAVE_MAC_BYTESWAP) +# include +#elif defined(HAVE_OPENBSD_BYTESWAP) +# include +#endif + +namespace TagLib +{ + + inline ushort byteSwap(ushort x) + { +#if defined(HAVE_GCC_BYTESWAP_16) + + return __builtin_bswap16(x); + +#elif defined(HAVE_MSC_BYTESWAP) + + return _byteswap_ushort(x); + +#elif defined(HAVE_GLIBC_BYTESWAP) + + return __bswap_16(x); + +#elif defined(HAVE_MAC_BYTESWAP) + + return OSSwapInt16(x); + +#elif defined(HAVE_OPENBSD_BYTESWAP) + + return swap16(x); + +#else + + return ((x >> 8) & 0xff) | ((x & 0xff) << 8); + +#endif + } + + inline uint byteSwap(uint x) + { +#if defined(HAVE_GCC_BYTESWAP_32) + + return __builtin_bswap32(x); + +#elif defined(HAVE_MSC_BYTESWAP) + + return _byteswap_ulong(x); + +#elif defined(HAVE_GLIBC_BYTESWAP) + + return __bswap_32(x); + +#elif defined(HAVE_MAC_BYTESWAP) + + return OSSwapInt32(x); + +#elif defined(HAVE_OPENBSD_BYTESWAP) + + return swap32(x); + +#else + + return ((x & 0xff000000u) >> 24) + | ((x & 0x00ff0000u) >> 8) + | ((x & 0x0000ff00u) << 8) + | ((x & 0x000000ffu) << 24); + +#endif + } + + inline ulonglong byteSwap(ulonglong x) + { +#if defined(HAVE_GCC_BYTESWAP_64) + + return __builtin_bswap64(x); + +#elif defined(HAVE_MSC_BYTESWAP) + + return _byteswap_uint64(x); + +#elif defined(HAVE_GLIBC_BYTESWAP) + + return __bswap_64(x); + +#elif defined(HAVE_MAC_BYTESWAP) + + return OSSwapInt64(x); + +#elif defined(HAVE_OPENBSD_BYTESWAP) + + return swap64(x); + +#else + + return ((x & 0xff00000000000000ull) >> 56) + | ((x & 0x00ff000000000000ull) >> 40) + | ((x & 0x0000ff0000000000ull) >> 24) + | ((x & 0x000000ff00000000ull) >> 8) + | ((x & 0x00000000ff000000ull) << 8) + | ((x & 0x0000000000ff0000ull) << 24) + | ((x & 0x000000000000ff00ull) << 40) + | ((x & 0x00000000000000ffull) << 56); + +#endif + } + +}; + +#endif + +#endif