Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2865)

Issue 5755058: Issue 2376: Automatic footnotes on \null markups causes unexpected results (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years, 1 month ago by dak
Modified:
12 years, 1 month ago
Reviewers:
mike, MikeSol
CC:
lilypond-devel_gnu.org
Base URL:
http://git.savannah.gnu.org/gitweb/?p=lilypond.git/trunk/
Visibility:
Public.

Description

Issue 2376: Automatic footnotes on \null markups causes unexpected results The page layout routines passed around pointers to stencils rather indiscriminately and worked on them rather than on stencil copies. Sort of copy-on-write without the copy. This tries working on actual copies where appropriate.

Patch Set 1 #

Total comments: 3

Patch Set 2 : Ok, hope I got most of the problems in interfaces and usage and did not change meanings. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+59 lines, -57 lines) Patch
M lily/include/page-layout-problem.hh View 1 2 chunks +3 lines, -2 lines 0 comments Download
M lily/page-breaking.cc View 1 2 chunks +7 lines, -7 lines 0 comments Download
M lily/page-layout-problem.cc View 1 9 chunks +49 lines, -48 lines 0 comments Download

Messages

Total messages: 5
MikeSol
http://codereview.appspot.com/5755058/diff/1/lily/page-breaking.cc File lily/page-breaking.cc (right): http://codereview.appspot.com/5755058/diff/1/lily/page-breaking.cc#newcode584 lily/page-breaking.cc:584: } Just a C++ question - do these lines ...
12 years, 1 month ago (2012-03-07 07:30:42 UTC) #1
dak
http://codereview.appspot.com/5755058/diff/1/lily/page-breaking.cc File lily/page-breaking.cc (right): http://codereview.appspot.com/5755058/diff/1/lily/page-breaking.cc#newcode584 lily/page-breaking.cc:584: } On 2012/03/07 07:30:42, MikeSol wrote: > Just a ...
12 years, 1 month ago (2012-03-07 07:40:58 UTC) #2
dak
http://codereview.appspot.com/5755058/diff/1/lily/page-layout-problem.cc File lily/page-layout-problem.cc (right): http://codereview.appspot.com/5755058/diff/1/lily/page-layout-problem.cc#newcode343 lily/page-layout-problem.cc:343: return footnote_separator; Uh, Mike? You call a Scheme function ...
12 years, 1 month ago (2012-03-07 08:48:56 UTC) #3
mike_apollinemike.com
On Mar 7, 2012, at 8:48 AM, dak@gnu.org wrote: > Given the level and amount ...
12 years, 1 month ago (2012-03-07 12:52:41 UTC) #4
dak
12 years, 1 month ago (2012-03-07 13:25:54 UTC) #5
"mike@apollinemike.com" <mike@apollinemike.com> writes:

> On Mar 7, 2012, at 8:48 AM, dak@gnu.org wrote:
>
>> Given the level and amount of code you write, it might be worth
>> investing the time rereading the garbage collection chapter of the Guile
>> manual.
>> 
>
> You're right that I know nothing about guile's garbage
> collection...it'd help to know this.

In a nutshell: if an SCM object is not referenced, the garbage collector
is free to throw it and its contents away.

As a reference counts:

a) getting marked using scm_gc_mark during garbage collection (mark
phase) because another referenced object does this.  All Scheme data
structures do that to their members (with the exception of "weak" parts
of a hash table).  Our own "Scheme" objects need to do this to their
contents via their own mark subroutines (like derived_mark).

b) getting permanently "protected".  Many of our own data structures
when created with new start out in protected state (since they don't
have an SCM referencing them yet, hard to avoid) and convert into SCM
via a call to unprotect () once they are properly initialized so that
calling their mark routine does not cause uninitialized garbage to be
marked.

c) having an SCM type variable in the stack referencing it.  This is a
somewhat shaky operation since the compiler may optimize variables away
when they are no longer needed.  If that is a concern, you can use
scm_remember_upto_here_1 and its cousins to keep the SCM variables
alive.

Strictly speaking, code like

      Stencil *s = unsmob_stencil (Text_interface::interpret_markup (layout, pro
      if (!s)
        {
          programming_error ("Your numbering function needs to return a stencil.
          footnote_number_markups.push_back (SCM_EOL);
          footnote_number_stencils.push_back (Stencil (Box (Interval (0, 0), Int
        }
      else
        {
          footnote_number_markups.push_back (markup);
          footnote_number_stencils.push_back (*s);
        }
      counter++;

is already borderline.  From the time of unsmob_stencil, the returned
markup is no longer protected as an SCM object.  If
footnote_number_markups.push_back were to cause Scheme garbage
collection to trigger, *s would likely already be trashed.

If we get a multithreaded garbage collector at one point of time, you
first need to assign the result of interpret_markup to an SCM variable
and put an scm_remember_upto_here_1 on this variable after the last use
of the unsmobbed stencil pointer.  Of course, if the unsmobbed object is
part of a larger protected data structure, you need not worry all that
much.  Much of the Grob * in our code base is rather laissez-faire about
protection because the grobs are usually registered somewhere else.  For
example, Grob_info does not bother protecting its contents at all if I
remember correctly because it assumes that they will live longer than
the Grob_info because of unrelated reasons.

> I'll investigate.  It'd also be good to do a little write-up for the
> CG w/ garbage collection dos and don'ts in the LilyPond base
> (i.e. what mark_smob, derived_mark, unsmob_thingee, smobbed_copy,
> self_scm & co. all mean).

A smobbed_copy is a Scheme object with the same contents as the original
but not using it (and thus also not protecting it from collection).  A
self_scm is a Scheme object referencing the original.  unsmob gives a
pointer to the unwrapped object.  mark_smob is called during the mark
phase of a referenced object and should in turn mark all SCM objects
that it references.

-- 
David Kastrup
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b