[fpc-pascal] Range checking in a for loop
Consider the following program: program test; var a: array [1..3] of Integer; i: Integer; begin for i := 1 to 4 do a[i] := i; end. The compiler will accept this code happily, despite the fact that there's an out of bounds array index when i = 4. Since the behavior of for loop in FPC (at least in non Delphi / TP mode) is deterministic, it should be possible to check whether the index is out of bounds or not. Isn't it? Or is there any situation where it's not? -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Range-checking-in-a-for-loop-tp3235085p3235085.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Heaptrc with symbolic stack trace or map file on Mac OS X ?
Hello, I'm trying to find a memory leak but I am unable to get a symbolic stack trace from the heaptrc dump. Also the option -Xm does not generate a map file on Mac OS X. Or at least I don't see it. If I could get a detailed map file with line numbers and offsets, I would probably be happy. Any ideas? Thanks. Cheers, Tobias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Heaptrc with symbolic stack trace or map file on Mac OS X ?
On 25 Oct 2010, at 11:33, Tobias Giesen wrote: I'm trying to find a memory leak but I am unable to get a symbolic stack trace from the heaptrc dump. Automatically symbolicating stack traces is currently only supported when using Stabs debug information on Mac OS X (make sure to also compile with -gl to include the symbolication unit). Also the option -Xm does not generate a map file on Mac OS X. Or at least I don't see it. It's indeed not implemented for Mac OS X. You can manually tell the linker to create it by passing the following options to FPC: -k-map -kmapfilename.map If I could get a detailed map file with line numbers and offsets, I would probably be happy. It's probably easier to either (temporarily) switch to Stabs debug information, or to compile with DWARF debug info and then script gdb to convert the addresses to line numbers: First convert a backtrace to gdb commands: sed -e 's/^ \$/info line *0x/' > trace.gdb (paste the backtrace) and then press ctrl-d Then have gdb execute the commands: gdb executable_name -batch -x trace.gdb E.g.: $ ./tt6 Heap dump by heaptrc unit 1 memory blocks allocated : 10/16 0 memory blocks freed : 0/0 1 unfreed memory blocks : 10 True heap size : 327680 (16 used in System startup) True free heap : 327568 Should be : 327584 Call trace for block $000C2060 size 10 $2578 $25A0 $25C4 $00031F68 $2530 $2240 $B104 $ sed -e 's/^ \$/info line *0x/' > trace.gdb $2578 $25A0 $25C4 $00031F68 $2530 $2240 $B104 $ gdb tt6 -batch -x trace.gdb Reading symbols for shared libraries .. done Line 6 of "tt6.pp" starts at address 0x2578 and ends at 0x2588 . Line 11 of "tt6.pp" starts at address 0x25a0 and ends at 0x25b0 . Line 15 of "tt6.pp" starts at address 0x25c4 and ends at 0x25d8 . Line 300 of "../bsd/system.pp" starts at address 0x31f68 and ends at 0x31f7c $PPCHAR$PPCHAR+108>. No line number information available for address 0x2530 <_start+748> No line number information available for address 0x2240 No line number information available for address 0xb104 Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Range checking in a for loop
On Mon, 25 Oct 2010 01:06:16 -0700 (PDT), leledumbo wrote about [fpc-pascal] Range checking in a for loop: [snip] >program test; > >var > a: array [1..3] of Integer; > i: Integer; >begin > for i := 1 to 4 do >a[i] := i; >end. > >The compiler will accept this code happily, despite the fact that >there's an out of bounds array index when i = 4. There is no reason in the for-loop construct that "i" cannot have the value 4; it is only a problem when "i" is used as a subscript on the array "a". Try declaring i : 1..3; instead, as that range matches the array's bounds. You should then get a range check at compile time. It is also the idiomatic Pascal way of doing this. -- Regards, Dave [RLU #314465] === david.w.n...@ntlworld.com (David W Noon) === signature.asc Description: PGP signature ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Range checking in a for loop
25.10.2010 16:06, leledumbo wrote: Consider the following program: program test; var a: array [1..3] of Integer; i: Integer; begin for i := 1 to 4 do a[i] := i; end. The compiler will accept this code happily, despite the fact that there's an out of bounds array index when i = 4. Since the behavior of for loop in FPC (at least in non Delphi / TP mode) is deterministic, it should be possible to check whether the index is out of bounds or not. Isn't it? Or is there any situation where it's not? a[i] is an expression. You can write a[(i+j)/n] there and compiler will fail to calculate whether the expression match the bound in this case. Moreover, to create a dynamic array you usually use ^a[0..0] type and it would be sad if compiler rejected any index <> 0 for this case. Anyway, if you want to be sure you are in array bounds just use Low(a) as the lower bound and High(a) as the high bound. Best regards, Paul Ishenin. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Range checking in a for loop
On 25 Oct 2010, at 13:24, David W Noon wrote: Try declaring i : 1..3; instead, as that range matches the array's bounds. You should then get a range check at compile time. With current released versions, you won't get such a compile time error. I fixed that just yesterday in svn though (r16213). Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Range checking in a for loop
On 25 Oct 2010, at 13:54, Jonas Maebe wrote: On 25 Oct 2010, at 13:24, David W Noon wrote: Try declaring i : 1..3; instead, as that range matches the array's bounds. You should then get a range check at compile time. With current released versions, you won't get such a compile time error. ... if range checking is disabled (then you'll only get a warning). When range checking is enabled, you do get an error already. I fixed that just yesterday in svn though (r16213). and now you get an error under all circumstances (common sense and Delphi-compatible). Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Widestring memory leaks with FPC 2.4.0?
Hello, I'm using FPC 2.4.0 on Mac and I have a problem with WideString memory leaks. Is there any known issue, such that temporary WideStrings are not always freed, or any bug in reference counting? Cheers, Tobias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Widestring memory leaks with FPC 2.4.0?
On 25 Oct 2010, at 14:53, Tobias Giesen wrote: I'm using FPC 2.4.0 on Mac and I have a problem with WideString memory leaks. Is there any known issue, such that temporary WideStrings are not always freed, or any bug in reference counting? No. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Re: Range checking in a for loop
OK, thanks. I just want to know why such a thing cannot be detected at compile time. So, a good typing practice is the solution, right? Like this: program test; type TArrayRange = 1..3; TArray = array[TArrayRange] of Integer; var a: TArray; i: TArrayRange; begin for i := 1 to 4 do a[i] := i; end. -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Range-checking-in-a-for-loop-tp3235085p3235405.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Widestring memory leaks with FPC 2.4.0?
Hi, I am doing a regular heaptrc.DumpHeap now and I see that WideString memory blocks are still allocated for string values which are no longer in use. Is the memory freed in some lazy way? Or should a value that is no longer assigned to any WideString be freed immediately? Cheers, Tobias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] TPLY
I recently saw a semi working example of a Java to Delphi converter that was done with javacc. Unfortunately it would only convert simple java (v 1.4 maybe). Can anyone recommend a good place to start reading or offer any advise to accomplish this with TPLY. I am looking into porting some Java libraries to FPC 2.5.x, and am unfamiliar with the TPLY tools. Thanks, Brian ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Widestring memory leaks with FPC 2.4.0?
On 25 Oct 2010, at 19:08, Tobias Giesen wrote: > I am doing a regular heaptrc.DumpHeap now and I see that WideString > memory blocks are still allocated for string values which are no > longer in use. Is the memory freed in some lazy way? Or should a > value that is no longer assigned to any WideString be freed > immediately? There can always be hidden temps around. Unless heaptrc shows leaks when the program exits, no memory leaks happen. Jonas___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Widestring memory leaks with FPC 2.4.0?
> Unless heaptrc shows leaks when the program exits, no memory leaks > happen. It's a leak. The program loses hundreds of MBs of memory just by working with WideStrings. I compared it against FPC 2.2.4 - no leak. An SVN snapshot of 2.5.1 from around 3 months ago also leaks. Will update from SVN now. Cheers, Tobias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Widestring memory leaks with FPC 2.4.0?
In our previous episode, Tobias Giesen said: > > Unless heaptrc shows leaks when the program exits, no memory leaks > > happen. > > It's a leak. The program loses hundreds of MBs of memory just by > working with WideStrings. I compared it against FPC 2.2.4 - no leak. > An SVN snapshot of 2.5.1 from around 3 months ago also leaks. Note that on Windows 2.2.4 has the "Kylix" widestring, while 2.4.0 and later have a "COM" widestring. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Widestring memory leaks with FPC 2.4.0?
On 25 Oct 2010, at 20:35, Tobias Giesen wrote: > It's a leak. The program loses hundreds of MBs of memory just by > working with WideStrings. I compared it against FPC 2.2.4 - no leak. Then you'll have to provide a compilable example that demonstrates the problem so we can fix it. Jonas___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Widestring memory leaks with FPC 2.4.0?
> Then you'll have to provide a compilable example that demonstrates > the problem so we can fix it. I will try! Cheers, Tobias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Widestring memory leaks with FPC 2.4.0?
Hi, the latest 2.5.1 SVN leaks too (on Mac i386). Will try to isolate it. Cheers, Tobias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Widestring Questions
Hi, is it possible to turn off reference counting, for a test? Is there a difference between UnicodeString and WideString on the Mac version (i386) of FPC 2.4 / 2.5? Cheers, Tobias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Widestring Questions
On 25 Oct 2010, at 23:25, Tobias Giesen wrote: > is it possible to turn off reference counting, for a test? No. > Is there a difference between UnicodeString and WideString on the > Mac version (i386) of FPC 2.4 / 2.5? No. UnicodeString and WideString only differ on Windows. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Widestring Questions
Hi, I think the problem might be that Widestring reference counting is not thread safe. But it worked fine in FPC 2.2. I will add some UniqueString calls and also try to isolate the issue. Cheers, Tobias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Cross-compiling with FPC 2.5.1
I use the scripts buildcrossbinutils.sh and buildcrosssnapshot.sh to buils the FPC 2.4.2 cross compiler (linux to win32). However when I do the same steps but with FPC 2.5.1, I get the following error: make all LINKSMART=1 CREATESMART=1 make[4]: Entering directory `/home/me/Programs/fpc/fpsrc/2.5.1/packages/hermes' /home/me/Programs/fpc/cross_fpc/cross/bin/i686-cygwin-as --32 -o units/i386-win32/mmx_clr.o src/i386/mmx_clr.as make[4]: /home/me/Programs/fpc/cross_fpc/cross/bin/i686-cygwin-as: Command not found make[4]: *** [mmx_clr.o] Error 127 make[4]: Leaving directory `/home/me/Programs/fpc/fpsrc/2.5.1/packages/hermes' make[3]: *** [fpc_smart] Error 2 make[3]: Leaving directory `/home/me/Programs/fpc/fpsrc/2.5.1/packages/hermes' make[2]: *** [hermes_smart] Error 2 make[2]: Leaving directory `/home/me/Programs/fpc/fpsrc/2.5.1/packages' make[1]: *** [packages_smart] Error 2 make[1]: Leaving directory `/home/me/Programs/fpc/fpsrc/2.5.1' make: *** [build-stamp.i386-win32] Error 2 What should I do to build the 2.5.1 crosscompiler successully? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Widestring Questions
2010/10/26 Tobias Giesen : > I think the problem might be that Widestring reference counting is not > thread safe. But it worked fine in FPC 2.2. A bug may show anytime anywhere, but the built in ref counted string types are AFAIK thread safe what concerns the ref count per se. I suspect a subtle flaw in the client code is more probable. -- bflm freepascal-bits.blogspot.com ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal