Index: tools/llvm-objdump/MachODump.cpp =================================================================== --- tools/llvm-objdump/MachODump.cpp +++ tools/llvm-objdump/MachODump.cpp @@ -202,6 +202,28 @@ typedef std::vector DiceTable; typedef DiceTable::iterator dice_table_iterator; +struct XarFile { + xar_t xar; + XarFile(const char *filename, int32_t flags) { + xar = xar_open(filename, flags); + } + ~XarFile() { + xar_close(xar); + } + operator xar_t() { return xar; } +}; + +struct XarIter { + xar_iter_t iter; + XarIter() { + iter = xar_iter_new(); + } + ~XarIter() { + xar_iter_free(iter); + } + operator xar_iter_t() { return iter; } +}; + // This is used to search for a data in code table entry for the PC being // disassembled. The j parameter has the PC in j.first. A single data in code // table entry can cover many bytes for each of its Kind's. So if the offset, @@ -5802,14 +5824,12 @@ } static void PrintXarFilesSummary(const char *XarFilename, xar_t xar) { - xar_iter_t xi; xar_file_t xf; - xar_iter_t xp; const char *key, *type, *mode, *user, *group, *size, *mtime, *name, *m; char *endp; uint32_t mode_value; - xi = xar_iter_new(); + XarIter xi; if (!xi) { errs() << "Can't obtain an xar iterator for xar archive " << XarFilename << "\n"; @@ -5818,7 +5838,7 @@ // Go through the xar's files. for (xf = xar_file_first(xar, xi); xf; xf = xar_file_next(xi)) { - xp = xar_iter_new(); + XarIter xp; if(!xp){ errs() << "Can't obtain an xar iterator for xar archive " << XarFilename << "\n"; @@ -5880,9 +5900,7 @@ if(name != nullptr) outs() << name; outs() << "\n"; - xar_iter_free(xp); } - xar_iter_free(xi); } static void DumpBitcodeSection(MachOObjectFile *O, const char *sect, @@ -5950,15 +5968,15 @@ errs() << XarEC.message() << "\n"; return; } - ToolOutputFile XarFile(XarFilename, FD); - raw_fd_ostream &XarOut = XarFile.os(); + ToolOutputFile XarOutputFile(XarFilename, FD); + raw_fd_ostream &XarOut = XarOutputFile.os(); StringRef XarContents(sect, size); XarOut << XarContents; XarOut.close(); if (XarOut.has_error()) return; - xar_t xar = xar_open(XarFilename.c_str(), READ); + XarFile xar(XarFilename.c_str(), READ); if (!xar) { errs() << "Can't create temporary xar archive " << XarFilename << "\n"; return; @@ -5998,24 +6016,21 @@ outs() << Buffer->getBuffer() << "\n"; // TODO: Go through the xar's files. - xar_iter_t xi = xar_iter_new(); + XarIter xi; if(!xi){ errs() << "Can't obtain an xar iterator for xar archive " << XarFilename.c_str() << "\n"; - xar_close(xar); return; } for(xar_file_t xf = xar_file_first(xar, xi); xf; xf = xar_file_next(xi)){ const char *key; - xar_iter_t xp; const char *member_name, *member_type, *member_size_string; size_t member_size; - xp = xar_iter_new(); + XarIter xp; if(!xp){ errs() << "Can't obtain an xar iterator for xar archive " << XarFilename.c_str() << "\n"; - xar_close(xar); return; } member_name = NULL; @@ -6080,10 +6095,7 @@ } } } - xar_iter_free(xp); } - xar_iter_free(xi); - xar_close(xar); } #endif // defined(HAVE_LIBXAR)