[fpc-devel] Access Violation with nested DLL's compiled by FPC (and some more info on bug #4538)

Stefan van den Berg chtk at xs4all.nl
Sat Dec 10 14:26:09 CET 2005


I wrote this before my reply to L505. Seems I forgot to send it. So, 
better lae then never, here it is.

> Jonas Maebe wrote:
>> 
>> On 9 dec 2005, at 16:03, Marc Weustink wrote:
>> 
>> 
>> 
>> http://www.freepascal.org/bugs/showsource.php3?ID=4538
> 
> Whoops, I didn't saw that there was a bugrep.
>

No biggy.

> I'm not shure if FPC behaves the same as Delphi, but I think it does.
> 
> In Delphi you cannot exchange ansistrings between dlls, unless you have 
> a shared memory manager. Normally each exe (or dll) has its own memory 
> manager. So when you pass a string to a dll and it it goes out of scope 
> there (since it is changed) it is released there. So a allocated memory 
> block from one manager is freed in another. This gives all kinds of 
> unexpected errors at strange places.
> 
> IIRC the way constant strings are allocates it changed, so that may be 
> the reason that you didn't see the error on dlls generated by an older fpc.

The bugreport, as I submitted it, doesn't describe the complete picture, 
so I tried to explain it further in my original mail. Yes, when using a 
main app and two libraries, compiled with 2.1.1 on Win32, I get an AV 
when TestFunc in dll2 is called from dll1. And if I compile the sample 
pascal files with 2.0.0 on Win32 or any version on Linux and execute the 
main app, this doesn't result in an AV.

So because of this, at first, I thought that 2.0.0 on Win32 and all 
versions on Linux were safe. But after some time (and after I submitted 
the bug) I found out I was wrong, when I ran into a situation with a 
third level library on Linux. I got the same type of error there as I 
did on Win32 using 2.1.1.


> 
> Marc





More information about the fpc-devel mailing list