From fa51d5257828d13e36dad651fc275455cc32463c Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Mon, 9 May 2011 20:22:04 +0200 Subject: [PATCH] Workaround for gcc 4.2.x. g++ 4.2 (and possibly earlier) apparently call a copy constructor when passing a temporary to a function that takes a const reference. Added code to allow copy-constructing the AI*Access classes for this compiler. g++-4.2.x also bails out when it encounters files that do not end on a newline. So, also added those where they were missing. --- indra/llaudio/llaudiodecodemgr.cpp | 2 +- indra/llcommon/aithreadsafe.h | 41 +++++++++++++++++++- indra/newview/ascentfloatercontactgroups.cpp | 2 +- indra/newview/ascentfloatercontactgroups.h | 2 +- indra/newview/ascentprefssys.h | 2 +- indra/newview/dsaparam.cpp | 2 +- indra/newview/emerald.cpp | 2 +- indra/newview/emeraldboobutils.cpp | 2 +- indra/newview/llpanelobject.cpp | 2 +- indra/newview/llphysicsmotion.cpp | 2 +- indra/newview/llpreviewgesture.cpp | 2 +- indra/newview/llpreviewscript.cpp | 2 +- indra/newview/llsavedsettingsglue.cpp | 2 +- indra/newview/qtoolalign.cpp | 2 +- indra/newview/qtoolalign.h | 2 +- indra/newview/scriptcounter.h | 2 +- indra/newview/wlfPanel_AdvSettings.cpp | 2 +- 17 files changed, 55 insertions(+), 18 deletions(-) diff --git a/indra/llaudio/llaudiodecodemgr.cpp b/indra/llaudio/llaudiodecodemgr.cpp index 908eca5a6..41930f539 100644 --- a/indra/llaudio/llaudiodecodemgr.cpp +++ b/indra/llaudio/llaudiodecodemgr.cpp @@ -723,4 +723,4 @@ BOOL LLAudioDecodeMgr::addDecodeRequest(const LLUUID &uuid) } return FALSE; -} \ No newline at end of file +} diff --git a/indra/llcommon/aithreadsafe.h b/indra/llcommon/aithreadsafe.h index 0d0a6ac1d..795c15e0a 100644 --- a/indra/llcommon/aithreadsafe.h +++ b/indra/llcommon/aithreadsafe.h @@ -36,6 +36,11 @@ #include "llthread.h" #include "llerror.h" +// g++ 4.2.x (and before?) have the bug that when you try to pass a temporary +// to a function taking a const reference, it still calls the copy constructor. +// Define this to hack around that. +#define AI_NEED_ACCESS_CC (defined(__GNUC__) && (((__GNUC__ == 4) && (__GNUC_MINOR__ < 3)) || (__GNUC__ < 4))) + template struct AIReadAccessConst; template struct AIReadAccess; template struct AIWriteAccess; @@ -66,6 +71,10 @@ protected: // Accessors. T const* ptr() const { return reinterpret_cast(mMemory); } T* ptr() { return reinterpret_cast(mMemory); } + +#if AI_NEED_ACCESS_CC + int mAccessCopyCount; +#endif }; /** @@ -239,12 +248,18 @@ struct AIReadAccessConst mState(readlocked) { mWrapper.mRWLock.rdlock(); +#if AI_NEED_ACCESS_CC + mWrapper.mAccessCopyCount = 1; +#endif } //! Destruct the AI*Access object. // These should never be dynamically allocated, so there is no need to make this virtual. ~AIReadAccessConst() { +#if AI_NEED_ACCESS_CC + if (--(this->mWrapper.mAccessCopyCount) > 0) return; +#endif if (mState == readlocked) mWrapper.mRWLock.rdunlock(); else if (mState == writelocked) @@ -267,9 +282,14 @@ protected: AIThreadSafe& mWrapper; //!< Reference to the object that we provide access to. state_type const mState; //!< The lock state that mWrapper is in. +#if !AI_NEED_ACCESS_CC private: // Disallow copy constructing directly. AIReadAccessConst(AIReadAccessConst const&); +#else +public: + AIReadAccessConst(AIReadAccessConst const& orig) : mWrapper(orig.mWrapper), mState(orig.mState) { mWrapper.mAccessCopyCount++; } +#endif }; /** @@ -461,7 +481,13 @@ template struct AIAccess { //! Construct a AIAccess from a non-constant AIThreadSafeSimple. - AIAccess(AIThreadSafeSimple& wrapper) : mWrapper(wrapper) { this->mWrapper.mMutex.lock(); } + AIAccess(AIThreadSafeSimple& wrapper) : mWrapper(wrapper) + { + this->mWrapper.mMutex.lock(); +#if AI_NEED_ACCESS_CC + this->mWrapper.mAccessCopyCount = 1; +#endif + } //! Access the underlaying object for (read and) write access. T* operator->() const { return this->mWrapper.ptr(); } @@ -469,14 +495,25 @@ struct AIAccess //! Access the underlaying object for (read and) write access. T& operator*() const { return *this->mWrapper.ptr(); } - ~AIAccess() { this->mWrapper.mMutex.unlock(); } + ~AIAccess() + { +#if AI_NEED_ACCESS_CC + if (--(this->mWrapper.mAccessCopyCount) > 0) return; +#endif + this->mWrapper.mMutex.unlock(); + } protected: AIThreadSafeSimple& mWrapper; //!< Reference to the object that we provide access to. +#if !AI_NEED_ACCESS_CC private: // Disallow copy constructing directly. AIAccess(AIAccess const&); +#else +public: + AIAccess(AIAccess const& orig) : mWrapper(orig.mWrapper) { this->mWrapper.mAccessCopyCount++; } +#endif }; #endif diff --git a/indra/newview/ascentfloatercontactgroups.cpp b/indra/newview/ascentfloatercontactgroups.cpp index 80f8a2204..d4097493d 100644 --- a/indra/newview/ascentfloatercontactgroups.cpp +++ b/indra/newview/ascentfloatercontactgroups.cpp @@ -238,4 +238,4 @@ void ASFloaterContactGroups::populateGroupList() } } } -} \ No newline at end of file +} diff --git a/indra/newview/ascentfloatercontactgroups.h b/indra/newview/ascentfloatercontactgroups.h index ed9fa44f1..809dce781 100644 --- a/indra/newview/ascentfloatercontactgroups.h +++ b/indra/newview/ascentfloatercontactgroups.h @@ -92,4 +92,4 @@ email for me right now, also in all cap. my father not very understand of free softwares and he make a fun of RMS. -*/ \ No newline at end of file +*/ diff --git a/indra/newview/ascentprefssys.h b/indra/newview/ascentprefssys.h index f9e507d9f..d62c9bdf1 100644 --- a/indra/newview/ascentprefssys.h +++ b/indra/newview/ascentprefssys.h @@ -100,4 +100,4 @@ protected: BOOL mSpellDisplay; }; -#endif \ No newline at end of file +#endif diff --git a/indra/newview/dsaparam.cpp b/indra/newview/dsaparam.cpp index e4c89d40e..c7720e61e 100644 --- a/indra/newview/dsaparam.cpp +++ b/indra/newview/dsaparam.cpp @@ -66,4 +66,4 @@ DSA *get_dsa2048() if ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL)) { DSA_free(dsa); return(NULL); } return(dsa); - } \ No newline at end of file + } diff --git a/indra/newview/emerald.cpp b/indra/newview/emerald.cpp index 1d89381cf..c2a31a65f 100644 --- a/indra/newview/emerald.cpp +++ b/indra/newview/emerald.cpp @@ -590,4 +590,4 @@ EDSA::~EDSA() { delete mDSAImpl; mDSAImpl = NULL; -} \ No newline at end of file +} diff --git a/indra/newview/emeraldboobutils.cpp b/indra/newview/emeraldboobutils.cpp index 12b784a7e..6d1238976 100644 --- a/indra/newview/emeraldboobutils.cpp +++ b/indra/newview/emeraldboobutils.cpp @@ -186,4 +186,4 @@ EmeraldBoobState EmeraldBoobUtils::idleUpdate(const EmeraldGlobalBoobConfig &con newState.boobGrav = llclamp(newState.boobGrav, -1.5f, 2.0f); return newState; -} \ No newline at end of file +} diff --git a/indra/newview/llpanelobject.cpp b/indra/newview/llpanelobject.cpp index f6ce2fe3b..9f8561835 100644 --- a/indra/newview/llpanelobject.cpp +++ b/indra/newview/llpanelobject.cpp @@ -2771,4 +2771,4 @@ void LLPanelObject::onPasteRotClip(void* user_data) calcp->setVar(LLCalc::Y_ROT, mClipboardRot.mV[VY]); calcp->setVar(LLCalc::Z_ROT, mClipboardRot.mV[VZ]); self->sendRotation(FALSE); -} \ No newline at end of file +} diff --git a/indra/newview/llphysicsmotion.cpp b/indra/newview/llphysicsmotion.cpp index 18ec57fe7..d69ebd0b2 100644 --- a/indra/newview/llphysicsmotion.cpp +++ b/indra/newview/llphysicsmotion.cpp @@ -847,4 +847,4 @@ void LLPhysicsMotion::reset() mCharacter->setVisualParamWeight((*iter).mParam,(*iter).mParam->getDefaultWeight()); } } -} \ No newline at end of file +} diff --git a/indra/newview/llpreviewgesture.cpp b/indra/newview/llpreviewgesture.cpp index d26c7a64b..1c7a57abc 100644 --- a/indra/newview/llpreviewgesture.cpp +++ b/indra/newview/llpreviewgesture.cpp @@ -1789,4 +1789,4 @@ void LLPreviewGesture::onDonePreview(LLMultiGesture* gesture, void* data) self->mPreviewGesture = NULL; self->refresh(); -} \ No newline at end of file +} diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp index ad54f5009..7b6bab72e 100644 --- a/indra/newview/llpreviewscript.cpp +++ b/indra/newview/llpreviewscript.cpp @@ -2669,4 +2669,4 @@ void LLLiveLSLEditor::saveAs() fclose(fp); fp = NULL; } -// \ No newline at end of file +// diff --git a/indra/newview/llsavedsettingsglue.cpp b/indra/newview/llsavedsettingsglue.cpp index 0e58b5f89..72879837f 100644 --- a/indra/newview/llsavedsettingsglue.cpp +++ b/indra/newview/llsavedsettingsglue.cpp @@ -182,4 +182,4 @@ void LLSavedSettingsGlue::setColor4(const std::string &name, LLColor4 value) gSavedSettings.setColor4(name, value); else gSavedPerAccountSettings.setColor4(name, value); -}*/ \ No newline at end of file +}*/ diff --git a/indra/newview/qtoolalign.cpp b/indra/newview/qtoolalign.cpp index 166c93f6a..b40faef40 100644 --- a/indra/newview/qtoolalign.cpp +++ b/indra/newview/qtoolalign.cpp @@ -626,4 +626,4 @@ void QToolAlign::align() LLSelectMgr::getInstance()->sendMultipleUpdate(UPD_POSITION); -} \ No newline at end of file +} diff --git a/indra/newview/qtoolalign.h b/indra/newview/qtoolalign.h index 168453da4..1bef073ba 100644 --- a/indra/newview/qtoolalign.h +++ b/indra/newview/qtoolalign.h @@ -46,4 +46,4 @@ private: BOOL mForce; }; -#endif // Q_QTOOLALIGN_H \ No newline at end of file +#endif // Q_QTOOLALIGN_H diff --git a/indra/newview/scriptcounter.h b/indra/newview/scriptcounter.h index 3e1f305fd..b1c737189 100644 --- a/indra/newview/scriptcounter.h +++ b/indra/newview/scriptcounter.h @@ -75,4 +75,4 @@ private: static bool doDelete; static std::stringstream sstr; static int countingDone; -}; \ No newline at end of file +}; diff --git a/indra/newview/wlfPanel_AdvSettings.cpp b/indra/newview/wlfPanel_AdvSettings.cpp index 757853c61..aef9e3276 100644 --- a/indra/newview/wlfPanel_AdvSettings.cpp +++ b/indra/newview/wlfPanel_AdvSettings.cpp @@ -178,4 +178,4 @@ void wlfPanel_AdvSettings::onChangePresetName(LLUICtrl* ctrl, void * userData) current_preset = combo_box->getSelectedValue().asString(); LLWaterParamManager::instance()->loadPreset(current_preset); } -} \ No newline at end of file +}