forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Program crash on derived type array

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
Anonymous
Guest





PostPosted: Thu Nov 17, 2005 4:44 am    Post subject: Program crash on derived type array Reply with quote

I am encountering various problems in relation to derived types
Here is the shortest test case I can produce:
[pre]
module my_string

type string
private
character, pointer:: chars(Smile => null()
end type

interface assignment (=)
module procedure s_ass_c
end interface

private s_ass_c

contains
elemental subroutine s_ass_c(var,expr)
type(string) , intent(out) :: var
character(len=*), intent(in) :: expr
integer :: lc,i

lc = len(expr)

if(associated(var%chars))deallocate(var%chars)
allocate(var%chars(1:lc))
do i = 1,lc
var%chars(i) = expr(i:i)
enddo
end subroutine s_ass_c

end module my_string

module my_mod
use my_string
type my_type
type(string) :: buf
end type

type my_other_type
type(my_type),dimension(1:10) :: buf_arr
end type

end module my_mod

program test
use my_mod

type(my_type) :: t
type(my_type) :: t_arr(1:2)
type(my_other_type) :: t_other

t%buf = "Works"

t_arr(1)%buf = "Works too!"

t_other%buf_arr(1)%buf = "Works not!"

end program[/pre]

This program crashes when trying to execute the line in bold. Actually the crash takes place in the assignement procedure, where the
Code:
associated
thinks the members of the
Code:
chars
array are associated while they are not and the subsequent
Code:
deallocate
crashes.

Here is the error.txt from the crash:
[pre]
Runtime error from program:c:temptest.exe
Access Violation
The instruction at address 0362373e attempted to read from location 2020201c

036236cf __DEALLOCATE [+006f]

MY_STRING!S_ASS_C - in file test.f90 at line 24 [+002b]

main - in file test.f90 at line 59 [+0139]


eax=0000000a ebx=0000310e ecx=0360fc20
edx=00000001 esi=00404038 edi=20202020
ebp=0360fb70 esp=0360fb4c IOPL=2
ds=0023 es=0023 fs=003b
gs=0000 cs=001b ss=0023
flgs=00010202 [NC OP NZ SN DN NV]

0362373e cmp [edi-0x4],0xabcdef12
03623745 jne 3623751
0362374b add edi,0xfc
[/pre]

I have encountered the error with our licensed version of FTN95 v4.71, but the trial version 4.80 does also produce the error.

(The "string" type and the assignment procedure are part of an implementatin of the ISO_VARYING_STRINGS module by J.L.Schonfelder that one can find at various places on the web.)
Back to top
Anonymous
Guest





PostPosted: Thu Nov 17, 2005 5:46 am    Post subject: Program crash on derived type array Reply with quote

Have you tried compiling with /undef? It should produce a more meaningful message.
Back to top
Anonymous
Guest





PostPosted: Thu Nov 17, 2005 11:54 am    Post subject: Program crash on derived type array Reply with quote

I just tried it, the message does not change a lot.

[pre]
Runtime error from program:d:devbugslgotemp@.exe
Access Violation
The instruction at address 0362376e attempted to read from location 8080807c

036236ff __DEALLOCATE [+006f]

036ef5a6 __PFREE [+01b2]

MY_STRING!S_ASS_C - in file derived_type_1.f90 at line 22 [+004e]

TEST - in file derived_type_1.f90 at line 54 [+00fe]


eax=0a0a0000 ebx=00003188 ecx=0000000a
edx=0a0a0010 esi=0360fbb4 edi=80808080
ebp=0360faec esp=0360fac8 IOPL=2
ds=0023 es=0023 fs=003b
gs=0000 cs=001b ss=0023
flgs=00010282 [NC OP NZ NS DN NV]

0362376e cmp [edi-0x4],0xabcdef12
03623775 jne 3623781
0362377b add edi,0xfc
[/pre]
Back to top
Anonymous
Guest





PostPosted: Thu Nov 17, 2005 3:19 pm    Post subject: Program crash on derived type array Reply with quote

Jonny

Looks like you have found a bug here.
The initialisation (=> null() ) has not been applied in the last case so the deallocate causes a runtime exception.

A work-around is to explicitly nullify with a call to nullify(t_other%buf_arr(1)%buf%chars) before the assignment (i.e. before the first time this particular variable is used).

Back to top
Anonymous
Guest





PostPosted: Fri Nov 18, 2005 1:04 am    Post subject: Program crash on derived type array Reply with quote

Paul,
thanks for replying quickly.

The workaround works, however as the chars component is private to the string type, and also because a test for ASSOCIATED is done in other parts of the strings module, what I will have to do is never test for association and always allocate a new target. This of course will leak memory.

While experimenting with this I stumbled over another compiler problem. I'll open a new thread for it

Johny
Back to top
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7924
Location: Salford, UK

PostPosted: Fri Nov 18, 2005 1:50 am    Post subject: Program crash on derived type array Reply with quote

Jonny

I think that we will be able to fix the bug before long but probably not before the next release.
In the meantime you could consider adding an extra field to the TYPE to indicate the allocated state.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7924
Location: Salford, UK

PostPosted: Fri Nov 25, 2005 1:03 pm    Post subject: Program crash on derived type array Reply with quote

Johny

This bug has now been fixed and the fix will be included in the next release.
Back to top
View user's profile Send private message AIM Address
Johny



Joined: 17 Nov 2005
Posts: 2

PostPosted: Tue Nov 29, 2005 11:47 am    Post subject: Program crash on derived type array Reply with quote

Paul,

thank you for the reply.
I will eagerly wait for the next release, as the workaround proposed earlier does not work either. Any component in the derived type does not get properly initialized.
Back to top
View user's profile Send private message
JohnyBergmann



Joined: 21 Nov 2005
Posts: 5

PostPosted: Fri Jan 13, 2006 12:42 am    Post subject: Program crash on derived type array Reply with quote

Hello,

with the release 4.90, the above code now works correctly



Johny
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group