compilerplugins/clang/pahole-all-classes.py | 156 ++++++++++++++-------------- include/svx/nbdtmg.hxx | 6 - package/inc/ThreadedDeflater.hxx | 4 package/source/zipapi/ThreadedDeflater.cxx | 4 registry/source/reflwrit.cxx | 9 - sax/source/tools/CachedOutputStream.hxx | 12 +- sc/inc/colorscale.hxx | 4 sc/inc/pivot.hxx | 12 +- sc/source/core/data/colorscale.cxx | 18 +-- sc/source/core/data/pivot2.cxx | 10 - sc/source/filter/inc/condformatbuffer.hxx | 12 -- vcl/inc/salmenu.hxx | 8 - vcl/inc/unx/gtk/gtksalmenu.hxx | 6 - vcl/inc/wall2.hxx | 6 - vcl/unx/gtk/gtksalmenu.cxx | 8 - 15 files changed, 139 insertions(+), 136 deletions(-)
New commits: commit ea20fcce1dac735a9730ab6672bf60ccec595e71 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Mon Jul 22 16:10:32 2019 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Tue Jul 23 06:46:41 2019 +0200 close some more holes in structures and improve the pahole script so I can just run it once over the whole codebase Change-Id: I7e1775974a3a61f8c0e40646158f01163ace60cc Reviewed-on: https://gerrit.libreoffice.org/76122 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/compilerplugins/clang/pahole-all-classes.py b/compilerplugins/clang/pahole-all-classes.py index ec8d20e767e7..b95b92543427 100755 --- a/compilerplugins/clang/pahole-all-classes.py +++ b/compilerplugins/clang/pahole-all-classes.py @@ -23,10 +23,10 @@ import re # search for all the class names in the file produced by the unusedfields loplugin #a = subprocess.Popen("grep 'definition:' workdir/loplugin.unusedfields.log | sort -u", stdout=subprocess.PIPE, shell=True) -a = subprocess.Popen("cat ../libo/n1", stdout=subprocess.PIPE, shell=True) +a = subprocess.Popen("cat n1", stdout=subprocess.PIPE, shell=True) -classSourceLocDict = dict() classSet = set() +classSourceLocDict = dict() with a.stdout as txt: for line in txt: tokens = line.decode('utf8').strip().split("\t") @@ -36,98 +36,104 @@ with a.stdout as txt: if "anonymous" in className: continue # ignore duplicates if className in classSet: continue - # for now, just check the stuff in /sc/inc - if srcLoc.startswith("a"): - classSourceLocDict[srcLoc] = className - classSet.add(className) + classSet.add(className) + classSourceLocDict[className] = srcLoc a.terminate() -gdbProc = subprocess.Popen("gdb", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) - -stdin = io.TextIOWrapper(gdbProc.stdin, 'utf-8') - -# make gdb load all the debugging info -stdin.write("set confirm off\n") -for filename in sorted(os.listdir('instdir/program')): - if filename.endswith(".so"): - stdin.write("add-symbol-file instdir/program/" + filename + "\n") -stdin.flush() - - # Some of the pahole commands are going to fail, and I cannot read the error stream and the input stream # together because python has no way of (easily) doing a non-blocking read. # So I have to write the commands out using a background thread, and then read the entire resulting # stream out below. -def write_pahole_commands(): - for srcLoc in sorted(classSourceLocDict.keys()): - className = classSourceLocDict[srcLoc] - stdin.write("echo " + className + " " + srcLoc + "\n") +def write_pahole_commands(classes): + for className in classes: + stdin.write("echo " + className + " " + classSourceLocDict[className] + "\n") stdin.write("pahole " + className + "\n") stdin.flush() stdin.write("echo all-done\n") stdin.flush() stdin.close() # only way to make it flush the last echo command -_thread.start_new_thread( write_pahole_commands, () ) - # Use generator because lines often end up merged together in gdb's output, and we need # to split them up, and that creates a mess in the parsing logic. -def read_generator(): +def read_generator(gdbOutput): while True: - line = gdbProc.stdout.readline().decode('utf8').strip() + line = gdbOutput.readline().decode('utf8').strip() for split in line.split("(gdb)"): split = split.strip() if len(split) == 0: continue if "all-done" in split: return yield split -firstLineRegex = re.compile("/\*\s+(\d+)\s+\*/ struct") -fieldLineRegex = re.compile("/\*\s+(\d+)\s+(\d+)\s+\*/ ") -holeLineRegex = re.compile("/\* XXX (\d+) bit hole, try to pack \*/") -# sometimes pahole can't determine the size of a sub-struct, and then it returns bad data -bogusLineRegex = re.compile("/\*\s+\d+\s+0\s+\*/") -structLines = list() -foundHole = False -cumulativeHoleBits = 0 -structSize = 0 -foundBogusLine = False -# pahole doesn't report space at the end of the structure, so work it out myself -sizeOfFields = 0 -for line in read_generator(): - structLines.append(line) - firstLineMatch = firstLineRegex.match(line) - if firstLineMatch: - structSize = int(firstLineMatch.group(1)) - holeLineMatch = holeLineRegex.match(line) - if holeLineMatch: - foundHole = True - cumulativeHoleBits += int(holeLineMatch.group(1)) - fieldLineMatch = fieldLineRegex.match(line) - if fieldLineMatch: - fieldSize = int(fieldLineMatch.group(2)) - sizeOfFields = int(fieldLineMatch.group(1)) + fieldSize - if bogusLineRegex.match(line): - foundBogusLine = True - if line == "}": - # Ignore very large structs, packing those is not going to help much, and - # re-organising them can make them much less readable. - if foundHole and len(structLines) < 12 and structSize < 100 and not foundBogusLine: - # Verify that we have enough hole-space that removing it will result in a structure - # that still satisfies alignment requirements, otherwise the compiler will just put empty - # space at the end of the struct. - # TODO improve detection of the required alignment for a structure - potentialSpace = (cumulativeHoleBits / 8) + (sizeOfFields - structSize) - if potentialSpace >= 8: - for line in structLines: - print(line) - if (sizeOfFields - structSize) > 0: - print("hole at end of struct: " + str(sizeOfFields - structSize)) - # reset state - structLines.clear() - foundHole = False - cumulativeHoleBits = 0 - structSize = 0 - foundBogusLine = False - actualStructSize = 0 +classList = sorted(classSet) + +# Process 200 classes at a time, otherwise gdb's memory usage blows up and kills the machine +# +while len(classList) > 0: + + currClassList = classList[1:200]; + classList = classList[200:] + + gdbProc = subprocess.Popen("gdb", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) + + stdin = io.TextIOWrapper(gdbProc.stdin, 'utf-8') + + # make gdb load all the debugging info + stdin.write("set confirm off\n") + for filename in sorted(os.listdir('instdir/program')): + if filename.endswith(".so"): + stdin.write("add-symbol-file instdir/program/" + filename + "\n") + stdin.flush() + + + _thread.start_new_thread( write_pahole_commands, (currClassList,) ) + + firstLineRegex = re.compile("/\*\s+(\d+)\s+\*/ struct") + fieldLineRegex = re.compile("/\*\s+(\d+)\s+(\d+)\s+\*/ ") + holeLineRegex = re.compile("/\* XXX (\d+) bit hole, try to pack \*/") + # sometimes pahole can't determine the size of a sub-struct, and then it returns bad data + bogusLineRegex = re.compile("/\*\s+\d+\s+0\s+\*/") + structLines = list() + foundHole = False + cumulativeHoleBits = 0 + structSize = 0 + foundBogusLine = False + # pahole doesn't report space at the end of the structure, so work it out myself + sizeOfFields = 0 + for line in read_generator(gdbProc.stdout): + structLines.append(line) + firstLineMatch = firstLineRegex.match(line) + if firstLineMatch: + structSize = int(firstLineMatch.group(1)) + holeLineMatch = holeLineRegex.match(line) + if holeLineMatch: + foundHole = True + cumulativeHoleBits += int(holeLineMatch.group(1)) + fieldLineMatch = fieldLineRegex.match(line) + if fieldLineMatch: + fieldSize = int(fieldLineMatch.group(2)) + sizeOfFields = int(fieldLineMatch.group(1)) + fieldSize + if bogusLineRegex.match(line): + foundBogusLine = True + if line == "}": + # Ignore very large structs, packing those is not going to help much, and + # re-organising them can make them much less readable. + if foundHole and len(structLines) < 12 and structSize < 100 and not foundBogusLine: + # Verify that we have enough hole-space that removing it will result in a structure + # that still satisfies alignment requirements, otherwise the compiler will just put empty + # space at the end of the struct. + # TODO improve detection of the required alignment for a structure + potentialSpace = (cumulativeHoleBits / 8) + (sizeOfFields - structSize) + if potentialSpace >= 8: + for line in structLines: + print(line) + if (sizeOfFields - structSize) > 0: + print("hole at end of struct: " + str(sizeOfFields - structSize)) + # reset state + structLines.clear() + foundHole = False + cumulativeHoleBits = 0 + structSize = 0 + foundBogusLine = False + actualStructSize = 0 -gdbProc.terminate() + gdbProc.terminate() diff --git a/include/svx/nbdtmg.hxx b/include/svx/nbdtmg.hxx index 0131b7d68ecc..c0d61ea92d28 100644 --- a/include/svx/nbdtmg.hxx +++ b/include/svx/nbdtmg.hxx @@ -71,11 +71,11 @@ typedef std::vector< std::shared_ptr<NumSettings_Impl> > NumSettingsArr_Impl; class SVX_DLLPUBLIC BulletsSettings { public: - bool bIsCustomized; + vcl::Font aFont; OUString sDescription; sal_Unicode cBulletChar; - vcl::Font aFont; - BulletsSettings() : bIsCustomized(false), cBulletChar(0) {} + bool bIsCustomized; + BulletsSettings() : cBulletChar(0), bIsCustomized(false) {} }; diff --git a/package/inc/ThreadedDeflater.hxx b/package/inc/ThreadedDeflater.hxx index 7a86fbbd72ca..3bd7e4bc966a 100644 --- a/package/inc/ThreadedDeflater.hxx +++ b/package/inc/ThreadedDeflater.hxx @@ -38,11 +38,11 @@ class ThreadedDeflater final class Task; // Note: All this should be lock-less. Each task writes only to its part // of the data, flags are atomic. + std::vector<std::vector<sal_Int8>> outBuffers; + std::shared_ptr<comphelper::ThreadTaskTag> threadTaskTag; css::uno::Sequence<sal_Int8> inBuffer; int zlibLevel; - std::shared_ptr<comphelper::ThreadTaskTag> threadTaskTag; std::atomic<int> pendingTasksCount; - std::vector<std::vector<sal_Int8>> outBuffers; public: // Unlike with Deflater class, bNoWrap is always true. diff --git a/package/source/zipapi/ThreadedDeflater.cxx b/package/source/zipapi/ThreadedDeflater.cxx index f5fedee0273b..19bbda01bbb7 100644 --- a/package/source/zipapi/ThreadedDeflater.cxx +++ b/package/source/zipapi/ThreadedDeflater.cxx @@ -60,8 +60,8 @@ private: }; ThreadedDeflater::ThreadedDeflater(sal_Int32 nSetLevel) - : zlibLevel(nSetLevel) - , threadTaskTag(comphelper::ThreadPool::createThreadTaskTag()) + : threadTaskTag(comphelper::ThreadPool::createThreadTaskTag()) + , zlibLevel(nSetLevel) , pendingTasksCount(0) { } diff --git a/registry/source/reflwrit.cxx b/registry/source/reflwrit.cxx index 77ae435101ee..afb01d96b213 100644 --- a/registry/source/reflwrit.cxx +++ b/registry/source/reflwrit.cxx @@ -174,16 +174,15 @@ sal_uInt32 writeDouble(sal_uInt8* buffer, double v) struct CPInfo { - CPInfoTag const m_tag; union { const sal_Char* aUtf8; RTUik* aUik; RTConstValueUnion aConst; } m_value; - - sal_uInt16 m_index; struct CPInfo* m_next; + CPInfoTag const m_tag; + sal_uInt16 m_index; CPInfo(CPInfoTag tag, struct CPInfo* prev); @@ -193,9 +192,9 @@ struct CPInfo }; CPInfo::CPInfo(CPInfoTag tag, struct CPInfo* prev) - : m_tag(tag) + : m_next(nullptr) + , m_tag(tag) , m_index(0) - , m_next(nullptr) { if (prev) { diff --git a/sax/source/tools/CachedOutputStream.hxx b/sax/source/tools/CachedOutputStream.hxx index 8eca0a4c84e1..0a2db555752a 100644 --- a/sax/source/tools/CachedOutputStream.hxx +++ b/sax/source/tools/CachedOutputStream.hxx @@ -33,19 +33,19 @@ class CachedOutputStream /// When buffer hits this size, it's written to mxOutputStream static const sal_Int32 mnMaximumSize = 0x10000; + /// ForMerge structure is used for sorting elements in Writer + std::shared_ptr< ForMergeBase > mpForMerge; + const css::uno::Sequence<sal_Int8> mpCache; /// Output stream, usually writing data into files. css::uno::Reference< css::io::XOutputStream > mxOutputStream; - sal_Int32 mnCacheWrittenSize; - const css::uno::Sequence<sal_Int8> mpCache; uno_Sequence *pSeq; + sal_Int32 mnCacheWrittenSize; bool mbWriteToOutStream; - /// ForMerge structure is used for sorting elements in Writer - std::shared_ptr< ForMergeBase > mpForMerge; public: - CachedOutputStream() : mnCacheWrittenSize(0) - , mpCache(mnMaximumSize) + CachedOutputStream() : mpCache(mnMaximumSize) , pSeq(mpCache.get()) + , mnCacheWrittenSize(0) , mbWriteToOutStream(true) {} diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx index aa3e6f6e7e60..236dac698c54 100644 --- a/sc/inc/colorscale.hxx +++ b/sc/inc/colorscale.hxx @@ -43,11 +43,11 @@ class SC_DLLPUBLIC ScColorScaleEntry { private: double mnVal; - Color maColor; std::unique_ptr<ScFormulaCell> mpCell; std::unique_ptr<ScFormulaListener> mpListener; - ScColorScaleEntryType meType; ScConditionalFormat* mpFormat; + Color maColor; + ScColorScaleEntryType meType; void setListener(); diff --git a/sc/inc/pivot.hxx b/sc/inc/pivot.hxx index c374c952641e..2dcb9b2f1e0b 100644 --- a/sc/inc/pivot.hxx +++ b/sc/inc/pivot.hxx @@ -114,13 +114,13 @@ typedef std::vector< std::unique_ptr<ScDPLabelData> > ScDPLabelDataVector; struct ScPivotField { - SCCOL nCol; ///< 0-based dimension index (not source column index) + css::sheet::DataPilotFieldReference maFieldRef; + long mnOriginalDim; ///< >= 0 for duplicated field. PivotFunc nFuncMask; + SCCOL nCol; ///< 0-based dimension index (not source column index) sal_uInt8 mnDupCount; - css::sheet::DataPilotFieldReference maFieldRef; - explicit ScPivotField( SCCOL nNewCol = 0 ); ScPivotField( const ScPivotField& r ); @@ -156,13 +156,13 @@ struct ScPivotParam struct ScPivotFuncData { - SCCOL mnCol; + css::sheet::DataPilotFieldReference maFieldRef; + long mnOriginalDim; PivotFunc mnFuncMask; + SCCOL mnCol; sal_uInt8 mnDupCount; - css::sheet::DataPilotFieldReference maFieldRef; - explicit ScPivotFuncData( SCCOL nCol, PivotFunc nFuncMask ); #if DEBUG_PIVOT_TABLE diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx index 1a932df73b53..3fa03b5b6988 100644 --- a/sc/source/core/data/colorscale.cxx +++ b/sc/source/core/data/colorscale.cxx @@ -151,24 +151,24 @@ bool ScFormulaListener::NeedsRepaint() const ScColorScaleEntry::ScColorScaleEntry(): mnVal(0), - meType(COLORSCALE_VALUE), - mpFormat(nullptr) + mpFormat(nullptr), + meType(COLORSCALE_VALUE) { } ScColorScaleEntry::ScColorScaleEntry(double nVal, const Color& rCol, ScColorScaleEntryType eType): mnVal(nVal), + mpFormat(nullptr), maColor(rCol), - meType(eType), - mpFormat(nullptr) + meType(eType) { } ScColorScaleEntry::ScColorScaleEntry(const ScColorScaleEntry& rEntry): mnVal(rEntry.mnVal), + mpFormat(rEntry.mpFormat), maColor(rEntry.maColor), - meType(rEntry.meType), - mpFormat(rEntry.mpFormat) + meType(rEntry.meType) { setListener(); if(rEntry.mpCell) @@ -181,10 +181,10 @@ ScColorScaleEntry::ScColorScaleEntry(const ScColorScaleEntry& rEntry): ScColorScaleEntry::ScColorScaleEntry(ScDocument* pDoc, const ScColorScaleEntry& rEntry): mnVal(rEntry.mnVal), - maColor(rEntry.maColor), mpCell(), - meType(rEntry.meType), - mpFormat(rEntry.mpFormat) + mpFormat(rEntry.mpFormat), + maColor(rEntry.maColor), + meType(rEntry.meType) { setListener(); if(rEntry.mpCell) diff --git a/sc/source/core/data/pivot2.cxx b/sc/source/core/data/pivot2.cxx index 03c3e16259be..3c1ce479a845 100644 --- a/sc/source/core/data/pivot2.cxx +++ b/sc/source/core/data/pivot2.cxx @@ -74,18 +74,18 @@ OUString const & ScDPLabelData::getDisplayName() const // ScPivotField ScPivotField::ScPivotField(SCCOL nNewCol) : - nCol(nNewCol), mnOriginalDim(-1), nFuncMask(PivotFunc::NONE), + nCol(nNewCol), mnDupCount(0) {} ScPivotField::ScPivotField( const ScPivotField& rPivotField ) : - nCol(rPivotField.nCol), + maFieldRef(rPivotField.maFieldRef), mnOriginalDim(rPivotField.mnOriginalDim), nFuncMask(rPivotField.nFuncMask), - mnDupCount(rPivotField.mnDupCount), - maFieldRef(rPivotField.maFieldRef) + nCol(rPivotField.nCol), + mnDupCount(rPivotField.mnDupCount) {} long ScPivotField::getOriginalDim() const @@ -151,9 +151,9 @@ ScPivotParam& ScPivotParam::operator=( const ScPivotParam& rPivotParam ) // ScPivotFuncData ScPivotFuncData::ScPivotFuncData( SCCOL nCol, PivotFunc nFuncMask ) : - mnCol( nCol ), mnOriginalDim(-1), mnFuncMask(nFuncMask), + mnCol( nCol ), mnDupCount(0) {} diff --git a/sc/source/filter/inc/condformatbuffer.hxx b/sc/source/filter/inc/condformatbuffer.hxx index 8fbca5c0febf..0c79374a203f 100644 --- a/sc/source/filter/inc/condformatbuffer.hxx +++ b/sc/source/filter/inc/condformatbuffer.hxx @@ -235,17 +235,15 @@ private: struct ExCfRuleModel { - ExCfRuleModel() : mbGradient( false ), mnAxisColor( UNSIGNED_RGB_TRANSPARENT ), mnNegativeColor( UNSIGNED_RGB_TRANSPARENT ), mbIsLower( true ) {} - // DataBar - bool mbGradient; - OUString maAxisPosition; + ExCfRuleModel() : mnAxisColor( UNSIGNED_RGB_TRANSPARENT ), mnNegativeColor( UNSIGNED_RGB_TRANSPARENT ), mbGradient( false ), mbIsLower( true ) {} // AxisColor ::Color mnAxisColor; // NegativeFillColor ::Color mnNegativeColor; - // Cfvo - bool mbIsLower; - OUString maColorScaleType; + OUString maAxisPosition; // DataBar + OUString maColorScaleType; // Cfvo + bool mbGradient; // DataBar + bool mbIsLower; // Cfvo }; class ExtCfDataBarRule : public WorksheetHelper diff --git a/vcl/inc/salmenu.hxx b/vcl/inc/salmenu.hxx index 6829e3a623d1..c696503549e6 100644 --- a/vcl/inc/salmenu.hxx +++ b/vcl/inc/salmenu.hxx @@ -29,12 +29,12 @@ class SalFrame; struct SalItemParams { - sal_uInt16 nId; // item Id - MenuItemType eType; // MenuItem-Type - MenuItemBits nBits; // MenuItem-Bits + Image aImage; // Image VclPtr<Menu> pMenu; // Pointer to Menu OUString aText; // Menu-Text - Image aImage; // Image + MenuItemType eType; // MenuItem-Type + sal_uInt16 nId; // item Id + MenuItemBits nBits; // MenuItem-Bits }; struct SalMenuButtonItem diff --git a/vcl/inc/unx/gtk/gtksalmenu.hxx b/vcl/inc/unx/gtk/gtksalmenu.hxx index b973684b21f1..858584398974 100644 --- a/vcl/inc/unx/gtk/gtksalmenu.hxx +++ b/vcl/inc/unx/gtk/gtksalmenu.hxx @@ -158,11 +158,11 @@ public: GtkSalMenuItem( const SalItemParams* ); virtual ~GtkSalMenuItem() override; - sal_uInt16 const mnId; // Item ID - MenuItemType const mnType; // Item type - bool mbVisible; // Item visibility. GtkSalMenu* mpParentMenu; // The menu into which this menu item is inserted GtkSalMenu* mpSubMenu; // Submenu of this item (if defined) + MenuItemType const mnType; // Item type + sal_uInt16 const mnId; // Item ID + bool mbVisible; // Item visibility. }; #endif // INCLUDED_VCL_INC_UNX_GTK_GTKSALMENU_HXX diff --git a/vcl/inc/wall2.hxx b/vcl/inc/wall2.hxx index cad63ee4332d..37cd4fa66812 100644 --- a/vcl/inc/wall2.hxx +++ b/vcl/inc/wall2.hxx @@ -27,12 +27,12 @@ class ImplWallpaper friend class Wallpaper; private: - Color maColor; + boost::optional<tools::Rectangle> mpRect; std::unique_ptr<BitmapEx> mpBitmap; std::unique_ptr<Gradient> mpGradient; - boost::optional<tools::Rectangle> mpRect; - WallpaperStyle meStyle; std::unique_ptr<BitmapEx> mpCache; + Color maColor; + WallpaperStyle meStyle; public: ImplWallpaper(); diff --git a/vcl/unx/gtk/gtksalmenu.cxx b/vcl/unx/gtk/gtksalmenu.cxx index 70edf5f91f9c..150475912a43 100644 --- a/vcl/unx/gtk/gtksalmenu.cxx +++ b/vcl/unx/gtk/gtksalmenu.cxx @@ -1427,11 +1427,11 @@ int GtkSalMenu::GetMenuBarHeight() const */ GtkSalMenuItem::GtkSalMenuItem( const SalItemParams* pItemData ) : - mnId( pItemData->nId ), - mnType( pItemData->eType ), - mbVisible( true ), mpParentMenu( nullptr ), - mpSubMenu( nullptr ) + mpSubMenu( nullptr ), + mnType( pItemData->eType ), + mnId( pItemData->nId ), + mbVisible( true ) { } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits