|
Post by rikky on Feb 3, 2021 8:10:26 GMT 1
Hello I'm using the newest bacon, just released. FUNCTION FORMAT$(digits) 'zero_digits$ = "%.0f" 'one_digit$ = "%.1f" 'two_digits$ = "%.2f" LOCAL return$ return$ = "%." & STR$(digits) & "f" RETURN return$ 'PRINT VAL("123") / VAL("8") FORMAT PRINT_FORMAT$(3) END FUNCTION
bla$ = FORMAT$(2)
PRINT VAL("1.23456789") FORMAT "%.2f" PRINT
PRINT VAL("1.23456789") FORMAT bla$ PRINT
PRINT VAL("1.23456789") FORMAT FORMAT$(2) PRINT
PRINT VAL("1.23456789") FORMAT "%.2f" TO blabla$ PRINT blabla$
PRINT VAL("1.23456789") FORMAT bla$ TO blabla$ PRINT blabla$
PRINT VAL("1.23456789") FORMAT FORMAT$(2) TO blabla$ PRINT blabla$
result: 1.23 1.23 1.23 1.23 1.23 *** Error in `./test': free(): invalid pointer: 0x01e79719 *** ERROR: signal ABORT received - internal error. Try to compile the program with TRAP LOCAL to find the cause. I'm sure that it did work, not too long ago. Rik.
|
|
|
Post by bigbass on Feb 3, 2021 17:00:23 GMT 1
Hello Rik
this may or not be a bug (that's not my decision) I just offer solutions to get code to compile and run
the FUNCTION with a return type char*
FUNCTION FORMAT$(digits) TYPE char*
worked for me
hope that could be useful Joe
|
|
|
Post by vovchik on Feb 3, 2021 17:25:59 GMT 1
Dear Rik and Joe,
Thanks for pointing out the anomaly (Rik) and for the fix (Joe). TYPE char* works fine...
And, as I just discovered, so does STRING:
FUNCTION FORMAT$(digits) TYPE STRING
With kind regards, vovchik
|
|
|
Post by Pjot on Feb 3, 2021 22:15:16 GMT 1
Hi Rik, This is a complicated situation, and I need more time to find a good solution. For the record, the code does not work in previous versions of BaCon either. It cannot be compiled even before 4.3. So it never would work in BaCon. If we look at the cause of the problem, you'll see why it never would have worked. Namely, the reason is that both the PRINT..FORMAT..TO statement and also the function 'FORMAT$' share the same internal variable, and both try to free them. Exactly this is the reason that I started to cleanup the code in 4.2 and 4.3, to get rid of as much of these internal variables. Because they can lead to a clash. The solution of vovchik and Joe is a valid workaround for this particular situation. I recommend to apply it for now.
But the root cause seems to be more severe, and this is why I need more time to find a long-term fix. Best regards, Peter
|
|
|
Post by rikky on Feb 3, 2021 23:06:50 GMT 1
I already had another workaround, so there is no need to rush. bla$ = FORMAT$(2) PRINT VAL("1.23456789") FORMAT bla$ TO blabla$ PRINT blabla$ I was pretty sure it was working so I tried some museum versions, and BaCon version 4.1.1 on Linux armv7l - (c) Peter van Eerten - MIT License. works. result 4.1.1 : 1.23 1.23 1.23 1.23 1.23 1.23 Rik.
|
|
|
Post by Pjot on Feb 4, 2021 7:31:23 GMT 1
Well, thats weird, because for me it does not even compile: $ bash current/bacon-4.1.1/bacon.sh -v
BaCon version 4.1.1 on Linux x86_64 - Shell - (c) Peter van Eerten - MIT License.
$ bash current/bacon-4.1.1/bacon.sh -y -p -o -g -@ debug1 Converting 'debug1.bac'... 37 char*:MAIN:__b2c__loop_result__b2c__string_var char*:MAIN:blabla__b2c__string_var long:FORMAT__b2c__string_var:digits char*:FORMAT__b2c__string_var:return__b2c__string_var Converting 'debug1.bac'... done, 37 lines were processed in 1 seconds. Analyzing dependencies... concat error malloc memcheck minmax str utf8 Applying indentation... done. Compiling 'debug1.bac'... cc -g -c debug1.bac.c cc -o debug1 debug1.bac.o -lm
debug1.bac.c:74:37: warning: implicit declaration of function '__b2c__string_var'; did you mean 'CL__b2c__string_var'? [-Wimplicit-function-declaration]
INFO: see full error report (y/[n])?
So there seems to be another issue in 4.1.1 as well But I will fix it for the latest only, of course. BR Peter
|
|
|
Post by rikky on Feb 4, 2021 7:51:25 GMT 1
bacon.4.1.1.sh also doesn't compile over here. It's the executable that does it. And to be honest, I did NOT take this executable from the website, but from my own system somewhere. So it might be a bacon.4.1.1 FOSSIL.
|
|
|
Post by Pjot on Feb 5, 2021 21:22:05 GMT 1
|
|
|
Post by rikky on Feb 6, 2021 7:18:48 GMT 1
Yes, Now it works result: 1.23 1.23 1.23 1.23 1.23 1.23 Thanks. Rik.
|
|