~ chicken-core (chicken-5) 3bb9fd97db7be7d43cd6221f7bb2f37c86b3e5fb


commit 3bb9fd97db7be7d43cd6221f7bb2f37c86b3e5fb
Author:     Peter Bex <peter@more-magic.net>
AuthorDate: Sat Aug 22 17:52:18 2015 +0200
Commit:     Peter Bex <peter@more-magic.net>
CommitDate: Sat Aug 22 19:37:25 2015 +0200

    C_build_rest needs to know effective argc

diff --git a/chicken.h b/chicken.h
index 767b457b..5a1d9da8 100644
--- a/chicken.h
+++ b/chicken.h
@@ -1789,7 +1789,7 @@ C_fctexport C_word C_fcall C_h_intern(C_word *slot, int len, C_char *str) C_regp
 C_fctexport C_word C_fcall C_h_intern_in(C_word *slot, int len, C_char *str, C_SYMBOL_TABLE *stable) C_regparm;
 C_fctexport C_word C_fcall C_intern2(C_word **ptr, C_char *str) C_regparm;
 C_fctexport C_word C_fcall C_intern3(C_word **ptr, C_char *str, C_word value) C_regparm;
-C_fctexport C_word C_fcall C_build_rest(C_word *ptr, C_word n, C_word *av) C_regparm;
+C_fctexport C_word C_fcall C_build_rest(C_word **ptr, C_word c, C_word n, C_word *av) C_regparm;
 C_fctexport void C_bad_memory(void) C_noret;
 C_fctexport void C_bad_memory_2(void) C_noret;
 C_fctexport void C_bad_argc(int c, int n) C_noret;
diff --git a/runtime.c b/runtime.c
index 8106ac43..c616b42a 100644
--- a/runtime.c
+++ b/runtime.c
@@ -2406,21 +2406,25 @@ C_regparm int C_fcall C_in_scratchspacep(C_word x)
 
 /* Cons the rest-aguments together: */
 
-C_regparm C_word C_fcall C_build_rest(C_word *ptr, C_word n, C_word *av)
+C_regparm C_word C_fcall C_build_rest(C_word **ptr, C_word c, C_word n, C_word *av)
 {
-  C_word x = C_SCHEME_END_OF_LIST;
+  C_word
+    x = C_SCHEME_END_OF_LIST,
+    *p = *ptr;
   C_SCHEME_BLOCK *node;
-  av += n;
 
-  while(--n) {
-    node = (C_SCHEME_BLOCK *)ptr;
-    ptr += 3;
+  av += c;
+
+  while(--c >= n) {
+    node = (C_SCHEME_BLOCK *)p;
+    p += 3;
     node->header = C_PAIR_TYPE | (C_SIZEOF_PAIR - 1);
     node->data[ 0 ] = *(--av);
     node->data[ 1 ] = x;
     x = (C_word)node;
   }
 
+  *ptr = p;
   return x;
 }
 
Trap