From: Michal H. <ms...@gm...> - 2008-03-17 16:38:54
|
Rebased patch after merge from devel-jms-cleanup-1 branch is attached. Nothing else has changed here. Could you review and give it ACK or NAK, so that I can pop it from my patch stack? On Wed, Mar 12, 2008 at 05:49:52PM +0100, Michal Hocko wrote: > Attached patch updates _printDbg macro to be more obvious for usage so > that it is used as any other expresion (like function call). So you have > to put semicolon at all situations when function requires it. > All places where semicolon has to be used and it isn't are correct too. > > > Background: > =========== > Normaly each expression has to be followed by `;' > Original implementation of printDbg, which is used by higher-level macros > (like kernelPrintDbg etc.), used semicolon so user of high-level debug > macros was free to use or not use it. > Moreover, _printDbg uses: > { > if() { > ... > } > } > > This way, however, has several non obvious flaws. > e.g. > if(condition) > kernelPrintDbg(...); > else > something else; > > produces error for kernelPrintDbg because it gets > if() > { > // expanded kernelPrintDbg > }; > else > something else; > > To make it correctly, you have to do: > if(condition) { > kernelPrintDbg(...) // semicolon is can be here > }else > something else; > > > -- > Michal Hocko > Index: src/gui/menu.cc > =================================================================== > RCS file: /cvsroot/pdfedit/pdfedit/src/gui/menu.cc,v > retrieving revision 1.41 > diff -u -p -r1.41 menu.cc > --- src/gui/menu.cc 22 Feb 2008 08:42:05 -0000 1.41 > +++ src/gui/menu.cc 12 Mar 2008 14:03:37 -0000 > @@ -434,7 +434,7 @@ int Menu::addItem(QMenuData *parent,cons > if (s.isNull()) s=""; > if (s.find(accelChar)>=0) { > //Already used > - guiPrintDbg(debug::DBG_WARN,"Accelerator for " << Q_OUT(caption) << " is already used elsewhere!") > + guiPrintDbg(debug::DBG_WARN,"Accelerator for " << Q_OUT(caption) << " is already used elsewhere!"); > } else { > //Not yet used > s=s+accelChar; > Index: src/kernel/cobject.cc > =================================================================== > RCS file: /cvsroot/pdfedit/pdfedit/src/kernel/cobject.cc,v > retrieving revision 1.97 > diff -u -p -r1.97 cobject.cc > --- src/kernel/cobject.cc 22 Feb 2008 08:42:07 -0000 1.97 > +++ src/kernel/cobject.cc 12 Mar 2008 14:03:37 -0000 > @@ -111,7 +111,7 @@ parseStreamToContainer (T& container, :: > utilsPrintDbg (debug::DBG_DBG, "Container length: " << container.size()); > > if (len != container.size()) > - utilsPrintDbg(debug::DBG_ERR, "Stream buffer length ("<<container.size()<<") doesn't match Length value ("<<len<<").") > + utilsPrintDbg(debug::DBG_ERR, "Stream buffer length ("<<container.size()<<") doesn't match Length value ("<<len<<")."); > > assert (len == container.size()); > // Cleanup > Index: src/kernel/cpage.cc > =================================================================== > RCS file: /cvsroot/pdfedit/pdfedit/src/kernel/cpage.cc,v > retrieving revision 1.106 > diff -u -p -r1.106 cpage.cc > --- src/kernel/cpage.cc 22 Feb 2008 08:42:07 -0000 1.106 > +++ src/kernel/cpage.cc 12 Mar 2008 14:03:37 -0000 > @@ -443,7 +443,7 @@ using namespace debug; > } > } > if(!erased) > - kernelPrintDbg(debug::DBG_WARN, "Removed value is not in annotStorage.") > + kernelPrintDbg(debug::DBG_WARN, "Removed value is not in annotStorage."); > }catch(ElementBadTypeException & ) > { > kernelPrintDbg(debug::DBG_WARN, "oldValue dereferenced value is not dictionary."); > Index: src/kernel/cpdf.cc > =================================================================== > RCS file: /cvsroot/pdfedit/pdfedit/src/kernel/cpdf.cc,v > retrieving revision 1.104 > diff -u -p -r1.104 cpdf.cc > --- src/kernel/cpdf.cc 10 Mar 2008 20:15:55 -0000 1.104 > +++ src/kernel/cpdf.cc 12 Mar 2008 14:03:37 -0000 > @@ -1890,7 +1890,7 @@ using namespace debug; > return i->second; > } > > - kernelPrintDbg(DBG_DBG, "No mapping for "<<ref) > + kernelPrintDbg(DBG_DBG, "No mapping for "<<ref); > > // mapping doesn't exist yet, so tries to create one > // fetches object according reference > @@ -2374,7 +2374,7 @@ int CPdf::close(bool saveFlag) > <<strerror(err) << "\""); > } > > - kernelPrintDbg(debug::DBG_INFO, "Instance deleted.") > + kernelPrintDbg(debug::DBG_INFO, "Instance deleted."); > return 0; > } > > @@ -2410,7 +2410,7 @@ using namespace utils; > CPage * page=CPageFactory::getInstance(pageDict_ptr); > shared_ptr<CPage> page_ptr(page); > pageList.insert(PageList::value_type(pos, page_ptr)); > - kernelPrintDbg(DBG_DBG, "New page added to the pageList size="<<pageList.size()) > + kernelPrintDbg(DBG_DBG, "New page added to the pageList size="<<pageList.size()); > > return page_ptr; > } > @@ -2550,7 +2550,7 @@ using namespace utils; > { > // all CPages from this sub tree are removed and invalidated > // difference is set to -getKidsCount value (total page lost) > - kernelPrintDbg(DBG_DBG, "oldValue was intermediate node dictionary.") > + kernelPrintDbg(DBG_DBG, "oldValue was intermediate node dictionary."); > difference = -getKidsCount(oldValue, &nodeCountCache); > > // gets reference of oldValue - which is the root of removed > @@ -2708,7 +2708,7 @@ using namespace utils; > kernelPrintDbg(DBG_DBG, "Original position="<<i->first<<" new="<<i->first+difference); > pageList.insert(PageList::value_type(i->first+difference, i->second)); > } > - kernelPrintDbg(DBG_INFO, "pageList consolidation done.") > + kernelPrintDbg(DBG_INFO, "pageList consolidation done."); > } > > > @@ -3029,7 +3029,7 @@ using namespace utils; > shared_ptr<CDict> newPageDict_ptr=IProperty::getSmartCObjectPtr<CDict>(getIndirectProperty(pageRef)); > shared_ptr<CPage> newPage_ptr(CPageFactory::getInstance(newPageDict_ptr)); > pageList.insert(PageList::value_type(storePostion+append, newPage_ptr)); > - kernelPrintDbg(DBG_DBG, "New page added to the pageList size="<<pageList.size()) > + kernelPrintDbg(DBG_DBG, "New page added to the pageList size="<<pageList.size()); > return newPage_ptr; > } > > Index: src/utils/debug.h > =================================================================== > RCS file: /cvsroot/pdfedit/pdfedit/src/utils/debug.h,v > retrieving revision 1.28 > diff -u -p -r1.28 debug.h > --- src/utils/debug.h 22 Feb 2008 08:42:09 -0000 1.28 > +++ src/utils/debug.h 12 Mar 2008 14:03:37 -0000 > @@ -146,7 +146,7 @@ unsigned int changeDebugLevel(unsigned i > * REMARK: This is a macro, because we want to output line number and file name. > * We can't force GCC to do inlining, we can just give a hint. > */ > -#define printDbg(prefix, dbgLevel,msg) _printDbg((prefix),(dbgLevel),std::cerr,msg); > +#define printDbg(prefix, dbgLevel,msg) _printDbg((prefix),(dbgLevel),std::cerr,msg) > > /** Alias to printDbg for kernel messages. > * @param dbgLevel Priority of message. > @@ -185,16 +185,15 @@ unsigned int changeDebugLevel(unsigned i > * @endcode > */ > #define _printDbg(prefix, level, stream, msg) \ > -{ \ > - if ( debug::debugLevel >= level) \ > - { \ > + do { \ > + if (debug::debugLevel >= level) { \ > (stream) << level <<":"<<prefix<<":" \ > << __FILE__ << ":" << __FUNCTION__ <<":"<< __LINE__ \ > << ": " \ > << msg \ > << std::endl; \ > } \ > -} > + }while(0) > > // ============================================================================= > } // namespace debug > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Pdfedit-devel mailing list > Pdf...@li... > https://lists.sourceforge.net/lists/listinfo/pdfedit-devel -- Michal Hocko |