...sorry Manuel, a carriage-return missed when I copied my screen. The result of the program execution is really :
dataOK1 = 12346789-123456789-123456789-, len is: 30 dataOK2 = 12346789-123456789-123456789-, len is: 30 data-not-KO = 1234, len is: 30 Also, notice that if I compile the same code with bigloo-3.1 , then it works. The trace becomes dataOK1 = 12346789-123456789-123456789-, len is: 30 dataOK2 = 12346789-123456789-123456789-, len is: 30 data-not-KO = 12346789-123456789-123456789-, len is: 30 (.... data-not-KO becomes OK indeed, as we expected) Regards, Michel -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Bruant, Michel Sent: Friday, October 21, 2016 4:40 PM To: [email protected] Cc: [email protected] Subject: RE: [bigloo] let binding with c Hi Manuel, You can compile the files I copy/paste in the email, below = "bigloo -c failc.c ; bigloo fail.scm failc.o -o toto" Then execute, and see the result: > toto dataOK1 = 12346789-123456789-123456789-, len is: 30 dataOK2 = 12346789-123456789-123456789-, len is: 30 data-not-KO = 1234, len is: 30 Let me comment: - we have a C structure, a kind of buffer with 2 fields 'data' and 'length' And we have a C function that set 'data' to a buf (filled) in the global area, and set 'len' to 30. In the scheme part, we construct an instance of c-struct and call the c-function that initialize it; in a 'let*' then, we try to retrieve the data content in the scheme, thanks to 3 bindings, corresponding to 3 trials. I would expect 3 identical results. I can't explain why the latest trial is not ok. It looks like the 'if' says 'true' in the 3rd binding , but we expect 'false' that leads to a correct bind of the data. ...at the same time , a similar 'if' in the 2nd binding works fine ... that's even more strange. Tell me if you need more info. Thanks, regards, Michel :::::::::::::: fail.h :::::::::::::: typedef struct { int len; char* data; } c_struct; :::::::::::::: fail.scm :::::::::::::: (module main (main main) (extern (include "fail.h") (type c_struct (struct (len::int "len") (data::string "data")) "c_struct") (c_fill_struct::int (c_struct*) "c_fill_struct")) ) (define (main argv) (let ((my-struct (c_struct* 0 "old"))) (process my-struct))) (define (process my-struct) (let* ((my-struct (c_struct* -1 "init-content")) (res (c_fill_struct my-struct)) (dataOK1 (pragma::bstring "string_to_bstring_len( $1, $2 )" (c_struct*-data my-struct) (c_struct*-len my-struct))) (dataOK2 (if (equal? (c_struct*-len my-struct) 999) "we should not get this because -len is not 999" (pragma::bstring "string_to_bstring_len( $1, $2 )" (c_struct*-data my-struct) (c_struct*-len my-struct)))) (data-not-KO (if (equal? (c_struct*-len my-struct) 999) (c_struct*-data my-struct) ;; we should not get this, ...but it looks we get it !! (pragma::bstring "string_to_bstring_len( $1, $2 )" (c_struct*-data my-struct) (c_struct*-len my-struct)))) ) (print "dataOK1 = " dataOK1 ", len is: " (c_struct*-len my-struct) ) (print "dataOK2 = " dataOK2 ", len is: " (c_struct*-len my-struct) ) (print "data-not-KO = " data-not-KO ", len is: " (c_struct*-len my-struct) ) )) :::::::::::::: failc.c :::::::::::::: #include <stdlib.h> #include "./fail.h" char buf[100] = "123456789-123456789-123456789-zzzzzz....."; int c_fill_struct (c_struct * my_c_struct) { buf[4] = 0; // return 'buf' , declare 30 bytes are significant, my_c_struct->len = 30 ; my_c_struct->data = buf; return 0; } -----Original Message----- From: [email protected]<mailto:[email protected]> [mailto:[email protected]] Sent: Friday, October 21, 2016 8:43 AM To: Bruant, Michel Cc: [email protected]<mailto:[email protected]> Subject: RE: [bigloo] let binding with c > If few lines can illustrate it, then that may be manageable. Yes. That will help a lot. Thanks in advance, -- Manuel
