[fpc-pascal] ansistrings, exceptions, pascal call stack and access violations

David Emerson dle3ab at angelbase.com
Wed Nov 3 21:55:27 CET 2004


Peter wrote:

>The problem is that the call to the empty ansistring routine will create a
>temp ansistring for the parameter. And ansistring variables or temps need
>to be finalized. This call to finalize() destroyes the backtrace since it
>writes at the same location in the stack that was also used by
>test_division_by_zero. We can't solve easily.

I was afraid it might be something like this! Interestingly, even if I move the test_division_by_zero function to be BEFORE the call to the do_nothing_with_an_ansistring function, I still get the same behavior -- so it seems to be creating that temp ansistring param even before it gets to the call to the function that needs it. (( Perhaps this has something to do with threading or jumping or whatever you call it when the program starts a new task before it's finished with the old one in order to use resources efficiently. ))


Marco wrote:

>I get: (1.9.5 as of today)
>
>-bash-2.05b$ ./exectest 
>An unhandled exception occurred at 0x0806CBFC :
>EDivByZero : Division by zero
>  $0806CBFC  TEST_DIVISION_BY_ZERO,  line 14 of exectest.pp
>  $0806CC81  PLAY_WITH_STRINGS,  line 24 of exectest.pp
>  $0806CCFF  main,  line 31 of exectest.pp
>
>-bash-2.05b$ 

this is rather encouraging... however, I'm using 1.9.4, and am a little hesitant to step out on the bleeding edge of cvs with the project :-) but I may give it a shot.


>If I change all occurances of "string" to "ansistring", then:
>
>-bash-2.05b$ ./exectest 
>An unhandled exception occurred at 0x0806CC1C :
>EDivByZero : Division by zero
>  $0806CC1C  TEST_DIVISION_BY_ZERO,  line 14 of exectest.pp
>  $BFBFF994  main,  line 22 of /home2/marcov/cvs/devel/fpc/rtl/inc/heap.inc
>
>Are you sure you compiled all units with -gl?
>(...)
>it sounds like your sysutils is not compiled -gl, however it could also
>be a FPC version thing (I'm using a current versioN)

I get the same behavior if I change all the strings to ansistrings (PLAY_WITH_STRINGS function call is missing from the stack trace.)

For the test program (and for my project) I always have the -gl flag in fpc.cfg. However I haven't compiled the sysutils unit, so I'm going to try that and see if it makes a difference. I'm a little skeptical due to Peter's comment, but the sources.tar just finished downloading, so I'll try my luck...


Thanks,
David







More information about the fpc-pascal mailing list