From: David Kastrup Date: Mon, 23 Jan 2017 23:29:22 +0000 (+0100) Subject: Issue 5041: Using eq? on numbers is undefined behavior X-Git-Url: https://git.donarmstrong.com/lilypond.git?a=commitdiff_plain;h=ca342a542bee6a28662c88b497819c86f904fb40;p=lilypond.git Issue 5041: Using eq? on numbers is undefined behavior Fix this. Also with regard to string comparisons (to the empty string, but still rather iffy). --- 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 index 0000000000..2cac27f8fb --- /dev/null +++ b/Documentation/snippets/new/transposing-pitches-with-minimum-accidentals-smart-transpose.ly @@ -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 { } +} diff --git a/Documentation/snippets/transposing-pitches-with-minimum-accidentals-smart-transpose.ly b/Documentation/snippets/transposing-pitches-with-minimum-accidentals-smart-transpose.ly index df6ce9d6c0..3b209f08e2 100644 --- a/Documentation/snippets/transposing-pitches-with-minimum-accidentals-smart-transpose.ly +++ b/Documentation/snippets/transposing-pitches-with-minimum-accidentals-smart-transpose.ly @@ -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 diff --git a/input/regression/scheme-text-spanner.ly b/input/regression/scheme-text-spanner.ly index d97d215363..71bc1ff61d 100644 --- a/input/regression/scheme-text-spanner.ly +++ b/input/regression/scheme-text-spanner.ly @@ -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))))) diff --git a/lily/accidental-engraver.cc b/lily/accidental-engraver.cc index 1be735b0ed..95ebf7caa9 100644 --- a/lily/accidental-engraver.cc +++ b/lily/accidental-engraver.cc @@ -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); } diff --git a/lily/axis-group-interface.cc b/lily/axis-group-interface.cc index 38a193caf6..ac6f85feb8 100644 --- a/lily/axis-group-interface.cc +++ b/lily/axis-group-interface.cc @@ -946,7 +946,7 @@ Axis_group_interface::skyline_spacing (Grob *me) vector 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]); diff --git a/lily/multi-measure-rest-engraver.cc b/lily/multi-measure-rest-engraver.cc index 04ef91fc88..0a6071b614 100644 --- a/lily/multi-measure-rest-engraver.cc +++ b/lily/multi-measure-rest-engraver.cc @@ -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); diff --git a/lily/stencil-integral.cc b/lily/stencil-integral.cc index 1b9aa5181b..2a61da2388 100644 --- a/lily/stencil-integral.cc +++ b/lily/stencil-integral.cc @@ -894,9 +894,8 @@ stencil_dispatcher (vector &boxes, vector stencil_traverser (PangoMatrix trans, SCM expr) { - if (scm_is_null (expr)) - return vector (); - 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 (); else if (scm_is_eq (scm_car (expr), ly_symbol2scm ("combine-stencil"))) { diff --git a/ly/articulate.ly b/ly/articulate.ly index 1dc0e5566b..2b418cee7b 100644 --- a/ly/articulate.ly +++ b/ly/articulate.ly @@ -287,10 +287,10 @@ #(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)))) @@ -300,10 +300,10 @@ #(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)))) @@ -647,20 +647,20 @@ ((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)))))))) @@ -692,7 +692,7 @@ (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))) diff --git a/scm/bar-line.scm b/scm/bar-line.scm index 86d12d9b21..3fad8f8912 100644 --- a/scm/bar-line.scm +++ b/scm/bar-line.scm @@ -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)))) diff --git a/scm/fret-diagrams.scm b/scm/fret-diagrams.scm index 3738d2cabf..6dda452928 100644 --- a/scm/fret-diagrams.scm +++ b/scm/fret-diagrams.scm @@ -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)))))) diff --git a/scm/output-lib.scm b/scm/output-lib.scm index 46d085ef8f..5184fdb337 100644 --- a/scm/output-lib.scm +++ b/scm/output-lib.scm @@ -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))