Le 17/10/2015 12:00, Georg Baum a écrit :
Guillaume Munch wrote:
But if the memory usage is still too high, various solutions:
* pointer comparison (what is your opinion on pointer comparison vs.
using a counter?)
* variable-length integers encoding.
* pointer comparison, but somehow keep the possibility to use a counter
instead for using jointly with the other debug options.

The two last ones are probably too complicated. As I see it, we do now have
a trade off between easier debugging (ids), and less memory consumption
(pointers). Apart from that, both solutions would work. Since you are the
one who is probably doing most of the debugging work please decide, I am now
fine with either solution.


The choice is simple, because just adding a new variable member to math
insets as per the attached (trivial) .diff leads to new segfaults with
math macros. The .diff must be applied to current master (before or
after my upcoming TexRow patches). Compiler is g++ 4.9.2 in C++11 mode
(I did not try with C++98). Then open the attached segv-math-demo.lyx,
select all and hold Ctrl+C until it crashes (not more than a few seconds).

The backtrace is as follows:

#0 0x0000000000816c47 in lyx::MathMacro::optionals (this=this@entry=0x978e140)
    at ../../src/mathed/MathMacro.cpp:733
#1  0x00000000007f8bf9 in lyx::MathData::detachMacroParameters (
this=this@entry=0x6451df0, cur=cur@entry=0x0, macroPos=macroPos@entry=0)
    at ../../src/mathed/MathData.cpp:528
#2  0x00000000007facab in lyx::MathData::updateMacros (this=0x6451df0,
    cur=cur@entry=0x0, mc=..., utype=utype@entry=lyx::OutputUpdate)
    at ../../src/mathed/MathData.cpp:437
#3  0x00000000004b7fac in lyx::Buffer::updateMacroInstances (
    this=this@entry=0x8885a60, utype=utype@entry=lyx::OutputUpdate)
    at ../../src/Buffer.cpp:3365
#4  0x0000000000567a28 in lyx::(anonymous namespace)::putClipboard (
    paragraphs=..., docclass=std::shared_ptr (count 5, weak 0) 0x2ad5390,
    plaintext=L"(…)"...)
    at ../../src/CutAndPaste.cpp:548
#5  0x0000000000568f32 in lyx::cap::copySelection (cur=...,
    plaintext=L"(…)"...)
    at ../../src/CutAndPaste.cpp:1026


In addition, I saw the following message several times while preparing
the MWE (though I do not know if it's relevant):

Buffer.cpp (334): Warning: a buffer should not have two parents!


The crash does not occur if we only apply the diff on InsetMath.h, i.e.
if we change the structure of the class but leave the new member
uninitialized. (An ironic twist on the g++-5 crash-on-copy bug which
occurs when some variables are not initialized that I saw passing on the
list, if you want.)

So it seems in that mathed/ is in a brittle state. This is a deeper
reason for just using pointers for now. This seems serious. Or did
I miss something obvious to C++ experts?


Guillaume

diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
index 94b4d68..e8e2778 100644
--- a/src/mathed/InsetMathNest.cpp
+++ b/src/mathed/InsetMathNest.cpp
@@ -81,14 +81,16 @@ using cap::selClearOrDel;
 
 
 InsetMathNest::InsetMathNest(Buffer * buf, idx_type nargs)
-	: InsetMath(buf), cells_(nargs), lock_(false)
+	: InsetMath(buf), cells_(nargs), lock_(false),
+	  uid_(0)
 {
 	setBuffer(*buf);
 }
 
 
 InsetMathNest::InsetMathNest(InsetMathNest const & inset)
-	: InsetMath(inset), cells_(inset.cells_), lock_(inset.lock_)
+	: InsetMath(inset), cells_(inset.cells_), lock_(inset.lock_),
+	  uid_(0)
 {}
 
 
diff --git a/src/mathed/InsetMathNest.h b/src/mathed/InsetMathNest.h
index b9cc1f6..326bbef 100644
--- a/src/mathed/InsetMathNest.h
+++ b/src/mathed/InsetMathNest.h
@@ -193,6 +193,8 @@ private:
 	bool cursorMathForward(Cursor & cur);
 	/// move cursor backwards
 	bool cursorMathBackward(Cursor & cur);
+	///
+	int uid_;
 
 protected:
 	/// we store the cells in a vector

Attachment: segv-math-demo.lyx
Description: application/lyx

Attachment: segv-math-demo-aux.lyx
Description: application/lyx

Reply via email to