[Kde-games-devel] Legacy code problem in libkdegames/kgame

Albert Astals Cid aacid at kde.org
Sat Dec 31 12:37:06 UTC 2011


El Dijous, 29 de desembre de 2011, a les 13:13:44, Ian Wadham va escriure:
> In libkdegames/kgame there is a header file kgamepropertyarray.h which
> contains a definition for class KGamePropertyArray.  In this class there is
> a method declaration and definition as follows:
> 
>   void sort()
>   {
>     QByteArray b;
>     QDataStream s(b, QIODevice::WriteOnly);
>     ….
>   }
> 
> This compiles in most environments (apparently) but failed to compile when
> I used Macports to port kdegames 4.7.4 to my Apple Macbook.  The offending
> header is referenced by KFourInLine.  I am still investigating the details,
> so I do not yet know whether KFourInline actually uses
> KGamePropertyArray::sort(), but I thought I should draw this problem to the
> KDE Games group's attention, seeing as we are so close to a KDE SC 4.8
> release and (I think I read somewhere) there might be no more releases on
> the KDE SC 4.7 branch.
> 
> What I wonder is whether anyone else has any ideas, fixes or workarounds for
> this?
> 
> I also wonder how this code compiles at all in KDE Games' day-to-day work
> and in KDE SC releases?
> 
> In Qt 4.7, QDataStream can have a constructor with a const QByteArray & and
> no second parameter, so the QByteArray must have read-only mode.  Or it can
> be constructed with a QByteArray * and a second parameter for the mode,
> which can then be ReadOnly, WriteOnly, etc.
> 
> Neither constructor matches the existing code, so whatever compiler Macports
> is using is quite right to flag an error, but why don't other compilers,
> especially the ones KDE releases use?

Ok, now answering with the correct answer :D

gcc seems to be smart enough not to try to compile the template code if noone 
uses it, and since there is no code in KDE using KGamePropertyArray::sort(), 
it does not fail to compile, if you add this patch

Index: /home/kdeunstable/kdegames/kfourinline/src/kwin4doc.cpp                                                                                                                                                                                                                 
===================================================================
--- /home/kdeunstable/kdegames/kfourinline/src/kwin4doc.cpp     (revision 
1266286)
+++ /home/kdeunstable/kdegames/kfourinline/src/kwin4doc.cpp     (working copy)
@@ -75,6 +75,7 @@
 
   // Game initialization
   mField.resize(42);
+  mField.sort();
 
   // ****************************************
   // NOTE: Do not i18n the strings here. They

It will fail to compile in gcc too, thus this means that the sort() function 
is useless because it can not be effectively used at all. 

I will remove KGamePropertyArray::sort() after sending this email.

Albert

> 
> The code in question seems to be a holdover from Qt 3 days.  See:
> http://doc.qt.nokia.com/3.3/qdatastream.html#QDataStream-3
> The constructor with plain QByteArray and a mode was allowed back then.
> 
> All the best, Ian W.
> 
> P.S. I have upgraded my Macbook to OS X 10.7.2 Lion and XCode 4.2.1 and
> am currently re-building all my Macports "ports" of Qt-mac, kdelibs (4.7)
> and kdegames (4.7.4), after upgrading Macports to v. 2.0.3.  I think this
> may be bringing in some newer, tougher compilers, but I have not yet
> investigated that.
> 
> _______________________________________________
> kde-games-devel mailing list
> kde-games-devel at kde.org
> https://mail.kde.org/mailman/listinfo/kde-games-devel


More information about the kde-games-devel mailing list