Xref: utzoo comp.lang.pascal:4069 comp.sys.ibm.pc.misc:1554 Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!dkuug!freja.diku.dk!terra From: terra@diku.dk (Morten Welinder) Newsgroups: comp.lang.pascal,comp.sys.ibm.pc.misc Subject: TP overlays are not safe! Keywords: tp, overlays, bug Message-ID: <1990Sep10.101723.11142@diku.dk> Date: 10 Sep 90 10:17:23 GMT Organization: Department Of Computer Science, University Of Copenhagen Lines: 47 Turbo Pascal 5.5 has a problem with the O+ switch; it doesn't work. Setup: The following code is placed in an overlaid unit (#1): writeln( pos( { pos has 2 (>1) arguments, 1st is a string } '.', { 1st argument is string CONSTANT } myfunc)); { calls other modules (#2,...). } Problem: The expression '.' generates a reference to the code segment; CS and some offset is pushed. Then myfunc is called and (a pointer to) the result is pushed. Finally pos is called. Since the second expression may cause unit #1 to be disposed of by the overlay manager, there is simply no way to ensure that unit #1 is reloaded at the same address before the pos-function is evaluated. If it is reloaded elsewhere, the first argument is LOST. The problem may arise with as little as three units. I will post source code when I can get my fingers at it. The problem only shows if little memory is available for the overlay buffer. Debugging consumes a large amount of memory. Solution: 1. Yell at Borland 2. Take special care when using string constant as non last argument in an overlaid unit. Rearange the expression: s:=myfunc; writeln(pos('.',s)); 3a.Make the overlay buffer large enough to hold all active units. (Then #1 will not be disposed of.) 3b.Do not change the size of the buffer. (The #1 will be loaded at the same address.) Morten Welinder terra@freja.diku.dk