[fpc-pascal] JSON stream load/save recursive structure
Hi there, Can fpjson handle load AND save of the following structure from/to json: PTreeStructure = ^TTreeStructure; TTreeStructure = class name: string; value: Integer; items: array of PTreeStructure; end; Thanks! xrfang ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] libevent for socket
Hi All, Could anyone help me with some samples of writing socket program with libevent, or is there any adapter/wrapper already exists for freepascal? Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] FPC 3 inclusion for debian/ubuntu?
> > > T > he experimental repository > > contains a file > fpc_3.0.0+dfsg-1_all.deb > which is only 38Kb, and is for "all" architecture. > > Sorry I digged inside and found the actual file. That's a "meta" package. However, there is no MIPS build. To build fpc executables for MIPS, I have to do cross-compiling? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] FPC 3 inclusion for debian/ubuntu?
On Mon, Dec 14, 2015 at 5:27 PM, Jonas Maebewrote: > It's already in the Debian experimental repository: > https://packages.debian.org/search?searchon=names=fpc > > You will have to ask the Debian/Ubuntu project when they plan to include > it in which release. > The experimental repository contains a file fpc_3.0.0+dfsg-1_all.deb which is only 38Kb, and is for "all" architecture. As a matter of fact, I usually get the latest version of fpc from the download site of Lazarus. The reason I ask is that I expect to get non-intel architecture (armhf, mips etc.) builds of fpc-3. Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] FPC 3 inclusion for debian/ubuntu?
Hi There, Just curious, will the freshly release FPC 3 be included in the current or next release of debian/ubuntu repository? Thanks! ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] status of fpc-mips
Hi All, I plan to port my program to a MIPS based openwrt router. The hardware is based on Atheros AR9331. I wonder if FPC for MIPS linux cross compiler is usable or not and what FPC version it currently support? Also, btw, last time I asked similar question about the RaspberryPi, and know that there are ARMEL/ARMHF. Is there similar concept on MIPS platform? i.e. if I successfully compile a program for MIPS, is it guaranteed to work on all MIPS compliant CPUs? Thanks a lot. Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Linking failed on RaspberryPi
Another problem is, as I downloaded the wrong version and ran its install.sh (as root), how can I uninstall it? Thanks! 2015-09-16 9:29 GMT+08:00 Xiangrong Fang <xrf...@gmail.com>: > I asked on the list before. The version shipped with Pi is 2.6.0, and is > said to be very buggy, I need version 2.6.4, so I downloaded from official > site. > > > > 2015-09-15 19:52 GMT+08:00 Jonas Maebe <jonas.ma...@elis.ugent.be>: > >> On 15/09/15 13:28, Xiangrong Fang wrote: >> >>> I downloaded arm linux distribution from freeepascal website >>> (sourceforge). So, I should get it work by fixing crti as suggested by >>> PB, or I shall get the compiler from Pi website as suggested by Jonas? >>> >> >> You don't get it from the Pi website, but by using the package manager of >> your linux distribution (apt). >> >> The version from the FPC website is not appropriate for your Linux >> distribution, as it is for ARMEL and you have ARMHF. >> >> >> Jonas >> >> >> ___ >> fpc-pascal maillist - fpc-pascal@lists.freepascal.org >> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal >> > > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Linking failed on RaspberryPi
Hi Peter, xrfang@pi ~ $ grep FI /etc/fpc.cfg # nested #IFNDEF, #IFDEF, #ENDIF, #ELSE, #DEFINE, #UNDEF are allowed # -d is the same as #DEFINE #DEFINE NEEDCROSSBINUTILS xrfang@pi ~ $ ls /usr/lib/**/crti.o /usr/lib/arm-linux-gnueabihf/crti.o Thanks! 2015-09-15 20:06 GMT+08:00 Peter: > It would be useful to see the output of these two commands > > grep Fl /etc/fpc.cfg > ls /usr/lib/**/crti.o > > > Jonas knows a lot more about FPC than I do! > > Regards, > PB > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Linking failed on RaspberryPi
I asked on the list before. The version shipped with Pi is 2.6.0, and is said to be very buggy, I need version 2.6.4, so I downloaded from official site. 2015-09-15 19:52 GMT+08:00 Jonas Maebe <jonas.ma...@elis.ugent.be>: > On 15/09/15 13:28, Xiangrong Fang wrote: > >> I downloaded arm linux distribution from freeepascal website >> (sourceforge). So, I should get it work by fixing crti as suggested by >> PB, or I shall get the compiler from Pi website as suggested by Jonas? >> > > You don't get it from the Pi website, but by using the package manager of > your linux distribution (apt). > > The version from the FPC website is not appropriate for your Linux > distribution, as it is for ARMEL and you have ARMHF. > > > Jonas > > > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Linking failed on RaspberryPi
I downloaded arm linux distribution from freeepascal website (sourceforge). So, I should get it work by fixing crti as suggested by PB, or I shall get the compiler from Pi website as suggested by Jonas? 2015-09-15 19:11 GMT+08:00 Peter <pe...@pblackman.plus.com>: > On 14/09/15 21:09, Mark Morgan Lloyd wrote: > > Peter wrote: > >> On 04/09/15 02:15, Xiangrong Fang wrote: > >>> . > >>> Is there anything missing from my FPC installation? > >>> TIA for any hint. > >> > >> To build FPC programs on linux one generally needs a variant of > >> libc-dev, which is not part of FPC itself. > >> The package you need might be libc6-dev, or some other combination of > >> 'libc' and 'dev'. > >> > >> Please post the solution if/when you find it for the benefit of others. > >> This same question seems to keep poping up on this list. > > > > You mean like I did [checks] on the 31st? > > http://lists.freepascal.org/pipermail/fpc-pascal/2015-August/045157.html > > > > And that was without any particular additions, other than what came with > > Raspbian 2014 as standard; Raspbian 2015 doesn't need most of those > > options (i.e. either miss out the -FL and -Fl options, or follow > > Martin's procedure). > > > > > The symbols the OP is missing are defined in crti.o > Without further information from him, its impossible to know whether the > problem is that > 1) crti.o is not installed (its libc..dev not FPC) > 2) The -Fl option does not use the right path for the system in use. > > I would suggest the following; > try the command > ls /usr/lib/**/crti.o > > If it works, use the given path for -Fl (as per the links already given > in this thread. > If it does not work, install the libc package that contains crti.o, and > repeat the test. > > > Regards, > PB > > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Linking failed on RaspberryPi
Hi All, I try to compile my program on Pi, with the official FPC 2.6.4 for arm linux, but get the following error: /usr/lib/fpc/2.6.4/units/arm-linux/rtl/cprt0.o: In function `_haltproc_eabi': (.text+0x88): undefined reference to `_fini' /usr/lib/fpc/2.6.4/units/arm-linux/rtl/cprt0.o: In function `_haltproc_eabi': (.text+0x90): undefined reference to `_init' Is there anything missing from my FPC installation? TIA for any hint. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Fatal: Internal error 200305103
Hello, I got Fatal: Internal error 200305103 while try to compile the attached file on my raspi. The file is a class helper. I wonder if that is supported on FPC 2.6.0 or not? And whether this problem has anything to do with ARM? unit cipher; {$mode objfpc}{$H+} interface uses sysutils, BlowFish; type TBlowFish = BlowFish.TBlowFish; TBlowFishModes = class helper for TBlowFish private procedure CryptCTR(IV: QWord; buf: Pointer; len: Integer); inline; public constructor Create(key: Pointer; KeySize: Integer); procedure EncryptCTR(IV: QWord; buf: Pointer; len: Integer); procedure DecryptCTR(IV: QWord; buf: Pointer; len: Integer); procedure EncryptCBC(IV: QWord; buf: Pointer; len: Integer); procedure DecryptCBC(IV: QWord; buf: Pointer; len: Integer); end; implementation constructor TBlowFishModes.Create(key: Pointer; KeySize: Integer); begin inherited Create(PBlowFishKey(key)^, KeySize); end; procedure TBlowFishModes.EncryptCTR(IV: QWord; buf: Pointer; len: Integer); begin CryptCTR(IV, Buf, len); end; procedure TBlowFishModes.DecryptCTR(IV: QWord; buf: Pointer; len: Integer); begin CryptCTR(IV, Buf, len); end; procedure TBlowFishModes.CryptCTR(IV: QWord; buf: Pointer; len: Integer); var i, cnt, res: Integer; ipt: QWord; iptb: array[0..7] of Byte absolute ipt; ptb: PQWord; ptr: PByte; begin cnt := len div 8; res := len mod 8; for i := 0 to cnt - 1 do begin ipt := IV xor i; Encrypt(TBFBlock(ipt)); ptb := PQWord(buf + i * 8); ptb^ := ptb^ xor ipt; end; if res 0 then begin //process last block less than 8 byte ipt := IV xor cnt; for i := 0 to res - 1 do begin ptr := PByte(buf + cnt * 8 + i); ptr^ := ptr^ xor iptb[i]; end; end; end; procedure TBlowFishModes.EncryptCBC(IV: QWord; buf: Pointer; len: Integer); var i, cnt, res: Integer; ptb: PQWord; last, prelast: QWord; begin if len = 8 then begin CryptCTR(IV, buf, len); Exit; end; cnt := len div 8; res := len mod 8; if res = 0 then begin prelast := PQWord(buf+(cnt-2)*8)^; last := PQWord(buf+(cnt-1)*8)^; res := 8; Dec(cnt, 2); end else begin prelast := PQWord(buf+(cnt-1)*8)^; last := PQWord(buf+cnt*8)^; Dec(cnt); end; for i := 0 to cnt - 1 do begin ptb := PQWord(buf + i * 8); ptb^ := ptb^ xor IV; Encrypt(TBFBlock(ptb^)); IV := ptb^; end; prelast := prelast xor IV; Encrypt(TBFBlock(prelast)); Move(prelast, PByte(buf+(cnt+1)*8)^, res); last := last xor prelast; Encrypt(TBFBlock(last)); PQWord(buf+cnt*8)^ := last; end; procedure TBlowFishModes.DecryptCBC(IV: QWord; buf: Pointer; len: Integer); type QWB = array[0..7] of Byte; var i, cnt, res: Integer; ptb: PQWord; ctx: QWord; last, prelast: QWord; begin if len = 8 then begin CryptCTR(IV, buf, len); Exit; end; cnt := len div 8; res := len mod 8; if res = 0 then begin prelast := PQWord(buf+(cnt-2)*8)^; last := PQWord(buf+(cnt-1)*8)^; Dec(cnt, 2); end else begin prelast := PQWord(buf+(cnt-1)*8)^; last := PQWord(buf+cnt*8)^; Dec(cnt); end; for i := 0 to cnt - 1 do begin ptb := PQWord(buf + i * 8); ctx := ptb^; Decrypt(TBFBlock(ptb^)); ptb^ := ptb^ xor IV; IV := ctx; end; Decrypt(TBFBlock(prelast)); if res 0 then begin for i := res to 7 do QWB(last)[i] := QWB(prelast)[i]; end else res := 8; prelast := prelast xor last; Move(prelast, PByte(buf+(cnt+1)*8)^, res); Decrypt(TBFBlock(last)); PQWord(buf+cnt*8)^ := last xor IV; end; end. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] shift right operation with variables
Hi All, I noticed a strange behavior with the following program: program tt; {$mode objfpc}{$H+} uses sysutils; var res: Integer; mask1, mask2: QWord; begin mask1 := $ shr 24; WriteLn(IntToHex(mask1, 16)); res := 24; mask2 := $ shr res; WriteLn(IntToHex(mask2, 16)); end. The output is: 00FF 00FF Why they are different? How can I ensure the result is like SHR with constant. Thanks! ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] quality of FPC random
Hi All, I need to generate random numbers to be used as IV of block ciphers. My question is: is FPC built-in PRNG good enough as comparing to /dev/urandom? On the other hand, /dev/urandom in my impression is fairly slow, how is the speed of Random() comparing to that? Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] quality of FPC random
2015-08-14 21:47 GMT+08:00 Jonas Maebe jonas.ma...@elis.ugent.be: Xiangrong Fang wrote on Fri, 14 Aug 2015: I need to generate random numbers to be used as IV of block ciphers. My question is: is FPC built-in PRNG good enough as comparing to /dev/urandom? No PRNG is suited for that purpose, because every PRNG is by definition predictable and you need unpredictable numbers for IVs. Well, practically, how can I get totally unpredictable numbers? On stackoverflow, someone suggested using hash value of data as IV, but that's still flawed somehow. Without introduce hardware source like a dongle or other devices (which is not acceptable for my purpose), I suppose good quality PRNGs are the only thing that I can use? Also, why FPC random number are not comparable to /dev/urandom? Despite the difference in their quality and speed (if any), what's the difference between them? especially, what are the typical use cases of these 2 PRNGs when they are designed? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] alignment of records
By using the correct types for the fields: http://www.freepascal.org/docs-html/rtl/ctypes/index-3.html E.g., unsigned long is not (always) the same as dword. OK, as a matter of fact, the stuff was copied from output of h2pas conversion program. :-) I will use ctypes to test again. However, another issue: if I use this : {$CODEALIGN RECORDMIN=4} It worked. i.e. output size same as C version. I wonder what's the difference between $CODEALIGN and $A/$PACKRECORDS? Also, if I use packed records, alignment will never take place, regardless of $A settings, right? Thanks! Xiangrong Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] alignment of records
Hi All, I try to port a program from C to Pascal, see the following example: #include stdio.h #include sys/socket.h #include linux/if.h void main() { printf(ifmap=%ld\n, sizeof(struct ifmap)); } I converted it to: est.c test.pas X program test; {$mode objfpc}{$PACKRECORDS C} type ifmap = record mem_start: dword; mem_end: dword; base_addr: word; irq: byte; dma: byte; port: byte; end; begin WriteLn('ifmap=', SizeOf(ifmap)); end. The C struct's size is 24, but pascal record is 16.The ifmap struct is defined as: struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; /* 3 bytes spare */ }; How can I instruct FPC to align records exactly same as GCC? Thanks! ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] alignment of records
It seems that $packrecord does not work at all. I did some research and found this document: http://www.freepascal.org/docs-html/ref/refsu19.html compiled and ran the example on that page, I got: Size Trec1 : 4 Offset B : 2 Size Trec2 : 3 Offset B : 1 Size Trec3 : 2 Offset B : 1 Size Trec4 : 2 Offset B : 1 Size Trec5 : 5 Offset B : 1 Offset C : 4 Size Trec6 : 5 Offset B : 1 Offset C : 4 Size Trec7 : 9 Offset B : 1 Offset C : 8 Size Trec8 : 9 Offset B : 1 Offset C : 8 While the expected output, as stated in the document above, should be: Size Trec1 : 4 Offset B : 2 Size Trec2 : 3 Offset B : 1 Size Trec3 : 2 Offset B : 1 Size Trec4 : 2 Offset B : 1 Size Trec5 : 8 Offset B : 4 Offset C : 7 Size Trec6 : 8 Offset B : 4 Offset C : 7 Size Trec7 : 12 Offset B : 4 Offset C : 11 Size Trec8 : 16 Offset B : 8 Offset C : 15 2015-08-07 10:48 GMT+08:00 Xiangrong Fang xrf...@gmail.com: Hi All, I try to port a program from C to Pascal, see the following example: #include stdio.h #include sys/socket.h #include linux/if.h void main() { printf(ifmap=%ld\n, sizeof(struct ifmap)); } I converted it to: est.c test.pas X program test; {$mode objfpc}{$PACKRECORDS C} type ifmap = record mem_start: dword; mem_end: dword; base_addr: word; irq: byte; dma: byte; port: byte; end; begin WriteLn('ifmap=', SizeOf(ifmap)); end. The C struct's size is 24, but pascal record is 16.The ifmap struct is defined as: struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; /* 3 bytes spare */ }; How can I instruct FPC to align records exactly same as GCC? Thanks! ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] manipulate tun/tap in free pascal
Hi there, Is there any example to write a tun/tap driver (or adapter, whatever) on Linux using free pascal? Thanks! ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] fcl-net and fpasync
Hi All, I try to write a tcp client program, and found this page: http://pascalgeek.blogspot.com/2012/06/encryption-decryption-and-asynchronous.html which is the only resource I found using fcl-net. But there is a big problem: it did not tell how to receive message back from the server. I tried to write something like: EventLoop.Run; while true do begin Stream.WriteAnsiString('Hello'); WriteLn('Server Reply: ' + Stream.ReadAnsiString); Sleep(1000); end; //Active := false; And at the server side, Msg := FClientStream.ReadAnsiString; WriteLn(AddrToString(FClientStream.PeerAddress) + ': ' + Msg); FClientStream.WriteAnsiString('World!'); //added by me It simply generated a runtime error: EReadError : Stream read error As a matter of fact, I also tried to create a thread like this: procedure TMyTCPClient.ConnStateChanged(Sender: TClientConnectionSocket; OldState, NewState: TConnectionState); begin if NewState = connConnected then begin WriteLn('Connected!'); TMsgReceiver.Create(Stream); end; end; constructor TMyTCPClient.TMsgReceiver.Create(AStream: TSocketStream); begin inherited Create(False); FStream := AStream; FreeOnTerminate := True; end; procedure TMyTCPClient.TMsgReceiver.Execute; var s: string; begin while True do begin WriteLn('Now try to receive something...'); s := FStream.ReadAnsiString; WriteLn('Received: ', s); end; end; But it did not receive anything! How can I enable **bi-directional**, asynchronous (event driven) communication using fcl-net, also, is there any document on fpasync?? Thanks a lot! xrfang ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] SQLDB: how to use TSQLTransaction
Hi All, Sorry that I don't know if SQLDB belongs to fpc or lazarus, so I posted to both lists. I am confused about the use of transaction in SQLDB. I tried to use in in my non-gui app. Here is the code: function TPortfolio.ConfirmTransaction(id: Integer): Boolean; begin with qr do begin SQL.Text := Format('UPDATE records SET status=%d WHERE id=%d AND status=%d', [TR_SUCCESS, id, TR_PENDING]); ExecSQL; WriteLn('Confirming: ', id, ', affected: ', RowsAffected); //tr.Commit; //WriteLn('Confirming: ', id, ', affected: ', RowsAffected); Result := RowsAffected 0; end; end; It seems that I must assign a TSQLTransaction object to the TSQLQuery object, otherwise it doesn't work. I also found that without call tr.Commit, the ExecSQL will not take effect, at least for INSERT statements. In the above function, I found the first WriteLn will output rows-affected as 1, and the 2nd (after tr.Commit) will output rows-affected as -1! I then commented out the tr.Commit; statement, it STILL worked. Now my questions are: 1. How to control the use of transactions in SQLDB? Sometime I do NOT want transaction, but want the DDL/DML statement to be executed immediately. Why sometime SQLDB's ExecSQL won't take effect if not followed by a Commit? BTW, I tried to set tr.Active to true/false before execute the sql, but it seems not making a difference? 2. What is the meaning of -1 as returned by RowsAffected? Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] load a library twice
Hi All, Is the following correct: var h1, h2: TLibHandle; lib1, lib2: string; begin lib1 := 'library.so'; lib2 := 'library.so'; h1 := LoadLibrary(lib1); h2 := LoadLibrary(lib2); end. The reason I need this is that I would like to keep the possibility to provide different group of functions in the same or two different libraries. For example, lib1 provides function A, lib2 provide function B, or, lib3 provide both function A and B. If I open the same library via 2 different handles, are they actually pointing to the same memory address internally, so that if I UnloadLibrary, it will cause something like access violation in the second call? Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] how to use signals in freepascal?
2015-03-17 17:06 GMT+08:00 Michael Schnell mschn...@lumino.de: IPC between applications or within an application ? between application. If between application are both don in fpc and under your control ? actually, multiple instance of the same application. Lazarus or pure fpc ? pure fpc. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] how to use signals in freepascal?
2015-03-17 16:28 GMT+08:00 Michael Schnell mschn...@lumino.de: As there are similar concepts implemented in fpc and Lazarus in a cross-platform manner, could you give the reason why you want too use platform-specific (low level) concepts like Unix-Signals (or Windows messages) ? (I don't doubt there are in some special projects.) Actually, I do *not* insist on using unix signals in a cross-platform way. I just need a simple IPC mechanism, without the hassle of e.g. a socket server. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] how to use signals in freepascal?
You should not use this in fact, it is meant for internal use. To write a signal handler on unix, see http://www.freepascal.org/docs-html/rtl/baseunix/fpsigaction.html there is an example. I tried example57, it worked, but I still do not know some peculiar behaviors in it. I will ask later, after some investigations. However, what is HookSignal for? How to use it? Or it is just a stub and not functional yet? Thanks! ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] how to use signals in freepascal?
Hi All, I have some questions regarding event and signals: 1) RTLEventWaitFor can a program waiting for an RTLEvent be notified by an RTLEventSet from ANOTHER process? 2) Unix Signals I see HookSignal() in the sysutils documentation, but there is nothing said on how to use it. Is it used to write my own signal handler on Linux? Could anyone give a sample program? Also, is there a list of defined RtlSigNums? 3) Unix-style Signals on Windows If possible, I would like to have cross platform signal handling in my app. I found this: https://github.com/graemeg/freepascal/blob/master/rtl/win32/signals.pp Does it mean that if I uses signals, I will have same capability on both linux and windows? Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] how to use procedure of object in C
Hi all, I define a procedure like this: type TDataHandler = procedure(data: Pointer) of object; procedure SetHandler(h: TDataHandler); external cdecl; Now, can I implement SetHandler in a library written in C, then call h in C? Thankyou. -- Sent from Gmail Mobile ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] how to use procedure of object in C
2015-03-10 0:33 GMT+08:00 OBones obo...@free.fr: How about using TMethod? procedure DataHandler(DummySelf: Pointer; data: Pointer); begin // do what you want to do, DummySelf is always nil. end; var Method: TMethod; begin Method.Data := nil; Method.Code := @DataHandler; SetHandler(TDataHandler(Method)); end; I'm not sure how this works, but it seems that you are deliberately converting a normal procedure to a method. What I want is exactly opposite - I want to convert a method to a normal procedure. If I define the interfact of DataHandler like this: TDataHandler = procedure(data: Pointer); cdecl; It is very easy to use in an so, no matter it is written in C or pascal. But the problem is, I want to do this: SetHandler(h); where h is a METHOD, not a normal procedure. Because I want to use the handler wrapped in my Class. However, like in my first mail, if I define THandler a procedure of object, it makes easier to SetHandler(AMethod); but how can I use that procedure of object pointer in the so? Thanks! ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Use sleep in thread
2015-02-26 21:53 GMT+08:00 Marco van de Voort mar...@stack.nl: No, basically a sleeping thread is marked in the scheduler as do not schedule for nn ticks. The thread doesn't run to evaluate if it should contiue. That is the scheduler/kernel's task. That's even better. And the key point is, after nn ticks, it is **AUTOMATICALLY** re-scheduled, without the need of knowledge of other threads/processes running on the system! This is the effect of a thread voluntarily gives up its cpu share, but not let other thread to control its fate. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Use sleep in thread
2015-02-26 18:50 GMT+08:00 Henry Vermaak henry.verm...@gmail.com: Sleep is for granting the CPU for other processes for (at least) a predefined time. See the mail of the original poster: this is what he asked for. Thats right. This is incorrect, since if you pause a thread with sleep(), you'll have to loop to check when you're supposed to wake up. I use rtlevent, but only meant to maintain a pool of threads, while there is no task for a thread it is blocked waiting for an event. BUT, that cannot be used to prioritize a thread. While you block a thread using rtlevent, it can only be unblocked from another thread. While you use sleep(), it still get time share of the CPU, only that it does nothing until sleep finishes, right? That way, it only consume a tiny amount of computing power while sleeping. This, in my view, is the price I have to pay to achieve my purpose? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Use sleep in thread
Hi All, Can I use Sleep() in a thread to give up cpu time to other threads running at the same time, so as to adjust the relative niceness of a group of workers working on the same subject (in which each thread take part of the whole task). Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Use sleep in thread
2015-02-25 22:47 GMT+08:00 Dmitry Boyarintsev skalogryz.li...@gmail.com: I presume most of the systems would make the sleeping thread to yield the execution time for other threads. The questionable behavior might occur in case of sleep(0); (should it yield the remaining time or just return immediately - up to the OS). And multi-cpu might also do something different. Yes, I am particularly interested in behavior of SMP system. i.e. my purpose of using threads is to take full advantages of all CPU cores. As far as I know, setting thread priority does not always work, it may require root privilege for example. I would like to use Sleep() to control relative time share of all threads in the pool. For example, I run 3 threads on a dual-core system, with thread 1 and 2 share core-1, and thread 3 taking all computing power of core-2... Now the problem is, can I use Sleep to control thread 1 to run at 50% of the speed of thread 2 (which is not throttled), providing that all threads are doing same kind of task, so that they are comparable? Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Use sleep in thread
2015-02-25 23:16 GMT+08:00 hinsta...@yandex.ru: not sure if this helps, but: for example, if you want thread T to run using approx. 70% of max. available capacity, try this: repeat T.Resume; Sleep(70); T.Resume; Sleep(30); until ... This seems not what I want. I would like to schedule it from within the thread. My demo program is here: https://github.com/xrfang/fpcollection/blob/master/src/demos/asyncdo/demo.lpr TAsyncDo is the class I wrote to have a procedure run in parallel. I want to control priority of the thread from within the worker, not from the main thread. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] compare currency and double
Thank you! I have changed all occurrences of Currency to Double in my program. 2014-12-08 21:25 GMT+08:00 Jonas Maebe jonas.ma...@elis.ugent.be: On 07 Dec 2014, at 16:07, Jonas Maebe wrote: That's because currency has a bigger range than double. Or rather: a double cannot exactly represent every possible currency value. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] compare currency and double
Hi All, I have the following code: var val: Currency; res: Double; begin val := 2345.67; res := 1e300; if val = res then WriteLn('val =res') else WriteLn('val res'); end; The program compile and runs correctly on Linux x64, and Win7 32bit, but failed (SIGFPE) on Win7 64bit. Can I safely compare a Currency against a Double? Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Problem with heaptrc
Hi All, I use heap trace utility to see if there are memory leak in my program. The source is here: https://github.com/xrfang/fpcollection/blob/aefa04f0374c94298facd8d57d4a25dafe10b753/src/demos/cache/demo.lpr My problem is, at the beginning of the main program, I have a costant definition: const ITEM_COUNT = 500; If I set ITEM_COUNT to a small value, say 50 or 5000, everything is OK, no memory leak. But with the above value, it will cause HEAPTRC to fall in an endless loop, generating messages like: Call trace for block $7F41693AA680 size 40 $0040071F line 29 of demo.lpr $00400180 While line 29 is this: 27 for i := 0 to ITEM_COUNT - 1 do begin 28for j := 0 to 4 do key[j] := $deadbeef + i + j; 29h.Add(@key, SizeOf(PtrUInt) * 5, Pointer($deadbeef + i)); 30 end; Could anyone tell me why heaptrc will fall in an endless loop, and does my program have memory leak? Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Problem with heaptrc
2014-11-09 22:05 GMT+08:00 Tomas Hajny xhaj...@hajny.biz: On 9 Nov 14, at 21:58, Xiangrong Fang wrote: Are you sure that it really is endless (i.e. did you let to run for a sufficiently long time)? If you increase the amount of allocated blocks (which is what happens in case of increasing your constant), traversing through all the blocks (especially if they are not freed at the end) may indeed take fairly long time... You are right Tomas, it finished, generated a 300M+(!) trace file, looks like this: ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Problem with heaptrc
2014-11-09 22:14 GMT+08:00 Xiangrong Fang xrf...@gmail.com: 2014-11-09 22:05 GMT+08:00 Tomas Hajny xhaj...@hajny.biz: On 9 Nov 14, at 21:58, Xiangrong Fang wrote: Are you sure that it really is endless (i.e. did you let to run for a sufficiently long time)? If you increase the amount of allocated blocks (which is what happens in case of increasing your constant), traversing through all the blocks (especially if they are not freed at the end) may indeed take fairly long time... You are right Tomas, it finished, generated a 300M+(!) trace file, looks like this: Heap dump by heaptrc unit 8137678 memory blocks allocated : 258591549/258591552 5226767 memory blocks freed : 142155109/142155112 2910911 unfreed memory blocks : 116436440 True heap size : 951812096 True free heap : 392917184 Should be : 462779048 Call trace for block $7F57C456D680 size 40 $0040071F line 29 of demo.lpr $00400180 The last 3 likes repeated until the end of 300M log data! Why when ITEM_COUNT is small, there is no memory leak, but when it is large, there are so many leaks? Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Problem with heaptrc
2014-11-09 22:38 GMT+08:00 Michael Van Canneyt mich...@freepascal.org: Code like this: ci := PCacheItem((buf + SizeOf(Pointer) * Random(FDepth))^); for i := 0 to FDepth - 1 do begin slot := buf + SizeOf(Pointer) * i; if Pointer(slot^) = nil then begin Inc(N); Pointer(slot^) := GetMem(SizeOf(TCacheItem)); ci := PCacheItem(slot^); makes me frown, because the first assignment to ci is useless, so highly suspect. You are right Michael. I just found that if there is no free slot, I use Random Replacement to dump one of the existing cached item, whose key is not freed, which caused memory leak. Thanks! Xiangrong. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Effective memory allocation
2014-11-03 23:40 GMT+08:00 Adriaan van Os f...@microbizz.nl: Xiangrong Fang wrote: Hi All, I am programming a Bloom Filter and need a high-performance way to On what platform are you doing this ? I am programming on Linux, but it will be used on both Windows and Linux, Windows is the primary target. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Effective memory allocation
2014-11-04 6:35 GMT+08:00 Nico Erfurth n...@erfurth.eu: Well, the first thing you should ask yourself is Do I REALLY need such a large bloom filter. Everything larger than the last level cache will seriously harm your performance as you are going to trigger a lot of cache and TLB misses. In general you should target for typical L1-Cache sizes (16-32KByte) or if REALLY necessary L2-Cache-sizes (256KByte-32MByte). Everything above that will make the performance go down rapidly, especially in hashing-application the CPU can't prefetch data properly as the access-patterns are erratic. I didn't think of things like cache and TLB misses. Because I try to use BloomFilter and HASH to avoid repeated calculation and/or lookups which are time consuming. So, I don't think it will harm performance, unless bloom filter lookup is slower than the calculation, am I right? Thanks! ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Effective memory allocation
Hi All, I am programming a Bloom Filter and need a high-performance way to allocate and wipe large block of memory. I did the following test: program getmem; {$mode objfpc}{$H+} uses epiktimer; const SIZE = 1024 * 1024 * 1024; CNT = 10; var a: array of Byte; p: Pointer; et: TEpikTimer; i: Integer; t1, t2: TimerData; begin et := TEpikTimer.Create(nil); et.Clear(t1); et.Clear(t2); for i := 1 to CNT do begin et.Start(t1); p := GetMemory(SIZE); //SetLength(a, SIZE); et.Stop(t1); et.Start(t2); FillQWord(p^, SIZE div 8, 0); //FillQWord(a[0], SIZE div 8, 0); et.Stop(t2); FreeMem(p); //a := nil; end; WriteLn('Alloc: ', et.Elapsed(t1) / CNT); WriteLn('Clear: ', et.Elapsed(t2) / CNT); end. The result is: Using GetMemory: Alloc: 9.40781697E-0001 Clear: 2.13420202E-0001 Using SetLength: Alloc: 2.8100E-0005 Clear: 7.74975504E-0001 It is understandable that GetMemory() is faster than SetLength(), but why the difference in FillQWord()? Also, I usually use pointer to pass block of memory to functions. How do I implement a function with the following signature: procedure MyProc(var Buf; Len: Integer): I mean, how to handle var Buf inside the procedure body? Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Effective memory allocation
Sorry, the results in previous mail was mis-labeled. The result is: Using SetLength: Alloc: 9.40781697E-0001 Clear: 2.13420202E-0001 Using GetMemory: Alloc: 2.8100E-0005 Clear: 7.74975504E-0001 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Effective memory allocation
2014-11-03 2:50 GMT+08:00 Sven Barth pascaldra...@googlemail.com: If you use SetLength the dynamic array consists not only of the array data, but also of an information record in front of it. This will likely lead to the data not being aligned correctly (FillQWord works best with 8-Byte alignment). So what about testing FillDWord or FillChar? Just to see whether they would be faster. It is quite strange that if I use SetLength+FillByte, it is really faster (for the FillByte), but if I use GetMemory+FillByte, it is not faster than using FillDWord or FillQWord. I found this in FPC doc (for $ALIGN switch): This switch is recognized for Turbo Pascal Compatibility, but is not yet implemented. The alignment of data will be different in any case, since Free Pascalis a 32-bit compiler. It is a pity that this switch is not recognized yet. But I need to understand the last statement, will alignment be different or not? Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Effective memory allocation
2014-11-03 14:39 GMT+08:00 Sven Barth pascaldra...@googlemail.com: Would you mind to show the timings that you got for FillChar? :) Using FillChar is always about 5% (or less) faster than FillQWord when used with GetMemory, but will be around 20%-40% faster if the memory is allocated by SetLength. Additionally this switch won't help you. The memory buffer that is allocated by SetLength is also allocated using GetMemory. So the buffer itself *is* aligned. But you don't get the start byte of the buffer in case of SetLength, but the first byte after the information record which might not be aligned correctly and *no* compiler switch will help you with that. Then the problem remains with SetLength vs. GetMemory... Why SetLength is about 1x (!) slower than GetMemory? allocating 1G memory took about 0.1 second by SetLength, but is about 1E-5 via GetMemory. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Is TFPList thread safe?
2014-10-02 14:16 GMT+08:00 Michael Van Canneyt mich...@freepascal.org: TFPList is not thread-safe. You need to use TThreadList if you want a thread-safe list. Critical sections use OS calls, so there is always a performance penalty. I think the only thread-critical operation I need is to add item to the list, so I will use critical section myself, not replace TFPList with TThreadList, for simplicity and performance reason... Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Is TFPList thread safe?
2014-10-02 22:09 GMT+08:00 Michael Schnell mschn...@lumino.de: AFAIR, in Linux, the fpc RTL calls the pthread library mutex... function. This library uses Futex, if the arch supports that, and uses the plain old MUTEX system call if the arch does not support FUTEX. I need my program to work on both Linux and Windows, can I still use FUTEX? For Critical Sections, FPC has the TCriticalSection object, is there a TMutex object? Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Is TFPList thread safe?
2014-10-02 22:23 GMT+08:00 Xiangrong Fang xrf...@gmail.com: 2014-10-02 22:09 GMT+08:00 Michael Schnell mschn...@lumino.de: AFAIR, in Linux, the fpc RTL calls the pthread library mutex... function. This library uses Futex, if the arch supports that, and uses the plain old MUTEX system call if the arch does not support FUTEX. I found some quotes online: For Windows, critical sections are lighter-weight than mutexes. Mutexes can be shared between processes, but always result in a system call to the kernel which has some overhead. Critical sections can only be used within one process, but have the advantage that they only switch to kernel mode in the case of contention. I only need lock WITHIN my own application, so, it seems that critical sections are better. Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Is TFPList thread safe?
2014-10-02 23:07 GMT+08:00 Jonas Maebe jonas.ma...@elis.ugent.be: On 02 Oct 2014, at 15:59, Xiangrong Fang wrote: It will make your program unstable (adding an element to an fplist can cause the entire internal array to move, so if you are in the middle of a read operation at the same time, that read operation will either read invalid data or crash). Unless you are an expert at multithreaded programming, don't try to optimise existing thread-safe structures (and definitely don't perform premature optimisations). I don't intend to do any optimization. I just think that I need to enter a critical section, add item to the list, then leave the critical section. I am definitely not expert in thread programming, but I am clear about the logic of my class and program. Actually, it is a TTree object I wrote, using TFPList to store sibling nodes. There are a lot of TFPList (one per tree node). I just need to make sure that there are no more than one thread operating on the same node at the same time. Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Is TFPList thread safe?
Hi, I would like to know if TFPList is thread-safe or not? And if I make a component thread-safe by using critical sections etc. Is the performance penalty noticeable? Thanks. Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] key-value engine for FPC
Hi All, Is there any good performance Key-Value storage engine written in free pascal, or can be linked with FPC application? I need an embedded storage engine with good performance for a generic (non-binary) tree structure with the following properties and operations: - tree node has 2 properties: data (byte array), and 0~N sub-nodes - a fast way to iterate through all leaf nodes - find parent, and parent of parent, until root - get / iterate all siblings of a node (order is NOT important) - insert node / set parent of a node - cut-off or free (delete) a sub-tree Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] PostMessage vs. QueueAsyncCall
Hi, In a previous email asking about PostMessage, Michael suggested I used QueueAsyncCall instead, because although it's OK to use PostMessage, but it is considered a Windows Legacy, or only for Delphi compatibility. However, in actual use, I feel that PostMessage does a better job for code separation. Because when use PostMessage, GUI (or main thread) related code are written in the main form, and the thread will not need to use the Forms unit. My question is, why cannot Lazarus just use PostMessage, but invent the QueueAsyncCall() method? What is the rationale, or, why PostMessage is considered windows-ish (read: not fit into LCL very well?), apart from the fact that it is a Windows API? Thanks, Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Random thread lockup. QueueAsyncCall??
2014-09-18 23:10 GMT+08:00 Xiangrong Fang xrf...@gmail.com: I suspect that it is blocked on the RTLeventWaitFor, because if I use this: RTLeventWaitFor(Barrier, 1000); It will periodically pause for 1 second, then continue. I found the problem myself. Instead of writing: while not Terminated do begin RTLeventWaitFor(Barrier); if not IsPrime then Number := 0; Application.QueueAsyncCall(@AddPrime, PtrInt(Self)); RTLeventResetEvent(Barrier); end; I should write: while not Terminated do begin RTLeventWaitFor(Barrier); RTLeventResetEvent(Barrier); if not IsPrime then Number := 0; Application.QueueAsyncCall(@AddPrime, PtrInt(Self)); end; Because when doing the AsyncCall, the main thread may have called RTLeventSetEvent BEFORE the RTLeventResetEvent() is called. Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] EpikTimer: maximum elapsed seconds
Hi there, I would like to know the maximum number of seconds EpikTimer can count. I put a program running for over 24 hours, but epiktimer told me only about less than 2000 seconds passed, when I click the finish button. Thanks. Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Optimal number of threads for SMP
Hi All, If my application needs SPEED, i.e. take full advantage of CPU capabilities, and the application has no I/O operation at all (neither disk nor network), it seems no need to create threads more than the number of CPU cores (hyper-threads)? Am I right? Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] detect CPU cores
Hi All, Is there a platform independent (specifically Windows and Linux) way to detect cores and hyper-threads of the CPU? I am writing a calculation intensive app and would like to fully utilize SMP capability of the CPU. Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] detect CPU cores
I found this code on the net: http://code.google.com/p/fpos/source/browse/kernel/cpuid.pas?r=c387b381d7a05f9328693cdcf59b0b4f633294e4 It's part of the FreePascal Operationg System project. I suppose it is compatible with FreePascal of course. But while compiled, I got lots of errors, such as: cpuid.pas(28,3) Error: Unrecognized opcode pushfd cpuid.pas(29,10) Error: Unknown identifier EAX cpuid.pas(30,13) Error: Unknown identifier EDX Even I added {$mode objfpc}{$H+} does not help. I tried to compile this code on this platform: CPU: i3 M 390 OS: Ubuntu x64 FPC: 2.6.4 How to use assembly in fpc anyway? Thanks. 2014-09-12 22:28 GMT+08:00 Dmitry Boyarintsev skalogryz.li...@gmail.com: If you're talking bout x88_64, i386 platforms, you should be able to do it using CPUID instruction http://en.wikipedia.org/wiki/CPUID thanks, Dmitry On Fri, Sep 12, 2014 at 10:07 AM, Xiangrong Fang xrf...@gmail.com wrote: Hi All, Is there a platform independent (specifically Windows and Linux) way to detect cores and hyper-threads of the CPU? I am writing a calculation intensive app and would like to fully utilize SMP capability of the CPU. Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] detect CPU cores
2014-09-13 0:28 GMT+08:00 Dmitry Boyarintsev skalogryz.li...@gmail.com: You're compiling for x64, You need to replace eax and edx with rax and rdx, since e?x are available for i386 only. My situation is, I program and test on Ubuntu x64 on a i3-M390. Then compile it to Windows 32bit on a VirtualBox on this machine, then run it on a Windows 32bit running on a rather old pentium dual core (T-something, I don't know if it is 32bit or 64bit processor). regarding e?x vs. r?x, is it only related to the CPU, or also has something to do with the OS (32bit or 64bit)? How to do conditional compiling for assembly code? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] cthread and cmem
Hi All, which one should be the *first* unit to use? cthread or cmem? Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Handling virtual abstract method in case of generics
Hi all, I am having trouble with the following code: generic TVectorT = class type DataType = array of T; private //... protected //... public //... end; generic TSortableVectorT = class(specialize TVectorT) protected function OnSort(v1, v2: T): Integer; virtual; abstract; //... public procedure Sort(Reversed: Boolean = False; OldOrder: PIntegerDynArray = nil); //... end; TIntegerVector = class(specialize TSortableVectorInteger) protected function OnSort(v1, v2: Integer): Integer; override; end; The error I got is: Error: Forward declaration not solved TIntegerVector.TSortableVector$LongInt.OnSort(LongInt,LongInt):LongInt; The original code of vector is here: https://github.com/xrfang/fpcollection/blob/master/src/units/vector.pas I am having trouble with the original code while specializing TVector with a Record type that does not have comparison operators. So I decide to make OnSort() abstract, and add it whenever needed. I am running FPC 2.6.4 on Linux x64. Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Operator overloading and generic class
Hi All, While I try to compile this code: program demo; {$mode objfpc}{$H+} uses tree; type TIntTree = class(specialize TTreeInteger) end; TITTree = class(specialize TTreeTIntTree) end; operator (it1, it2: TIntTree): Boolean; begin Result := it1.Data it2.Data; end; var itt: TITTree; begin end. I got the following error: tree.pas(324,11) Error: Operator is not overloaded: TIntTree TIntTree The complete code for tree.pas is here: https://github.com/xrfang/fpcollection/blob/master/src/units/tree.pas Even I defined the needed operator like above, it still refuse to compile. How to solve this? Thanks in advance! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Operator overloading and generic class
Sorry, I asked similar question long time ago, I found it in my gmail. Please ignore this question. However, I hope FPC will add this feature in future release anyway. 2014-08-26 16:17 GMT+08:00 Xiangrong Fang xrf...@gmail.com: Hi All, While I try to compile this code: program demo; {$mode objfpc}{$H+} uses tree; type TIntTree = class(specialize TTreeInteger) end; TITTree = class(specialize TTreeTIntTree) end; operator (it1, it2: TIntTree): Boolean; begin Result := it1.Data it2.Data; end; var itt: TITTree; begin end. I got the following error: tree.pas(324,11) Error: Operator is not overloaded: TIntTree TIntTree The complete code for tree.pas is here: https://github.com/xrfang/fpcollection/blob/master/src/units/tree.pas Even I defined the needed operator like above, it still refuse to compile. How to solve this? Thanks in advance! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] warning about hiding method in ancestor class
Hello All, I have a unit here: https://github.com/xrfang/pastats/blob/master/src/units/datalist.pas which report this error: /home/xrfang/git/pastats/src/units/datalist.pas(61,17) Warning: An inherited method is hidden by constructor TDataFrame.Create; However, the following code, which also define a new constructor without using overload, does NOT have such warning. program Project1; {$mode objfpc}{$H+} type TBase = class public constructor Create(AName: string); end; TDerived = class(TBase) public constructor Create; end; constructor TDerived.Create; begin WriteLn('Creator of TDerived... anonymous'); end; constructor TBase.Create(AName: string); begin WriteLn('Creator of TBase: ', AName); end; var obj: TDerived; begin obj := TDerived.Create; end. If I use reintroduce, I can suppress this warning. But my question is, why is this warning NOT displayed in the above sample code? In general, shall I use reintroduce keyword? Is it related to generics? Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] why constructor of TObject is NOT virtual but destructor is?
Hi All, I would like to know the benefit of making constructor / destructor virtual. As described here: http://c2.com/cgi/wiki?VirtualConstructor The benefit of virtual constructor seems related to class reference. As far as I understand, it is related to how LCL works, like: CreateComponent(AComponent: TComponentClass); My questions are: 1) if the above understanding is correct AND COMPLETE, why the constructor of TObject is not virtual? What problem will appear IF we make it virtual? 2) What is the purpose of making destructor of TObject virtual? Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] override or virtual override
Hi All, Is the property of virtual inherited? i.e. if a method in parent class is virtual, same method in child class is also virtual, right? TBase = class public destructor Destroy; override; //-- is this enough destructor Destroy; virtual; override; //or this to ensure it is still virtual? end; Thanks, Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Double specialization of generic class
Hi Sven, I am using fpc 2.6.2. I am very sorry that I don't have time to compile and install 2.7.1 at this time. It's good to know that it works, at least in 2.7.1. I will report the problem again while I start using 2.7.1 or when it is released as 2.8 :-) For now, another suggestion regarding this error is the error message it gave out, which is not understandable (error -139), I only find out the cause of this by comparing my source code in git. I hope this is also improved in 2.7 or later. Thanks! Shannon 2014-04-15 13:34 GMT+08:00 Sven Barth pascaldra...@googlemail.com: On 15.04.2014 03:51, Xiangrong Fang wrote: Hi, I got strange ppcx64 error: -139, which I found is caused by this: type TNodeStack = specialize TVectorTNodeHash; where TNodeHash itself is a specialization: type PNode = ^TNode; //TNode is a plain record TNodeHash = specialize TTreapInteger, PNode; Is it true that specialization of a generic class using another specialized generic class is not allowed? No, that should work. Maybe some bug. Is there any error message? Could you present the full compiler output, please? You are using 2.7.1, right? Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Double specialization of generic class
2014-04-15 17:21 GMT+08:00 Sven Barth pascaldra...@googlemail.com: Am 15.04.2014 08:47 schrieb Xiangrong Fang xrf...@gmail.com: It's good to know that it works, at least in 2.7.1. I will report the problem again while I start using 2.7.1 or when it is released as 2.8 :-) That's the point: I don't know wether it compiles in 2.7.1 as I did not test it. If you could provide a minimal sample (which fails in 2.6.2) and report that as a bug I could ensure that 2.7.1 works correctly there. I cannot replicate the problem using a minimal program, because it gives out different error message. The following minimal program compiles OK: program vectr; type generic TGeneric1T = class end; generic TGeneric2T = class end; TSpec1 = specialize TGeneric1Integer; TSpec2 = specialize TGeneric2TSpec1; begin end. While the following program generate different error: program vectr; uses treap, vector; type TNodeHash = specialize TTreapInteger, string; TNodeVector = class(specialize TVectorTNodeHash) protected function OnSort(v1, v2: T): Integer; override; end; operator (nh1, nh2: TNodeHash): Boolean; begin Result := nh1.Count nh2.Count; end; operator (nh1, nh2: TNodeHash): Boolean; begin Result := nh1.Count nh2.Count; end; function TNodeVector.OnSort(v1, v2: T): Integer; begin Result := 0; end; begin end. gives error message: vector.pas(149,9) Error: Operator is not overloaded: TTreap$LongInt$AnsiString TTreap$LongInt$AnsiString vector.pas(151,14) Error: Operator is not overloaded: TTreap$LongInt$AnsiString TTreap$LongInt$AnsiString vectr.lpr(28) Fatal: There were 2 errors compiling module, stopping The two used units can be downloaded here: https://github.com/xrfang/fpcollection/ While in my real program, I have this: type TCmhWaves = specialize TVectorTCmhWave; The thing is, even if I do NOT use this definition at all, it still crashes the compiler. By crash I mean I get this from lazarus: Compiling wmodel.lError: /usr/bin/ppcx64 can't be executed, error message: Failed to execute /usr/bin/ppcx64, error code: -139 TCmhWave is a specialized subclass of My TTreap class (also on github), it does NOT overload the and operators either. So my question is: 1) why my simplified example still require overloaded operator, although I have already done so? 2) If this is the cause of error (TCmhWave does not have these operators defined), why the compiler returns error code: -139 instead of more detailed errors? BTW, on my first attempt to debug this problem in lazbuild (command line) I get some error related to VMA, but unfortunately I forgot what it is and cannot get it shown again. Is there any way to customize the lazbuild by some switches to let it output more messages? Thanks. xrfang@OP380:~/Sync/wmodel$ lazbuild wmodel.lpi primary config path: /home/xrfang/.lazarus TPkgManager.CheckCompileNeedDueToDependencies State file of LCL 1.2.0.3 is newer than state file of Package: cairocanvas_pkg 0.0 TLazPackageGraph.CheckIfPackageNeedsCompilation normal output dir is not writable: /usr/share/lazarus/1.2.0/components/cairocanvas/lib/x86_64-linux/gtk2/ TLazPackageGraph.GetFallbackOutputDir cairocanvas_pkg: /home/xrfang/.lazarus/lib/cairocanvas_pkg/lib/x86_64-linux/gtk2 TParsedCompilerOptions.SetOutputDirectoryOverride New=/home/xrfang/.lazarus/lib/cairocanvas_pkg/lib/x86_64-linux/gtk2 TLazPackageGraph.CheckIfCurPkgOutDirNeedsCompile Compiler params changed for Printer4Lazarus 0.5 Old= -MObjFPC -Scgi -O1 -g -gl -vewnhi -Fi/usr/share/lazarus/1.2.0/components/printers/unix -Fi/usr/share/lazarus/1.2.0/components/printers/win32 -Fi/usr/share/lazarus/1.2.0/components/printers/carbon -Fi/usr/share/lazarus/1.2.0/components/printers/qt -Fu/usr/share/lazarus/1.2.0/components/printers/unix -Fu/usr/share/lazarus/1.2.0/components/printers/win32 -Fu/usr/share/lazarus/1.2.0/components/printers/carbon -Fu/usr/share/lazarus/1.2.0/components/printers/qt -Fu/usr/share/lazarus/1.2.0/packager/units/x86_64-linux -Fu/usr/share/lazarus/1.2.0/components/lazutils/lib/x86_64-linux -Fu/usr/share/lazarus/1.2.0/lcl/units/x86_64-linux -Fu/usr/share/lazarus/1.2.0/lcl/units/x86_64-linux/gtk2 -Fu/usr/share/lazarus/1.2.0/components/cairocanvas/lib/x86_64-linux/gtk2 -Fu/usr/share/lazarus/1.2.0/components/printers/ -FU/usr/share/lazarus/1.2.0/components/printers/lib/x86_64-linux/gtk2/ -l -dLCL -dLCLgtk2 -dUseCache -dNativePrint -dUSEUNICODE printer4lazarus.pas Now= -MObjFPC -Scgi -O1 -g -gl -vewnhi -Fi/usr/share/lazarus/1.2.0/components/printers/unix -Fi/usr/share/lazarus/1.2.0/components/printers/win32 -Fi/usr/share/lazarus/1.2.0/components/printers/carbon -Fi/usr/share/lazarus/1.2.0/components/printers/qt -Fu/usr/share/lazarus/1.2.0/components/printers/unix -Fu/usr/share/lazarus/1.2.0/components/printers/win32 -Fu/usr/share/lazarus/1.2.0/components/printers/carbon -Fu/usr/share/lazarus/1.2.0/components/printers/qt -Fu/usr/share/lazarus/1.2.0/packager/units
Re: [fpc-pascal] Double specialization of generic class
2014-04-15 20:26 GMT+08:00 Sven Barth pascaldra...@googlemail.com: Compiling wmodel.lError: /usr/bin/ppcx64 can't be executed, error message: Failed to execute /usr/bin/ppcx64, error code: -139 Is there really a ppcx64 in /usr/bin? And is it really executable? (try /usr/bin/ppcx64 -i in a shell) Also check you Lazarus settings that you've setup the correct fpc binary and that you project's target settings are set to the correct platform (maybe you are trying to compile for x86_64 without having a x84_64 compiler installed). No problem with the executable. I run it from command line, which is ok. i.e. ppcx64 is not corrupted, nor there is any authorization problem. Also, if I remove the unused declaration, the error is gone. Doesn't -139 have any meaning to you? Regards, Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Double specialization of generic class
Hi, I got strange ppcx64 error: -139, which I found is caused by this: type TNodeStack = specialize TVectorTNodeHash; where TNodeHash itself is a specialization: type PNode = ^TNode; //TNode is a plain record TNodeHash = specialize TTreapInteger, PNode; Is it true that specialization of a generic class using another specialized generic class is not allowed? Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] function mapping to array?
Hi All, Is the following possible: type TFunc=function(x: Double): Double; procedure apply(f: TFunc; var x: array of Double); var i: Integer; begin for i := 0 to Length(x) - 1 do x[i] := f(x[i]); end; apply(@sqrt, x); -- how can I apply() to built-in functions? Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] reference counting of multi-dimensional array
If I have this: var a2: array of array of Integer; i, j: Integer; begin SetLength(a2, 3); for i := 0 to 2 do begin SetLength(a[i], 3); for j := 0 to 2 do a[i][j] := 1; end; a2 := nil; -- will this free all memory of a[0]...a[2]? end; Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Two double related question
Hi All, I am trying to convert an R program to pascal. Having 2 problems: 1. In R, ln(0) is -Inf (negative infinity) and ln(-1) is NaN, while in FPC (2.6.2), ln(0) is NaN, and ln(-1) is -Inf, why? Mathematically, I think R's rationale is better because ln(x) approaches -Inf while X approaches 0. 2. How can I tell the compiler NOT to generate EDivideByZero or any similar stuff, but just return the IEEE Infinity NegInfinity or Nan accordingly? I know that they are defined in the math unit. Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] procedure modifiers
Hi All, I wonder where should I put procedure modifiers, in the interface section, or implementation section, or both? e.g. interface function test(data: Integer): Integer; inline; -- here? implementation function test(data: Integer): Integer; inline; -- here? begin //.. end; Thanks, Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] nested inline
Hi All, Is nested inline allowed? i.e. will the compiler generate inlined code for the following source: procedure a; inline; begin end; procedure b; inline; begin a; end; if I call b() in the main program, will the compile copy code for both a and b to avoid function calls? Thanks, Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] dynamic array reference count
Hi there, I just want to confirm one thing: var a, b: array of Integer; begin SetLength(a, 100); SetLength(b, 100); a := b; end. Now a will point to the same memory block as b. Since dynamic arrays are ref counted, I don't need to worry about the memory originally allocated for a, right? Thanks, Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] dynamic array reference count
Thanks, this is important to know! ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] weird compiler(?) problem
2014-02-14 14:45 GMT+08:00 Sven Barth pascaldra...@googlemail.com: @Xiangrong Fang: do you use 2.6.2 or 2.7.1? I use 2.6.2 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] weird compiler(?) problem
Hi All, I encountered a very strange problem. The code looks like this: //In Unit1.pas: //sel is an object of TIntVector and //TIntVector = specialize TVectorInteger *sel.Sort([soEliminateNA, soReversed]); * //In vector.pas: procedure TVector.Sort(Options: SortOptions); var i, gap, order, first, last, pos: Integer; Temp: T; begin *if FCount 2 then** Exit; -- problem here* if soReversed in Options then order := 1 else order := -1; ... ... My purpose is to skip sorting if the vector's element count is less than 2. Now the problem is that this statement does not have any effect (see attached screenshot). The debugger refuse to stop on the breakpoint, but goes directly to the line below it! What's more strange is that if I change the line to break after “then”, i.e.: begin *if FCount 2 then* *Exit;* if soReversed in Options then order := 1 else order := -1; ... ... Now it worked! I also wrote a simple test program, but can NOT reproduce this bug there. My TVector source code is here: https://github.com/xrfang/fpcollection/blob/master/src/units/vector.pas Any help is greatly appreciated. Sincerely, Xiangrong attachment: screen.png___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] weird compiler(?) problem
Hi Sven, I don't know how to find that, could you please explain? Attached dbg.tar.bz2 is the demo program and assembly code generated by the compile. Where is the point of specialization in that file? My working program is quite complex, I copied part of the code related to this problem in snippet.pas Thank you! Xiangrong 2014-02-13 23:53 GMT+08:00 Sven Barth pascaldra...@googlemail.com: Am 13.02.2014 16:42, schrieb Xiangrong Fang: Hi All, I encountered a very strange problem. The code looks like this: //In Unit1.pas: //sel is an object of TIntVector and //TIntVector = specialize TVectorInteger *sel.Sort([soEliminateNA, soReversed]); * //In vector.pas: procedure TVector.Sort(Options: SortOptions); var i, gap, order, first, last, pos: Integer; Temp: T; begin *if FCount 2 then**Exit; -- problem here* if soReversed in Options then order := 1 else order := -1; ... ... My purpose is to skip sorting if the vector's element count is less than 2. Now the problem is that this statement does not have any effect (see attached screenshot). The debugger refuse to stop on the breakpoint, but goes directly to the line below it! What's more strange is that if I change the line to break after “then”, i.e.: begin *if FCount 2 then*** *Exit;* if soReversed in Options then order := 1 else order := -1; ... ... Now it worked! I also wrote a simple test program, but can NOT reproduce this bug there. My TVector source code is here: https://github.com/xrfang/ fpcollection/blob/master/src/units/vector.pas Any help is greatly appreciated. Could you please check/compare the generated assembler code? Use -al to have the compiler generate it and you'll need to look at the file where you specialized the TVector. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal dbg.tar.bz2 Description: BZip2 compressed data type TWaveStack = specialize TVectorPointer; TIntVector = specialize TVectorInteger; ... ... var i: Integer; cw: TCmhWave; n: TTreeNode; ws: TWaveStack; sel: TIntVector; had_first: Boolean; procedure RecNodeIndex(node: TTreeNode); begin if (node.Level = 0) and (node.Text '') then sel.Push(node.Index); end; begin ws := TWaveStack.Create(nil); with tvb, tvb.Items do try if SelectionCount = 1 then begin n := Selected; if n nil then begin while n.Parent nil do n := n.Parent; tbCfm.Enabled := TCmhWave(n.Data).Mode = 0; end; for i := 0 to TopLvlCount - 1 do begin if TopLvlItems[i].Text = '' then Continue; ws.Push(TopLvlItems[i].Data); end; end else begin had_first := False; sel := TIntVector.Create(-1); try for i := 0 to SelectionCount - 1 do begin n := GetSelections(i); if n.Index = Selected.Index then had_first := True; RecNodeIndex(n); end; if (not had_first) then RecNodeIndex(Selected); sel.Sort([soEliminateNA, soReversed]); while sel.Count 0 do ws.Push(TopLvlItems[sel.Pop].Data); finally sel.Free; end; end; ... ... ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] weird compiler(?) problem
2014-02-14 0:16 GMT+08:00 Martin Frb laza...@mfriebe.de: Is it just the debugger does not stop? But the statement is executed (stopping in the next line never happens with FCount = 2)? Check your setup http://wiki.lazarus.freepascal.org/Debugger_Setup - NO smartlinking - NO optimization -O1 is often, but not always ok, so if there is an issue, then use -O- Your image does not show the blue dots in the gutter (where the breakpoint ,and green arrow are). That indicates there is something wrong with the debug info. Or maybe you have 2 units of the same name ,and use relative path ( ../ )? This can cause problems in some cases. Because gdb does not always deal with the .. , and then the IDE must specify the unit by name only, which is ambiguous. Debugger problem is minor. I know I am missing the blue dots here. But the MAJOR problem is that in the attached screenshot, FCount is 0, which is of course smaller than 2, but it does NOT Exit! This caused a SIGSEGV because in the code below I do this: last := FCount - 1; FItems[last] ... //-- which results in FItems[-1]; And smartlinking never turned on, switching off optimization in lazarus does not help either. Regards, Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] weird compiler(?) problem
Hi Sven, Sorry that I overlooked the problem. It is indeed a debugger problem. It just stopped on the next line, but if I continue it just quit the function nicely. So, now the minor problem is, I don't have the blue dots :) Sincerely, Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] weird compiler(?) problem
blue dots comes back after I switch back to O1... Sorry for the false alarm... but this seems a debugger problem in lazarus anyway... 2014-02-14 0:34 GMT+08:00 Xiangrong Fang xrf...@gmail.com: Hi Sven, Sorry that I overlooked the problem. It is indeed a debugger problem. It just stopped on the next line, but if I continue it just quit the function nicely. So, now the minor problem is, I don't have the blue dots :) Sincerely, Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] weird compiler(?) problem
Hi Martin, 2014-02-14 1:14 GMT+08:00 Martin Frb laza...@mfriebe.de: With -O2 and above the debugger does not always work. In case of such optimization the debug info compiled into the exe by fpc is not always accurate. It is not just blue dots, inspecting variables may show random data, Debugging with O2 and up, if you must, requires to only look at the disassembler and register window. registers can only be trusted in the ttop stackframe. selecting any other may not show correct info. I never use optimization option other than O1, I think O1 is the default. As Sven suggested, I tried turning off optimization, and back on, still at O1 level. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Memory leak in GetEnumerator
Hi All, I used HeapTrc on my TTreap class: https://github.com/xrfang/fpcollection/blob/master/src/units/treap.pas It reported memory leak in the following procedure: function TTreap.GetEnumerator: TTreap; begin Result := TTreap.Create; //-- memory leak here Result.ProxyFor := Self; ... ... end; Typical usage of the TTreap enumerator is: for n in aTreap do begin //do something with n end; My question is: will the for-loop automatically free the enumerator after usage? How to fix leaks in my ttreap class? Thanks a lot! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Memory leak in GetEnumerator
You are right, the bug is fixed, and another bug in the GetEnumerator are also found and fixed. This is my first time using heaptrc. Thanks a lot. 2013/12/27 Jeppe Græsdal Johansen je...@j-software.dk Den 27-12-2013 10:16, Xiangrong Fang skrev: Hi All, I used HeapTrc on my TTreap class: https://github.com/xrfang/fpcollection/blob/master/src/units/treap.pas It reported memory leak in the following procedure: function TTreap.GetEnumerator: TTreap; begin Result := TTreap.Create; //-- memory leak here Result.ProxyFor := Self; ... ... end; Typical usage of the TTreap enumerator is: for n in aTreap do begin //do something with n end; My question is: will the for-loop automatically free the enumerator after usage? How to fix leaks in my ttreap class? Thanks a lot! Xiangrong Your constructor allocates a new NullNode, which gets overwritten in GetEnumerator, and hence the enumerator NullNode is never freed. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Is this behavior related to calling convention?
I have this function: function Compare(v1, v2: Integer): Integer; And called like this: Result := Compare(stack.Pop, stack.Pop); The behavior is that the second Pop is evaluated first, thus reversed the meaning of the function. Is it true that all parameter evaluation goes from right to left? Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] virtual method and generics
Hi, In my TTree class: https://github.com/xrfang/fpcollection/blob/master/src/units/tree.pas I have the following method: function TTree.Load(s: TStream): Integer; var lv, c: QWord; node: TTree; buf: Pointer; begin Clear; if not ReadNodeData(s, lv, buf, c) then Exit(0); DoRestore(buf); OnRestore;//-- CALL#1 FreeMem(buf, c); Result := 1; node := Self; while ReadNodeData(s, lv, buf, c) do begin while (node nil) and (lv node.Level) do node := node.Parent; if (lv = node.Level) and (node Self) then node := TTree.Create(Data, node.Parent) else node := TTree.Create(Data, node); node.DoRestore(buf); node.OnRestore; //-- CALL#2 FreeMem(buf, c); Inc(Result); end; end; Now I have a problem. CALL#1 is virtual as expected (sub-class's OnRestore is called), but CALL#2 is not virtual, it just call the (empty) OnRestore method defined in TTree. How to solve this problem? Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Re: virtual method and generics
2013/11/19 Xiangrong Fang xrf...@gmail.com Now I have a problem. CALL#1 is virtual as expected (sub-class's OnRestore is called), but CALL#2 is not virtual, it just call the (empty) OnRestore method defined in TTree. How to solve this problem? BTW, this also does NOT solve the problem: TSelfType(node).OnRestore; ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] optionally uses a unit
2013/11/18 Mark Morgan Lloyd markmll.fpc-pas...@telemetry.co.uk There are definitely hazards, but I think that an exists() predicate of some form would definitely be useful. For example, inside an {$ifdef persist} it would give the developers the ability to have a tailored error message advising the maintainer that if persists.pas didn't exist he should also get such-and-such a project from local svn, and set up appropriate symlinks. The major issue would be directories and search paths. That's also what I want to achieve. My original purpose is to reduce dependencies by put non-critical functions into a separate aux unit while make the main unit still workable without the aux unit. As to the search path, I would suggest searching the current path (which *this* unit resides in), plus the path defined in project options. I also suggest to disable path component in this proposed directive, i.e.: {$ifexists some/relative/path/filename.pas} and {$ifexists /some/absolute/path/filename.pas} are BOTH NOT allowed, only {$ifexists filename.pas} is allowed. I don't know if this conforms to fpc traditions or not. As to the concern about existing ppu or .o file, I think it is not a problem, because you just follow the normal rule to compare file datetime of the .o and .pas file. I don't like to rely on make files as fpc has its own building system. Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] optionally uses a unit
Hi All, Is it possible to optionally use a unit? e.g. unit myunit; uses {$ifexists persist.pas}persist,{$endif} Classes; type TMyClass = class public {$ifexists persist.pas} procedure SaveToStream(s: TStream); {$endif} end; Thanks, Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] use of inherited keyword
Hi, Is it OK to use inherited in any instance method? i.e. It is OK to do this: procedure TChildClass.DoIt;//override begin inherited DoIt; end; But is it ok to do this: procedure TChildClass.SomethinElse;//NOT DoIt begin inherited DoIt; //... ... end; I tried, it seems ok, but I am not sure, because I had a strange access violation in my code which I cannot reproduce in simplified version of the code, so I suspect this might be an invalid use and correct by coincidence? Thanks! Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] The overload keyword
Hi All, According to http://www.freepascal.org/docs-html/ref/refsu72.html, the overload keyword is mostly optional and for delphi compatiblity only. But on Oct. 27, Sven replied my question about hide a public constructor in base class: I don't understand why this does not work: f := TFileStream.Create; I know that TFileStream's Create require a file name parameter, but as TFileStream is inherited from TObject, which has a Create without parameter. This is why I feel that it is possible to HIDE a public constructor from ancestor. No, I don't think so. If you want users to use the original constructor as well you'd need to declare yours as overload. If it would be possible to call TFileStream.Create without parameters then the instance would be in an inconsistent state, so only calling the constructor with arguments should be possible (which is the case for TFileStream. So this is definitely by design. Now my question is: in this case overload keyword DO make a difference? Then, how to overload? e.g.: In base class: constructor Create; In child class: constructor Create(param1:...; param2: ...): overload; i.e. overload does NOT require functions to have same parameter list or return type? Also, it does not require the overload keyword in base class? Otherwise programmers need to modify the base class, which is not good. Thanks, Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] private type and type compatibility
Hi All, I have the following class: type generic TVectorT = class private type TDataType = array of T; private FData: TDataType; ... ... public ... ... function Slice(APos: Integer = -1; ACount: Integer = -1): TDataType; end; The Slice() method return a portion of the data as a dynamic array. My question is, as I define TDataType as PRIVATE type, why it is still usable outside of the class? In the main program I did: type TIntVector = specialize TVectorInteger; var iv: TIntVector; ia: array of Integer; begin iv := TIntVector.Create; ... ... ia := iv.Slice; end. This will assign a TDataType (is it TVector$TDataType or TIntVector$TDataType? I don't know) to an array of Integer. Why this assignment works? i.e. how does the type system work?! Best Regards, Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] private type and type compatibility
2013/10/30 Sven Barth pascaldra...@googlemail.com I think it is an error. You declare something as private, and then you use it in a public function ? If that is not a visibility clash, I don't know what is :) I agree, but the question is should we declare this as a bug in the language and thus fix it which might lead to adjustments of legacy (2.6.x) code or use a warning. I personally would do the former (and better sooner than later). We need to keep the current behavior in mode Delphi however... (Note: Delphi additionally allows to access protected types from external units; could be related to the point that helper types allow access to protected types and fields as well...) I also agree that it is a bug. That's why I am confused. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] private type and type compatibility
2013/10/30 Jonas Maebe jonas.ma...@elis.ugent.be The tdynarray type is not visible in the program because u1 is not in its uses clause (it's not in scope whatsoever), and nevertheless there is no problem to use it. It's of course not exactly the same (tdynarray isn't declared as private to u1), but at the scope visibility level it is the same situation as far as I am concerned. I don't think they are the same. tdynarray is not usable in main program because you did not uses u1, NOT because the type is defined as PRIVATE! As a matter of fact, if you define tdynarray as private (not in interface section), there is no way you can use it as a return type of an exported (public) function. This is a very consistent scoping rule! In my example, if the code is like this: generic TVectorT = class private type TDataType = array of T; private function proc: TDataType; end; Then I think it is ok, because this PRIVATE type is used by PRIVATE function. What do you think? Sincerely, Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] private type and type compatibility
2013/10/30 Sven Barth pascaldra...@googlemail.com It's a bit annoying that the usage private/protected types in public/published functions is allowed... (this is however Delphi compatible) Maybe this should be adjusted for non-Delphi modes for language consistency... (maybe at least as a warning which could be elevated to an error if someone wants) Alternatively, consider do NOT allow access modifiers for NESTED types, instead, the visibility of nested types follow the class they are embeded in. Anyway, what is the purpose of HIDE a nested type? Regards, Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] private type and type compatibility
2013/10/30 Martin laza...@mfriebe.de I think there is no problem with: var a: array of Integer begin A:= obj.proc; You are NOT using the type. You are using the value. pascal is strong-typed. You are actually using type along with its value. e.g. var a: array of Double; begin a := obj.proc; This will emit a COMPILE time error because compiler know these 2 types are not compatible. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] private type and type compatibility
2013/10/30 Jonas Maebe jonas.ma...@elis.ugent.be This is not equivalent. A private type declaration in a class adds a new identifier that is visible inside that class. You then use it, still in that class, to declare the return type of a function. Next, in a scope where that type identifier is no longer visible, you call the function. My example is a complete match to that scenario as far as identifier visibility is concerned (you use a type in a scope where it is visible to declare a function return type, and then call the function in a scope where it is not visible). In your example, the type is not visible in the place where the function is declared but only where it is defined . This is logically WRONG. Because to the machine, any function return value can be seen as an array of bytes, for example, a pointer is array[0..3] of Byte on a 32-bit machine. The purpose of type system is to explain what these bytes stands for. So, if a type is out-of-scope, how do you interpret the data? The current delphi compatible implementation IS using the type information to compile the program, i.e. although it is not visible, it is indeed used by the compile, which, in my opinion, violates visibility rules. Standing on your view point, if a type is no longer visible, but a variable (function return value) of that type is in current scope, and understood by the program, this means, this value itself carries type information! Is is kind of meta data available in Pascal? If so, I think RTTI should work for ANY kind of primitive data types. Regards, Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] private type and type compatibility
2013/10/30 Martin laza...@mfriebe.de Since the type is part of value, and the value is public, all of the type that is accessed through the value is available. Same as you can access a private field through a public property. Access a private variable via public property is analogous to function calls, isn't it? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] WHY compiler should be public?
2013/10/27 Michael Van Canneyt mich...@freepascal.org Ah. The 'private' constructor is called FROM ANOTHER INSTANCE. You didn't say that. That currently can't be done. Michael. So, in this case, can/should I make my constructor private, ignoring the warning, or just make it public to play it safe? Regards, Xiangrong ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal