]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/GraphicsConverter.cpp
Avoid null pointer dereference
[lyx.git] / src / graphics / GraphicsConverter.cpp
index 63b6a44633adddf084f498dbb425e8ae7ac76dcf..c97e76663d3b1d746a37e07627d587b18d196341 100644 (file)
 
 #include "GraphicsConverter.h"
 
-#include "Buffer.h"
 #include "Converter.h"
 #include "Format.h"
-#include "LyXRC.h"
 
-#include "frontends/alert.h"
 #include "support/lassert.h"
 #include "support/convert.h"
 #include "support/debug.h"
@@ -25,9 +22,7 @@
 #include "support/filetools.h"
 #include "support/ForkedCalls.h"
 #include "support/lstrings.h"
-#include "support/os.h"
 
-#include "support/bind.h"
 #include "support/TempFile.h"
 
 #include <sstream>
@@ -40,10 +35,12 @@ namespace lyx {
 
 namespace graphics {
 
-class Converter::Impl : public boost::signals2::trackable {
+class Converter::Impl {
 public:
        ///
-       Impl(FileName const &, FileName const &, string const &, string const &, string const &);
+       Impl(Converter const & parent, FileName const & doc_fname,
+            FileName const & from_file, string const & to_file_base,
+            string const & from_format, string const & to_format);
 
        ///
        void startConversion();
@@ -58,10 +55,12 @@ public:
        /** At the end of the conversion process inform the outside world
         *  by emitting a signal.
         */
-       typedef boost::signals2::signal<void(bool)> SignalType;
+       typedef signal<void(bool)> sig;
        ///
-       SignalType finishedConversion;
+       sig finishedConversion;
 
+       ///
+       Converter const & parent_;
        ///
        FileName const doc_fname_;
        ///
@@ -85,25 +84,19 @@ bool Converter::isReachable(string const & from_format_name,
 
 
 Converter::Converter(FileName const & doc_fname,
-                    FileName const & from_file, string const & to_file_base,
-                    string const & from_format, string const & to_format)
-       : pimpl_(new Impl(doc_fname, from_file, to_file_base, from_format, to_format))
+                     FileName const & from_file, string const & to_file_base,
+                     string const & from_format, string const & to_format)
+       : pimpl_(make_shared<Impl>(*this, doc_fname, from_file, to_file_base, from_format, to_format))
 {}
 
 
-Converter::~Converter()
-{
-       delete pimpl_;
-}
-
-
 void Converter::startConversion() const
 {
        pimpl_->startConversion();
 }
 
 
-boost::signals2::connection Converter::connect(slot_type const & slot) const
+connection Converter::connect(slot_type const & slot) const
 {
        return pimpl_->finishedConversion.connect(slot);
 }
@@ -124,10 +117,10 @@ static void build_script(string const & doc_fname,
                  ostream & script);
 
 
-Converter::Impl::Impl(FileName const & doc_fname,
+Converter::Impl::Impl(Converter const & parent, FileName const & doc_fname,
                      FileName const & from_file, string const & to_file_base,
                      string const & from_format, string const & to_format)
-       : doc_fname_(doc_fname), valid_process_(false), finished_(false)
+       : parent_(parent), doc_fname_(doc_fname), valid_process_(false), finished_(false)
 {
        LYXERR(Debug::GRAPHICS, "Converter c-tor:\n"
                << "doc_fname:        " << doc_fname
@@ -188,9 +181,13 @@ void Converter::Impl::startConversion()
                return;
        }
 
-       ForkedCall::SignalTypePtr ptr =
-               ForkedCallQueue::add(script_command_);
-       ptr->connect(bind(&Impl::converted, this, _1, _2));
+       ForkedCall::sigPtr ptr = ForkedCallQueue::add(script_command_);
+       weak_ptr<Converter::Impl> this_ = parent_.pimpl_;
+       ptr->connect([this_](pid_t pid, int retval){
+                       if (auto p = this_.lock()) {
+                               p->converted(pid, retval);
+                       }
+               });
 }
 
 
@@ -283,8 +280,7 @@ static void build_script(string const & doc_fname,
        LYXERR(Debug::GRAPHICS, "build_script ... ");
        typedef Graph::EdgePath EdgePath;
 
-       script << "#!/usr/bin/env python\n"
-                 "# -*- coding: utf-8 -*-\n"
+       script << "# -*- coding: utf-8 -*-\n"
                  "import os, shutil, sys\n\n"
                  "def unlinkNoThrow(file):\n"
                  "  ''' remove a file, do not throw if an error occurs '''\n"
@@ -377,9 +373,9 @@ static void build_script(string const & doc_fname,
 
                // If two formats share the same extension we may get identical names
                if (outfile == infile && conv.result_file().empty()) {
-                       TempFile tempfile(addExtension("gconvertXXXXXX", conv.To()->extension()));
-                       tempfile.setAutoRemove(false);
-                       outfile = tempfile.name().toFilesystemEncoding();
+                       TempFile tmpfile(addExtension("gconvertXXXXXX", conv.To()->extension()));
+                       tmpfile.setAutoRemove(false);
+                       outfile = tmpfile.name().toFilesystemEncoding();
                }
 
                if (!theConverters().checkAuth(conv, doc_fname))