]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 5041: Using eq? on numbers is undefined behavior
authorDavid Kastrup <dak@gnu.org>
Mon, 23 Jan 2017 23:29:22 +0000 (00:29 +0100)
committerDavid Kastrup <dak@gnu.org>
Mon, 30 Jan 2017 13:14:31 +0000 (14:14 +0100)
Fix this.  Also with regard to string comparisons (to the empty
string, but still rather iffy).

Documentation/snippets/new/transposing-pitches-with-minimum-accidentals-smart-transpose.ly [new file with mode: 0644]
Documentation/snippets/transposing-pitches-with-minimum-accidentals-smart-transpose.ly
input/regression/scheme-text-spanner.ly
lily/accidental-engraver.cc
lily/axis-group-interface.cc
lily/multi-measure-rest-engraver.cc
lily/stencil-integral.cc
ly/articulate.ly
scm/bar-line.scm
scm/fret-diagrams.scm
scm/output-lib.scm

diff --git a/Documentation/snippets/new/transposing-pitches-with-minimum-accidentals-smart-transpose.ly b/Documentation/snippets/new/transposing-pitches-with-minimum-accidentals-smart-transpose.ly
new file mode 100644 (file)
index 0000000..2cac27f
--- /dev/null
@@ -0,0 +1,84 @@
+\version "2.19.22"
+
+\header {
+  lsrtags = "pitches, scheme-language, workaround"
+
+  texidoc = "
+This example uses some Scheme code to enforce enharmonic modifications
+for notes in order to have the minimum number of accidentals.  In this
+case, the following rules apply:
+
+Double accidentals should be removed
+
+
+B sharp -> C
+
+
+E sharp -> F
+
+
+C flat -> B
+
+
+F flat -> E
+
+
+In this manner, the most natural enharmonic notes are chosen.
+
+"
+  doctitle = "Transposing pitches with minimum accidentals (\"Smart\" transpose)"
+}
+#(define (naturalize-pitch p)
+   (let ((o (ly:pitch-octave p))
+         (a (* 4 (ly:pitch-alteration p)))
+         ;; alteration, a, in quarter tone steps,
+         ;; for historical reasons
+         (n (ly:pitch-notename p)))
+     (cond
+      ((and (> a 1) (or (eqv? n 6) (eqv? n 2)))
+       (set! a (- a 2))
+       (set! n (+ n 1)))
+      ((and (< a -1) (or (eqv? n 0) (eqv? n 3)))
+       (set! a (+ a 2))
+       (set! n (- n 1))))
+     (cond
+      ((> a 2) (set! a (- a 4)) (set! n (+ n 1)))
+      ((< a -2) (set! a (+ a 4)) (set! n (- n 1))))
+     (if (< n 0) (begin (set! o (- o 1)) (set! n (+ n 7))))
+     (if (> n 6) (begin (set! o (+ o 1)) (set! n (- n 7))))
+     (ly:make-pitch o n (/ a 4))))
+
+#(define (naturalize music)
+   (let ((es (ly:music-property music 'elements))
+         (e (ly:music-property music 'element))
+         (p (ly:music-property music 'pitch)))
+     (if (pair? es)
+         (ly:music-set-property!
+          music 'elements
+          (map naturalize es)))
+     (if (ly:music? e)
+         (ly:music-set-property!
+          music 'element
+          (naturalize e)))
+     (if (ly:pitch? p)
+         (begin
+           (set! p (naturalize-pitch p))
+           (ly:music-set-property! music 'pitch p)))
+     music))
+
+naturalizeMusic =
+#(define-music-function (m)
+   (ly:music?)
+   (naturalize m))
+
+music = \relative c' { c4 d e g }
+
+\score {
+  \new Staff {
+    \transpose c ais { \music }
+    \naturalizeMusic \transpose c ais { \music }
+    \transpose c deses { \music }
+    \naturalizeMusic \transpose c deses { \music }
+  }
+  \layout { }
+}
index df6ce9d6c098260ec418a76c1ce22337da923153..3b209f08e2465aef6cf510c4feb954c1907bc3a2 100644 (file)
@@ -1,9 +1,10 @@
-%% DO NOT EDIT this file manually; it is automatically
-%% generated from LSR http://lsr.di.unimi.it
-%% Make any changes in LSR itself, or in Documentation/snippets/new/ ,
-%% and then run scripts/auxiliar/makelsr.py
-%%
-%% This file is in the public domain.
+% DO NOT EDIT this file manually; it is automatically
+% generated from Documentation/snippets/new
+% Make any changes in Documentation/snippets/new/
+% and then run scripts/auxiliar/makelsr.py
+%
+% This file is in the public domain.
+%% Note: this file works from version 2.19.22
 \version "2.19.22"
 
 \header {
@@ -42,10 +43,10 @@ In this manner, the most natural enharmonic notes are chosen.
          ;; for historical reasons
          (n (ly:pitch-notename p)))
      (cond
-      ((and (> a 1) (or (eq? n 6) (eq? n 2)))
+      ((and (> a 1) (or (eqv? n 6) (eqv? n 2)))
        (set! a (- a 2))
        (set! n (+ n 1)))
-      ((and (< a -1) (or (eq? n 0) (eq? n 3)))
+      ((and (< a -1) (or (eqv? n 0) (eqv? n 3)))
        (set! a (+ a 2))
        (set! n (- n 1))))
      (cond
index d97d215363db1d3f07414365b404e0122d408097..71bc1ff61d9da6f4f56d664cc293db24e502026c 100644 (file)
@@ -97,7 +97,7 @@ start and stop.")
        (ly:spanner-set-bound! spanner RIGHT item)))
 
 #(define (axis-offset-symbol axis)
-   (if (eq? axis X) 'X-offset 'Y-offset))
+   (if (eqv? axis X) 'X-offset 'Y-offset))
 
 #(define (set-axis! grob axis)
   (if (not (number? (ly:grob-property grob 'side-axis)))
@@ -105,7 +105,7 @@ start and stop.")
         (set! (ly:grob-property grob 'side-axis) axis)
         (ly:grob-chain-callback
          grob
-         (if (eq? axis X)
+         (if (eqv? axis X)
              ly:side-position-interface::x-aligned-side
              side-position-interface::y-aligned-side)
          (axis-offset-symbol axis)))))
index 1be735b0ed2dab1d7478370fb38d2daa59bf4be9..95ebf7caa97e8e72bbb0e1543a055411ea4a5ef9 100644 (file)
@@ -314,7 +314,7 @@ Accidental_engraver::make_standard_accidental (Stream_event * /* note */,
   */
   for (vsize i = 0; i < left_objects_.size (); i++)
     {
-      if (scm_is_eq (left_objects_[i]->get_property ("side-axis"), scm_from_int (X_AXIS)))
+      if (ly_is_equal (left_objects_[i]->get_property ("side-axis"), scm_from_int (X_AXIS)))
         Side_position_interface::add_support (left_objects_[i], a);
     }
 
index 38a193caf63dfc4659dc10a1245d2c9ab2785c69..ac6f85feb8e25bb810875d47567708194d762cd3 100644 (file)
@@ -946,7 +946,7 @@ Axis_group_interface::skyline_spacing (Grob *me)
       vector<Grob *> current_elts;
       current_elts.push_back (elements[i]);
       while (i + 1 < elements.size ()
-             && scm_is_eq (elements[i + 1]->get_property ("outside-staff-priority"), priority))
+             && ly_is_equal (elements[i + 1]->get_property ("outside-staff-priority"), priority))
         {
           if (!to_boolean (elements[i + 1]->get_property ("cross-staff")))
             current_elts.push_back (elements[i + 1]);
index 04ef91fc881a5744ae84615bdf2aadfe042738c5..0a6071b6144de4cb30260789e5f5067762c45590 100644 (file)
@@ -145,7 +145,7 @@ Multi_measure_rest_engraver::initialize_grobs ()
           Grob *last = 0;
           for (vsize i = 0; i < text_.size (); i++)
             {
-              if (scm_is_eq (dir, text_[i]->get_property ("direction")))
+              if (ly_is_equal (dir, text_[i]->get_property ("direction")))
                 {
                   if (last)
                     Side_position_interface::add_support (text_[i], last);
index 1b9aa5181b4e2426c915e7db3106e52052b003c5..2a61da23882454b8eda1844816bfacdbdb4cde74 100644 (file)
@@ -894,9 +894,8 @@ stencil_dispatcher (vector<Box> &boxes,
 vector<Transform_matrix_and_expression>
 stencil_traverser (PangoMatrix trans, SCM expr)
 {
-  if (scm_is_null (expr))
-    return vector<Transform_matrix_and_expression> ();
-  else if (scm_is_eq (expr, ly_string2scm ("")))
+  if (scm_is_null (expr)
+      || (scm_is_string (expr) && scm_is_true (scm_string_null_p (expr))))
     return vector<Transform_matrix_and_expression> ();
   else if (scm_is_eq (scm_car (expr), ly_symbol2scm ("combine-stencil")))
     {
index 1dc0e5566b1868a8153501e4be362487e40641fe..2b418cee7b265e13083e5aeec1eae4595ab61425 100644 (file)
 #(define (ac:up note)
   (let* ((pitch (ly:music-property note 'pitch))
          (notename (ly:pitch-notename pitch))
-         (new-notename (if (eq? notename 6) 0 (+ 1 notename)))
+         (new-notename (if (eqv? notename 6) 0 (+ 1 notename)))
          (alterations (ly:music-property ac:current-key 'pitch-alist))
          (new-alteration (cdr (assq new-notename alterations)))
-         (new-octave (if (eq? new-notename 0) (+ 1 (ly:pitch-octave pitch))
+         (new-octave (if (eqv? new-notename 0) (+ 1 (ly:pitch-octave pitch))
                       (ly:pitch-octave pitch)))
        )
    (set! (ly:music-property note 'pitch)(ly:make-pitch new-octave new-notename new-alteration))))
 #(define (ac:down note)
   (begin  (let* ((pitch (ly:music-property note 'pitch))
          (notename (ly:pitch-notename pitch))
-         (new-notename (if (eq? notename 0) 6 (- notename 1)))
+         (new-notename (if (eqv? notename 0) 6 (- notename 1)))
          (alterations (ly:music-property ac:current-key 'pitch-alist))
          (new-alteration (cdr (assq new-notename alterations)))
-         (new-octave (if (eq? new-notename 6) (- (ly:pitch-octave pitch) 1)
+         (new-octave (if (eqv? new-notename 6) (- (ly:pitch-octave pitch) 1)
                       (ly:pitch-octave pitch)))
        )
    (set! (ly:music-property note 'pitch)(ly:make-pitch new-octave new-notename new-alteration))))
 
        ((SlurEvent)
         (let ((direction (ly:music-property e 'span-direction)))
-         (set! ac:inSlur (eq? direction -1))
-         (set! at-end-of-slur (eq? direction 1))
+         (set! ac:inSlur (eqv? direction -1))
+         (set! at-end-of-slur (eqv? direction 1))
          (loop factor newelements tail actions)))
 
        ((TrillSpanEvent)
         (let ((direction (ly:music-property e 'span-direction)))
-         (set! ac:inTrill (eq? direction -1))
+         (set! ac:inTrill (eqv? direction -1))
          (if ac:inTrill
           (loop factor newelements tail (cons 'trill actions))
           (loop factor (cons e newelements) tail actions))))
 
        ((PhrasingSlurEvent)
         (let ((direction (ly:music-property e 'span-direction)))
-         (set! ac:inPhrasingSlur (eq? direction -1))
+         (set! ac:inPhrasingSlur (eqv? direction -1))
          (loop factor newelements tail actions)))
 
        (else (loop factor (cons e newelements) tail actions))))))))
           (len (ly:duration-log ac:currentDuration))
           (dots (ly:duration-dot-count ac:currentDuration)))
 
-         (if (not (eq? num denom))
+         (if (not (eqv? num denom))
           (make-sequential-music
            (list (ac:to128 music)
            (make-music 'EventChord 'elements
@@ -1013,7 +1013,7 @@ articulate = #(define-music-function (music)
          (grace-orig-len (ly:music-length grace))
          (main-orig-len (ly:music-length main))
          (numerator (ly:moment-main-numerator maindur))
-         (factor (if (eq? (remainder numerator 3) 0)
+         (factor (if (eqv? (remainder numerator 3) 0)
                   (ly:make-moment 1/3) (ly:make-moment 1/2))))
    (ly:music-compress grace
     (ly:moment-mul factor (ly:moment-div main-orig-len grace-orig-len)))
index 86d12d9b217fe8c5f70ef869ff6d2e5a718955fb..3fad8f8912949bf96a9944b6a1019432be850cb3 100644 (file)
@@ -512,7 +512,7 @@ opening bracket will be drawn, for @code{RIGHT} we get the closing bracket."
                                               (interval-start extent)
                                               Y))))
 
-    (if (eq? dir LEFT)
+    (if (eqv? dir LEFT)
         stencil
         (ly:stencil-scale stencil -1 1))))
 
index 3738d2cabfaf5ccb8912794881157457c9ff05e2..6dda45292852bdc0937521eda8abb1286d343b91 100644 (file)
@@ -872,7 +872,7 @@ at @var{fret}."
          label-stencil
          (stencil-coordinates
           (* size fret-distance (1+ label-vertical-offset))
-          (if (eq? label-dir LEFT)
+          (if (eqv? label-dir LEFT)
               (- label-outside-diagram)
               (+ (* size string-distance (1- string-count))
                  label-outside-diagram))))))
index 46d085ef8f62212a0b022916ec12019f3a48095e..5184fdb3377fae3444b6d3a6b40a3d7075ab7611 100644 (file)
@@ -1205,7 +1205,7 @@ and draws the stencil based on its coordinates.
   ;; outer let to trigger suicide
   (let ((sten (ly:hairpin::print grob)))
     (if (grob::is-live? grob)
-        (let* ((decresc? (eq? (ly:grob-property grob 'grow-direction) LEFT))
+        (let* ((decresc? (eqv? (ly:grob-property grob 'grow-direction) LEFT))
                (thick (ly:grob-property grob 'thickness 0.1))
                (thick (* thick (layout-line-thickness grob)))
                (xex (ly:stencil-extent sten X))