Re: PieceTables? Hmm...

Jeff Hostetler (jeff@abisource.com)
Sun, 25 Apr 1999 05:26:08 -0500


hello. don't i know you from a previous common employer ??

Matt Kimball wrote:
>
> So, after playing with it a bit, I found a reliable way to crash it:
>
> 1. Start up AbiWord
> 2. Type Alt-Enter, Backspace, Delete
>
> Ok, so at this point I wanted to get my hands dirty and see if I could
> fix the bug, so I started traipsing through the source, and it looks
> like the section created with the Alt-Enter is being deleted with the
> backspace, but its child block doesn't have its m_pSectionLayout
> pointer updated when this happends, so we get a block with a stale
> m_pSectionLayout pointer.

yes that looks to be the problem. BTW there's a Test_Dump method that
will (in 0.5.4 and earlier) dump the contents of the piece table to a
file (dump.ptbl.%d). in the current CVS view and in the upcomming 0.5.5
it will also dump the contents of the format/layout (dump.fmt.%d). these
will either be in your current directory or in the exe directory. check
src/wp/ap/xp/ap_LB_Default.cpp for the key/mouse binding in your view of
the src. it's probably worth the effort to do a CVS update to get my
latest enhancements to the debug info....

> So I trace through the code in the src/text tree for a while and look
> at all that it does, but there is a lot going on, and a lot of it
> isn't immediately obvious and isn't documented. So, I'm not very
> clear on what exactly should be updating the stale pointer.

i'm going to hold off on tracking this down myself (although i did
verify that it crashes) so that i can help you do it. it seems that
you've stumbled upon a nice rough edge (sorry). there are two pieces
of code: the PieceTable and the Format/Layout. the PieceTable represents
the content of the document along with its undo/redo. the Format/Layout
(along with the Format/View code) deals with all issues of presentation.
the problem you are seeing is on the edge between these two bodies of
code.

launch it again, do a Test_Dump; hit Alt-Enter, do a Test_Dump;
and hit Backspace, do a Test_Dump. you'll should see in the second
dump <section><block><section><block> (in the new fmt dump you'll
see <section><block><text len=0><section><block><text len=0>).
the insertion point should be after the second block (it's not printed
in the dump).

in the third dump, we have <section><block><block>.

i'm thinking that the backspace operation should have deleted both
the section and the block rather than just the second section. that
is after the backspace the dump should (give or take a pointer value)
look like the first dump.

if so the DELETE operation shouldn't have any effect, since it'll be
at the end of the document.

> Furthermore, pt_PieceTable.h seems to reference some
> ".../dev/design/PieceTable.html" somewhere, but I can't find it. So,
> uhh, where is it, and is there any documentation on the stuff in the
> src/text tree which I perhaps missed? What can I read to figure what
> is going on in all that src/text stuff?

unfortunately, the docs are a little thin in this area. the PieceTable.html
do is <embarrassed>still</embarrassed> still on the main web site
[ http://www.abisource.com/dev/design/PieceTable.html ] but consists
of my intial design notes -- i've been working on rewriting it but i've
not made much progress in a while. notes on the Format/Layout can be found
in the source tree in abi/docs/AbiWord_LayoutDesign.html -- but again this
is a little thin.

as a quick roadmap, i offer the following -- i don't know how helpful
it'll be as you've probably already mastered most of this, but anyway....

changes to the document originate in src/wp/ap/xp/ap_EditMethods in
response to user actions. these call src/text/fmt/fv_View routines.
these call into the PieceTable to actually effect change in the document.
the PieceTable makes callbacks into the Format/Layouts (there can be more
than one of these per document when we have multiple windows open on a
document). The Format/Layout makes corresponding changes to its data
structures and updates the screen as necessary.

the piece table holds things in "fragments". everything is a frag -- section,
block, text, inline-image, computed-field, etc. and in a linear ordering.

the layout holds things in "layouts" and "runs". "layouts" reflect the
block structure of the document (section, paragraphs, columns, etc) and
"runs" represent the in-line content (text, computed-field, inline-images, etc)

there is a rough correspondence between frags and layouts and runs, but
it's not easy to describe. for example a single text fragment might hold
an entire paragraph's content, but will be represented as a series of
runs -- one for each line that the line breaker produces.

for quick access back and forth across the boundary, the PieceTable
and Layout exchange "handles" (sdh & sfh) for every strux (section, block).

hope this helps (and thanks for the prod to update our docs :-)
jeff



This archive was generated by hypermail 1.03b2.