From c38370d1c3dc594b17c53c28582f8092a15901d9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Mon, 3 Nov 2003 17:47:28 +0000 Subject: [PATCH] the exception safety patch git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8020 a592a061-630c-0410-9148-cb99ea01b6c8 --- po/POTFILES.in | 1 - src/ChangeLog | 26 +++++++++- src/MenuBackend.C | 5 +- src/Thesaurus.C | 5 +- src/buffer.C | 4 +- src/bufferlist.C | 7 +-- src/factory.C | 95 +++++++++++++++++++------------------ src/insets/ChangeLog | 17 +++++++ src/insets/insetbibitem.C | 2 +- src/insets/insetexternal.C | 12 ++--- src/insets/insethfill.C | 2 +- src/insets/insetinclude.C | 2 +- src/insets/insettabular.C | 30 ++++++------ src/insets/insettext.C | 3 +- src/insets/insettheorem.C | 6 +-- src/insets/render_base.h | 4 +- src/insets/render_button.C | 5 +- src/insets/render_button.h | 2 +- src/insets/render_graphic.C | 7 +-- src/insets/render_graphic.h | 2 +- src/insets/render_preview.C | 5 +- src/insets/render_preview.h | 2 +- src/ispell.C | 5 +- src/iterators.C | 2 +- src/lyx_cb.C | 5 +- src/lyxsocket.C | 27 ++++++----- src/lyxtextclass.C | 6 ++- src/lyxvc.C | 14 +++--- src/lyxvc.h | 4 +- src/mathed/ChangeLog | 12 +++++ src/mathed/formulamacro.C | 4 +- src/mathed/math_extern.C | 22 ++++----- src/mathed/math_parser.C | 4 +- src/paragraph.C | 2 +- src/paragraph.h | 2 +- src/paragraph_funcs.C | 40 ++++++++-------- src/rowpainter.C | 2 +- src/support/ChangeLog | 12 +++++ src/support/forkedcall.h | 8 ++-- src/support/forkedcontr.C | 2 +- src/support/getcwd.C | 16 ++++--- src/support/os_os2.C | 8 +++- src/support/tempname.C | 14 +++--- src/tex2lyx/text.C | 2 +- src/trans_mgr.C | 10 ++-- src/trans_mgr.h | 8 ++-- src/undo.C | 2 +- 47 files changed, 285 insertions(+), 192 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index 19447ffb6d..37d020bc53 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -194,7 +194,6 @@ src/mathed/ref_inset.C src/paragraph.C src/paragraph_funcs.C src/rowpainter.C -src/support/path_defines.C src/text.C src/text2.C src/text3.C diff --git a/src/ChangeLog b/src/ChangeLog index 1ba35ce9cd..320fe5dee7 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,27 @@ +2003-11-03 Lars Gullik Bjønnes + + * trans_mgr.h: store t1_ and t2_ in scoped_ptr + * trans_mgr.C: adjust + + * paragraph_funcs.C (readParToken): exception safety + + * lyxvc.h: store the vcs pointer in a scoped_ptr + * lyxvc.C: adjust + + * lyxsocket.C (serverCallback): exception safety + + * lyx_cb.C (AutoSaveBuffer): make it return a auto_ptr + + * ispell.C (clone): make it return a auto_ptr + + * factory.C (createInset): exception safety + (readInset): exception safety + + * bufferlist.C (newBuffer): exception safety + + * Thesaurus.C (Thesaurus): use initialization for aik_ + + * MenuBackend.C (expandToc): exception safety. 2003-11-03 André Pönitz @@ -21,7 +45,7 @@ * text3.C: * lyxfunc.C: - * cursor.C (dispatch): + * cursor.C (dispatch): * BufferView_pimpl.C (dispatch): adjust for DispatchResult changes * dispatchresult.h: remove UNDISPATCHED, DISPATCHED and diff --git a/src/MenuBackend.C b/src/MenuBackend.C index b127b7fa99..40c6151121 100644 --- a/src/MenuBackend.C +++ b/src/MenuBackend.C @@ -51,6 +51,7 @@ using lyx::support::contains; using lyx::support::MakeDisplayPath; using lyx::support::token; +using std::auto_ptr; using std::endl; using std::find_if; using std::max; @@ -598,7 +599,7 @@ void expandToc(Menu & tomenu, LyXView const * view) continue; // All the rest is for floats - Menu * menu = new Menu; + auto_ptr menu(new Menu); lyx::toc::Toc::const_iterator ccit = cit->second.begin(); lyx::toc::Toc::const_iterator eend = cit->second.end(); for (; ccit != eend; ++ccit) { @@ -610,7 +611,7 @@ void expandToc(Menu & tomenu, LyXView const * view) string const & floatName = cit->first; // Is the _(...) really needed here? (Lgb) MenuItem item(MenuItem::Submenu, _(floatName)); - item.submenu(menu); + item.submenu(menu.release()); tomenu.add(item); } diff --git a/src/Thesaurus.C b/src/Thesaurus.C index e8a6385cff..562bd74883 100644 --- a/src/Thesaurus.C +++ b/src/Thesaurus.C @@ -23,9 +23,8 @@ using std::sort; Thesaurus::Thesaurus() -{ - aik_ = new Aiksaurus; -} + : aik_(new Aiksaurus) +{} Thesaurus::~Thesaurus() diff --git a/src/buffer.C b/src/buffer.C index 9d646999e6..6c55642d37 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1460,13 +1460,13 @@ bool Buffer::hasParWithID(int id) const PosIterator Buffer::pos_iterator_begin() { - return PosIterator(¶graphs(), paragraphs().begin(), 0); + return PosIterator(¶graphs(), paragraphs().begin(), 0); } PosIterator Buffer::pos_iterator_end() { - return PosIterator(¶graphs(), paragraphs().end(), 0); + return PosIterator(¶graphs(), paragraphs().end(), 0); } diff --git a/src/bufferlist.C b/src/bufferlist.C index 7ae6d255d5..a5b0c820ea 100644 --- a/src/bufferlist.C +++ b/src/bufferlist.C @@ -38,6 +38,7 @@ using lyx::support::OnlyFilename; using lyx::support::removeAutosaveFile; using lyx::support::prefixIs; +using std::auto_ptr; using std::endl; using std::find; using std::find_if; @@ -127,12 +128,12 @@ void BufferList::release(Buffer * buf) Buffer * BufferList::newBuffer(string const & s, bool ronly) { - Buffer * tmpbuf = new Buffer(s, ronly); + auto_ptr tmpbuf(new Buffer(s, ronly)); tmpbuf->params().useClassDefaults(); lyxerr[Debug::INFO] << "Assigning to buffer " << bstore.size() << endl; - bstore.push_back(tmpbuf); - return tmpbuf; + bstore.push_back(tmpbuf.get()); + return tmpbuf.release(); } diff --git a/src/factory.C b/src/factory.C index 246e1c1afb..587fdd2072 100644 --- a/src/factory.C +++ b/src/factory.C @@ -20,6 +20,7 @@ #include "funcrequest.h" #include "LColor.h" #include "lyxlex.h" +#include "paragraph.h" #include "insets/insetbibitem.h" #include "insets/insetbibtex.h" @@ -62,6 +63,7 @@ using lyx::support::compare_ascii_no_case; +using std::auto_ptr; using std::endl; using std::string; @@ -130,8 +132,9 @@ InsetOld * createInset(FuncRequest const & cmd) case LFUN_INSET_WIDE_FLOAT: // check if the float type exists if (params.getLyXTextClass().floats().typeExist(cmd.argument)) { - InsetFloat * p = new InsetFloat(params, cmd.argument); + auto_ptr p(new InsetFloat(params, cmd.argument)); p->wide(true, params); + return p.release(); } lyxerr << "Non-existent float type: " << cmd.argument << endl; return 0; @@ -177,12 +180,12 @@ InsetOld * createInset(FuncRequest const & cmd) if (bv->theLockingInset()) { lyxerr << "Locking inset code: " << static_cast(bv->theLockingInset()->lyxCode()); - InsetCaption * inset = new InsetCaption(params); + auto_ptr inset(new InsetCaption(params)); inset->setOwner(bv->theLockingInset()); inset->setAutoBreakRows(true); inset->setDrawFrame(InsetText::LOCKED); inset->setFrameColor(LColor::captionframe); - return inset; + return inset.release(); } return 0; @@ -233,18 +236,18 @@ InsetOld * createInset(FuncRequest const & cmd) InsetExternalParams iep; InsetExternalMailer::string2params(cmd.argument, buffer, iep); - InsetExternal * inset = new InsetExternal; + auto_ptr inset(new InsetExternal); inset->setParams(iep, buffer); - return inset; + return inset.release(); } else if (name == "graphics") { Buffer const & buffer = *cmd.view()->buffer(); InsetGraphicsParams igp; InsetGraphicsMailer::string2params(cmd.argument, buffer, igp); - InsetGraphics * inset = new InsetGraphics; + auto_ptr inset(new InsetGraphics); inset->setParams(igp); - return inset; + return inset.release(); } else if (name == "include") { InsetCommandParams iip; @@ -320,7 +323,7 @@ InsetOld * readInset(LyXLex & lex, Buffer const & buf) << endl; } - InsetOld * inset = 0; + auto_ptr inset; lex.next(); string const tmptok = lex.getString(); @@ -335,21 +338,21 @@ InsetOld * readInset(LyXLex & lex, Buffer const & buf) // This strange command allows LyX to recognize "natbib" style // citations: citet, citep, Citet etc. if (compare_ascii_no_case(cmdName.substr(0,4), "cite") == 0) { - inset = new InsetCitation(inscmd); + inset.reset(new InsetCitation(inscmd)); } else if (cmdName == "bibitem") { lex.printError("Wrong place for bibitem"); - inset = new InsetBibitem(inscmd); + inset.reset(new InsetBibitem(inscmd)); } else if (cmdName == "bibtex") { - inset = new InsetBibtex(inscmd); + inset.reset(new InsetBibtex(inscmd)); } else if (cmdName == "index") { - inset = new InsetIndex(inscmd); + inset.reset(new InsetIndex(inscmd)); } else if (cmdName == "include") { - inset = new InsetInclude(inscmd); + inset.reset(new InsetInclude(inscmd)); } else if (cmdName == "label") { - inset = new InsetLabel(inscmd); + inset.reset(new InsetLabel(inscmd)); } else if (cmdName == "url" || cmdName == "htmlurl") { - inset = new InsetUrl(inscmd); + inset.reset(new InsetUrl(inscmd)); } else if (cmdName == "ref" || cmdName == "eqref" || cmdName == "pageref" @@ -358,18 +361,18 @@ InsetOld * readInset(LyXLex & lex, Buffer const & buf) || cmdName == "prettyref") { if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) { - inset = new InsetRef(inscmd, buf); + inset.reset(new InsetRef(inscmd, buf)); } } else if (cmdName == "tableofcontents") { - inset = new InsetTOC(inscmd); + inset.reset(new InsetTOC(inscmd)); } else if (cmdName == "listofalgorithms") { - inset = new InsetFloatList("algorithm"); + inset.reset(new InsetFloatList("algorithm")); } else if (cmdName == "listoffigures") { - inset = new InsetFloatList("figure"); + inset.reset(new InsetFloatList("figure")); } else if (cmdName == "listoftables") { - inset = new InsetFloatList("table"); + inset.reset(new InsetFloatList("table")); } else if (cmdName == "printindex") { - inset = new InsetPrintIndex(inscmd); + inset.reset(new InsetPrintIndex(inscmd)); } else { lyxerr << "unknown CommandInset '" << cmdName << "'" << std::endl; @@ -379,64 +382,64 @@ InsetOld * readInset(LyXLex & lex, Buffer const & buf) } } else { if (tmptok == "Quotes") { - inset = new InsetQuotes; + inset.reset(new InsetQuotes); } else if (tmptok == "External") { - inset = new InsetExternal; + inset.reset(new InsetExternal); } else if (tmptok == "FormulaMacro") { - inset = new InsetFormulaMacro; + inset.reset(new InsetFormulaMacro); } else if (tmptok == "Formula") { - inset = new InsetFormula; + inset.reset(new InsetFormula); } else if (tmptok == "Graphics") { - inset = new InsetGraphics; + inset.reset(new InsetGraphics); } else if (tmptok == "Note" || tmptok == "Comment" || tmptok == "Greyedout") { - inset = new InsetNote(buf.params(), tmptok); + inset.reset(new InsetNote(buf.params(), tmptok)); } else if (tmptok == "Boxed" || tmptok == "ovalbox" || tmptok == "Shadowbox" || tmptok == "Doublebox" || tmptok == "Ovalbox" || tmptok == "Frameless") { - inset = new InsetBox(buf.params(), tmptok); + inset.reset(new InsetBox(buf.params(), tmptok)); } else if (tmptok == "Branch") { - inset = new InsetBranch(buf.params(), string()); + inset.reset(new InsetBranch(buf.params(), string())); } else if (tmptok == "Include") { InsetCommandParams p("Include"); - inset = new InsetInclude(p); + inset.reset(new InsetInclude(p)); } else if (tmptok == "Environment") { lex.next(); - inset = new InsetEnvironment(buf.params(), lex.getString()); + inset.reset(new InsetEnvironment(buf.params(), lex.getString())); } else if (tmptok == "ERT") { - inset = new InsetERT(buf.params()); + inset.reset(new InsetERT(buf.params())); } else if (tmptok == "InsetSpace") { - inset = new InsetSpace; + inset.reset(new InsetSpace); } else if (tmptok == "Tabular") { - inset = new InsetTabular(buf); + inset.reset(new InsetTabular(buf)); } else if (tmptok == "Text") { - inset = new InsetText(buf.params()); + inset.reset(new InsetText(buf.params())); } else if (tmptok == "Foot") { - inset = new InsetFoot(buf.params()); + inset.reset(new InsetFoot(buf.params())); } else if (tmptok == "Marginal") { - inset = new InsetMarginal(buf.params()); + inset.reset(new InsetMarginal(buf.params())); } else if (tmptok == "OptArg") { - inset = new InsetOptArg(buf.params()); + inset.reset(new InsetOptArg(buf.params())); } else if (tmptok == "Minipage") { - inset = new InsetMinipage(buf.params()); + inset.reset(new InsetMinipage(buf.params())); } else if (tmptok == "Float") { lex.next(); string tmptok = lex.getString(); - inset = new InsetFloat(buf.params(), tmptok); + inset.reset(new InsetFloat(buf.params(), tmptok)); } else if (tmptok == "Wrap") { lex.next(); string tmptok = lex.getString(); - inset = new InsetWrap(buf.params(), tmptok); + inset.reset(new InsetWrap(buf.params(), tmptok)); #if 0 } else if (tmptok == "List") { - inset = new InsetList; + inset.reset(new InsetList); } else if (tmptok == "Theorem") { - inset = new InsetList; + inset.reset(new InsetList); #endif } else if (tmptok == "Caption") { - inset = new InsetCaption(buf.params()); + inset.reset(new InsetCaption(buf.params())); } else if (tmptok == "FloatList") { - inset = new InsetFloatList; + inset.reset(new InsetFloatList); } else { lyxerr << "unknown Inset type '" << tmptok << "'" << std::endl; @@ -448,5 +451,5 @@ InsetOld * readInset(LyXLex & lex, Buffer const & buf) inset->read(buf, lex); } - return inset; + return inset.release(); } diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 0296b86086..841eb0b773 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,20 @@ +2003-11-03 Lars Gullik Bjønnes + + * render_base.h: make clone return an auto_ptr + * render_button.C (clone): adjust + * render_graphic.C (clone): adjust + * render_preview.C (clone): adjust + + * insettheorem.C (clone): return an auto_ptr + + * insettext.C (priv_dispatch): exception safety + + * insettabular.C: store the file scope variable paste_tabular in a + scoped_ptr, adjust usage. + + * insetexternal.C (setParams): exception safety + + * insetbibitem.C (clone): exception safety 2003-11-03 André Pönitz diff --git a/src/insets/insetbibitem.C b/src/insets/insetbibitem.C index f1afd96c76..f76b685cc6 100644 --- a/src/insets/insetbibitem.C +++ b/src/insets/insetbibitem.C @@ -53,7 +53,7 @@ InsetBibitem::~InsetBibitem() auto_ptr InsetBibitem::clone() const { - InsetBibitem * b = new InsetBibitem(params()); + auto_ptr b(new InsetBibitem(params())); b->setCounter(counter); return auto_ptr(b); } diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 355bf8ef0e..552dd15b62 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -580,8 +580,8 @@ void InsetExternal::setParams(InsetExternalParams const & p, case RENDERBUTTON: { RenderButton * button_ptr = renderer_->asButton(); if (!button_ptr) { - button_ptr = new RenderButton; - renderer_.reset(button_ptr); + renderer_.reset(new RenderButton); + button_ptr = renderer_->asButton(); } button_ptr->update(getScreenLabel(params_, buffer), true); @@ -590,10 +590,10 @@ void InsetExternal::setParams(InsetExternalParams const & p, } case RENDERGRAPHIC: { RenderGraphic * graphic_ptr = renderer_->asGraphic(); if (!graphic_ptr) { - graphic_ptr = new RenderGraphic; + renderer_.reset(new RenderGraphic); + graphic_ptr = renderer_->asGraphic(); graphic_ptr->connect( boost::bind(&InsetExternal::statusChanged, this)); - renderer_.reset(graphic_ptr); } graphic_ptr->update(get_grfx_params(params_)); @@ -604,12 +604,12 @@ void InsetExternal::setParams(InsetExternalParams const & p, RenderMonitoredPreview * preview_ptr = renderer_->asMonitoredPreview(); if (!preview_ptr) { - preview_ptr = new RenderMonitoredPreview; + renderer_.reset(new RenderMonitoredPreview); + preview_ptr = renderer_->asMonitoredPreview(); preview_ptr->connect( boost::bind(&InsetExternal::statusChanged, this)); preview_ptr->fileChanged( boost::bind(&InsetExternal::fileChanged, this)); - renderer_.reset(preview_ptr); } if (preview_ptr->monitoring()) diff --git a/src/insets/insethfill.C b/src/insets/insethfill.C index f2d9ecc8e4..7f29a62866 100644 --- a/src/insets/insethfill.C +++ b/src/insets/insethfill.C @@ -33,7 +33,7 @@ void InsetHFill::metrics(MetricsInfo &, Dimension & dim) const dim.wid = 3; dim.asc = 3; dim.des = 3; - dim_ = dim; + dim_ = dim; } diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index c7f6421578..fdb5b0eb98 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -402,7 +402,7 @@ int InsetInclude::linuxdoc(Buffer const & buffer, ostream & os, lyxerr[Debug::LATEX] << "writefile:" << writefile << endl; LatexRunParams runp = runparams; - runp.nice = buffer.niceFile(); + runp.nice = buffer.niceFile(); tmp->makeLinuxDocFile(writefile, runp, true); } diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 96963ae297..65fa7c3bee 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -61,7 +61,7 @@ int const ADD_TO_HEIGHT = 2; int const ADD_TO_TABULAR_WIDTH = 2; /// -LyXTabular * paste_tabular = 0; +boost::scoped_ptr paste_tabular; struct TabularFeature { @@ -144,7 +144,7 @@ string const featureAsString(LyXTabular::Feature feature) bool InsetTabular::hasPasteBuffer() const { - return (paste_tabular != 0); + return (paste_tabular.get() != 0); } @@ -1019,9 +1019,12 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, ++p; } maxCols = max(cols, maxCols); - delete paste_tabular; - paste_tabular = new LyXTabular(bv->buffer()->params(), - this, rows, maxCols); + + paste_tabular.reset( + new LyXTabular(bv->buffer()->params(), + this, rows, maxCols) + ); + string::size_type op = 0; int cell = 0; int cells = paste_tabular->getNumberOfCells(); @@ -1057,8 +1060,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, // so that the clipboard is used and it goes on // to default // and executes LFUN_PASTESELECTION in insettext! - delete paste_tabular; - paste_tabular = 0; + paste_tabular.reset(); } } case LFUN_PASTE: @@ -2247,8 +2249,7 @@ bool InsetTabular::copySelection(BufferView * bv) if (sel_row_start > sel_row_end) swap(sel_row_start, sel_row_end); - delete paste_tabular; - paste_tabular = new LyXTabular(tabular); + paste_tabular.reset(new LyXTabular(tabular)); paste_tabular->setOwner(this); for (int i = 0; i < sel_row_start; ++i) @@ -2274,7 +2275,7 @@ bool InsetTabular::copySelection(BufferView * bv) true, true); ostringstream os; - LatexRunParams const runparams; + LatexRunParams const runparams; paste_tabular->ascii(*bv->buffer(), os, runparams, ownerPar(*bv->buffer(), this).params().depth(), true, '\t'); bv->stuffClipboard(os.str()); @@ -2617,11 +2618,12 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf, int ocol = 0; int row = 0; if (usePaste) { - delete paste_tabular; - paste_tabular = new LyXTabular(bv->buffer()->params(), - rows, maxCols); + paste_tabular.reset( + new LyXTabular(bv->buffer()->params(), rows, maxCols) + ); + paste_tabular->setOwner(this); - loctab = paste_tabular; + loctab = paste_tabular.get(); cols = 0; } else { loctab = &tabular; diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 44de629aba..b8d80cf7ae 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -858,7 +858,8 @@ InsetText::priv_dispatch(FuncRequest const & cmd, result = DispatchResult(true); } else { replaceSelection(bv->getLyXText()); - text_.insertInset(new InsetNewline); + auto_ptr ins(new InsetNewline); + text_.insertInset(ins.release()); updflag = true; } break; diff --git a/src/insets/insettheorem.C b/src/insets/insettheorem.C index 2f51cd1b21..100330498f 100644 --- a/src/insets/insettheorem.C +++ b/src/insets/insettheorem.C @@ -56,14 +56,14 @@ void InsetTheorem::write(Buffer const * buf, ostream & os) const } -InsetBase * InsetTheorem::clone() const +auto_ptr InsetTheorem::clone() const { #ifdef WITH_WARNINGS #warning Is this inset used? If YES this is WRONG!!! (Jug) #endif - InsetTheorem * result = new InsetTheorem; - + auto_ptr result(new InsetTheorem); result->setCollapsed(!isOpen()); + return result; } diff --git a/src/insets/render_base.h b/src/insets/render_base.h index 0ca610723a..e8a0468e0d 100644 --- a/src/insets/render_base.h +++ b/src/insets/render_base.h @@ -14,6 +14,8 @@ #include "dimension.h" +#include + class MetricsInfo; class PainterInfo; @@ -26,7 +28,7 @@ class RenderBase { public: virtual ~RenderBase() {} - virtual RenderBase * clone() const = 0; + virtual std::auto_ptr clone() const = 0; /// compute the size of the object returned in dim virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0; diff --git a/src/insets/render_button.C b/src/insets/render_button.C index 3200ac5b86..55c001b3fd 100644 --- a/src/insets/render_button.C +++ b/src/insets/render_button.C @@ -19,6 +19,7 @@ #include "frontends/Painter.h" using std::string; +using std::auto_ptr; RenderButton::RenderButton() @@ -26,9 +27,9 @@ RenderButton::RenderButton() {} -RenderBase * RenderButton::clone() const +auto_ptr RenderButton::clone() const { - return new RenderButton(*this); + return auto_ptr(new RenderButton(*this)); } diff --git a/src/insets/render_button.h b/src/insets/render_button.h index 01a7244c4f..770eae304c 100644 --- a/src/insets/render_button.h +++ b/src/insets/render_button.h @@ -22,7 +22,7 @@ class RenderButton : public RenderBase public: RenderButton(); - RenderBase * clone() const; + std::auto_ptr clone() const; /// compute the size of the object returned in dim virtual void metrics(MetricsInfo & mi, Dimension & dim) const; diff --git a/src/insets/render_graphic.C b/src/insets/render_graphic.C index 376b142a86..05f939cf68 100644 --- a/src/insets/render_graphic.C +++ b/src/insets/render_graphic.C @@ -31,6 +31,7 @@ using lyx::support::AbsolutePath; using lyx::support::OnlyFilename; using std::string; +using std::auto_ptr; RenderGraphic::RenderGraphic() @@ -46,9 +47,9 @@ RenderGraphic::RenderGraphic(RenderGraphic const & other) {} -RenderBase * RenderGraphic::clone() const +auto_ptr RenderGraphic::clone() const { - return new RenderGraphic(*this); + return auto_ptr(new RenderGraphic(*this)); } @@ -80,7 +81,7 @@ boost::signals::connection RenderGraphic::connect(slot_type const & slot) const namespace { - + string const statusMessage(graphics::ImageStatus status) { switch (status) { diff --git a/src/insets/render_graphic.h b/src/insets/render_graphic.h index 3d67e5f54f..7da3fa949a 100644 --- a/src/insets/render_graphic.h +++ b/src/insets/render_graphic.h @@ -25,7 +25,7 @@ class RenderGraphic : public RenderBase public: RenderGraphic(); RenderGraphic(RenderGraphic const &); - RenderBase * clone() const; + std::auto_ptr clone() const; /// compute the size of the object returned in dim void metrics(MetricsInfo & mi, Dimension & dim) const; diff --git a/src/insets/render_preview.C b/src/insets/render_preview.C index f1dd4511c9..df24bf20c2 100644 --- a/src/insets/render_preview.C +++ b/src/insets/render_preview.C @@ -31,6 +31,7 @@ #include using std::string; +using std::auto_ptr; namespace graphics = lyx::graphics; namespace support = lyx::support; @@ -55,9 +56,9 @@ RenderPreview::RenderPreview(RenderPreview const & other) {} -RenderBase * RenderPreview::clone() const +auto_ptr RenderPreview::clone() const { - return new RenderPreview(*this); + return auto_ptr(new RenderPreview(*this)); } diff --git a/src/insets/render_preview.h b/src/insets/render_preview.h index 88f87acdaf..4e5f8a97fc 100644 --- a/src/insets/render_preview.h +++ b/src/insets/render_preview.h @@ -46,7 +46,7 @@ public: RenderPreview(); RenderPreview(RenderPreview const &); - RenderBase * clone() const; + std::auto_ptr clone() const; /// Compute the size of the object, returned in dim void metrics(MetricsInfo &, Dimension & dim) const; diff --git a/src/ispell.C b/src/ispell.C index f1abc99bf0..8cfdddf97f 100644 --- a/src/ispell.C +++ b/src/ispell.C @@ -36,6 +36,7 @@ using std::strlen; using std::strpbrk; #endif +using std::auto_ptr; using std::endl; using std::max; using std::string; @@ -50,8 +51,8 @@ public: int * in, int * out, int * err) : params(p), lang(l), pipein(in), pipeout(out), pipeerr(err) {} /// - virtual lyx::support::ForkedProcess * clone() const { - return new LaunchIspell(*this); + virtual auto_ptr clone() const { + return auto_ptr(new LaunchIspell(*this)); } /// int start(); diff --git a/src/iterators.C b/src/iterators.C index ee67075ab5..609f6e6bba 100644 --- a/src/iterators.C +++ b/src/iterators.C @@ -369,7 +369,7 @@ bool operator!=(ParConstIterator const & iter1, ParConstIterator const & iter2) PosIterator ParIterator::asPosIterator(lyx::pos_type pos) const { PosIterator p; - + int const last = size() - 1; for (int i = 0; i < last; ++i) { ParPosition & pp = pimpl_->positions[i]; diff --git a/src/lyx_cb.C b/src/lyx_cb.C index ca6afd6dcc..f1843b0796 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -68,6 +68,7 @@ using lyx::support::user_lyxdir; namespace os = lyx::support::os; +using std::auto_ptr; using std::back_inserter; using std::copy; using std::endl; @@ -215,8 +216,8 @@ public: AutoSaveBuffer(BufferView & bv, string const & fname) : bv_(bv), fname_(fname) {} /// - virtual ForkedProcess * clone() const { - return new AutoSaveBuffer(*this); + virtual auto_ptr clone() const { + return auto_ptr(new AutoSaveBuffer(*this)); } /// int start(); diff --git a/src/lyxsocket.C b/src/lyxsocket.C index 429d6ee2e8..e3a84683e5 100644 --- a/src/lyxsocket.C +++ b/src/lyxsocket.C @@ -27,6 +27,8 @@ #include #include + +using std::auto_ptr; using std::endl; using std::string; @@ -75,17 +77,16 @@ string const & LyXServerSocket::address() const // is OK and if the number of clients does not exceed MAX_CLIENTS void LyXServerSocket::serverCallback() { - LyXDataSocket * client = new LyXDataSocket(this); + auto_ptr client(new LyXDataSocket(this)); if (client->connected()) { if (clients.size() == MAX_CLIENTS) { client->writeln("BYE:Too many clients connected"); } else { - clients.insert(client); - lyx_gui::set_datasocket_callback(client); + lyx_gui::set_datasocket_callback(client.get()); + clients.insert(client.release()); return; } } - delete client; } @@ -141,15 +142,15 @@ void LyXServerSocket::close(LyXDataSocket * client) // Debug // void LyXServerSocket::dump() const // { -// lyxerr << "LyXServerSocket debug dump.\n" -// << "fd = " << fd_ << ", address = " << address_ << ".\n" -// << "Clients: " << clients.size() << ".\n"; -// if (!clients.empty()) { -// std::set::const_iterator client = clients.begin(); -// std::set::const_iterator end = clients.end(); -// for (; client != end; ++client) -// lyxerr << "fd = " << (*client)->fd() << "\n"; -// } +// lyxerr << "LyXServerSocket debug dump.\n" +// << "fd = " << fd_ << ", address = " << address_ << ".\n" +// << "Clients: " << clients.size() << ".\n"; +// if (!clients.empty()) { +// std::set::const_iterator client = clients.begin(); +// std::set::const_iterator end = clients.end(); +// for (; client != end; ++client) +// lyxerr << "fd = " << (*client)->fd() << "\n"; +// } // } diff --git a/src/lyxtextclass.C b/src/lyxtextclass.C index e713642d50..002d51df83 100644 --- a/src/lyxtextclass.C +++ b/src/lyxtextclass.C @@ -233,8 +233,10 @@ bool LyXTextClass::Read(string const & filename, bool merge) if (le == TC_ENVIRONMENT) lay.is_environment = true; if (!(error = do_readStyle(lexrc, lay))) - layoutlist_.push_back - (boost::shared_ptr(new LyXLayout(lay))); + layoutlist_.push_back( + boost::shared_ptr(new LyXLayout(lay)) + ); + if (defaultlayout_.empty()) { // We do not have a default // layout yet, so we choose diff --git a/src/lyxvc.C b/src/lyxvc.C index b4dae54556..21c934f102 100644 --- a/src/lyxvc.C +++ b/src/lyxvc.C @@ -38,15 +38,13 @@ using std::pair; LyXVC::LyXVC() { - vcs = 0; owner_ = 0; } +// for the sake of boost::scoped_ptr LyXVC::~LyXVC() -{ - delete vcs; -} +{} bool LyXVC::file_found_hook(string const & fn) @@ -54,13 +52,13 @@ bool LyXVC::file_found_hook(string const & fn) string found_file; // Check if file is under RCS if (!(found_file = RCS::find_file(fn)).empty()) { - vcs = new RCS(found_file); + vcs.reset(new RCS(found_file)); vcs->owner(owner_); return true; } // Check if file is under CVS if (!(found_file = CVS::find_file(fn)).empty()) { - vcs = new CVS(found_file, fn); + vcs.reset(new CVS(found_file, fn)); vcs->owner(owner_); return true; } @@ -107,14 +105,14 @@ void LyXVC::registrer() << "LyXVC: registering " << MakeDisplayPath(filename) << " with CVS" << endl; - vcs = new CVS(cvs_entries, filename); + vcs.reset(new CVS(cvs_entries, filename)); } else { lyxerr[Debug::LYXVC] << "LyXVC: registering " << MakeDisplayPath(filename) << " with RCS" << endl; - vcs = new RCS(filename); + vcs.reset(new RCS(filename)); } vcs->owner(owner_); diff --git a/src/lyxvc.h b/src/lyxvc.h index 8c929f23fa..7c9b22f89f 100644 --- a/src/lyxvc.h +++ b/src/lyxvc.h @@ -12,6 +12,8 @@ #ifndef LYX_VC_H #define LYX_VC_H +#include + #include @@ -100,7 +102,7 @@ private: Buffer * owner_; /// - VCS * vcs; + boost::scoped_ptr vcs; }; #endif diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 2a0459ac6a..b8020d6613 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,15 @@ +2003-11-03 Lars Gullik Bjønnes + + * math_parser.C (parse1): exception safety + + * math_extern.C (splitScripts): exception safety + (extractFunctions): exception safety + (extractIntegrals): exception safety + (extractSums): exception safety + (extractDiff): exception safety + + * formulamacro.C (read): exception safety + 2003-11-01 Lars Gullik Bjønnes * adjust for DispatchResult changes diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index fd0ceea5af..ae49819f1f 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -114,9 +114,9 @@ void InsetFormulaMacro::read(Buffer const &, LyXLex & lex) void InsetFormulaMacro::read(std::istream & is) { - MathMacroTemplate * p = new MathMacroTemplate(is); + auto_ptr p(new MathMacroTemplate(is)); setInsetName(p->name()); - MathMacroTable::create(MathAtom(p)); + MathMacroTable::create(MathAtom(p.release())); //metrics(); } diff --git a/src/mathed/math_extern.C b/src/mathed/math_extern.C index e0d575daf4..ab7e39c904 100644 --- a/src/mathed/math_extern.C +++ b/src/mathed/math_extern.C @@ -47,7 +47,7 @@ using lyx::support::subst; using std::string; using std::endl; using std::find_if; - +using std::auto_ptr; using std::istringstream; using std::ostream; using std::ostringstream; @@ -289,13 +289,13 @@ void splitScripts(MathArray & ar) // create extra script inset and move superscript over MathScriptInset * p = ar[i].nucleus()->asScriptInset(); - MathScriptInset * q = new MathScriptInset(true); + auto_ptr q(new MathScriptInset(true)); std::swap(q->up(), p->up()); p->removeScript(true); // insert new inset behind ++i; - ar.insert(i, MathAtom(q)); + ar.insert(i, MathAtom(q.release())); } //lyxerr << "\nScripts to: " << ar << endl; } @@ -464,13 +464,13 @@ void extractFunctions(MathArray & ar) extractScript(exp, jt, ar.end()); // create a proper inset as replacement - MathExFuncInset * p = new MathExFuncInset(name); + auto_ptr p(new MathExFuncInset(name)); // jt points to the "argument". Get hold of this. MathArray::iterator st = extractArgument(p->cell(0), jt, ar.end()); // replace the function name by a real function inset - *it = MathAtom(p); + *it = MathAtom(p.release()); // remove the source of the argument from the array ar.erase(it + 1, st); @@ -540,7 +540,7 @@ void extractIntegrals(MathArray & ar) continue; // core ist part from behind the scripts to the 'd' - MathExIntInset * p = new MathExIntInset("int"); + auto_ptr p(new MathExIntInset("int")); // handle scripts if available if (!testIntSymbol(*it)) { @@ -554,7 +554,7 @@ void extractIntegrals(MathArray & ar) // remove used parts ar.erase(it + 1, tt); - *it = MathAtom(p); + *it = MathAtom(p.release()); } //lyxerr << "\nIntegrals to: " << ar << endl; } @@ -604,7 +604,7 @@ void extractSums(MathArray & ar) continue; // create a proper inset as replacement - MathExIntInset * p = new MathExIntInset("sum"); + auto_ptr p(new MathExIntInset("sum")); // collect lower bound and summation index MathScriptInset const * sub = ar[i]->asScriptInset(); @@ -633,7 +633,7 @@ void extractSums(MathArray & ar) // cleanup ar.erase(it + 1, tt); - *it = MathAtom(p); + *it = MathAtom(p.release()); } //lyxerr << "\nSums to: " << ar << endl; } @@ -682,7 +682,7 @@ void extractDiff(MathArray & ar) } // create a proper diff inset - MathDiffInset * diff = new MathDiffInset; + auto_ptr diff(new MathDiffInset); // collect function, let jt point behind last used item MathArray::iterator jt = it + 1; @@ -731,7 +731,7 @@ void extractDiff(MathArray & ar) // cleanup ar.erase(it + 1, jt); - *it = MathAtom(diff); + *it = MathAtom(diff.release()); } //lyxerr << "\nDiffs to: " << ar << endl; } diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index eaa3e99520..95a0481164 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -1165,7 +1165,7 @@ void Parser::parse1(MathGridInset & grid, unsigned flags, // Disabled else if (1 && t.cs() == "ar") { - MathXYArrowInset * p = new MathXYArrowInset; + auto_ptr p(new MathXYArrowInset); // try to read target parse(p->cell(0), FLAG_OTPTION, mode); // try to read label @@ -1176,7 +1176,7 @@ void Parser::parse1(MathGridInset & grid, unsigned flags, //lyxerr << "read label: " << p->cell(1) << endl; } - cell->push_back(MathAtom(p)); + cell->push_back(MathAtom(p.release())); //lyxerr << "read cell: " << cell << endl; } #endif diff --git a/src/paragraph.C b/src/paragraph.C index 44c829d8ad..e95ab46dd5 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -1535,7 +1535,7 @@ bool Paragraph::isMultiLingual(BufferParams const & bparams) string const Paragraph::asString(Buffer const & buffer, bool label) const { - LatexRunParams runparams; + LatexRunParams runparams; return asString(buffer, runparams, label); } diff --git a/src/paragraph.h b/src/paragraph.h index c616edbac6..977520372d 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -92,7 +92,7 @@ public: std::string const Paragraph::asString(Buffer const & buffer, lyx::pos_type beg, lyx::pos_type end, - bool label) const; + bool label) const; /// std::string const asString(Buffer const &, LatexRunParams const & runparams, diff --git a/src/paragraph_funcs.C b/src/paragraph_funcs.C index 73308f4047..d2c6cef87f 100644 --- a/src/paragraph_funcs.C +++ b/src/paragraph_funcs.C @@ -59,6 +59,7 @@ using lyx::support::contains; using lyx::support::split; using lyx::support::subst; +using std::auto_ptr; using std::endl; using std::string; using std::vector; @@ -996,7 +997,7 @@ void linuxdocParagraphs(Buffer const & buf, ostream & os, LatexRunParams const & runparams) { - + Paragraph::depth_type depth = 0; // paragraph depth string item_name; vector environment_stack(5); @@ -1154,8 +1155,8 @@ void docbookParagraphs(Buffer const & buf, // environment tag closing for (; depth > par->params().depth(); --depth) { - if (!environment_inner[depth].empty()) - sgml::closeEnvTags(os, false, environment_inner[depth], + if (!environment_inner[depth].empty()) + sgml::closeEnvTags(os, false, environment_inner[depth], command_depth + depth); sgml::closeTag(os, depth + command_depth, false, environment_stack[depth]); environment_stack[depth].erase(); @@ -1165,7 +1166,7 @@ void docbookParagraphs(Buffer const & buf, if (depth == par->params().depth() && environment_stack[depth] != style->latexname() && !environment_stack[depth].empty()) { - sgml::closeEnvTags(os, false, environment_inner[depth], + sgml::closeEnvTags(os, false, environment_inner[depth], command_depth + depth); sgml::closeTag(os, depth + command_depth, false, environment_stack[depth]); @@ -1184,7 +1185,7 @@ void docbookParagraphs(Buffer const & buf, if (depth != 0) //error(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size())); ; - + command_name = style->latexname(); sgmlparam = style->latexparam(); @@ -1254,7 +1255,7 @@ void docbookParagraphs(Buffer const & buf, environment_inner[depth] = "!-- --"; sgml::openTag(os, depth + command_depth, false, environment_stack[depth]); } else { - sgml::closeEnvTags(os, false, environment_inner[depth], + sgml::closeEnvTags(os, false, environment_inner[depth], command_depth + depth); } @@ -1320,7 +1321,7 @@ void docbookParagraphs(Buffer const & buf, // Close open tags for (int d = depth; d >= 0; --d) { if (!environment_stack[depth].empty()) { - sgml::closeEnvTags(os, false, environment_inner[depth], + sgml::closeEnvTags(os, false, environment_inner[depth], command_depth + depth); } } @@ -1462,33 +1463,34 @@ int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & tok } } } else { - InsetOld * inset = 0; + auto_ptr inset; if (token == "\\SpecialChar" ) - inset = new InsetSpecialChar; + inset.reset(new InsetSpecialChar); else - inset = new InsetSpace; + inset.reset(new InsetSpace); inset->read(buf, lex); - par.insertInset(par.size(), inset, font, change); + par.insertInset(par.size(), inset.release(), + font, change); } } else if (token == "\\i") { - InsetOld * inset = new InsetLatexAccent; + auto_ptr inset(new InsetLatexAccent); inset->read(buf, lex); - par.insertInset(par.size(), inset, font, change); + par.insertInset(par.size(), inset.release(), font, change); } else if (token == "\\backslash") { par.insertChar(par.size(), '\\', font, change); } else if (token == "\\newline") { - InsetOld * inset = new InsetNewline; + auto_ptr inset(new InsetNewline); inset->read(buf, lex); - par.insertInset(par.size(), inset, font, change); + par.insertInset(par.size(), inset.release(), font, change); } else if (token == "\\LyXTable") { - InsetOld * inset = new InsetTabular(buf); + auto_ptr inset(new InsetTabular(buf)); inset->read(buf, lex); - par.insertInset(par.size(), inset, font, change); + par.insertInset(par.size(), inset.release(), font, change); } else if (token == "\\bibitem") { InsetCommandParams p("bibitem", "dummy"); - InsetBibitem * inset = new InsetBibitem(p); + auto_ptr inset(new InsetBibitem(p)); inset->read(buf, lex); - par.insertInset(par.size(), inset, font, change); + par.insertInset(par.size(), inset.release(), font, change); } else if (token == "\\hfill") { par.insertInset(par.size(), new InsetHFill, font, change); } else if (token == "\\lyxline") { diff --git a/src/rowpainter.C b/src/rowpainter.C index 0c892be7bb..6e1909b1f3 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -416,7 +416,7 @@ void RowPainter::paintSelection() } return; } - + if (startrow != rit_ && endrow != rit_) { if (y_ > starty && y_ < endy) { int w = width_; diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 4d2b06a823..df4afcd0f1 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,15 @@ +2003-11-03 Lars Gullik Bjønnes + + * tempname.C (tempName): use scoped_array for exception safety + + * os_os2.C (init): use scoped_array for exception safety + + * getcwd.C (getcwd): use scoped_array for exception safety + + * forkedcontr.C (addCall): adjust + + * forkedcall.h: make clone return a auto_ptr + 2003-11-01 Lars Gullik Bjønnes * debugstream.h: add a default constructor that does not setup a diff --git a/src/support/forkedcall.h b/src/support/forkedcall.h index 20ca2da766..f456d431e7 100644 --- a/src/support/forkedcall.h +++ b/src/support/forkedcall.h @@ -32,6 +32,8 @@ #include +#include + namespace lyx { namespace support { @@ -50,7 +52,7 @@ public: /// virtual ~ForkedProcess() {} /// - virtual ForkedProcess * clone() const = 0; + virtual std::auto_ptr clone() const = 0; /** A SignalType signal is can be emitted once the forked process * has finished. It passes: @@ -139,8 +141,8 @@ private: class Forkedcall : public ForkedProcess { public: /// - virtual ForkedProcess * clone() const { - return new Forkedcall(*this); + virtual std::auto_ptr clone() const { + return std::auto_ptr(new Forkedcall(*this)); } /** Start the child process. diff --git a/src/support/forkedcontr.C b/src/support/forkedcontr.C index 7c9edc0393..99cc6c7429 100644 --- a/src/support/forkedcontr.C +++ b/src/support/forkedcontr.C @@ -78,7 +78,7 @@ void ForkedcallsController::addCall(ForkedProcess const & newcall) if (!timeout_->running()) timeout_->start(); - forkedCalls.push_back(newcall.clone()); + forkedCalls.push_back(newcall.clone().release()); childrenChanged(); } diff --git a/src/support/getcwd.C b/src/support/getcwd.C index fb9d531715..95f7c5ddd9 100644 --- a/src/support/getcwd.C +++ b/src/support/getcwd.C @@ -15,6 +15,9 @@ #include "support/lyxlib.h" +#include + +using boost::scoped_array; using std::string; @@ -39,18 +42,17 @@ string const lyx::support::getcwd() { int n = 256; // Assume path is less than 256 chars char * err; - char * tbuf = new char[n]; + scoped_array tbuf(new char[n]); // Safe. Hopefully all getcwds behave this way! - while (((err = l_getcwd(tbuf, n)) == 0) && (errno == ERANGE)) { + while (((err = l_getcwd(tbuf.get(), n)) == 0) && (errno == ERANGE)) { // Buffer too small, double the buffersize and try again - delete[] tbuf; - n = 2 * n; - tbuf = new char[n]; + n *= 2; + tbuf.reset(new char[n]); } string result; - if (err) result = tbuf; - delete[] tbuf; + if (err) + result = tbuf.get(); return result; } diff --git a/src/support/os_os2.C b/src/support/os_os2.C index 2c3e8a3008..bf73d8e505 100644 --- a/src/support/os_os2.C +++ b/src/support/os_os2.C @@ -21,6 +21,10 @@ #define INCL_DOSERRORS #include +#include + +using boost::scoped_array; + namespace { string binpath_; @@ -44,12 +48,12 @@ void init(int * argc, char ** argv[]) APIRET rc = DosGetInfoBlocks(&ptib, &ppib); if (rc != NO_ERROR) exit(rc); - char* tmp = new char[256]; + scoped_array tmp(new char[256]); // This is the only reliable way to retrieve the executable name. rc = DosQueryModuleName(ppib->pib_hmte, 256L, tmp); if (rc != NO_ERROR) exit(rc); - string p = tmp; + string p = tmp.get(); p = slashify_path(p); binname_ = OnlyFilename(p); binname_.erase(binname_.length()-4, string::npos); diff --git a/src/support/tempname.C b/src/support/tempname.C index ee41011721..408e332a80 100644 --- a/src/support/tempname.C +++ b/src/support/tempname.C @@ -19,6 +19,10 @@ #include "debug.h" #include "os.h" +#include + +using boost::scoped_array; + using std::string; using std::endl; @@ -49,15 +53,14 @@ string const lyx::support::tempName(string const & dir, string const & mask) tmpfl += "XXXXXX"; // The supposedly safe mkstemp version - char * tmpl = new char[tmpfl.length() + 1]; // + 1 for '\0' - tmpfl.copy(tmpl, string::npos); + scoped_array tmpl(new char[tmpfl.length() + 1]); // + 1 for '\0' + tmpfl.copy(tmpl.get(), string::npos); tmpl[tmpfl.length()] = '\0'; // terminator - int const tmpf = make_tempfile(tmpl); + int const tmpf = make_tempfile(tmpl.get()); if (tmpf != -1) { - string const t(tmpl); + string const t(tmpl.get()); ::close(tmpf); - delete [] tmpl; lyxerr[Debug::FILES] << "Temporary file `" << t << "' created." << endl; return t; @@ -65,7 +68,6 @@ string const lyx::support::tempName(string const & dir, string const & mask) lyxerr[Debug::FILES] << "LyX Error: Unable to create temporary file." << endl; - delete [] tmpl; return string(); } } diff --git a/src/tex2lyx/text.C b/src/tex2lyx/text.C index 80827286c4..a1817e0410 100644 --- a/src/tex2lyx/text.C +++ b/src/tex2lyx/text.C @@ -1075,7 +1075,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, ss << '{' << p.verbatim_item() << "}\n"; handle_ert(os, ss.str(), context); } - + else if (t.cs() == "bibliographystyle") { // store new bibliographystyle bibliographystyle = p.verbatim_item(); diff --git a/src/trans_mgr.C b/src/trans_mgr.C index 6fa5319709..297d9db89d 100644 --- a/src/trans_mgr.C +++ b/src/trans_mgr.C @@ -191,11 +191,9 @@ TransManager::TransManager() {} +// For the sake of boost::scoped_ptr. TransManager::~TransManager() -{ - delete t1_; - delete t2_; -} +{} int TransManager::SetPrimary(string const & language) @@ -225,7 +223,7 @@ bool TransManager::setCharset(string const & str) void TransManager::EnablePrimary() { if (t1_->IsDefined()) - active_ = t1_; + active_ = t1_.get(); lyxerr[Debug::KBMAP] << "Enabling primary keymap" << endl; } @@ -234,7 +232,7 @@ void TransManager::EnablePrimary() void TransManager::EnableSecondary() { if (t2_->IsDefined()) - active_ = t2_; + active_ = t2_.get(); lyxerr[Debug::KBMAP] << "Enabling secondary keymap" << endl; } diff --git a/src/trans_mgr.h b/src/trans_mgr.h index 083ef24914..a9e45777eb 100644 --- a/src/trans_mgr.h +++ b/src/trans_mgr.h @@ -17,6 +17,8 @@ #include "chset.h" #include "trans_decl.h" +#include + class LyXText; class Trans; @@ -137,9 +139,9 @@ private: /// Trans * active_; /// - Trans * t1_; + boost::scoped_ptr t1_; /// - Trans * t2_; + boost::scoped_ptr t2_; /// static Trans default_; /// @@ -152,7 +154,7 @@ public: /// TransManager(); /// - virtual ~TransManager(); + ~TransManager(); /// int SetPrimary(std::string const &); /// diff --git a/src/undo.C b/src/undo.C index 5b6156dde5..44524212f5 100644 --- a/src/undo.C +++ b/src/undo.C @@ -89,7 +89,7 @@ ParIterator num2pit(BufferView * bv, int num) for ( ; num && pit != end; ++pit, --num) ; - + if (pit != end) return pit; -- 2.39.2