From chohag at jtan.com Sun Sep 1 09:45:31 2024 From: chohag at jtan.com (chohag at jtan.com) Date: Sun, 01 Sep 2024 17:45:31 +0100 Subject: [CM] S7 C function arguments corrupted in loop Message-ID: <202409011645.481GjXFR418130@zeus.jtan.com> After a few rounds of golf I have arrived at this minimal demonstration of a problem where the arguments that a C function receives are not the arguments it is given. Originally the *wtf* let also declared an integer to look up but this was removed by the golf. If it were still there then only the *wtf* let and the final (map) would be necessary to see the problem occur. Everything else is here to demonstrate the problem not occurring. I have tested with today's s7 tarball. (require cload.scm) ; This is broken: (define *wtf* (let () (c-define `( (C-function ("anything" _anything "..." 2)) (in-C "static s7_pointer _anything (s7_scheme *sc, s7_pointer args) { printf(\"%s\", s7_object_to_c_string(sc, args)); return s7_nil(sc); }")) "" () "" "" "libs7crash") (curlet))) ; This is for demonstration: (define *other* (let ((one 1)) (define (anything . AB) (format #t "~A" AB) ()) (curlet))) ; Works fine if looping with for-each (for-each (lambda (N) ((*wtf* 'anything) "any string" (logior 42 (*other* 'one)))) '(ok fail)) (newline) ; -> ("any string" 43)("any string" 43) ; Works fine if not calling a C function (map (lambda (N) ((*other* 'anything) "any string" (logior 42 (*other* 'one)))) '(ok fail)) (newline) ; -> ("any string" 43)("any string" 43) ; This combination fails: ; call a C function found in a let ; have one of its arguments be a simple call to logior (or some others) ; have one of logior's arguments be looked up in a (any) let. ; loop at least twice ; ; The first argument to the C function will be replaced by the first ; argument to logior on the second and subsequent loop iterations (map (lambda (N) ((*wtf* 'anything) "any string" (logior 42 (*other* 'one)))) '(ok fail)) (newline) ; -> ("any string" 43)(42 43) Matthew From bil at ccrma.Stanford.EDU Sun Sep 1 13:31:15 2024 From: bil at ccrma.Stanford.EDU (bil at ccrma.Stanford.EDU) Date: Sun, 01 Sep 2024 13:31:15 -0700 Subject: [CM] S7 C function arguments corrupted in loop In-Reply-To: <202409011645.481GjXFR418130@zeus.jtan.com> References: <202409011645.481GjXFR418130@zeus.jtan.com> Message-ID: Thanks very much for the bug report! That was a tricky one -- I managed to overoptimize op_x_aa, using a constant list where it got stepped on. A quick fix, around line 90626, change sc->value = c_function_call(f)(sc, with_list_t2(fx_call(sc, cdr(code)), fx_call(sc, cddr(code)))); to sc->value = c_function_call(f)(sc, list_2(sc, fx_call(sc, cdr(code)), fx_call(sc, cddr(code)))); I need to figure out what the "right thing" is here. By the way, it had never occurred to me to use c-define in the midst of an expression like that -- kinda neat! I think I'll include something like that in the docs. Thanks again. From bil at ccrma.Stanford.EDU Mon Sep 9 13:47:28 2024 From: bil at ccrma.Stanford.EDU (bil at ccrma.Stanford.EDU) Date: Mon, 09 Sep 2024 13:47:28 -0700 Subject: [CM] Snd 24.7 Message-ID: <2172e9a79f4fe85ce09c7e393ba57aed@ccrma.stanford.edu> Snd 24.7: s7: added complex-vectors. These are directly compatible with gsl_vector_complex. make-iterator's optional third argument can be #t which tells s7 to choose the carrier based on the iterated sequence. s7_immutable has been deprecated, replaced by s7_set_immutable which has the necessary s7_scheme* argument. added s7_define_expansion. checked: sbcl 2.4.8 Thanks!: Matthew