[fpc-pascal] JSON stream load/save recursive structure

2017-01-09 Thread Xiangrong Fang
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

[fpc-pascal] libevent for socket

2016-01-05 Thread Xiangrong Fang
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

Re: [fpc-pascal] FPC 3 inclusion for debian/ubuntu?

2015-12-14 Thread Xiangrong Fang
> > > ​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

Re: [fpc-pascal] FPC 3 inclusion for debian/ubuntu?

2015-12-14 Thread Xiangrong Fang
On Mon, Dec 14, 2015 at 5:27 PM, Jonas Maebe wrote: > 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

[fpc-pascal] FPC 3 inclusion for debian/ubuntu?

2015-12-14 Thread Xiangrong Fang
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

[fpc-pascal] status of fpc-mips

2015-11-25 Thread Xiangrong Fang
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

Re: [fpc-pascal] Linking failed on RaspberryPi

2015-09-15 Thread Xiangrong Fang
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 b

Re: [fpc-pascal] Linking failed on RaspberryPi

2015-09-15 Thread Xiangrong Fang
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

Re: [fpc-pascal] Linking failed on RaspberryPi

2015-09-15 Thread Xiangrong Fang
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 do

Re: [fpc-pascal] Linking failed on RaspberryPi

2015-09-15 Thread Xiangrong Fang
: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 o

[fpc-pascal] Linking failed on RaspberryPi

2015-09-03 Thread Xiangrong Fang
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

[fpc-pascal] Fatal: Internal error 200305103

2015-08-22 Thread Xiangrong Fang
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,

[fpc-pascal] shift right operation with variables

2015-08-16 Thread Xiangrong Fang
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;

[fpc-pascal] quality of FPC random

2015-08-14 Thread Xiangrong Fang
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

Re: [fpc-pascal] quality of FPC random

2015-08-14 Thread Xiangrong Fang
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

Re: [fpc-pascal] alignment of records

2015-08-07 Thread Xiangrong Fang
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.

[fpc-pascal] alignment of records

2015-08-06 Thread Xiangrong Fang
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

Re: [fpc-pascal] alignment of records

2015-08-06 Thread Xiangrong Fang
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

[fpc-pascal] manipulate tun/tap in free pascal

2015-08-04 Thread Xiangrong Fang
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

2015-05-18 Thread Xiangrong Fang
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

[fpc-pascal] SQLDB: how to use TSQLTransaction

2015-04-10 Thread Xiangrong Fang
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

[fpc-pascal] load a library twice

2015-04-02 Thread Xiangrong Fang
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

Re: [fpc-pascal] how to use signals in freepascal?

2015-03-17 Thread Xiangrong Fang
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 ?

Re: [fpc-pascal] how to use signals in freepascal?

2015-03-17 Thread Xiangrong Fang
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

Re: [fpc-pascal] how to use signals in freepascal?

2015-03-16 Thread Xiangrong Fang
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

[fpc-pascal] how to use signals in freepascal?

2015-03-16 Thread Xiangrong Fang
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

[fpc-pascal] how to use procedure of object in C

2015-03-09 Thread Xiangrong Fang
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

Re: [fpc-pascal] how to use procedure of object in C

2015-03-09 Thread Xiangrong Fang
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;

Re: [fpc-pascal] Use sleep in thread

2015-02-26 Thread Xiangrong Fang
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

Re: [fpc-pascal] Use sleep in thread

2015-02-26 Thread Xiangrong Fang
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 ri​ght. This is incorrect, since if you pause a thread with

[fpc-pascal] Use sleep in thread

2015-02-25 Thread Xiangrong Fang
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

Re: [fpc-pascal] Use sleep in thread

2015-02-25 Thread Xiangrong Fang
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

Re: [fpc-pascal] Use sleep in thread

2015-02-25 Thread Xiangrong Fang
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

Re: [fpc-pascal] compare currency and double

2014-12-08 Thread Xiangrong Fang
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

[fpc-pascal] compare currency and double

2014-12-07 Thread Xiangrong Fang
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

[fpc-pascal] Problem with heaptrc

2014-11-09 Thread Xiangrong Fang
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:

Re: [fpc-pascal] Problem with heaptrc

2014-11-09 Thread Xiangrong Fang
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

Re: [fpc-pascal] Problem with heaptrc

2014-11-09 Thread Xiangrong Fang
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

Re: [fpc-pascal] Problem with heaptrc

2014-11-09 Thread Xiangrong Fang
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);

Re: [fpc-pascal] Effective memory allocation

2014-11-03 Thread Xiangrong Fang
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

Re: [fpc-pascal] Effective memory allocation

2014-11-03 Thread Xiangrong Fang
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

[fpc-pascal] Effective memory allocation

2014-11-02 Thread Xiangrong Fang
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:

Re: [fpc-pascal] Effective memory allocation

2014-11-02 Thread Xiangrong Fang
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 ___

Re: [fpc-pascal] Effective memory allocation

2014-11-02 Thread Xiangrong Fang
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

Re: [fpc-pascal] Effective memory allocation

2014-11-02 Thread Xiangrong Fang
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

Re: [fpc-pascal] Is TFPList thread safe?

2014-10-02 Thread Xiangrong Fang
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

Re: [fpc-pascal] Is TFPList thread safe?

2014-10-02 Thread Xiangrong Fang
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

Re: [fpc-pascal] Is TFPList thread safe?

2014-10-02 Thread Xiangrong Fang
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

Re: [fpc-pascal] Is TFPList thread safe?

2014-10-02 Thread Xiangrong Fang
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

[fpc-pascal] Is TFPList thread safe?

2014-10-01 Thread Xiangrong Fang
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

[fpc-pascal] key-value engine for FPC

2014-09-21 Thread Xiangrong Fang
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

[fpc-pascal] PostMessage vs. QueueAsyncCall

2014-09-19 Thread Xiangrong Fang
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

Re: [fpc-pascal] Random thread lockup. QueueAsyncCall??

2014-09-18 Thread Xiangrong Fang
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

[fpc-pascal] EpikTimer: maximum elapsed seconds

2014-09-16 Thread Xiangrong Fang
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] Optimal number of threads for SMP

2014-09-15 Thread Xiangrong Fang
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] detect CPU cores

2014-09-12 Thread Xiangrong Fang
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 ___

Re: [fpc-pascal] detect CPU cores

2014-09-12 Thread Xiangrong Fang
, 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

Re: [fpc-pascal] detect CPU cores

2014-09-12 Thread Xiangrong Fang
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

[fpc-pascal] cthread and cmem

2014-09-11 Thread Xiangrong Fang
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

2014-09-05 Thread Xiangrong Fang
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;

[fpc-pascal] Operator overloading and generic class

2014-08-26 Thread Xiangrong Fang
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:

Re: [fpc-pascal] Operator overloading and generic class

2014-08-26 Thread Xiangrong Fang
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

[fpc-pascal] warning about hiding method in ancestor class

2014-05-04 Thread Xiangrong Fang
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

[fpc-pascal] why constructor of TObject is NOT virtual but destructor is?

2014-05-04 Thread Xiangrong Fang
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:

[fpc-pascal] override or virtual override

2014-05-04 Thread Xiangrong Fang
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?

Re: [fpc-pascal] Double specialization of generic class

2014-04-15 Thread Xiangrong Fang
: 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

Re: [fpc-pascal] Double specialization of generic class

2014-04-15 Thread Xiangrong Fang
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

Re: [fpc-pascal] Double specialization of generic class

2014-04-15 Thread Xiangrong Fang
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

[fpc-pascal] Double specialization of generic class

2014-04-14 Thread Xiangrong Fang
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

[fpc-pascal] function mapping to array?

2014-03-28 Thread Xiangrong Fang
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] reference counting of multi-dimensional array

2014-03-27 Thread Xiangrong Fang
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] Two double related question

2014-03-25 Thread Xiangrong Fang
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.

[fpc-pascal] procedure modifiers

2014-03-15 Thread Xiangrong Fang
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,

[fpc-pascal] nested inline

2014-03-15 Thread Xiangrong Fang
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,

[fpc-pascal] dynamic array reference count

2014-03-15 Thread Xiangrong Fang
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,

Re: [fpc-pascal] dynamic array reference count

2014-03-15 Thread Xiangrong Fang
​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 Thread Xiangrong Fang
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

2014-02-13 Thread 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,

Re: [fpc-pascal] weird compiler(?) problem

2014-02-13 Thread Xiangrong Fang
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

Re: [fpc-pascal] weird compiler(?) problem

2014-02-13 Thread Xiangrong Fang
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

Re: [fpc-pascal] weird compiler(?) problem

2014-02-13 Thread Xiangrong Fang
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 ___

Re: [fpc-pascal] weird compiler(?) problem

2014-02-13 Thread Xiangrong Fang
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

Re: [fpc-pascal] weird compiler(?) problem

2014-02-13 Thread Xiangrong Fang
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,

[fpc-pascal] Memory leak in GetEnumerator

2013-12-27 Thread Xiangrong Fang
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; ...

Re: [fpc-pascal] Memory leak in GetEnumerator

2013-12-27 Thread Xiangrong Fang
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

[fpc-pascal] Is this behavior related to calling convention?

2013-12-07 Thread Xiangrong Fang
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?

[fpc-pascal] virtual method and generics

2013-11-19 Thread Xiangrong Fang
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);

[fpc-pascal] Re: virtual method and generics

2013-11-19 Thread Xiangrong Fang
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

Re: [fpc-pascal] optionally uses a unit

2013-11-18 Thread Xiangrong Fang
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

[fpc-pascal] optionally uses a unit

2013-11-17 Thread Xiangrong Fang
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] use of inherited keyword

2013-11-12 Thread Xiangrong Fang
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

[fpc-pascal] The overload keyword

2013-11-12 Thread Xiangrong Fang
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 :=

[fpc-pascal] private type and type compatibility

2013-10-30 Thread Xiangrong Fang
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

Re: [fpc-pascal] private type and type compatibility

2013-10-30 Thread Xiangrong Fang
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

Re: [fpc-pascal] private type and type compatibility

2013-10-30 Thread Xiangrong Fang
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

Re: [fpc-pascal] private type and type compatibility

2013-10-30 Thread Xiangrong Fang
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

Re: [fpc-pascal] private type and type compatibility

2013-10-30 Thread Xiangrong Fang
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

Re: [fpc-pascal] private type and type compatibility

2013-10-30 Thread Xiangrong Fang
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

Re: [fpc-pascal] private type and type compatibility

2013-10-30 Thread Xiangrong Fang
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

Re: [fpc-pascal] WHY compiler should be public?

2013-10-27 Thread Xiangrong Fang
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

  1   2   3   >