Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

discuss PC<>Acorn file transfer issues & the use of FDC, XFER, Omniflop/disk etc.
User avatar
jgharston
Posts: 3641
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by jgharston » Sun Sep 01, 2019 1:46 am

dhg2 wrote:
Sat Aug 31, 2019 10:24 pm
Today I tried to compile brandy on a spare computer with Debian Unstable. I'm using the latest version from github. I got this error:
Missed an #include from mos.h, fixed now.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

User avatar
bakoulis
Posts: 319
Joined: Wed Feb 08, 2012 9:45 pm
Location: Athens, Greece
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by bakoulis » Sun Sep 01, 2019 8:39 am

Now failed for me. Debian 9 with backports (64bit).
screen.png
Last edited by bakoulis on Sun Sep 01, 2019 8:42 am, edited 3 times in total.
2xElectron, 3xBBC B, BBC Master.
2xAcorn A310, A420/1, 2xA3000, 2xA3010, A3020, A4000, A5000.
2xRISC PC, Acorn Pocket Book, Acorn Pocket Book II.

Soruk
Posts: 428
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Soruk » Sun Sep 01, 2019 9:26 am

dhg2 wrote:
Sat Aug 31, 2019 10:24 pm
Hello,
Today I tried to compile brandy on a spare computer with Debian Unstable. I'm using the latest version from github. I got this error:

Code: Select all

/usr/bin/ld: src/fileio.o: in function `fileio_eof':
fileio.c:(.text+0x18c9): undefined reference to `kbd_pending'
/usr/bin/ld: src/mos.o: in function `mos_osbyte':
mos.c:(.text+0x6c6): undefined reference to `kbd_buffered'
/usr/bin/ld: src/mos.o: in function `mos_adval':
mos.c:(.text+0xa41): undefined reference to `kbd_buffered'
collect2: error: ld returned 1 exit status
make: *** [makefile:41: brandy] Error 1
In case it's useful, this is the information from 'gcc --version':

Code: Select all

gcc (Debian 9.2.1-6) 9.2.1 20190827
Please do:

Code: Select all

export BRANDY_BUILD_FLAGS=-DNEWKBD
make clean
make
and see how you get on.

User avatar
bakoulis
Posts: 319
Joined: Wed Feb 08, 2012 9:45 pm
Location: Athens, Greece
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by bakoulis » Sun Sep 01, 2019 9:43 am

with this commands compiled, but gives warnings.
Στιγμιότυπο από 2019-09-01 12-41-47.png
2xElectron, 3xBBC B, BBC Master.
2xAcorn A310, A420/1, 2xA3000, 2xA3010, A3020, A4000, A5000.
2xRISC PC, Acorn Pocket Book, Acorn Pocket Book II.

Soruk
Posts: 428
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Soruk » Sun Sep 01, 2019 11:36 am

bakoulis wrote:
Sun Sep 01, 2019 9:43 am
with this commands compiled, but gives warnings.
Στιγμιότυπο από 2019-09-01 12-41-47.png
Unused variables, nothing to worry about.

User avatar
Richard Russell
Posts: 897
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Richard Russell » Sun Sep 01, 2019 11:50 am

Soruk wrote:
Sun Sep 01, 2019 11:36 am
Unused variables, nothing to worry about.
It's undesirable nevertheless, because if people get used to seeing warnings every time it's compiled they may not notice if a new (potentially more important) one appears.

Soruk
Posts: 428
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Soruk » Sun Sep 01, 2019 9:12 pm

Richard Russell wrote:
Sun Sep 01, 2019 11:50 am
Soruk wrote:
Sun Sep 01, 2019 11:36 am
Unused variables, nothing to worry about.
It's undesirable nevertheless, because if people get used to seeing warnings every time it's compiled they may not notice if a new (potentially more important) one appears.
Of course, I completely agree. Right now the keyboard code is in a state of flux, and glitches can happen when building at the bleeding edge of the version control tree. It's not ideal, but I just wanted to let @bakoulis know that, in this instance, the warning wasn't anything to worry about.

Edit: I've just checked in a change that resolves the need for -DNEWKBD to be additionally defined.
Last edited by Soruk on Mon Sep 02, 2019 10:00 am, edited 2 times in total.

User avatar
bakoulis
Posts: 319
Joined: Wed Feb 08, 2012 9:45 pm
Location: Athens, Greece
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by bakoulis » Fri Sep 06, 2019 11:29 am

New warnings on last build:

Code: Select all

$ make
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/variables.c -c -o src/variables.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/tokens.c -c -o src/tokens.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/graphsdl.c -c -o src/graphsdl.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/strings.c -c -o src/strings.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/statement.c -c -o src/statement.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/stack.c -c -o src/stack.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/miscprocs.c -c -o src/miscprocs.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/mainstate.c -c -o src/mainstate.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/lvalue.c -c -o src/lvalue.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/keyboard.c -c -o src/keyboard.o
src/keyboard.c: In function ‘kbd_get0’:
src/keyboard.c:931:28: warning: implicit declaration of function ‘emulate_get’ [-Wimplicit-function-declaration]
   ch=-1; while (ch<0) { ch=emulate_get(); } /* Call legacy code   */
                            ^~~~~~~~~~~
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/iostate.c -c -o src/iostate.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/heap.c -c -o src/heap.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/functions.c -c -o src/functions.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/fileio.c -c -o src/fileio.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/evaluate.c -c -o src/evaluate.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/errors.c -c -o src/errors.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/mos.c -c -o src/mos.o
src/mos.c: In function ‘mos_osbyte’:
src/mos.c:2584:5: warning: unused variable ‘atmp’ [-Wunused-variable]
 int atmp, tmp;
     ^~~~
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/editor.c -c -o src/editor.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/convert.c -c -o src/convert.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/commands.c -c -o src/commands.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/brandy.c -c -o src/brandy.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/assign.c -c -o src/assign.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/net.c -c -o src/net.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/mos_sys.c -c -o src/mos_sys.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/soundsdl.c -c -o src/soundsdl.o
gcc  -o brandy src/variables.o src/tokens.o src/graphsdl.o src/strings.o src/statement.o src/stack.o src/miscprocs.o src/mainstate.o src/lvalue.o src/keyboard.o src/iostate.o src/heap.o src/functions.o src/fileio.o src/evaluate.o src/errors.o src/mos.o src/editor.o src/convert.o src/commands.o src/brandy.o src/assign.o src/net.o src/mos_sys.o src/soundsdl.o -lX11 -lm -lSDL

Last edited by bakoulis on Fri Sep 06, 2019 11:29 am, edited 1 time in total.
2xElectron, 3xBBC B, BBC Master.
2xAcorn A310, A420/1, 2xA3000, 2xA3010, A3020, A4000, A5000.
2xRISC PC, Acorn Pocket Book, Acorn Pocket Book II.

User avatar
dhg2
Posts: 134
Joined: Tue Oct 25, 2016 7:37 pm
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by dhg2 » Fri Sep 06, 2019 12:12 pm

Hello,

I think I might have found a bug in matrix brandy. For fun last night I wrote a program that makes an approximation of a sine/cosine curve. While I was doing that, I noticed that it behaved incorrectly on the latest version of matrix brandy, but it behaves correctly on older versions of matrix brandy and on pre-matrix versions of brandy, and on Richard Russell's BB4W.

Here's the program:
curve.txt
(1.67 KiB) Downloaded 9 times
Here are screenshots from brandy 1.20.1 and BB4W where it works correctly:
1_curve_brandy.png
2_curve_BB4W.png
Here's a screenshot from the most recent github version of matrix brandy where it behaves differently:
3_curve_matrixbrandy.png
Regards,
- Patrick

User avatar
Richard Russell
Posts: 897
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Richard Russell » Fri Sep 06, 2019 12:46 pm

dhg2 wrote:
Fri Sep 06, 2019 12:12 pm
it behaves correctly on ... Richard Russell's BB4W.
I don't understand how it can have done, since it includes this code:

Code: Select all

DEF PROCgcol(c%)
 GCOL (c%AND&FF0000)>>16, (c%AND&00FF00)>>8, c%AND&FF
ENDPROC
which has GCOL followed by three parameters. I know about the one-parameter and two-parameter variants of GCOL, but I've never come across a three-parameter one and unsurprisingly it raises a Syntax Error in BB4W when I try it here.

User avatar
dhg2
Posts: 134
Joined: Tue Oct 25, 2016 7:37 pm
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by dhg2 » Fri Sep 06, 2019 12:51 pm

Sorry, I forgot to mention that in the case of bb4w, I changed that procedure to something like this:

Code: Select all

COLOUR 4, r, g, b: GCOL 4
I also changed the MODE number to something different.
The rest of the program worked without modifications.

That's actually part of why I made a wrapper procedure for GCOL, so it would be more straighforward to adapt the program for bb4w and bbcsdl.
Last edited by dhg2 on Fri Sep 06, 2019 12:54 pm, edited 1 time in total.
Regards,
- Patrick

User avatar
Richard Russell
Posts: 897
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Richard Russell » Fri Sep 06, 2019 2:59 pm

dhg2 wrote:
Fri Sep 06, 2019 12:51 pm
Sorry, I forgot to mention that in the case of bb4w, I changed that procedure
Grr. You really don't want to get me started again on those GCOL extensions that don't even have VDU equivalents! :evil:

Soruk
Posts: 428
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Soruk » Fri Sep 06, 2019 10:11 pm

dhg2 wrote:
Fri Sep 06, 2019 12:12 pm
Hello,

I think I might have found a bug in matrix brandy. For fun last night I wrote a program that makes an approximation of a sine/cosine curve. While I was doing that, I noticed that it behaved incorrectly on the latest version of matrix brandy, but it behaves correctly on older versions of matrix brandy and on pre-matrix versions of brandy, and on Richard Russell's BB4W.
Thanks for highlighting this. Tricky bug to track down, but it's now fixed in git.

User avatar
sweh
Posts: 2070
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by sweh » Sun Sep 08, 2019 4:00 pm

Hmm, on a fully patched Debian 10 64bit machine

Code: Select all

% git pull
Already up to date.
% make clean
% make
...
% ./brandy
So far so good.

Now inside

Code: Select all

>load "examples/Mode7/telstar"

Arithmetic stack overflow
>
-DBRANDY_GITCOMMIT=\""ed7bcf9"\" -DBRANDY_GITBRANCH=\""master"\" -DBRANDY_GITDATE=\""Sun Sep 8 09:20:45 2019 +0100"\"
Rgds
Stephen

User avatar
sweh
Posts: 2070
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by sweh » Sun Sep 08, 2019 4:06 pm

And if I compile 32bit then it loads but I get an "Address exception at line 110", the "Brandy_GetVideoDriver" SYS call.
Last edited by sweh on Sun Sep 08, 2019 4:09 pm, edited 1 time in total.
Rgds
Stephen

Soruk
Posts: 428
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Soruk » Sun Sep 08, 2019 7:06 pm

I see what has happened. A recent merge from @jgharston has removed the offsetting used for Brandy's memory space. Unfortunately this has broken both 64-bit builds and the way I was passing back strings from SYS.

This should be fixed in my add_64int branch, I'll take a closer look at that tomorrow.

User avatar
Richard Russell
Posts: 897
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Richard Russell » Sun Sep 08, 2019 9:24 pm

Soruk wrote:
Sun Sep 08, 2019 7:06 pm
A recent merge from @jgharston has removed the offsetting used for Brandy's memory space.
I'm surprised that can happen, especially without you knowing. Is it because you are sharing StarDot's github account that he is able to make changes? I'm hoping nothing similar can happen to BBC BASIC for SDL 2.0, but as that's under my own github account maybe it gives me more control (or maybe not!).

Soruk
Posts: 428
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Soruk » Mon Sep 09, 2019 6:05 am

Richard Russell wrote:
Sun Sep 08, 2019 9:24 pm
Soruk wrote:
Sun Sep 08, 2019 7:06 pm
A recent merge from @jgharston has removed the offsetting used for Brandy's memory space.
I'm surprised that can happen, especially without you knowing. Is it because you are sharing StarDot's github account that he is able to make changes? I'm hoping nothing similar can happen to BBC BASIC for SDL 2.0, but as that's under my own github account maybe it gives me more control (or maybe not!).
I merged his keyboard changes, but hadn't spotted that change as well, and wasn't listed in his change summary in his pull request. Don't worry about your BBCSDL, nobody can directly change it.

Edit: I've backed the change out. Things should work again. I'll re-implement it on the add_64int branch, where 64-bit ints exist and will also help to shake out more 64-bit bugs there.
Last edited by Soruk on Mon Sep 09, 2019 8:37 am, edited 1 time in total.

Soruk
Posts: 428
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Soruk » Mon Sep 09, 2019 11:07 am

Richard Russell wrote:
Sun Sep 08, 2019 9:24 pm
Soruk wrote:
Sun Sep 08, 2019 7:06 pm
A recent merge from @jgharston has removed the offsetting used for Brandy's memory space.
I'm surprised that can happen, especially without you knowing. Is it because you are sharing StarDot's github account that he is able to make changes? I'm hoping nothing similar can happen to BBC BASIC for SDL 2.0, but as that's under my own github account maybe it gives me more control (or maybe not!).
To reiterate, I was the one who merged the pull request, nobody else has access to do that on my branch. So, do not worry about anybody being able to do something unexpected to BBCSDL.

Anyhow, I've backed out that change on the master branch, reinstated it on the add_64int branch and sure enough there were a lot of other instances of memory accesses not being 64-bit clean (as previously, all accesses were to an offset, which capped at 2GB, were 32-bit clean even on 64-bit hardware). This is now resolved on that branch, at least according to my quick testing.

To play with the 64-bit int branch, do:

Code: Select all

git checkout add_64int
git pull
make clean
make
...and to switch back:

Code: Select all

git checkout master
git pull
make clean
make
I've also forced a rebuild of this morning's nightly Win32 build, as the auto-build in the early hours would be totally broken.
Last edited by Soruk on Mon Sep 09, 2019 11:12 am, edited 1 time in total.

Soruk
Posts: 428
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Soruk » Mon Sep 09, 2019 11:14 am

sweh wrote:
Sun Sep 08, 2019 4:06 pm
And if I compile 32bit then it loads but I get an "Address exception at line 110", the "Brandy_GetVideoDriver" SYS call.
This should now be fixed! Sorry about that.

User avatar
Richard Russell
Posts: 897
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Richard Russell » Mon Sep 09, 2019 11:37 am

Soruk wrote:
Mon Sep 09, 2019 11:07 am
To reiterate, I was the one who merged the pull request, nobody else has access to do that on my branch. So, do not worry about anybody being able to do something unexpected to BBCSDL.
Fair enough. I am somewhat obsessive about regressions, for example before issuing a new version of BBCSDL I run 'diff' (well, 'windiff' actually) on every file that's changed from the previous release. Even so, something stupid still occasionally slips through, but at least I shouldn't miss a change that had happened 'accidentally'. In the 'old days' I also used to run every single supplied example program with each new release to make sure it still worked, but I admit I don't do that now.

User avatar
sweh
Posts: 2070
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by sweh » Tue Sep 10, 2019 1:53 am

Soruk wrote:
Mon Sep 09, 2019 11:14 am
sweh wrote:
Sun Sep 08, 2019 4:06 pm
And if I compile 32bit then it loads but I get an "Address exception at line 110", the "Brandy_GetVideoDriver" SYS call.
This should now be fixed! Sorry about that.
Seems to work for both 32bit and 64bit builds :-)

(I don't actually use this program; it's one of those "if I have time I should do something with it" background ideas. But every so often I just update and test and spotted an error)
Rgds
Stephen

Soruk
Posts: 428
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Soruk » Tue Sep 10, 2019 2:28 pm

I've reworked the signal handler and longjmp stuff to allow the same signal to be hit more than once - in particular SIGSEGV (which raises error "Address exception"). Up until now, reads and writes have been checked beforehand to see if it's in our workspace, or specific areas made available (e.g. GPIO mmap or virtual MODE 7 screen space). Now, these check functions are redundant (still present for now, but do nothing), as any illegal read or write will raise Address exception but won't crash Brandy itself.

Also, if Address exception occurs at any other point other than a bad peek or poke, that's the sign of a Brandy bug!

I've also built a new 64bit int Windows build in http://brandy.matrixnetwork.co.uk/testing/ for the curious or brave. :lol:

User avatar
Richard Russell
Posts: 897
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Richard Russell » Tue Sep 10, 2019 4:05 pm

Soruk wrote:
Tue Sep 10, 2019 2:28 pm
any illegal read or write will raise Address exception but won't crash Brandy itself.
I have mixed feelings about the desirability of trapping segfaults. Raymond Chen, the Microsoft guru and blogger, advises that it's best to let the application crash (I appreciate that you probably aren't using IsBadXxxPtr or similar) and that's basically what I do in BBCSDL. On the other hand that's only acceptable if the program crashing doesn't also bring down the 'IDE' or program editor, which might result in an unsaved program being lost (in BBCSDL the IDE and the user's program are run as separate processes so that situation shouldn't arise).

Admittedly in a programming language like BBC BASIC where a segfault can be caused by something as simple as ?12345678 = 0 crashing is arguably rather unfriendly and an error message like 'Address exception' is more informative, especially if it's able to tell you at what line the fault was triggered. But I'm unsure how safe it is to attempt to handle a segfault exception, especially in a cross-platform context; you're not supposed to do much in a signal handler. How do you do it?

Soruk
Posts: 428
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Soruk » Tue Sep 10, 2019 5:08 pm

Richard Russell wrote:
Tue Sep 10, 2019 4:05 pm
Admittedly in a programming language like BBC BASIC where a segfault can be caused by something as simple as ?12345678 = 0 crashing is arguably rather unfriendly and an error message like 'Address exception' is more informative, especially if it's able to tell you at what line the fault was triggered. But I'm unsure how safe it is to attempt to handle a segfault exception, especially in a cross-platform context; you're not supposed to do much in a signal handler. How do you do it?
I just report the error, then siglongjmp() to the error handler (from ON ERROR) or back to the immediate mode loop. This resets the signal handler stack putting everything nicely back where it should be. On Cygwin, siglongjmp() doesn't exist so using longjmp() instead, which works fine there where siglongjmp() is needed on Linux. But then I need to reinstate the signal handler after it's been fired.

User avatar
Richard Russell
Posts: 897
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Richard Russell » Tue Sep 10, 2019 5:29 pm

Soruk wrote:
Tue Sep 10, 2019 5:08 pm
I just report the error, then siglongjmp() to the error handler (from ON ERROR) or back to the immediate mode loop.
Yes, I understand how errors are handled (I do the same), I meant how do you intercept the segfault? Are you using 'sigaction()'? It's this at the man page that scares me: "Applications that use longjmp() and siglongjmp() from within signal handlers require rigorous protection in order to be portable".

Soruk
Posts: 428
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Soruk » Tue Sep 10, 2019 5:35 pm

Richard Russell wrote:
Tue Sep 10, 2019 5:29 pm
Soruk wrote:
Tue Sep 10, 2019 5:08 pm
I just report the error, then siglongjmp() to the error handler (from ON ERROR) or back to the immediate mode loop.
Yes, I understand how errors are handled (I do the same), I meant how do you intercept the segfault? Are you using 'sigaction()'? It's this at the man page that scares me: "Applications that use longjmp() and siglongjmp() from within signal handlers require rigorous protection in order to be portable".
Yes I am, and really I'm basically hoping for the best.... :lol: Testing on linux32, linux64 and Win32/Cygwin. I suppose I can make NetBSD and FreeBSD VMs. I draw the line at buying a Mac. :wink:
Last edited by Soruk on Tue Sep 10, 2019 5:37 pm, edited 1 time in total.

User avatar
Richard Russell
Posts: 897
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Richard Russell » Tue Sep 10, 2019 5:55 pm

Soruk wrote:
Tue Sep 10, 2019 5:35 pm
I draw the line at buying a Mac. :wink:
I sympathise, but I had no choice in order to create the MacOS and iOS editions of BBCSDL (I bought a Mac Mini so that I could at least share my monitor, mouse and keyboard using a KVM switch). There's also Android to add to the list of platforms I would need it to work on.

For the time being I think I'll leave segfaults untrapped, so that BBCSDL simply crashes; on the desktop platforms at least this is 'harmless' because the IDE, program editor etc. is unaffected. On the 'mobile' platforms the entire app crashes, but on those you can't run an unsaved program anyway so there should be no risk of losing edits. Maybe one day I'll try your technique and also "hope for the best" but I prefer not to take that sort of risk.

I discourage the use of indirection in BB4W and BBCSDL, the misuse of which is the easiest way to trigger a segfault, and recommend using structures instead. They provide all the protection that BASIC usually does in respect of testing array limits etc. so it shouldn't be possible to cause a segfault through a coding error.

Soruk
Posts: 428
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by Soruk » Tue Sep 10, 2019 6:05 pm

Richard Russell wrote:
Tue Sep 10, 2019 5:55 pm
Maybe one day I'll try your technique and also "hope for the best" but I prefer not to take that sort of risk.

I discourage the use of indirection in BB4W and BBCSDL, the misuse of which is the easiest way to trigger a segfault, and recommend using structures instead. They provide all the protection that BASIC usually does in respect of testing array limits etc. so it shouldn't be possible to cause a segfault through a coding error.
Believe me, it wasn't trivial getting the incantation right, but was glad to get there in the end. Only to discover the correct approach for Linux completely refused to build in Cygwin! Under Linux doing a longjmp() from a signal handler doesn't exit the handler so the signal handler can't be rearmed - but this approach works perfectly in Cygwin. On the other hand, siglongjmp() does exactly what I need, but doesn't exist in Cygwin. A few #defines and a typedef and it now works on both.

Edit: typos, typing on mobile, on a train.
Last edited by Soruk on Tue Sep 10, 2019 8:52 pm, edited 1 time in total.

User avatar
dhg2
Posts: 134
Joined: Tue Oct 25, 2016 7:37 pm
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.0 released

Post by dhg2 » Thu Sep 12, 2019 10:18 pm

I'm noticing a problem with the latest brandy from github. WAIT with a number parameter doesn't seem to work anymore. Typing, for example, "WAIT 1000" at the prompt just returns instantly.
Regards,
- Patrick

Post Reply