From 272e82d1174fdf303fcbbadc7648f75ac881ad3a Mon Sep 17 00:00:00 2001
From: David Kastrup <dak@gnu.org>
Date: Tue, 3 Nov 2015 13:36:54 +0100
Subject: [PATCH] Issue 4653: French beam ending on rest causes segfault

The issue here is that Stem::set-beaming may set one of the beaming
segment lists to #f instead of an empty list, and not all users of
"beaming" (in this case where_are_the_whole_beams) were prepared to
deal with this.
---
 lily/beam.cc          | 4 ++--
 lily/stem.cc          | 2 +-
 lily/tuplet-number.cc | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lily/beam.cc b/lily/beam.cc
index 206f6e9f4d..906483ed43 100644
--- a/lily/beam.cc
+++ b/lily/beam.cc
@@ -259,7 +259,7 @@ position_with_maximal_common_beams (SCM left_beaming, SCM right_beaming,
       for (SCM s = scm_car (right_beaming); scm_is_pair (s); s = scm_cdr (s))
         {
           int k = -right_dir * scm_to_int (scm_car (s)) + i;
-          if (scm_is_true (scm_c_memq (scm_from_int (k), left_beaming)))
+          if (scm_is_true (ly_memv (scm_from_int (k), left_beaming)))
             count++;
         }
 
@@ -1006,7 +1006,7 @@ where_are_the_whole_beams (SCM beaming)
 
   for (SCM s = scm_car (beaming); scm_is_pair (s); s = scm_cdr (s))
     {
-      if (scm_is_true (scm_c_memq (scm_car (s), scm_cdr (beaming))))
+      if (scm_is_true (ly_memv (scm_car (s), scm_cdr (beaming))))
 
         l.add_point (scm_to_int (scm_car (s)));
     }
diff --git a/lily/stem.cc b/lily/stem.cc
index 9cb84f57fa..f0335c58d2 100644
--- a/lily/stem.cc
+++ b/lily/stem.cc
@@ -91,7 +91,7 @@ Stem::get_beaming (Grob *me, Direction d)
 
   SCM lst = index_get_cell (pair, d);
 
-  int len = scm_ilength (lst);
+  int len = scm_ilength (lst); // -1 for dotted lists!
   return max (len, 0);
 }
 
diff --git a/lily/tuplet-number.cc b/lily/tuplet-number.cc
index 4d879ade4c..99e61b2ff5 100644
--- a/lily/tuplet-number.cc
+++ b/lily/tuplet-number.cc
@@ -336,7 +336,7 @@ count_beams_not_touching_stem (SCM beaming)
 
   for (SCM s = scm_car (beaming); scm_is_pair (s); s = scm_cdr (s))
     {
-      if (scm_is_true (scm_c_memq (scm_car (s), scm_cdr (beaming))))
+      if (scm_is_true (ly_memv (scm_car (s), scm_cdr (beaming))))
         ++count;
     }
 
-- 
2.39.5