Skip to Content.
Sympa Menu

texmacs-users - [TeXmacs] Texmacs segfaults when closing documents: Solved?

Subject: mailing-list for TeXmacs Users

List archive

[TeXmacs] Texmacs segfaults when closing documents: Solved?


Chronological Thread 
  • From: Enrique Perez-Terron <address@hidden>
  • To: address@hidden
  • Subject: [TeXmacs] Texmacs segfaults when closing documents: Solved?
  • Date: Fri, 03 Oct 2008 05:36:59 +0200

I have had a look at the source code. Widgets are ref-counted, and
automatically deleted when the refcount comes down to zero.

Setting a breakpoint in the destructor for edit_interface_rep, I found
the refcount was zero. However, when if calls is_attached(this) a new
reference is created, and when this reference is deleted as it goes out
of scope, the reference count goes to zero again. This initiates a
second call to the destructor for the same object.

The reference is created because is_attached() is declared to take a
'widget' object, ie a reference-counting pointer. The 'this' pointer is
just a pointer, but the compiler constructs a temporary 'widget' object.

I tried to add a boolean "is_dying" to the base class holding the
reference counter, and an additional condition before deleting, so it
only deletes if the refcount becomes zero and is_dying is false.

Then texmacs does not crash.
--- texmacs-1.0.6.14/src/Kernel/Abstractions/basic.hpp 2008-03-19
18:16:36.000000000 +0100
+++ texmacs-new/src/Kernel/Abstractions/basic.hpp 2008-10-03
04:41:13.000000000 +0200
@@ -105,14 +105,16 @@
extern int concrete_count;
struct concrete_struct {
int ref_count;
- inline concrete_struct (): ref_count (1) { DEBUG(concrete_count++); }
+ bool deleting;
+ inline concrete_struct (): ref_count (1), deleting(false)
{ DEBUG(concrete_count++); }
virtual inline ~concrete_struct () { DEBUG(concrete_count--); }
};

extern int abstract_count;
struct abstract_struct {
int ref_count;
- inline abstract_struct (): ref_count (0) { DEBUG(abstract_count++); }
+ bool deleting;
+ inline abstract_struct (): ref_count (0), deleting(false)
{ DEBUG(abstract_count++); }
virtual inline ~abstract_struct () { DEBUG(abstract_count--); }
};

@@ -131,9 +133,10 @@

******************************************************************************/

#define INC_COUNT(R) { (R)->ref_count++; }
-#define DEC_COUNT(R) { if(0==--((R)->ref_count)) delete (R); }
+#define DEC_COUNT(R) { if(!(R)->deleting && 0==--((R)->ref_count))
\
+ {(R)->deleting = true; delete (R);} }
#define INC_COUNT_NULL(R) { if ((R)!=NULL) (R)->ref_count++; }
-#define DEC_COUNT_NULL(R) { if ((R)!=NULL && 0==--((R)->ref_count))
delete (R); }
+#define DEC_COUNT_NULL(R) { if ((R)!=NULL) DEC_COUNT(R); }

// concrete
#define CONCRETE(PTR) \





Archive powered by MHonArc 2.6.19.

Top of Page