[taglib] backport fixes for ABI breakage (wrt taglib-1.8) (#1026080, #1027164)
Rex Dieter
rdieter at fedoraproject.org
Tue Nov 26 15:02:13 UTC 2013
commit 00b32434e5b9776da50728a8de4b905e9075131f
Author: Rex Dieter <rdieter at math.unl.edu>
Date: Tue Nov 26 09:02:03 2013 -0600
backport fixes for ABI breakage (wrt taglib-1.8) (#1026080, #1027164)
0002-Fixed-ABI-breakage-in-TagLib-String.patch | 107 +++++++++++++++++++
0003-Rewrote-ByteVector-replace-simpler.patch | 131 ++++++++++++++++++++++++
taglib.spec | 12 ++-
3 files changed, 249 insertions(+), 1 deletions(-)
---
diff --git a/0002-Fixed-ABI-breakage-in-TagLib-String.patch b/0002-Fixed-ABI-breakage-in-TagLib-String.patch
new file mode 100644
index 0000000..930439f
--- /dev/null
+++ b/0002-Fixed-ABI-breakage-in-TagLib-String.patch
@@ -0,0 +1,107 @@
+From 3bf30af66c8fd77a88d9379a0956ddb2fc70dc20 Mon Sep 17 00:00:00 2001
+From: Tsuda Kageyu <tsuda.kageyu at gmail.com>
+Date: Wed, 6 Nov 2013 17:01:21 +0900
+Subject: [PATCH 2/6] Fixed ABI breakage in TagLib::String
+
+---
+ taglib/toolkit/tstring.cpp | 20 ++++++++++++++++++--
+ taglib/toolkit/tstring.h | 12 ++++++++++--
+ tests/test_string.cpp | 14 ++++++++++++++
+ 3 files changed, 42 insertions(+), 4 deletions(-)
+
+diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp
+index 75a9833..fb6e947 100644
+--- a/taglib/toolkit/tstring.cpp
++++ b/taglib/toolkit/tstring.cpp
+@@ -209,8 +209,16 @@ String::String(const std::string &s, Type t)
+ String::String(const wstring &s, Type t)
+ : d(new StringPrivate())
+ {
+- if(t == UTF16 || t == UTF16BE || t == UTF16LE)
++ if(t == UTF16 || t == UTF16BE || t == UTF16LE) {
++ // This looks ugly but needed for the compatibility with TagLib1.8.
++ // Should be removed in TabLib2.0.
++ if (t == UTF16BE)
++ t = WCharByteOrder;
++ else if (t == UTF16LE)
++ t = (WCharByteOrder == UTF16LE ? UTF16BE : UTF16LE);
++
+ copyFromUTF16(s.c_str(), s.length(), t);
++ }
+ else {
+ debug("String::String() -- A TagLib::wstring should not contain Latin1 or UTF-8.");
+ }
+@@ -219,8 +227,16 @@ String::String(const wstring &s, Type t)
+ String::String(const wchar_t *s, Type t)
+ : d(new StringPrivate())
+ {
+- if(t == UTF16 || t == UTF16BE || t == UTF16LE)
++ if(t == UTF16 || t == UTF16BE || t == UTF16LE) {
++ // This looks ugly but needed for the compatibility with TagLib1.8.
++ // Should be removed in TabLib2.0.
++ if (t == UTF16BE)
++ t = WCharByteOrder;
++ else if (t == UTF16LE)
++ t = (WCharByteOrder == UTF16LE ? UTF16BE : UTF16LE);
++
+ copyFromUTF16(s, ::wcslen(s), t);
++ }
+ else {
+ debug("String::String() -- A const wchar_t * should not contain Latin1 or UTF-8.");
+ }
+diff --git a/taglib/toolkit/tstring.h b/taglib/toolkit/tstring.h
+index 57945be..605b9c2 100644
+--- a/taglib/toolkit/tstring.h
++++ b/taglib/toolkit/tstring.h
+@@ -134,13 +134,21 @@ namespace TagLib {
+
+ /*!
+ * Makes a deep copy of the data in \a s.
++ *
++ * /note If \a t is UTF16LE, the byte order of \a s will be swapped regardless
++ * of the CPU byte order. If UTF16BE, it will not be swapped. This behavior
++ * will be changed in TagLib2.0.
+ */
+- String(const wstring &s, Type t = WCharByteOrder);
++ String(const wstring &s, Type t = UTF16BE);
+
+ /*!
+ * Makes a deep copy of the data in \a s.
++ *
++ * /note If \a t is UTF16LE, the byte order of \a s will be swapped regardless
++ * of the CPU byte order. If UTF16BE, it will not be swapped. This behavior
++ * will be changed in TagLib2.0.
+ */
+- String(const wchar_t *s, Type t = WCharByteOrder);
++ String(const wchar_t *s, Type t = UTF16BE);
+
+ /*!
+ * Makes a deep copy of the data in \a c.
+diff --git a/tests/test_string.cpp b/tests/test_string.cpp
+index a815a0b..9a574b3 100644
+--- a/tests/test_string.cpp
++++ b/tests/test_string.cpp
+@@ -75,6 +75,20 @@ public:
+ String unicode3(L"\u65E5\u672C\u8A9E");
+ CPPUNIT_ASSERT(*(unicode3.toCWString() + 1) == L'\u672C');
+
++ String unicode4(L"\u65e5\u672c\u8a9e", String::UTF16BE);
++ CPPUNIT_ASSERT(unicode4[1] == L'\u672c');
++
++ String unicode5(L"\u65e5\u672c\u8a9e", String::UTF16LE);
++ CPPUNIT_ASSERT(unicode5[1] == L'\u2c67');
++
++ wstring stduni = L"\u65e5\u672c\u8a9e";
++
++ String unicode6(stduni, String::UTF16BE);
++ CPPUNIT_ASSERT(unicode6[1] == L'\u672c');
++
++ String unicode7(stduni, String::UTF16LE);
++ CPPUNIT_ASSERT(unicode7[1] == L'\u2c67');
++
+ CPPUNIT_ASSERT(strcmp(String::number(0).toCString(), "0") == 0);
+ CPPUNIT_ASSERT(strcmp(String::number(12345678).toCString(), "12345678") == 0);
+ CPPUNIT_ASSERT(strcmp(String::number(-12345678).toCString(), "-12345678") == 0);
+--
+1.8.4.2
+
diff --git a/0003-Rewrote-ByteVector-replace-simpler.patch b/0003-Rewrote-ByteVector-replace-simpler.patch
new file mode 100644
index 0000000..0b134ec
--- /dev/null
+++ b/0003-Rewrote-ByteVector-replace-simpler.patch
@@ -0,0 +1,131 @@
+From 4a7d31c87bf41c1de21cb725176d5b34c2a95720 Mon Sep 17 00:00:00 2001
+From: Tsuda Kageyu <tsuda.kageyu at gmail.com>
+Date: Thu, 14 Nov 2013 14:05:32 +0900
+Subject: [PATCH 3/6] Rewrote ByteVector::replace() simpler
+
+---
+ taglib/toolkit/tbytevector.cpp | 77 +++++++++++++++---------------------------
+ tests/test_bytevector.cpp | 5 +++
+ 2 files changed, 33 insertions(+), 49 deletions(-)
+
+diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp
+index b658246..566a20f 100644
+--- a/taglib/toolkit/tbytevector.cpp
++++ b/taglib/toolkit/tbytevector.cpp
+@@ -31,6 +31,7 @@
+ #include <iostream>
+ #include <cstdio>
+ #include <cstring>
++#include <cstddef>
+
+ #include <tstring.h>
+ #include <tdebug.h>
+@@ -508,62 +509,40 @@ ByteVector &ByteVector::replace(const ByteVector &pattern, const ByteVector &wit
+ if(pattern.size() == 0 || pattern.size() > size())
+ return *this;
+
+- const uint withSize = with.size();
+- const uint patternSize = pattern.size();
+- int offset = 0;
++ const size_t withSize = with.size();
++ const size_t patternSize = pattern.size();
++ const ptrdiff_t diff = withSize - patternSize;
++
++ size_t offset = 0;
++ while (true)
++ {
++ offset = find(pattern, offset);
++ if(offset == static_cast<size_t>(-1)) // Use npos in taglib2.
++ break;
+
+- if(withSize == patternSize) {
+- // I think this case might be common enough to optimize it
+ detach();
+- offset = find(pattern);
+- while(offset >= 0) {
+- ::memcpy(data() + offset, with.data(), withSize);
+- offset = find(pattern, offset + withSize);
+- }
+- return *this;
+- }
+
+- // calculate new size:
+- uint newSize = 0;
+- for(;;) {
+- int next = find(pattern, offset);
+- if(next < 0) {
+- if(offset == 0)
+- // pattern not found, do nothing:
+- return *this;
+- newSize += size() - offset;
+- break;
++ if(diff < 0) {
++ ::memmove(
++ data() + offset + withSize,
++ data() + offset + patternSize,
++ size() - offset - patternSize);
++ resize(size() + diff);
+ }
+- newSize += (next - offset) + withSize;
+- offset = next + patternSize;
+- }
+-
+- // new private data of appropriate size:
+- ByteVectorPrivate *newData = new ByteVectorPrivate(newSize, 0);
+- char *target = DATA(newData);
+- const char *source = data();
+-
+- // copy modified data into new private data:
+- offset = 0;
+- for(;;) {
+- int next = find(pattern, offset);
+- if(next < 0) {
+- ::memcpy(target, source + offset, size() - offset);
+- break;
++ else if(diff > 0) {
++ resize(size() + diff);
++ ::memmove(
++ data() + offset + withSize,
++ data() + offset + patternSize,
++ size() - diff - offset - patternSize);
+ }
+- int chunkSize = next - offset;
+- ::memcpy(target, source + offset, chunkSize);
+- target += chunkSize;
+- ::memcpy(target, with.data(), withSize);
+- target += withSize;
+- offset += chunkSize + patternSize;
+- }
+
+- // replace private data:
+- if(d->deref())
+- delete d;
++ ::memcpy(data() + offset, with.data(), with.size());
+
+- d = newData;
++ offset += withSize;
++ if(offset > size() - patternSize)
++ break;
++ }
+
+ return *this;
+ }
+diff --git a/tests/test_bytevector.cpp b/tests/test_bytevector.cpp
+index 9efd23a..eca74f8 100644
+--- a/tests/test_bytevector.cpp
++++ b/tests/test_bytevector.cpp
+@@ -239,6 +239,11 @@ public:
+ a.replace(ByteVector("ab"), ByteVector());
+ CPPUNIT_ASSERT_EQUAL(ByteVector("cdf"), a);
+ }
++ {
++ ByteVector a("abcdabf");
++ a.replace(ByteVector("bf"), ByteVector("x"));
++ CPPUNIT_ASSERT_EQUAL(ByteVector("abcdax"), a);
++ }
+ }
+
+ };
+--
+1.8.4.2
+
diff --git a/taglib.spec b/taglib.spec
index 7778f62..56f04f9 100644
--- a/taglib.spec
+++ b/taglib.spec
@@ -6,7 +6,7 @@
Name: taglib
Summary: Audio Meta-Data Library
Version: 1.9.1
-Release: 1%{?dist}
+Release: 2%{?dist}
License: LGPLv2 and MPL
#URL: http://launchpad.net/taglib
@@ -25,6 +25,10 @@ Patch1: taglib-1.5b1-multilib.patch
# try 2, kiss omit -L%_libdir
Patch2: taglib-1.5rc1-multilib.patch
+## upstream patches
+Patch1002: 0002-Fixed-ABI-breakage-in-TagLib-String.patch
+Patch1003: 0003-Rewrote-ByteVector-replace-simpler.patch
+
BuildRequires: cmake
BuildRequires: pkgconfig
BuildRequires: zlib-devel
@@ -65,6 +69,9 @@ Files needed when building software with %{name}.
## omit for now
%patch2 -p1 -b .multilib
+%patch1002 -p1 -b .0002
+%patch1003 -p1 -b .0003
+
%build
mkdir -p %{_target_platform}
@@ -128,6 +135,9 @@ make check -C %{_target_platform}
%changelog
+* Tue Nov 26 2013 Rex Dieter <rdieter at fedoraproject.org> 1.9.1-2
+- backport fixes for ABI breakage (wrt taglib-1.8) (#1026080, #1027164)
+
* Tue Oct 08 2013 Rex Dieter <rdieter at fedoraproject.org> 1.9.1-1
- taglib-1.9.1
More information about the scm-commits
mailing list