]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4618: Correct argument handling of Unpure_pure_call::call
authorDavid Kastrup <dak@gnu.org>
Wed, 23 Sep 2015 19:50:39 +0000 (21:50 +0200)
committerDavid Kastrup <dak@gnu.org>
Tue, 29 Sep 2015 05:30:49 +0000 (07:30 +0200)
When ly:make-unpure-pure-container is called with a single procedure
argument, this procedure is used for both unpure and pure calls.  It
turns out that the calling convention in call_pure_function places the
start/end arguments always in position 2/3 of the call.
Unpure_pure_call::call previously always dropped the last 2 arguments of
a pure call before passing the rest on.  Most calls take exactly 3
arguments (grob start end) where this does not make a difference, but
there may be use cases with a different number of arguments.

lily/unpure-pure-container.cc

index 2dff6eea992a402c7beaeaf567f6611ef41164c9..81bba591e41a2dbb2da69756ebe7333130698a3f 100644 (file)
 */
 #include "unpure-pure-container.hh"
 
-// Reroutes a call to the contained function after dropping last two
-// arguments.  Used for applying an "unpure" function in a "pure"
+// Reroutes a call to the contained function after dropping second and
+// third argument.  Used for applying an "unpure" function in a "pure"
 // context.
 class Unpure_pure_call : public Smob1<Unpure_pure_call>
 {
 public:
+  // Smob procedures unfortunately can only take at most 3 SCM
+  // arguments.  Otherwise we could use a "3, 0, 1" call signature and
+  // not require an argument count check of our own.
   LY_DECLARE_SMOB_PROC (&Unpure_pure_call::call, 2, 0, 1)
-  SCM call (SCM arg1, SCM arg2, SCM rest)
+  SCM call (SCM arg1, SCM, SCM rest)
   {
-    return scm_apply_0 (scm1 (),
-                        scm_list_head (scm_cons2 (arg1, arg2, rest),
-                                       scm_length (rest)));
+    if (!scm_is_pair (rest))
+      scm_wrong_num_args (scm1 ());
+    return scm_apply_1 (scm1 (), arg1, scm_cdr (rest));
   }
 };