On 04/20/2013 06:37 PM, Richard Heck wrote:
On 04/20/2013 12:16 PM, Georg Baum wrote:
Scott Kostyshak wrote:

I'm getting a SIGSEGV now. I can reproduce on Ubuntu 12.04 with the
following: 1. Open the User's Guide, Additional Features, Embedded
Objects, or Math manual. 2. Select all
3. Copy
Thanks, I can reproduce it. The attached patch works around the problem. It
looks like the temp buffer misses the math macro definitions (a call to
updateMacros() which should set docit_ did not help). Does anybody know a
better solution?

My general thought after looking at this is that we need to do some work on the paragraphs, after we paste them into the new buffer, and that the work we need to do is very much like what happens when we do a real paste. So perhaps the thing to do is try to use pasteParagraphList() here, or something of the sort, since all that work does actually get done there.

Of course, the problem here is that we need to pass a Cursor to pasteParagraphList(), and we do not have a BufferView for the temp Buffer. But it seems the right idea.

So what we really needed here is an updateMacros() call, but the other issue was that this only does what we need it to do---call recordLocation() to set docit_---if we are exporting the Buffer. So that had to be set, as well.

The attached patch works for me, but there are some things about it that are a bit hackish at this point. I'll work on it a bit more and fix that problem.

Richard

>From 009078790608fd7f33e6279dd275a5926cc77aaa Mon Sep 17 00:00:00 2001
From: Richard Heck <rgh...@lyx.org>
Date: Sat, 20 Apr 2013 19:15:00 -0400
Subject: [PATCH] Temp.

---
 src/Buffer.cpp      | 18 ------------------
 src/Buffer.h        | 19 ++++++++++++++++++-
 src/CutAndPaste.cpp |  8 ++++++--
 src/DocIterator.h   |  3 +++
 4 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index adda71f..1d9061c 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -3726,24 +3726,6 @@ bool Buffer::autoSave() const
 }
 
 
-// helper class, to guarantee this gets reset properly
-class Buffer::MarkAsExporting {
-public:
-	MarkAsExporting(Buffer const * buf) : buf_(buf)
-	{
-		LASSERT(buf_, /* */);
-		buf_->setExportStatus(true);
-	}
-	~MarkAsExporting()
-	{
-		buf_->setExportStatus(false);
-	}
-private:
-	Buffer const * const buf_;
-};
-
-
-
 void Buffer::setExportStatus(bool e) const
 {
 	d->doing_export = e;
diff --git a/src/Buffer.h b/src/Buffer.h
index 18e57f9..81b50c5 100644
--- a/src/Buffer.h
+++ b/src/Buffer.h
@@ -94,6 +94,9 @@ typedef std::set<Buffer *> CloneList;
  * minimal, probably not.
  * \author Lars Gullik Bjønnes
  */
+
+class MarkAsExporting;
+
 class Buffer {
 public:
 	/// What type of log will \c getLogName() return?
@@ -717,7 +720,6 @@ public:
 	int charCount(bool with_blanks) const;
 
 private:
-	class MarkAsExporting;
 	friend class MarkAsExporting;
 	/// mark the buffer as busy exporting something, or not
 	void setExportStatus(bool e) const;
@@ -753,6 +755,21 @@ private:
 };
 
 
+class MarkAsExporting {
+public:
+	MarkAsExporting(Buffer const * buf) : buf_(buf)
+	{
+		buf_->setExportStatus(true);
+	}
+	~MarkAsExporting()
+	{
+		buf_->setExportStatus(false);
+	}
+private:
+	Buffer const * const buf_;
+};
+
+
 } // namespace lyx
 
 #endif
diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp
index def5683..53547f0 100644
--- a/src/CutAndPaste.cpp
+++ b/src/CutAndPaste.cpp
@@ -99,7 +99,7 @@ bool checkPastePossible(int index)
 
 
 pair<PitPosPair, pit_type>
-pasteSelectionHelper(Cursor const & cur, ParagraphList const & parlist,
+pasteSelectionHelper(DocIterator const & cur, ParagraphList const & parlist,
 		     DocumentClassConstPtr oldDocClass, ErrorList & errorlist)
 {
 	Buffer const & buffer = *cur.buffer();
@@ -472,9 +472,13 @@ void putClipboard(ParagraphList const & paragraphs,
 	static Buffer * buffer = theBufferList().newInternalBuffer(
 		FileName::tempName("clipboard.internal").absFileName());
 	buffer->setUnnamed(true);
-	buffer->paragraphs() = paragraphs;
 	buffer->inset().setBuffer(*buffer);
 	buffer->params().setDocumentClass(docclass);
+	DocIterator dit = doc_iterator_begin(buffer, &buffer->inset());
+	ErrorList el;
+	pasteSelectionHelper(dit, paragraphs, docclass, el);
+	MarkAsExporting mex(buffer);
+	buffer->updateMacros();
 	string lyx;
 	ostringstream oslyx;
 	if (buffer->write(oslyx))
diff --git a/src/DocIterator.h b/src/DocIterator.h
index 3d5647c..8ca29d5 100644
--- a/src/DocIterator.h
+++ b/src/DocIterator.h
@@ -143,6 +143,9 @@ public:
 	/// are we in regexp-mode ?
 	bool inRegexped() const;
 
+	///
+	virtual void forceBufferUpdate() const {}
+
 	//
 	// math-specific part
 	//
-- 
1.7.11.7

Reply via email to