Re: [fpc-pascal] A cross-architecture Integer type for 32-bit and 64-bit

2010-12-23 Thread Bihar Anwar
Thanks Felipe.



- Original Message 
From: Felipe Monteiro de Carvalho felipemonteiro.carva...@gmail.com
To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org
Sent: Thu, December 23, 2010 5:00:04 AM
Subject: Re: [fpc-pascal] A cross-architecture Integer type for 32-bit and 
64-bit

PtrUInt or something similar.

-- 
Felipe Monteiro de Carvalho
___
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] A cross-architecture Integer type for 32-bit and 64-bit

2010-12-22 Thread Bihar Anwar
Is there a data typein FPC which is compiled as Cardinal in 32-bit, but 
compiled 
as UInt64 in 64-bit?



  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] stdcall on win64?

2010-09-06 Thread Bihar Anwar
stdcall calling convention is for Win32, right? E.g.

function Test: HRESULT; {$IFDEF WIN32}stdcall;{$ENDIF}

By using $IFDEF like that, will the code also work in Win64?

Thanks in advance.



  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] stdcall on win64?

2010-09-06 Thread Bihar Anwar
Thanks Florian. :-)



- Original Message 
From: Florian Klämpfl flor...@freepascal.org
To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org
Sent: Tue, September 7, 2010 2:01:31 AM
Subject: Re: [fpc-pascal] stdcall on win64?

Am 06.09.2010 18:27, schrieb Bihar Anwar:
 stdcall calling convention is for Win32, right? E.g.
 
 function Test: HRESULT; {$IFDEF WIN32}stdcall;{$ENDIF}
 
 By using $IFDEF like that, will the code also work in Win64?

Win64 ignores all calling conventions and uses only the calling
conventions from the abi defined by MS for Win64.
___
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] Recursion optimization by compiler

2010-09-03 Thread Bihar Anwar
After my previous post, TreeView and Nonrecursion, I'd tried to ask the same 
topics in stackoverflow.com 
(http://stackoverflow.com/questions/3630047/treeview-control-and-nonrecursion) 
and I got something new.

It is possible to recurse without using up the stack space.  Optimizing  
compilers are able to accomplish certain types of recursion into  efficient 
non-recursive loops, but the code has to be written into a tail recursion form.

Is there such a recursion optimization in FPC? If it is not enabled by default, 
how to enable it?


  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Recursion optimization by compiler

2010-09-03 Thread Bihar Anwar
September 3, 2010 7:17:57 PM, José Mejuto wrote:


 That kind of optimization to me only seems interesting in
 two possible situations, when calling functions is high
 costly or when there is a very limited stack amount (really,
 really small). From my point of view if you need more that
 1MB of stack size I'm quite sure that you are doing
 something wrong, because around 65000 recursion levels
 looks not very good.

 The recursion optimization is being done using regular RAM
 as a stack.

Thanks Jose, I agree with you. Since in my case I need less than 1MB of stack 
size, so there is no reason to use nonrecursive/iterative approach. 
Furthermore, 
recursion is more readable.

Thanks Jose for the code snippets. You introduce TStack that I'm not aware of. 

First, just curious, have somebody here ever benchmark performance between 
native stack and regular RAM as a stack?

Second, does FPC understand tail recursion?




___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Recursion optimization by compiler

2010-09-03 Thread Bihar Anwar
O Marco, I love you :-)



- Original Message 
From: Marco van de Voort mar...@stack.nl
To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org
Sent: Fri, September 3, 2010 11:02:52 PM
Subject: Re: [fpc-pascal] Recursion optimization by compiler


 Second, does FPC understand tail recursion?

Depends on version, do 

fpc -i |grep -i tailrec

to find out more.
___
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


Re: [fpc-pascal] TreeView and Nonrecursion

2010-09-02 Thread Bihar Anwar
On September 2, 2010 5:14:50 PM, Juha Manninen wrote:



 If your input data contains a string which always
 identifies the parent node then you can map the 
 string - parent node and find it later for adding
 a child node.

 Pseudo code again:
 ...
 ...
 If you don't have such ID then you must use recursion.

Thanks José and Juha, now I see the light. :-)


On September 2, 2010 8:11:53 PM, Flávio Etrusco wrote:

 When reading from registry and populating a treeview, a
 recursive function is the least of your worries regarding
 performance (or memory, if you're careful).

I'm a crash-phobia :-). Stack sizes are different among the OS platforms. A 
superdeep recursion will trigger a stack overflow exception.




___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] TreeView and Nonrecursion

2010-09-01 Thread Bihar Anwar
A Newbie question :-) Is it possible to fill TreeView (tree is naturally 
recursive) with a nonrecursive/iterative thinking paradigm? Are there some good 
examples regarding this matter in the Internet?

I post this question in FPC mailing list because my question actually about 
filling a tree in general.

Thanks in advance.



  

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TreeView and Nonrecursion

2010-09-01 Thread Bihar Anwar
On 2 September 2010 3:53:34 AM, Vannus wrote:


 i probably shouldn't open my mouth, as i don't quite understand the  
question... 

 however FRED from the game Freespace let you design missions  using a 
treeview.

Just to make my question clear, for example, I can fill a TreeView control with 
particular Registry keys by enumerating registry keys recursively and put them 
in the TreeView control; then for performance reason, I attempt to use a 
nonrecursive/iterative approach to enumerate registry keys, but how can I fill 
the TreeView since a tree is naturally recursive? Is recursion is the only 
way 
to achive it?



  ___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] [ANN] Beyond Compare 3.2 public beta is available

2010-06-29 Thread Bihar Anwar
Thanks Graeme, please keep inform us about anything special to FPC/Lazarus 
users. :-)



- Original Message 
From: Graeme Geldenhuys graemeg.li...@gmail.com
To: Other FPC related discussions. fpc-ot...@lists.freepascal.org; Lazarus 
mailing list laza...@lists.lazarus.freepascal.org; FPC-Pascal users 
discussions fpc-pascal@lists.freepascal.org
Sent: Tue, June 29, 2010 2:42:46 PM
Subject: [fpc-pascal] [ANN] Beyond Compare 3.2 public beta is available

Hi,

I just noticed that the Beyond Compare 3.2 public beta is available.
BC is probably the best file/folder comparison tool out there. The
v3.x version is available for Windows and Linux. It can compare data
files, Linux packages (.rpm, deb, tar.gz, tar.bz), images, source
code, binary .dfm files, version information inside .exe's etc.. This
tool is unbelievable and can even be used in scripts and do things
like sync folder, talk via SSH, SFTP. I've integrated BC with Midnight
Commander (linux console file manager) allowing me to easily select
files to compare via the F2 user menu. Nautilus (Gnome) and Window
Shell integration comes standard.


Public Beta
  http://www.scootersoftware.com/beta

Beyond Compare homepage:
  http://www.scootersoftware.com/


PS:
Best of all, it's written in Object Pascal! :-)  I'm not affiliated
with Scooter Software in any way, I just think Beyond Compare is an
extremely handy tool for any developer.


-- 
Regards,
  - Graeme -


___
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
___
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


Re: [fpc-pascal] Missing GetLastOSError() in DOS and MacOS

2010-06-10 Thread Bihar Anwar
On June 
10, 2010 1:00:27 PM, Tomas Hajny wrote:
... or whether it should return the last OS error for what OS function 
invoked recently (also directly without using RTL).


Yes, I think this one is agreed with other similar RTL functions.



  

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Negative RTL Error Codes in Some Platforms

2010-06-10 Thread Bihar Anwar
On June 
10, 2010 1:46:39 PM, Tomas Hajny wrote:

If I remember correctly, it's been done in order to differentiate standard
error 
codes (supposedly cross-platform and mostly inherited from TP/BP)
from all other error codes which may be 
triggered there and which are
completely platform specific. It's well possible that this convention has
never been documented and possibly not followed in implementations for
other platforms either. However, you shouldn't rely on the returned values
too much anyway. They 
depend not only on the underlying platform, but
possibly partly also 
on the specific implementation for the particular
platform - i.e. one RTL function originally based on a single OS API call
in the DOS 
(TP) times may require several subsequent OS API calls in an
implementation for another platform and you wouldn't really know which of
the calls returned the value and why unless you trace the implementation.

Thanks Tomas for your detail explanation. It's a logical reason.

However, you shouldn't rely on the returned values
too much anyway.

No, I just rely on such a returned values in a very few cases. For example, In 
Windows/OS2/DOS, when FindNext() encounters the end of a directory content, it 
returns ERROR_NO_MORE_FILES (18 or -18); whereas in UNIX, it returns -1 and 
errno is not set. Thus UNIX doesn;t consider it as an error, and this is more 
acceptable by me. So, my file searching function will return 0 in this 
situation. I'm certainly sure such a convention for the basic operations will 
never be changed in those OSes, so I attempt to handle this.

Thanks in advance. Cheers.



  

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Missing GetLastOSError() in DOS and MacOS

2010-06-10 Thread Bihar Anwar
June 
10, 2010 3:03:45 PM, Jonas Maebe wrote:

MacOS in the RTL stands for System 7.5 - Mac OS 9.2.x, i.e., the classic 
Mac OS which 
preceded Mac OS X. I don't think the sysutils unit was ever completely ported 
for that 
platform.


Thanks Jonas, your clarification strengthens my thought before. I saw other 
several defects in MacOS SysUtils, just mention the implementation of FindNext:

   Result:=DoFind (Rslt);  // whereas DoFind() is declared as a procedure

How can that be compiled?

I think, I will increase the requirement of my base units to at least the MacOS 
X.



  

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Negative RTL Error Codes in Some Platforms

2010-06-10 Thread Bihar Anwar
On June 10, 2010 6:12:42 PM, Tomas Hajny wrote:


OK, this is a slightly different story then. Win32 API function FindFirst
(and thus also the Delphi function FindFirst provided in SysUtils) returns
the search handle (positive value) in case of a success and -1 in case
of an error. The implementation for OS/2 and DOS passes the error
information directly (rather than relying on a subsequent call to
GetLastError, which is again a Win32 API call and not directly
transferable, or using GetLastOSError and relying on the fact that no
other OS API has been used by the RTL in the meantime), but it needs to
use a negative value in order to differentiate from possitive values
meaning success. The same logic is then in turn also used for FindNext
(although that one does never return search handles even on Windows).

Thanks Tomas, that explanation even makes me understand this FPC decision 
better.



  

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Negative RTL Error Codes in Some Platforms

2010-06-09 Thread Bihar Anwar
I look at the FPC RTL source codes and notice that in some OSes (e.g. OS/2, 
DOS) every RTL functions which call OS API functions will return the OS error 
code as a negative number. What is the reason behind this? I don't find such a 
convention in the official documentation of thouse OSes.



  

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Missing GetLastOSError() in DOS and MacOS

2010-06-09 Thread Bihar Anwar
I don't see SysUtils.GetLastOSError() in DOS. Looking at a glance, I think it 
will be a trivial effort by just returning Dos.DosError variable content.

Also, I notice that SysUtils.GetLastOSError() in MacOS is defined but it's 
implementation is empty. I've no knowledge on MacOS, so my question is... Is 
this by designed?



  

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] regex vs synregexpr unit

2010-06-07 Thread Bihar Anwar
OK guys, after contemplating all your suggestions, I decide to follow the 
SynEdit way, that is, synregexpr unit. I suppose this unit tends to get more 
maintenance in the future.

Concerning the C++ PCRE library, it is the most full-featured reg-expr 
implementation, but calling C++ functions from FPC code in a cross-platform way 
is complex enough and causes of possible crash will be hard to investigate.

Cheers.



  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] regex vs synregexpr unit

2010-06-06 Thread Bihar Anwar
Schindler Karl-Michael wrote on June 6, 2010 1:09:02 AM:
The pcre library (written in C) has a good reputation. You can get 
pascal headers from the Project JEDI Code Library (JCL).

Wow, that seems a more promising approach in the current time, I'll look on it. 
Thanks so much.

BTW, which approach should be used to call C functions from FPC: call them 
through DLL, or compile the C source into an .o file then link it with FPC code?


  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What is the lowest MS-DOS version supported by FPC?

2010-05-17 Thread Bihar Anwar


Tomas Hajny on May 17, 2010 5:43:07 PM wrote:

However, I don't think that anyone tried it with anything older than
MS-DOS 5.0 recently.

So, the safe assumption is fpc-compiled programs should run smoothly in 
at least MS-DOS 5.0. Thanks for the info.

If you really need to use an even older version (why?)

No, I won't use such old MS-DOS version, but it always good to let users know 
the minimum requirements.

if you encounter difficulties with FPC compiled programs running
 under such an old version, let me know, I may try to have a
look at it (I'm not completely sure if I still have access to anything
older than MS-DOS 4.01though).

Actually, I've been creating cross-platform libraries for my future programs. 
For MS-DOS, I will test the libraries in MS-DOS 5.0 as you suggest, and I will 
report any anomaly I find here or through the bug tracker. Thanks Thomas for 
your valuable time.



  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] What is the lowest MS-DOS version supported by FPC?

2010-05-15 Thread Bihar Anwar
I've tried googling and searching FPC mailing list for information about this 
one, but I found nothing. 
I just found in  http://www.delorie.com/djgpp/v2faq/faq3_1.html  that DJGPP  
requires MS-DOS version 3.1 or later.

Would someone here tell me exactly about lowest MS-DOS version supported by FPC?



  

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What is the lowest MS-DOS version supported by FPC?

2010-05-15 Thread Bihar Anwar
Vinzent Höfler on May 16, 2010 3:48:25 AM wrote:


 I've tried googling and searching FPC mailing list for information about
 this one, but I found nothing. 
 I just found in  http://www.delorie.com/djgpp/v2faq/faq3_1.html  that
 DJGPP  requires MS-DOS version 3.1 or later.
 
 Would someone here tell me exactly about lowest MS-DOS version supported
 by FPC?

 3.1, I'm pretty sure. AFAIK it doesn't use any specific DOS 5.x+ calls except 
 perhaps for checking for existence of DOS 7.x (Win95) LFN functions. And DOS 
 4.x was close to non-existent anyway.

 Of course, it has probably never tried with such old versions.

Thank you very much Vinzent.



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Does FPC has consts of portable OS error codes?

2010-05-12 Thread Bihar Anwar
Jonas Maebe on May 12, 2010 2:32:18 PM

On 12 May 2010, at 05:53, Bihar Anwar wrote:

 As the title says. :-)

 No, it doesn't.

Any reason for that? or it is not implemented yet?



  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Does FPC has consts of portable OS error codes?

2010-05-12 Thread Bihar Anwar
leledumbo onMay 12, 2010 3:58:09 PM


 Any reason for that? or it is not implemented yet?

 For the first one, usually errors in FPCgenerate exception, you can handle 
 that instead.

Yes, as you said usually, it is not always. For example, FindFirst() and 
FindNext return OS dependent error code.

 For the second, acombination of GetLastOSError and SysErrorMessage provides 
 what's needed.

In my case, this is not something I want.

I want to handle trivial errors (e.g. ERROR_ACCESS_DENIED, ERROR_NOT_READY, 
etc.) differ from fatal errors.

Trivial errors will allow users to retry the failed operation.



  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Does FPC has consts of portable OS error codes?

2010-05-11 Thread Bihar Anwar
As the title says. :-)

I mean 



  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Does FPC has consts of portable OS error codes?

2010-05-11 Thread Bihar Anwar
I mean, for example, are there something like:

  - fpcError_ERROR_PATH_NOT_FOUND = ESysENOENT  in UNIX
fpcError_ERROR_PATH_NOT_FOUND = ERROR_PATH_NOT_FOUND  in Windows

  - fpcERROR_FILENAME_EXCED_RANGE = ESysENAMETOOLONG  in UNIX
fpcERROR_FILENAME_EXCED_RANGE = ERROR_FILENAME_EXCED_RANGE  in Windows

  - etc.



  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Does FPC has consts of portable OS error codes?

2010-05-11 Thread Bihar Anwar
Something like this one: 
https://libxpl.arsoft.homeip.net/browser/trunk/errormap/xplErrorMap.cpp?rev=70


  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Where is the best place to declare an array?

2010-05-06 Thread Bihar Anwar
If I remember this correctly, I've formerly ever read somewhere (in my Delphi 
days) that array should be declared globally (not inside a function or 
procedure) so that access to the array will be faster. Is this correct? If yes, 
does this also true in FPC?

Thanks in advance.



  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Where is the best place to declare an array?

2010-05-06 Thread Bihar Anwar
Thanks Jose, Werner, and Jonas for the fantastic discussion and explanation.



  

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] dynamic array contents and system.move

2010-05-05 Thread Bihar Anwar
From: Aleksa Todorovic on May 5, 2010 3:13:12 PM


As of copying/moving array elements, why don't you use
simple for loop 
for that?

Because of performance optimization. TStringlist.Delete() and 
TStringlist.InsertItem() itself uses Move() instead of such loop.



  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Is this a reference counting bug?

2010-05-02 Thread Bihar Anwar
Florian Klaempfl:


 FPC and Delphi handle code generation for ref. counted types slightly
 different, so there might be cases where the ref. counter differs. As
 long as 
there is no memory leak when the vars are properly used, we
 don't 
consider it as a bug.

I see, well, there should be explanation about this in FPC doc.



  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] dynamic array contents and system.move

2010-05-02 Thread Bihar Anwar
Jürgen Hestermann wrote:
 Although I would have expected that special procedures exist to insert
 and remove array elements so that there is no need to do such things
 manually ...

David Emerson wrote:
These must be written on a case-by-case basis, for each type of array element.
Perhaps I'll tackle this someday as my first contribution to the fpc codebase.

I'm glad to hear this and thanks for that. I suggest there are 
DeleteArrayItems() and ShiftUpArrayItems(). The ShiftUpArrayItems() will just 
shift up items without resizing the array.




___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Is this a reference counting bug?

2010-05-02 Thread Bihar Anwar
On May 2, 2010 4:24:37 PM, Jonas Maebe wrote:


 The reference counting logic is considered to be an opaque implementation 
 detail (whose implementation can change at any time). It is undocumented by 
 design.

In fact, it was already documented in detail in FPC Language Reference Guide: 
3.2.4 Ansistrings; 3.3.1 Arrays: Dynamic Array; 7.6 Reference counting.

Moreover, I've seen many Delphi code snippets out there (e.g. 
http://www.cs.wisc.edu/~rkennedy/array-delete) rely on reference counting 
behaviour.



  

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Is this a reference counting bug?

2010-05-02 Thread Bihar Anwar
From: Jonas Maebe, May 2, 2010 7:05:46 PM


And the last one explicitly states No assumptions should be made about the 
number of temporary variables or the time when they are finalized.

I see, thanks Jonas for noting that statements.

I know, we've had bug reports about that in the past. Such code is simply 
broken. See e.g. http://bugs.freepascal.org/view.php?id=15526 and 
http://bugs.freepascal.org/view.php?id=9472

Thanks also for the your emphatic statement, and the links, of course.



  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Is this a reference counting bug?

2010-05-01 Thread Bihar Anwar
I found that the last element of a dynamic array starts with reference count = 
2 in FPC, but in Delphi is 1. Is this an FPC bug, or FPC implements reference 
counting differ from Delphi?

type
  PAnsiRec = ^TAnsiRec;
  TAnsiRec = packed Record
Ref,
Len   : SizeInt;
First : Char;
  end;

const
  AnsiRecLen = SizeOf(TAnsiRec);
  FirstOff   = SizeOf(TAnsiRec) - SizeOf(Char);

procedure Test;
var
  a: array of ansistring;

begin
  SetLength(a, 5);
  a[0] := IntToStr(0);
  a[1] := IntToStr(1);
  a[2] := IntToStr(2);
  a[3] := IntToStr(3);
  a[4] := IntToStr(4);

  WriteLn('a[0] = ', PAnsiRec(Pointer(a[0]) - FirstOff)^.Ref);  // Ref Count = 1
  WriteLn('a[1] = ', PAnsiRec(Pointer(a[1]) - FirstOff)^.Ref);  // Ref Count = 1
  WriteLn('a[2] = ', PAnsiRec(Pointer(a[2]) - FirstOff)^.Ref);  // Ref Count = 1
  WriteLn('a[3] = ', PAnsiRec(Pointer(a[3]) - FirstOff)^.Ref);  // Ref Count = 1
  WriteLn('a[4] = ', PAnsiRec(Pointer(a[4]) - FirstOff)^.Ref);  // Ref Count = 
2, why???
end;

begin
  Test;
  ReadLn;
end.



  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Is there a StringRefCount() equivalence?

2010-04-30 Thread Bihar Anwar
Thanks Jonas for your advice.



- Original Message 
From: Jonas Maebe jonas.ma...@elis.ugent.be
To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org
Sent: Fri, April 30, 2010 2:37:23 PM
Subject: Re: [fpc-pascal] Is there a StringRefCount() equivalence?


On 30 Apr 2010, at 05:42, Bihar Anwar wrote:

 By the way, how do I call internal compiler functions directly (maybe using a 
 tricky way) such as  system.fpc_ansistr_incr_ref()  and  
 system.fpc_ansistr_decr_ref?
 I couldn't call those kind of functions from my program, I guest it is caused 
 by compilerproc  definition.

You must never call these, because their behaviour can be changed or they can 
be removed altogether at any time.


Jonas
___
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


Re: [fpc-pascal] Is there a StringRefCount() equivalence?

2010-04-30 Thread Bihar Anwar
Because there are few certain condition when we need to observe what happened 
to ansistring/unicodestring variable. In my case now, I need it to learn how 
reference counting works. For example, using Move() on ref-counted string type 
is considered danger unless we do it properly, and I need to verify that 
everythings is correct after such operation.

I need StringRefCount() equivalence only for convenience, instead of writing a 
special codes/function in my program to achieve this. Well, if Delphi care 
about this need, why FPC not? :-)



- Original Message 
From: dmitry boyarintsev skalogryz.li...@gmail.com
To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org
Sent: Fri, April 30, 2010 3:22:22 PM
Subject: Re: [fpc-pascal] Is there a StringRefCount() equivalence?
 
On Fri, Apr 30, 2010 at 7:42 AM, Bihar Anwar bihar_an...@rocketmail.com wrote:
 I hope FPC developers will include StringRefCount() to the RTL.

Why would you need that?

thanks,
Dmitry
___
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 there a StringRefCount() equivalence?

2010-04-29 Thread Bihar Anwar
Delphi has StringRefCount() function (I'm not aware since what version it was 
introduced). I just curious, is there a function equivalent to it in FPC? 
Currently, I just steal a portion of code from System unit:

type
  PAnsiRec = ^TAnsiRec;
  TAnsiRec = packed record
Ref,
Len   : SizeInt;
First : Char;
  end;

const
  FirstOff   = SizeOf(TAnsiRec) - 1;

var
  S: ansistring;
  RefCount: SizeInt;

RefCount := PAnsiRec(S - FirstOff)^.Ref



  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Is there a StringRefCount() equivalence?

2010-04-29 Thread Bihar Anwar
Thanks Anton for your suggestion, I will apply it. I hope FPC developers will 
include StringRefCount() to the RTL.

By the way, how do I call internal compiler functions directly (maybe using a 
tricky way) such as  system.fpc_ansistr_incr_ref()  and  
system.fpc_ansistr_decr_ref?
I couldn't call those kind of functions from my program, I guest it is caused 
by compilerproc  definition.



- Original Message 
From: Anton Tichawa anton.tich...@chello.at
To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org
Sent: Fri, April 30, 2010 12:44:08 AM
Subject: Re: [fpc-pascal] Is there a StringRefCount() equivalence?

On Thu, 2010-04-29 at 10:30 -0700, Bihar Anwar wrote:
 Delphi has StringRefCount() function (I'm not aware since what version it was 
 introduced). I just curious, is there a function equivalent to it in FPC? 
 Currently, I just steal a portion of code from System unit:
 
 type
   PAnsiRec = ^TAnsiRec;
   TAnsiRec = packed record
 Ref,
 Len   : SizeInt;
 First : Char;
   end;
 
 const
   FirstOff   = SizeOf(TAnsiRec) - 1;

shouldn't that read e.g.


 const
   FirstOff   = SizeOf(TAnsiRec) - SizeOf(Char);
 

SCNR

Anton


___
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


Re: [fpc-pascal] Question about Deleting elements in Dynamic Array

2010-04-28 Thread Bihar Anwar
Thank you very much Henry, David, and Vincent. I think, I must go back to the 
basic of reference counting. Special thanks to David for the detail explanation.



  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Question about Deleting elements in Dynamic Array

2010-04-27 Thread Bihar Anwar
Just say, I have a dynamic array with size=5, and I want to delete elements 
from the index 0 to 2. Is there a trick (the fastest way) to delete those 
elements (0 to 2) without moving activities?

I've tried to make the dynamic array just pointing to 3rd element and set a new 
length for it, but fpc generates an unhandled exception.

var
  a: array of string;

SetLength(a, 5);
a[0] := 'aa'; a[1] := 'bb'; a[2] := 'cc'; a[3] := 'dd'; a[4] := 'ee';

a := @sl[3];   // this is the trick, but it doesn't work.
SetLength(a, 2)


Thank's in advance.



  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Question about Deleting elements in Dynamic Array

2010-04-27 Thread Bihar Anwar
- Original Message 

From: Henry Vermaak henry.verm...@gmail.com
To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org
Sent: Tue, April 27, 2010 10:19:45 PM

I think the right way to do this is:
a := copy(a, 3, length(a) - 3);
Presumably copy optimizes this adequately.

Henry
___

Would Move() be faster, instead of Copy()?



  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Question about Deleting elements in Dynamic Array

2010-04-27 Thread Bihar Anwar
Ok, I'll try to observe the compiled code using debugger and benchmark it if 
needed. BTW, what do you mean by allocating memory directly? Is there another 
way to allocate memory for dynamic array besides using SetLength()?



- Original Message 
From: Henry Vermaak henry.verm...@gmail.com
To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org
Sent: Wed, April 28, 2010 4:12:26 AM
Subject: Re: [fpc-pascal] Question about Deleting elements in Dynamic Array

On 27 April 2010 18:34, Bihar Anwar bihar_an...@rocketmail.com wrote:

 Would Move() be faster, instead of Copy()?

I guess so, have you tried to benchmark?  If you really need speed,
why don't you allocate the memory directly?

Henry
___
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


Re: [fpc-pascal] Question about Deleting elements in Dynamic Array

2010-04-27 Thread Bihar Anwar
I've tried to use Move() instead of Copy(). Any objection with the following 
code?

var
  a: array of string;

SetLength(a, 5);
a[0] := 'aa'; a[1] := 'bb'; a[2] := 'cc'; a[3] := 'dd'; a[4] := 'ee';

System.Move(a[3], a[0], 2 * SizeOf(string) );// instead of  a := Copy(a, 3, 
2);
SetLength(a, 2);



- Original Message 
From: dmitry boyarintsev skalogryz.li...@gmail.com
To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org
Sent: Wed, April 28, 2010 10:31:09 AM
Subject: Re: [fpc-pascal] Question about Deleting elements in Dynamic Array

On Wed, Apr 28, 2010 at 7:24 AM, Bihar Anwar bihar_an...@rocketmail.com wrote:
 Ok, I'll try to observe the compiled code using debugger and benchmark it if 
 needed. BTW, what do you mean by allocating memory directly? Is there another 
 way to allocate memory for dynamic array besides using SetLength()?

Copy() (from the existing dynamic array).
___
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] FindFirst()

2010-04-22 Thread Bihar Anwar
In Windows XP and upper, traversing directories starting from root directory 
(e.g. D:\) using FindFirst() and FindNext() will fail (ERROR_ACCESS_DENIED) 
when iteration encounters System Volume Information directory. I solved this 
by ignoring this error code and keep looping. However, I don't know the 
equivalent error code in Linux, FreeBSD, MacOS, etc. since I guest this 
behaviour should be there also in those OSes. Is there a universal way to 
handle this?

Thanks in advance.



  

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Initializing a record-type variable to get rid of the false-positive compiler hint

2010-04-15 Thread Bihar Anwar
Thanks Bart, forget my silly comments before, you did it cleverly.



- Original Message 
From: Bart bartjun...@gmail.com
To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org
Sent: Thu, April 15, 2010 10:02:33 PM
Subject: Re: [fpc-pascal] Initializing a record-type variable to get rid of  
the false-positive compiler hint

 FillByte(oSearchOptions, SizeOf(oSearchOptions), 0);

oSearchOptions := []; //It's an empty set

Bart
___
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


Re: Re[2]: [fpc-pascal] Initializing a record-type variable to get rid of the false-positive compiler hint

2010-04-15 Thread Bihar Anwar
Thank you very much Jose, that's a detail explanation. Forget my wrong 
observation before.



- Original Message 
From: José Mejuto joshy...@gmail.com
To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org
Sent: Thu, April 15, 2010 10:11:03 PM
Subject: Re[2]: [fpc-pascal] Initializing a record-type variable to get rid of 
the false-positive compiler hint

Hello FPC-Pascal,

Thursday, April 15, 2010, 6:43:41 AM, you wrote:

BA Thanks for your reply José, but what is the philosophy behind
BA the solution? and What are the reasons for $PUSH and $POP? Also, I
BA tried to remove the $HINTS directive, and it worked fine without
BA it. Could you explain this?

Rec parameter is qualified as out so, the enter values is
non-important and the compiler will not generate the non initialized
hint.

The $PUSH pushes in fpc stack the current settings about hints,
warnings, alignement, etc, then I change the hints to off, because
FillByte could produce (not sure with formal parameter) the hint
message and then $POP restores previous settings about hints and other
directives.

-- 
Best regards,
José

___
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] Initializing a record-type variable to get rid of the false-positive compiler hint

2010-04-14 Thread Bihar Anwar
I still need compiler hint generated by FPC at compiling (I don't want to turn 
it off), but the hint sometime disturbs me because it's a false-postive 
detection.

Supposing I have a record-type variable, could someone here tell me how to 
initialize it properly so that FPC could notice the initialization, since the 
FillByte() and FillChar() way do not cause FPC aware of it?

This is part of my code:

var
  oSearchOptions: TSearchFileOptions;

FillByte(oSearchOptions, SizeOf(oSearchOptions), 0);


I got this compiler hint when compiling: 
 Variable oSearchOptions does not seem to be initialized.


Thanks for any comments.



  
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Initializing a record-type variable to get rid of the false-positive compiler hint

2010-04-14 Thread Bihar Anwar
Thanks for your reply José, but what is the philosophy behind the solution? and 
What are the reasons for $PUSH and $POP? Also, I tried to remove the $HINTS 
directive, and it worked fine without it. Could you explain this?




- Original Message 
From: José Mejuto joshy...@gmail.com
Subject: Re: [fpc-pascal] Initializing a record-type variable to get rid of the 
false-positive compiler hint

BA Supposing I have a record-type variable, could someone here
BA tell me how to initialize it properly so that FPC could notice the
BA initialization, since the FillByte() and FillChar() way do not
BA cause FPC aware of it?

I'm using:

procedure InitRecord(out Rec; const ASize: SizeUint);
begin
{$PUSH}
{$HINTS OFF}
  FillByte(Rec,ASize,0);
{$POP}
end;

Unfortunatly it can not be inlined :( due the formal parameter.

-- 
Best regards,
José

___
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


Re: [fpc-pascal] (no subject)

2010-04-12 Thread Bihar Anwar
Thanks very much Bart, Thomas, and Graeme, they're precious information. I even 
didn't notice about the built-in feature within FPC and Lazarus IDE.

Thanks again.



- Original Message 
From: Graeme Geldenhuys graemeg.li...@gmail.com
To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org
Sent: Mon, April 12, 2010 8:09:42 PM
Subject: Re: [fpc-pascal] (no subject)

On 12 April 2010 14:27, Tomas Hajny xhaj...@hajny.biz wrote:

 These are obviously all valid. There's also another possibility though
 (having advantages and disadvantages compared to this) - you could have an
 include file specifying this define and reference this include file from
 all (relevant) source files.


100% correct Tomas, and a very handy option at that. We actually use
this method in our company projects. Only downside - don't forget to
specify the include file in each and every unit of your project.


-- 
Regards,
  - Graeme -


___
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
___
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


Re: [fpc-pascal] (no subject)

2010-04-11 Thread Bihar Anwar
Thanks Bart, I will try it.



- Original Message 
From: Bart bartjun...@gmail.com
To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org
Sent: Sun, April 11, 2010 4:51:54 PM
Subject: Re: [fpc-pascal] (no subject)

Simply define the compiler directive NOFORMSPLEASE when compiling your
console app.
The ProcessMessages is there (I guess) for allowing the Application
object to update screens (WinControls).

Since a console application does not link in LCL this is not necessary.

Bart
___
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


Re: [fpc-pascal] (no subject)

2010-04-11 Thread Bihar Anwar
Yes it works, but the {$DEFINE NOFORMSPLEASE} clause must be put in the unit 
itself. If I put the clause in the first line of my console project, the unit 
won't catch it.

How can I define a compiler directive that can be understood by all units in my 
project?

Anyway, thanks.



- Original Message 
From: Bart bartjun...@gmail.com
To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org
Sent: Sun, April 11, 2010 4:51:54 PM
Subject: Re: [fpc-pascal] (no subject)

Simply define the compiler directive NOFORMSPLEASE when compiling your
console app.
The ProcessMessages is there (I guess) for allowing the Application
object to update screens (WinControls).

Since a console application does not link in LCL this is not necessary.

Bart
___
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