Re: [fpc-devel] Cannot create Merge Request

2024-01-03 Thread Amir--- via fpc-devel

+1

On 1/3/24 21:53, Christo Crause wrote:

On Thu, Jan 4, 2024 at 6:18 AM Amir--- via fpc-devel
 wrote:

I do not see the option to upload attach the patch file?

In GitLab, scroll down to the bottom of the page showing your issue.
There should be an edit box where you can type a new comment. You can
also drag and drop a file into this box, or click on the paperclip
icon to attach a file.


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Cannot create Merge Request

2024-01-03 Thread Amir--- via fpc-devel

I do not see the option to upload attach the patch file?


On 1/3/24 02:39, Michael Van Canneyt wrote:



On Tue, 2 Jan 2024, Amir--- via fpc-devel wrote:


Hi there,

I never used gitlab before, so my question might be very stupid!
I am trying to follow the instruction here 
<https://wiki.lazarus.freepascal.org/Creating_A_Patch#Creating_a_patch_using_Git> 
to create a patch. I have created a Feature Request 
<https://gitlab.com/freepascal.org/fpc/source/-/issues/40578> but 
cannot figure out how to create a MergeRequest?


If you created a patch file, don't make a merge request. Simply attach 
the patch file to the issue.


To create a merge request, you must fork the gitlab repo on gitlab, 
create a
branch in your fork, commit the change in the branch, and then use the 
gitlab UI to create a merge request. When you push your change, gitlab 
will automatically

propose a URL to create the merge request and git will display it.

Michael.


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Cannot create Merge Request

2024-01-02 Thread Amir--- via fpc-devel

Hi there,

I never used gitlab before, so my question might be very stupid!
I am trying to follow the instruction here 
 
to create a patch. I have created a Feature Request 
 but cannot 
figure out how to create a MergeRequest?


Best,
Amir___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] PB2PAS: Proto Compiler for FPC

2021-02-25 Thread Amir via fpc-devel

Hi there,

  I would like to share the proto compiler I developed and get some 
feedback on it as well.


  The compiler's code is located https://github.com/AmirAavani/PB2PAS. 
The generated code(units) uses the units in 
https://github.com/AmirAavani/my-units/tree/master/PB2PAS.
  I attached two proto files and the generated unit files as well 
(Please see the ReadME file in the repo for more information).


The proto compiler works with proto3 
syntax(https://developers.google.com/protocol-buffers/docs/proto3). 
Right now, it does not support "bytes" (one could use string instead). 
Also, it does not support "service" as well (WIP).


It would be great if you could go through the output/code and let me 
know what you think (or if you have any comments). I have some specific 
questions:


1) For Repeated Fields, the message class will have the following three 
properties:

  constFieldName, MutableFeildName, and FieldName[Index: Integer].

Their definition looks like this:

property ConstFieldName: TFieldName read FFieldName;
property MutableFieldName: TFieldName read GetOrCreate write FFiledName;
property FieldName[Index: Integer]: TFieldName read GetFiledName;

Is there a better way to handle this. Specifically is there anyway to 
disable MsgObj.ConstFieldName.Add(...)?


2) A similar question about Getters for Non-simple fields (Fields that 
are messages, OneOf, etc). The code generates the following properties, 
per this kind of fields:

property FieldName: TFieldName read FFieldName write FFieldName;
property MutableFieldName: TFieldName read GetOrCreateFieldName;

Should I drop "write FFieldName" from the property FieldName?

3) I do not have a good answer for this one: Should the the items in a 
Map/List be freed in the class destructor?
  In the current implementation, the destructor frees the Maps/Lists 
and all their members. The issue is uncommenting  line 178 of Main.pp 
(attached) would cause a segfault. I had a couple of ideas about how to 
handle this, but none of them is perfect. Wondering what you think?


Regards,
Amir
syntax = "proto3";

package test;
option go_package = "Samples;testpb";

import "Samples/test_dep1.proto";

message MyMessage {
  message A {
int32 a_id = 1;
SubMessage a_sub_message = 2;
  }
  A a = 1100;
  map id_a_map = 1101;

  oneof MyOneOf {
AnEnum an_enum = 12;
deptest.AnEnum deptest_an_enum = 13;
string is_country = 1;
string is_state = 2;
string is_county = 3;
string is_city = 4;
string is_street = 5;
string is_str = 6;
int32 is_i = 8;
float is_f = 9;
double is_d = 10;
A is_a = 11;
  }
  message SubMessage {
int32 id = 1;
  }
  enum AnEnum {
NONE = 0;
V1 = 1;
V4 = 4;
  }
  repeated string rep_str = 122;
  repeated int32 rep_i = 123;
  repeated float ref_f = 124;
  repeated double rep_d = 125;
  repeated A rep_a=  126;

  double dd = 200;
  float f = 201;
  int32 i32 = 202;
  int64 i64 = 203;
  uint32 ui32 = 204;
  uint64 ui64 = 205;
  sint32 si32 = 206;
  sint64 si64 = 207;
  fixed32 f32 = 208;
  fixed64 f64 = 209;
  sfixed32 s32 = 210;
  sfixed64 s64 = 211;
  bool _b = 212;
  string an_s = 213;

  repeated double rdd = 300;
  repeated float rf = 301;
  repeated int32 ri32 = 302;
  repeated int64 ri64 = 303;
  repeated uint32 rui32 = 304;
  repeated uint64 rui64 = 305;
  repeated sint32 rsi32 = 306;
  repeated sint64 rsi64 = 307;
  repeated fixed32 rf32 = 308;
  repeated fixed64 rf64 = 309;
  repeated sfixed32 rs32 = 310;
  repeated sfixed64 rs64 = 311;
  repeated bool rb = 312;
  repeated string rs = 313;
  repeated AnEnum aenums = 314;

  map id_sub_message_map = 420;
  map an_int_int_map = 421;
  // map an_int_an_enum_map = 127;
  // map an_int_to_b_num_map = 128;
  map b_int_int_map = 429;

}
syntax = "proto3";

package deptest;
option go_package = "Samples;testpb";

enum AnEnum {
  V0 = 0;
  V1 = 1;
  V2 = 2;
}
unit TestUnit;
{$Mode objfpc}

interface

uses
 TestDep1Unit, classes, fgl, sysutils, ProtoHelperUnit, ProtoHelperListsUnit, 
ProtoStreamUnit, GenericCollectionUnit;

type
  TMyMessage = class;

  // message MyMessage
  { TMyMessage }
  TMyMessage = class(TBaseMessage)
  type
// AnEnum
TAnEnum = (
  ANENUM_NONE = 0,
  ANENUM_V1 = 1,
  ANENUM_V4 = 4
);

  // Forward Declarations.
  public type
TMyOneOf = class;
  public type
TA = class;
TSubMessage = class;

  public type
TMyOneOf = Class(TBaseOneOf)
private
  function GetAnEnum: TAnEnum;
  procedure SetAnEnum(_AnEnum: TAnEnum);
  function GetDeptestAnEnum: TestDep1Unit.TAnEnum;
  procedure SetDeptestAnEnum(_DeptestAnEnum: TestDep1Unit.TAnEnum);
  function GetIsCountry: AnsiString;
  procedure SetIsCountry(_IsCountry: AnsiString);
  function GetIsState: AnsiString;
  procedure SetIsState(_IsState: AnsiString);
  function GetIsCounty: AnsiString;
  procedure SetIsCoun

[fpc-devel] Do we need a TFPGMap.IsSorted method?

2020-09-01 Thread Amir via fpc-devel

Hi there,

  The other day, I wanted to write a code to memorize and search some 
values (something like the following):


    MyMap := TIntIntMap.Create;
    for  i := 1 to ABigNumber do
   MyMap.Insert(AnIncreasingFunction(i), 
ComputationallyExpensiveFunction(AnIncreasingFunction(i)));


To have fast lookup, I had to set myMap.Sorted := True. But then noticed 
that setting this property, in the worst case, requires O(ABigNumber^2) 
step:  TFPSMap.SetSorted is implemented as:

  if Value = FSorted then exit;
  FSorted := Value;
  if Value then Sort;

The keys are sorted and Sort is a quick sort (which sucks if the input 
data is already sorted).


Wondering if it makes sense to change the implementation to
  if Value = FSorted then exit;
  FSorted := Value;
  if Value and not IsSortedFunc then
 Sort;

The other option could be to add a new read-only MyMap.IsSorted where 
the getter is implemented as:


  if FSorted then
 Exit(True);
  FSorted := IsSortedFunc;
  Result := FSorted;

Thanks,
Amir
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Is the code in wiki correct?

2020-05-11 Thread Amir
I assume StringJoin and StringSplit are one of the basic operations on 
Array of Strings and Strings. It looks like there is no easy way to use 
TStringList (that is claimed by the wiki to be a fancy "dynamic array or 
set of Strings"). These are not CSV-kind of functionalities...

 Are these functionalities implemented in rtl?



On 5/8/20 11:53 PM, Michael Van Canneyt wrote:



On Fri, 8 May 2020, Amir wrote:


Hi there,

  I was looking for a native implementation for JoinStrings and ended 
up in TStringList-TStrings_Tutorial 
<https://wiki.freepascal.org/TStringList-TStrings_Tutorial>.



<https://wiki.freepascal.org/TStringList-TStrings_Tutorial>
In Conversion to and from delimited strings 
<https://wiki.freepascal.org/TStringList-TStrings_Tutorial#Conversion_to_and_from_delimited_strings> 
section, it claims the following code works if the separator is a 
string:

MyStringList:= TStringList.create;
MyStringList.SkipLastLineBreak := True;
MyStringList.add('1');
MyStringList.add('2');
MyStringList.add('3');
result := StringReplace(MyStringList.Text,Lineending,'\n', 
[rfReplaceAll, rfIgnoreCase]);


I believe this is not correct. What if there is a newline(LineEnding) 
in one of the strings?


It will also be replaced. So yes, the code is wrong for such a case.

TStringlist is not a silver bullet, and it is definitely not a 
replacement
for CSV-kind of functionality. If someone needs CSV, (s)he should use 
the TCSVDocument class.



Michael.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Is the code in wiki correct?

2020-05-09 Thread Amir

Hi there,

  I was looking for a native implementation for JoinStrings and ended 
up in TStringList-TStrings_Tutorial 
<https://wiki.freepascal.org/TStringList-TStrings_Tutorial>.



<https://wiki.freepascal.org/TStringList-TStrings_Tutorial>
In Conversion to and from delimited strings 
<https://wiki.freepascal.org/TStringList-TStrings_Tutorial#Conversion_to_and_from_delimited_strings> 
section, it claims the following code works if the separator is a string:

MyStringList:= TStringList.create;
MyStringList.SkipLastLineBreak := True;
MyStringList.add('1');
MyStringList.add('2');
MyStringList.add('3');
result := StringReplace(MyStringList.Text,Lineending,'\n', 
[rfReplaceAll, rfIgnoreCase]);


I believe this is not correct. What if there is a newline(LineEnding) in 
one of the strings?


Best,
Amir



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Creating Generic Object

2018-04-15 Thread Amir

Hi all,

  Currently, FPC allows declaring objects as
var
  MyMap: specialize TFPGMap<AnsiString, MyData>;

This is very nice feature since I do not need define every Map/List/etc 
as a  separate type.


But to create MyMap object, one has to write something like:
  MyMap := (specialize TFPGMap<AnsiString, MyData>).Create()

Wondering if there is any shorter way to handle the objects' 
initialization, .e.g., something like

  MyMap := auto.Create;


Thanks,
Amir
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Faster Implementation for IntToStr

2012-09-02 Thread Amir

Hi,

  In one of my project, I have to call IntToStr more than 10M times. I 
noticed that IntToStr calls Str function. I implemented my own version 
of IntToStr which is almost twice faster than the current implementation 
of IntToStr. I wonder if it is possible to use my code in IntToStr function.


  I attached my function, and also a sample code which calls MyIntToStr 
and IntToStr 1000 times. I used valgrind to compare the performance of 
the two function.


Amir
P.S. I understand that my code is not easy to read/understand, but the 
question is, should the code for a library be readable/easy to understand?


P.S. I compiled the project using
fpc -Sd -O3 IntToStr.lpr
version: 1
creator: callgrind-3.7.0
pid: 15863
cmd:  ./IntToStr
part: 1


desc: I1 cache: 
desc: D1 cache: 
desc: LL cache: 

desc: Timerange: Basic block 0 - 376150
desc: Trigger: Program termination

positions: line
events: Ir
summary: 2189171


ob=(1) /home/Amir/Desktop/Temp/Amir/Code/IntToStr
fl=(2) /home/Amir/Desktop/Temp/Amir/Code//IntToStr.lpr
fn=(2) main
89 7
cfi=(1) ???
cfn=(4) fpc_initializeunits
calls=1 -89 
* 64793
* 7
cfi=(1)
cfn=(142) fpc_pushexceptaddr
calls=1 -89 
* 24
* 2
cfi=(1)
cfn=(144) fpc_setjmp
calls=1 -89 
* 12
* 3
+1 4
+2 2
cfi=(1)
cfn=(228) SYSTEM_RANDOM$LONGINT$$LONGINT
calls=1 -92 
* 33740
-2 1000
+2 2000
cfi=(1)
cfn=(228)
calls=1000 -92 
* 68837
* 1001
+1 1001
cfi=(1)
cfn=(234) fpc_get_output
calls=1001 -93 
* 9009
* 3003
cfi=(1)
cfn=(152) fpc_ansistr_decr_ref
calls=1001 -93 
* 118009
* 4004
cfi=(1)
cfn=(236) SYSUTILS_INTTOSTR$LONGINT$$ANSISTRING
calls=1001 -93 
* 631621
* 4004
cfi=(1)
cfn=(250) fpc_write_text_ansistr
calls=1001 -93 
* 142564
* 1001
cfi=(1)
cfn=(254) fpc_iocheck
calls=1001 -93 
* 13013
* 2002
cfi=(1)
cfn=(256) fpc_writeln_end
calls=1001 -93 
* 180180
* 1001
cfi=(1)
cfn=(254)
calls=1001 -93 
* 13013
+1 1001
cfi=(1)
cfn=(234)
calls=1001 -94 
* 9009
* 3003
cfi=(1)
cfn=(152)
calls=1001 -94 
* 118118
* 4004
cfn=(272) P$INTTOSTR_MYINTTOSTR$LONGINT$$ANSISTRING
calls=1001 -43 
* 340011
* 4004
cfi=(1)
cfn=(250)
calls=1001 -94 
* 142564
* 1001
cfi=(1)
cfn=(254)
calls=1001 -94 
* 13013
* 2002
cfi=(1)
cfn=(256)
calls=1001 -94 
* 180180
* 1001
cfi=(1)
cfn=(254)
calls=1001 -94 
* 13013
-4 2003
cfi=(1)
cfn=(148) fpc_popaddrstack
calls=1 -90 
* 17
+7 2
cfi=(1)
cfn=(152)
calls=1 -97 
* 118
* 5
cfi=(1)
cfn=(274) SYSTEM_DO_EXIT
calls=1 -97 
* 60231

fn=(272)
51 6006
+1 3003
+7 1001
+2 3003
+3 1001
+2 3003
+1 1064
+3 4173
-1 23210
+3 3003
cfi=(1)
cfn=(244) fpc_ansistr_setlength
calls=1001 -72 
* 135135
+1 5005
+2 1001
+2 56958
+1 47465
+1 9493
-4 31482
+8 5005

fl=(1)
fn=(12) SYSTEM_init
0 3
cfn=(8) SYSTEM_SYSRESETFPU
calls=1 0 
0 22
0 5
cfn=(10) SYSTEM_SYSINITFPU
calls=1 0 
0 20
0 5
cfn=(14) SYSTEM_CHECKINITIALSTKLEN$QWORD$$QWORD
calls=1 0 
0 74
0 27
cfn=(22) SYSTEM_INSTALLSIGNALS
calls=1 0 
0 395
0 1
cfn=(30) SYSTEM_INITHEAP
calls=1 0 
0 184
0 1
cfn=(32) SYSTEM_SYSINITEXCEPTIONS
calls=1 0 
0 17
0 1
cfn=(34) SYSTEM_SYSINITSTDIO
calls=1 0 
0 1395
0 1
cfn=(48) SYSTEM_SYSINITEXECPATH
calls=1 0 
0 39
0 8
cfn=(52) SYSTEM_INITSYSTEMTHREADS
calls=1 0 
0 188
0 1
cfn=(58) SYSTEM_INITVARIANTMANAGER
calls=1 0 
0 1
0 1
cfn=(60) SYSTEM_INITUNICODESTRINGMANAGER
calls=1 0 
0 43
0 6

fn=(30)
0 14
cfn=(16) SYSTEM_FILLCHAR$formal$INT64$BYTE
calls=1 0 
0 80
0 7
cfn=(16)
calls=1 0 
0 80
0 3

fn=(74) SYSTEM_FPOPEN$PCHAR$LONGINT$LONGINT$$LONGINT
0 16
cfn=(46) SYSTEM_FPSYSCALL$INT64$INT64$INT64$INT64$$INT64
calls=2 0 
0 24
0 4

fn=(154) SYSTEM_TOBJECT_$__AFTERCONSTRUCTION
0 12

fn=(156) SYSUTILS_INITINTERNATIONAL
0 2
cfn=(158) SYSUTILS_INITINTERNATIONALGENERIC
calls=1 0 
0 96
0 1
cfn=(160) SYSUTILS_INITANSI
calls=1 0 
0 2866
0 2

fn=(174) SYSTEM_NORTLEVENTCREATE$$PRTLEVENT
0 27

fn=(178) SYSTEM_NOGETCURRENTTHREADID$$QWORD
0 15

fn=(188) SYSTEM_INITINTERFACEPOINTERS$TCLASS$POINTER
0 63

fn=(196) SYSTEM_BASICEVENTCREATE$POINTER$BOOLEAN$BOOLEAN$ANSISTRING$$POINTER
0 8
cfn=(198) SYSTEM_NOBASICEVENTCREATE$POINTER$BOOLEAN$BOOLEAN$ANSISTRING$$POINTER
calls=1 0 
0 10
0 2

fn=(198)
0 10

fn=(228)
0 7007
cfn=(230) SYSTEM_GENRAND_MT19937$$LONGINT
calls=1001 0 
0 88563
0 7007

fn=(254)
0 52052

fn=(256)
0 54054
cfn=(252) SYSTEM_FPC_WRITEBUFFER$TEXT$formal$INT64
calls=2002 0 
0 110110
0 12012
cfn=(258) SYSTEM_FILEWRITEFUNC$TEXTREC
calls=2002 0 
0 176176
0 8008

fn=(314) SYSUTILS_FREEANDNIL$formal
0 20
cfn=(304) SYSTEM_TOBJECT_$__FREE
calls=1 0 
0 7
cfn=(305) SYSTEM_TOBJECT_$__FREE'2
calls=3 0 
0 742
0 8

fn=(350) SYSTEM_TINTERFACEDOBJECT_$__BEFOREDESTRUCTION
0 6

fn=(374) SYSUTILS_finalize
0 2
cfn=(376) SYSUTILS_FREEDRIVESTR
calls=1 0 
0 192
0 1
cfn=(378) SYSUTILS_DONEEXCEPTIONS
calls=1 0 
0 503
0 3
cfn=(336) fpc_finalize
calls=1 0 
0 2260
0 2
cfn=(152)
calls=1 0 
0 14
0 4
cfn=(152)
calls=1 0 
0 14
0 4
cfn=(152)
calls=1 0 
0 9
0 4
cfn=(384) fpc_unicodestr_decr_ref
calls=1 0 
0 9
0 5
cfn=(336)
calls=1 0 
0 61
0 3
cfn=(336)
calls=1 0 
0 61
0 2
cfn=(152)
calls=1 0 
0 14
0 4
cfn=(152)
calls=1 0 
0 9
0 4

fn=(382) SYSTEM_RECORDRTTI$POINTER$POINTER

Re: [fpc-devel] Faster Implementation for IntToStr

2012-09-02 Thread Amir

Check the attachments on this email.

Amir

On 09/02/2012 12:07 PM, Amir wrote:

Hi,

   In one of my project, I have to call IntToStr more than 10M times. I
noticed that IntToStr calls Str function. I implemented my own version
of IntToStr which is almost twice faster than the current implementation
of IntToStr. I wonder if it is possible to use my code in IntToStr
function.

   I attached my function, and also a sample code which calls MyIntToStr
and IntToStr 1000 times. I used valgrind to compare the performance of
the two function.

Amir
P.S. I understand that my code is not easy to read/understand, but the
question is, should the code for a library be readable/easy to understand?

P.S. I compiled the project using
fpc -Sd -O3 IntToStr.lpr


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



program IntToStr;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, SysUtils
  { you can add units after this };

function MyIntToStr (n: Integer): AnsiString;
const
  Pow10: array [0..9] of Integer=
   (1, 10, 100, 1000, 1, 10, 100,
1000, 1, 10);

  function GetLength (n: Integer): Integer;
  var
Top, Bot, Mid: Integer;

  begin
Bot:= 0; Top:= 9;

if Pow10 [Top]= n then
  Exit (Top+ 1);
if n= Pow10 [Bot] then
  Exit (Bot+ 1);

while Bot= Top do
begin
  Mid:= (Top+ Bot) shr 1;

  if n Pow10 [Mid] then
Top:= Mid- 1
  else if Pow10 [Mid]= n then
Bot:= Mid+ 1
  else
Exit (Mid+ 1);

end;

Result:= Bot;
  end;

var
  RightPtr: PChar;
  Len: Integer;
  IsNegative: Boolean;

begin
  if n 0 then
  begin
n:= -n;
IsNegative:= True;

  end
  else
IsNegative:= False;

  if n= 0 then
Exit ('0');

  Len:= 0;

  if Pow10 [High (Pow10)] n then
Len:= High (Pow10)+ 1
  else
while Pow10 [Len]= n do
  Inc (Len);

  if IsNegative then
Inc (Len);
  SetLength (Result, Len);
  RightPtr:= @(Result [1])+ Len- 1;

  while n 0 do
  begin
RightPtr^:= char (48+ (n mod 10));
n:= n div 10;
Dec (RightPtr);

  end;

  if IsNegative then
Result [1]:= '-';

end;

var
  i: Integer;
  n: Integer;

begin
  for i:= 0 to 1000 do
  begin
n:= Random (MaxInt)- MaxInt div 2;
WriteLn (SysUtils.IntToStr (n), '.');
WriteLn (MyIntToStr (n), '.');

  end;
end.

version: 1
creator: callgrind-3.7.0
pid: 16913
cmd:  ./IntToStr
part: 1


desc: I1 cache: 
desc: D1 cache: 
desc: LL cache: 

desc: Timerange: Basic block 0 - 405678
desc: Trigger: Program termination

positions: line
events: Ir
summary: 2320476


ob=(1) /home/Amir/Desktop/Temp/Amir/Code/IntToStr
fl=(2) /home/Amir/Desktop/Temp/Amir/Code//IntToStr.lpr
fn=(274) P$INTTOSTR_MYINTTOSTR$LONGINT$$ANSISTRING
51 7007
+1 3003
+2 1515
+1 1010
+4 496
+2 3003
+3 1001
+2 3003
+1 154
+3 8210
-1 45670
+3 2002
+1 505
+1 1515
cfi=(1) ???
cfn=(244) fpc_ansistr_setlength
calls=505 -74 
* 68175
* 1488
cfi=(1)
cfn=(244)
calls=496 -74 
* 66960
+1 5005
+2 1001
+2 53880
+1 44900
+1 8980
-4 29943
+8 2002
+1 1010
cfi=(1)
cfn=(276) fpc_ansistr_unique
calls=505 -86 
* 7575
* 505
+2 6006

fn=(2) main
94 7
cfi=(1)
cfn=(4) fpc_initializeunits
calls=1 -94 
* 64793
* 7
cfi=(1)
cfn=(142) fpc_pushexceptaddr
calls=1 -94 
* 24
* 2
cfi=(1)
cfn=(144) fpc_setjmp
calls=1 -94 
* 12
* 3
+1 4
+2 2
cfi=(1)
cfn=(228) SYSTEM_RANDOM$LONGINT$$LONGINT
calls=1 -97 
* 33740
-2 1000
+2 2000
cfi=(1)
cfn=(228)
calls=1000 -97 
* 68837
* 3003
+1 1001
cfi=(1)
cfn=(234) fpc_get_output
calls=1001 -98 
* 9009
* 3003
cfi=(1)
cfn=(152) fpc_ansistr_decr_ref
calls=1001 -98 
* 118009
* 4004
cfi=(1)
cfn=(236) SYSUTILS_INTTOSTR$LONGINT$$ANSISTRING
calls=1001 -98 
* 621375
* 4004
cfi=(1)
cfn=(250) fpc_write_text_ansistr
calls=1001 -98 
* 142530
* 1001
cfi=(1)
cfn=(254) fpc_iocheck
calls=1001 -98 
* 13013
* 4004
cfi=(1)
cfn=(256) fpc_write_text_char
calls=1001 -98 
* 34034
* 1001
cfi=(1)
cfn=(254)
calls=1001 -98 
* 13013
* 2002
cfi=(1)
cfn=(258) fpc_writeln_end
calls=1001 -98 
* 180180
* 1001
cfi=(1)
cfn=(254)
calls=1001 -98 
* 13013
+1 1001
cfi=(1)
cfn=(234)
calls=1001 -99 
* 9009
* 3003
cfi=(1)
cfn=(152)
calls=1001 -99 
* 118118
* 4004
cfn=(274)
calls=1001 -48 
* 375524
* 4004
cfi=(1)
cfn=(250)
calls=1001 -99 
* 142530
* 1001
cfi=(1)
cfn=(254)
calls=1001 -99 
* 13013
* 4004
cfi=(1)
cfn=(256)
calls=1001 -99 
* 34034
* 1001
cfi=(1)
cfn=(254)
calls=1001 -99 
* 13013
* 2002
cfi=(1)
cfn=(258)
calls=1001 -99 
* 180180
* 1001
cfi=(1)
cfn=(254)
calls=1001 -99 
* 13013
-4 2003
cfi=(1)
cfn=(148) fpc_popaddrstack
calls=1 -95 
* 17
+7 2
cfi=(1)
cfn=(152)
calls=1 0 
* 118
* 5
cfi=(1)
cfn=(278) SYSTEM_DO_EXIT
calls=1 0 
* 60231

fl=(1)
fn=(14) SYSTEM_CHECKINITIALSTKLEN$QWORD$$QWORD
0 9
cfn=(16) SYSTEM_FILLCHAR$formal$INT64$BYTE
calls=1 0 
0 29
0 6
cfn=(18) SYSTEM_FPGETRLIMIT$LONGINT$PRLIMIT$$LONGINT
calls=1 0 
0 18
0 12

fn=(72) fpc_shortstr_concat
0

Re: [fpc-devel] Re: Faster Implementation for IntToStr

2012-09-02 Thread Amir
  I could not follow what the code does, as it is in assembly, but it 
looks like it has the same idea as mine.


  In general, how can one propose some changes in a library? Should the 
suggestion goes through this mailing list?


Amir

On 09/02/2012 05:24 PM, Jonas Maebe wrote:


On 02 Sep 2012, at 14:46, Max Nazhalov wrote:


And also an i386-speciic assembler variants in ./FPC_SRC/rtl/i386/i386.inc, which I 
suspect use approach similar to yours, but I'm not sure they are enabled..

{$if defined(disabled) and defined(regcall)}
procedure int_str(l:longword;out s:string);
...
procedure int_str(l:longint;out s:string);
{Optimized for speed, but balanced with size.}
const digits:array[0..9] of cardinal=
(0,10,100,1000,1,
  10,100,1000,
  1,10);
...
{$endif}


FWIW, these are disabled because they cause crashes.


Jonas___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel



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


Re: [fpc-devel] Strange Problem!

2012-04-25 Thread Amir


I am not sure what you mean be your program is not valid. I am 
initializing Result. Modify its content and ...


I already observed that if I use either shortstring or use indices to 
modify Result, this problem does not occur. But still I can't see what 
causes this problem. And I believe it is a bug, isn't it?


Amir

On 04/25/2012 04:25 AM, Flávio Etrusco wrote:

You program isn't valid. You're assigning a constant (a global
variable) to Result, so you shouldn't change it's contents through a
pointer (if you change it normally the compiler+RTL will COW the
value).
You can use a shortstring or:
Result := StringOfChar(' ', 16);

-Flávio

On Tue, Apr 24, 2012 at 7:36 PM, Amira...@aavani.net  wrote:

Hi,

I have encountered a strange problem. I developed the following function as
a faster implementation for IntToStr:


function MyIntToStr (n: Int64): AnsiString;
const
  MaxLength= 16;

var
  CurDigit: PChar;
  Sign: Boolean;

begin
  Result:= '';

  CurDigit:= @(Result [MaxLength]);
  Sign:= False;

  if n  0 then
  begin
Sign:= True;
n:= -n;

  end;
  if n= 0 then
Exit ('0');


  while n  0 do
  begin
CurDigit^:= Char (48+ n mod 10);
Dec (CurDigit);
n:= n div 10;

  end;
  if Sign then
CurDigit^:= '-';

end;

And then, in main , I have

begin
  WriteLn (MyIntToStr (5458));
  WriteLn (MyIntToStr (5458));
  WriteLn (MyIntToStr (2));

end.

The output is:
   5458
   5458
   5452

I tried gdb and noticed the first line of MyIntToStr (Result:= '...') is not
executed correctly. I am using fpc-2.6.0-1.x86_64


Thanks,
Amir
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


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


[fpc-devel] Strange Problem!

2012-04-24 Thread Amir

Hi,

I have encountered a strange problem. I developed the following function 
as a faster implementation for IntToStr:



function MyIntToStr (n: Int64): AnsiString;
const
  MaxLength= 16;

var
  CurDigit: PChar;
  Sign: Boolean;

begin
  Result:= '';

  CurDigit:= @(Result [MaxLength]);
  Sign:= False;

  if n 0 then
  begin
Sign:= True;
n:= -n;

  end;
  if n= 0 then
Exit ('0');


  while n 0 do
  begin
CurDigit^:= Char (48+ n mod 10);
Dec (CurDigit);
n:= n div 10;

  end;
  if Sign then
CurDigit^:= '-';

end;

And then, in main , I have

begin
  WriteLn (MyIntToStr (5458));
  WriteLn (MyIntToStr (5458));
  WriteLn (MyIntToStr (2));

end.

The output is:
   5458
   5458
   5452

I tried gdb and noticed the first line of MyIntToStr (Result:= '...') is 
not executed correctly. I am using fpc-2.6.0-1.x86_64



Thanks,
Amir
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] Faster InitObject

2012-02-23 Thread Amir

On 02/23/2012 02:59 AM, Hans-Peter Diettrich wrote:

Amir schrieb:

Hi,

I have a code, developed in object pascal, with many classes. The
project is working fine.
Today, I used callgrind (valgrind --tool=calgrind) to see which
function consumes the most execution time and I noticed that the most of
time in my project is consumed by fillchar function.

Incl. Self. Called Function
29.78 29.72 26M SYSTEM_FILLCHAR$formal$INT64$BYTE
19.07 19.07 123M SYSTEM_MOVE$formal$formal$INT64
3.63 3.63 70M SYSTEM_SYSGETMEM_FIXED$QWORD$$POINTER



I suspect that the procedure initialization time is added to the first
explicit statement. The initialization can include try-except/finally
blocks, memory allocation (in constructors) or more.

Please create another procedure or method, that uses FillChar not as the
first statement, and test again.

I am not sure what you are asking. The callgrind outputs the call tree 
and other information


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


Re: [fpc-devel] Faster InitObject

2012-02-23 Thread Amir

On 02/23/2012 01:20 AM, Alexander Shishkin wrote:


1) You can override TObject.NewInstance, w|o calling inherited. (Init
instance is called from NewInstance) and do whatever you want



What does each of the follwoing lines do? It looks like they are setting 
the function table for the object. So, I need them in my new NewInstance 
Implementation, don't I?


ppointer(instance)^:=pointer(self);
if PVmt(self)^.vIntfTable  @emptyintf then
  InitInterfacePointers(self,instance);
InitInstance:=TObject(Instance);

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


Re: [fpc-devel] Faster InitObject

2012-02-23 Thread Amir

On 02/23/2012 11:37 AM, Hans-Peter Diettrich wrote:

Amir schrieb:


Incl. Self. Called Function
29.78 29.72 26M SYSTEM_FILLCHAR$formal$INT64$BYTE
19.07 19.07 123M SYSTEM_MOVE$formal$formal$INT64
3.63 3.63 70M SYSTEM_SYSGETMEM_FIXED$QWORD$$POINTER



I suspect that the procedure initialization time is added to the first
explicit statement. The initialization can include try-except/finally
blocks, memory allocation (in constructors) or more.

Please create another procedure or method, that uses FillChar not as the
first statement, and test again.


I am not sure what you are asking. The callgrind outputs the call tree
and other information


It's not the first time that somebody complains about slow FillChar. I
simply doubt that it really as slow as reported. In above table I'd
expect that SysGetMem should be slower than FillChar.

DoDi

The performance of FillChar is not my problem, The main issue in my case 
is that my class has a big array defined inside it. I developed my code 
such that this array does not need to be initialized with zero initially 
(I have not assumed anything about the content of this array).

But the InitInstance function, initialize the array with zero.

I can see a simple solution to resolve my problem. I can change the 
array, in my class, to a dynamic array or pointer or ...
But what if I had, let's say, many variables inside my class? Or a big 
data structure?



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


[fpc-devel] Convert time to GMT

2008-08-13 Thread amir

Hi!

I want to have the date/time of my computer for GMT. As I searched the 
rtl.pdf, I found out that there are some functions
in OLDLinux unit which return the current time for GMT (not local 
timezone). I wonder if they can be used on Windows (It said

that those functions return the current kernel time which is in GMT).

I also found two functions for reading the local timezone but they are 
located in Unix and OLDUnix units. Do they have an implementation

on Windows?

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


[fpc-devel] FpFlock with Text as argument

2008-05-07 Thread amir

Hi,

I don't know if it is a bug or I am using fpflock incorrectly. I wanted 
to use fpflock to lock a file (and be sure that only one process at a 
time can have access to my file).


At first, I tried AssignFile and passed the TextFile(Text) variable to 
fpflock with LOCK_EX. It didn't work and both processes can access the file.

Both print After Flock.

Then I modify the code, and used fpopen instead of AssignFile and passed 
the cInt variable to fpflock . This worked.


I attached the codes of both experiments.

Amir


program FLockTest;
uses
  BaseUnix, Unix;
var
  InputFile: TextFile;
  S: String;
  
begin
  AssignFile (InputFile, 'Lock.txt');
  WriteLn ('Before Flock');
  Flush (Output);
  Fpflock (InputFile, LOCK_EX);
  WriteLn ('After Flock');
  Flush (Output);

  ReadLn (S);
  WriteLn (S);
  
  CloseFile (InputFile);
  WriteLn ('After CloseFile');

end.
program FLockTest;
uses
  BaseUnix, Unix;
var
  InputFile: cInt;
  S: String;
  
begin
  InputFile:= fpOPen ('Lock.txt', O_WrOnly);
  WriteLn ('Before Flock');
  Flush (Output);
  Fpflock (InputFile, LOCK_EX);
  WriteLn ('After Flock');
  Flush (Output);

  ReadLn (S);
  WriteLn (S);
  
  fpClose (InputFile);
  WriteLn ('After CloseFile');

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


Re: [fpc-devel] How to use fpFlock?

2008-05-06 Thread amir

So what wrong is with the following code?
When running two instance of this program, *both* print After Flock 
and wait for an input?


uses
 Unix;
var
 InputFile: TextFile;

begin
 AssignFile (InputFile, 'Lock.txt');
 WriteLn ('Before Flock');
 Flush (Output);
 Fpflock (InputFile, LOCK_SH);
 WriteLn ('After Flock');
 Flush (Output);

 Reset (InputFile);
 ReadLn;

 CloseFile (InputFile);

end.

ik wrote:

flock in Linux (at least) is blocking by default unless passed with
specific parameter.

You can try also to create a mutex that only when removed you will
access the procedure/function that try to write to the file, and the
process that created the mutex is the only one that can write to that
file.
You of course remove it when you closed the file.

Just an idea...

Ido

On Fri, May 2, 2008 at 5:35 AM, amir [EMAIL PROTECTED] wrote:
  

Hi,

 I have many process wanting to write in a file. Each process is going to
open the file as a writeonly (using Assignfile and rewrite or fpOpen with
o_WrOnly). But there is a risk that two processes simultaneously trying to
write a message in the file. I want to use fpflock to avoid this. Is it
possible? What I done is something like this:

 AssignFile (OutputFile, FileName);
 fpflock (OutputFile, LOCK_EX);
 Rewrite (OutputFile);
 ...

 The description of fpFlock does not  say anything about the default
behavior of fpFlock (Is it blocking?). What I saw told me that it is not
blocking.

 Is it the correct way of using fpFlock?


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






  


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


Re: [fpc-devel] How to use fpFlock?

2008-05-06 Thread amir
I have tried both of them (LOCK_SH and LOCK_EX). But the result was the 
same.


ik wrote:

You should use LOCK_EX instead (exclusive lock rather then shared lock).
From the man file (man 2 flock):

  LOCK_SH   Place a shared lock.  More than one process
may hold a shared lock for a given file at a given time.

  LOCK_EX   Place an exclusive lock.  Only one process may
hold an exclusive lock for a given file at a given time.

  LOCK_UN   Remove an existing lock held by this process.

Ido

On Tue, May 6, 2008 at 9:38 AM, amir [EMAIL PROTECTED] wrote:
  

So what wrong is with the following code?
 When running two instance of this program, *both* print After Flock and
wait for an input?

 uses
  Unix;
 var
  InputFile: TextFile;

 begin
  AssignFile (InputFile, 'Lock.txt');
  WriteLn ('Before Flock');
  Flush (Output);
  Fpflock (InputFile, LOCK_SH);
  WriteLn ('After Flock');
  Flush (Output);

  Reset (InputFile);
  ReadLn;

  CloseFile (InputFile);

 end.



 ik wrote:



flock in Linux (at least) is blocking by default unless passed with
specific parameter.

You can try also to create a mutex that only when removed you will
access the procedure/function that try to write to the file, and the
process that created the mutex is the only one that can write to that
file.
You of course remove it when you closed the file.

Just an idea...

Ido

On Fri, May 2, 2008 at 5:35 AM, amir [EMAIL PROTECTED] wrote:


  

Hi,

 I have many process wanting to write in a file. Each process is going


to


open the file as a writeonly (using Assignfile and rewrite or fpOpen


with


o_WrOnly). But there is a risk that two processes simultaneously trying


to


write a message in the file. I want to use fpflock to avoid this. Is it
possible? What I done is something like this:

 AssignFile (OutputFile, FileName);
 fpflock (OutputFile, LOCK_EX);
 Rewrite (OutputFile);
 ...

 The description of fpFlock does not  say anything about the default
behavior of fpFlock (Is it blocking?). What I saw told me that it is not
blocking.

 Is it the correct way of using fpFlock?


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








  

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






  


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


[fpc-devel] How to use fpFlock?

2008-05-05 Thread amir

Hi,

I have many process wanting to write in a file. Each process is going to 
open the file as a writeonly (using Assignfile and rewrite or fpOpen 
with o_WrOnly). But there is a risk that two processes simultaneously 
trying to write a message in the file. I want to use fpflock to avoid 
this. Is it possible? What I done is something like this:


AssignFile (OutputFile, FileName);
fpflock (OutputFile, LOCK_EX);
Rewrite (OutputFile);
...

The description of fpFlock does not  say anything about the default 
behavior of fpFlock (Is it blocking?). What I saw told me that it is not 
blocking.


Is it the correct way of using fpFlock?


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


Re: [fpc-devel] How to force the child's constructor to call its parent constructor

2007-10-22 Thread amir
It is a run-time error but what I am looking for is an compile-time 
error. It is not sensible(for me) to raise an exception because of bad 
implementation. Thanks for you idea ;)


Amir

Michael Schnell wrote:
Couldn't you check the ID in your after construction event and throw 
an exception if it's not set ?


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


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


[fpc-devel] How to force the child's constructor to call its parent constructor

2007-10-21 Thread amir
Is there any way to force the child constructor to call its 
parent(direct parent) constructor. Consider the following case:


 TParent= class (TObject)
 private
   ID: Integer;
 public
 constructor Create (MyIdentifier: Integer);

 end;

I want to force the all childs of TParent to call the Create constructor 
(with appropriate parameter). But one can implement a child class like this:

 constructor TChild.Create;
 begin
// do any thing but not use inherited.
 end;


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


Re: [fpc-devel] How to force the child's constructor to call its parent constructor

2007-10-21 Thread amir


Joao Morais wrote:

amir wrote:
I want to force the all childs of TParent to call the Create 
constructor (with appropriate parameter). But one can implement a 
child class like this:

 constructor TChild.Create;
 begin
// do any thing but not use inherited.
 end;


No way. But you can override the NewInstance method; constructors will 
call it for sure. You can also override the AfterConstruction method.


--
Joao Morais
How can I use the NewInstance or AfterConstruction methods for my 
purpose? I want to force the others to set ID. The TParent is written by 
me but anyone can write the TChild class.



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


[fpc-devel] Com Port

2007-01-16 Thread Amir Aavani

Hi,

How can I read/write through Com port by Lazarus/FPC?!

Yours,
Amir

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


Re: [fpc-devel] Mutex!

2006-11-06 Thread Amir Aavani

What you suggested is a kind of busy waiting. But I want a suspension.
In a message , i described my  main problem which was a while like this.

while true do
begin
ReadLn (S);
/// Lock Mutex
AThread:= TMyThread.Create (True);//Suspended
AThread.Prepare (S);
AThread.Resume;
///UnLock Mutex
end;

And I told to check if Criticalsession could work in my situation i 
write that sample code.


Any idea for my problem?
Vinzent Höfler wrote:

Amir Avani wrote:


Thanks Michael, you are right!
I want to know how should I use Criticalsections to make my program to
print only one here.


By not using them at all?

count := 0;

while true do
begin
   if count = 0
  WriteLn ('Here!');

   count := 1;
end {while};

Critical sections don't make sense in a non-threading context.


Vinzent.



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


Re: [fpc-devel] Mutex!

2006-11-05 Thread Amir Avani

Thanks Michael, you are right!
I want to know how should I use Criticalsections to make my program to
print only one here.
 
Michael Müller wrote:

 Am 05.11.2006 um 12:14 schrieb Colin Western:

 Amir Aavani wrote:
  InitCriticalSection (cs);
  while true do
  begin
EnterCriticalsection (cs);
WriteLn ('Here!');
  end;
LeaveCriticalsection (cs);

 Each Enter.. must be matched by a Leave..., and you don't need the
loop. The standard way of doing this is:

 I'm sure that this is clear for Amir. But in his example he (and me too)
expects that the loop should stop at the second time it calls
EnterCriticalsection() because the old critical section wasn't left.

 EnterCriticalsection (cs);
 try
   WriteLn ('Here!');
 finally
   LeaveCriticalsection (cs);
 end;

 But this is not an example to show how a critical section stops another one.

 Regards

 Michael


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



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


[fpc-devel] Mutex!

2006-11-04 Thread Amir Aavani

Is there any implementation for Mutex in FPC?
I have a piece of code in a procedure that I want to be accessible from 
one of many available threads, at a time.


While searching I found a post that announced Mutex is not implemented 
in FPC and suggest to use RTLCiticalSection 
(http://lists.freepascal.org/lists/fpc-pascal/2006-July/011295.html).  
Is there any article about it?


Yours,
Amir


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


Re: [fpc-devel] Mutex!

2006-11-04 Thread Amir Aavani

 Let me explain the problem with more details,

consider the following code:

while true do
begin
 ReadLn (S);
/// Lock Mutex
 AThread:= TMyThread.Create (True);//Suspended
 AThread.Prepare (S);
 AThread.Resume;
///UnLock Mutex
end;
...

To understand the EnterCriticalsection, I write the following code,  I 
was expect to see a single Here while a lot of here is printed.

Was I incorrect in anywhere?

 InitCriticalSection (cs);

 while true do
 begin
   EnterCriticalsection (cs);
   WriteLn ('Here!');
 end;
   LeaveCriticalsection (cs);


I referred to a document about EnterCriticalsection, It said that It 
prevent two different thread to access a critical section, but here


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


Re: [fpc-devel] Fast Bitmap access

2006-06-22 Thread Amir Aavani

dear peter
as i said, in Delphi there is property, named ScanLine, But, I can't 
find one in fpc.

peter green wrote:

1: try doing it exactly as you do in delphi
2: if 1 fails file a bug report and mark it as compatibility

  

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Amir Aavani
Sent: 21 June 2006 08:51
To: FPC developers' list
Subject: [fpc-devel] Fast Bitmap access


Hi there,

In Delphi, accessing to pixels of a Bitmap image via the property of 
Pixels is very time-consuming. For fast Bitmap editing,  reading usually 
developers use ScanLine property, which returns a pointer to a row of 
images.
I want to see if there is a similar property in fpc's TBitmap 
implementation.


Amir

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


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



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


[fpc-devel] Fast Bitmap access

2006-06-21 Thread Amir Aavani

Hi there,

In Delphi, accessing to pixels of a Bitmap image via the property of 
Pixels is very time-consuming. For fast Bitmap editing,  reading usually 
developers use ScanLine property, which returns a pointer to a row of 
images.
I want to see if there is a similar property in fpc's TBitmap 
implementation.


Amir

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


[fpc-devel] Which of them are right (Delphi or FPC)

2006-04-18 Thread Amir Aavani
I developed a project in lazarus (FPC) and now when I try to run it in 
Delphi, it acts incorrect!


I have a class TObjectCollection which is a collection of TObject:
TObjectCollection= class (TObject)
 FMembers: array of TObject;
  ...
   ...
   public
 property Member [Index: Integer]: TObject read GetMember;
 ...
 procedure Add (ANewMember: TObject);
 ...
 end;

And A TObject1Collection which is like this:
TObject1Collection= class (TObjectCollection)
 function GetMember: TObject1;
  ...
   ...
   public
 property Member [Index: Integer]: TObject1 read GetMember;
 ...
 procedure Add (ANewMember: TObject1);
 ...
 end;

procedure TObject1Collection.Add (ANewMember: TObject1);
begin
 (Self AS TObjectCollection).Add (ANewMember AS TObject);
end;

procedure TObject1Collection.GetMember: TObject1;
begin
 Result:= (Self AS TObjectCollection).Member AS TObject1;end;
end;

The code works correctly in lazarus, but in Delphi, the procedure 
TObject1Collection.Add call itself instead of TObjectCollection.Add. I 
changed the code like this:

 SelfAsTObjectCollection:= Self As TObjectCollection;
 SelfAsTObjectCollection.Add (ANewMember);
and the problem solved.
I want to know, which of us (me, Delphi, Freepascal) is wrong.


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


[fpc-devel] Lazarus

2006-03-18 Thread Amir Aavani

Is there any example(way) to develop a plugin for lazarus,?
for example, adding a new type of application to lazarus with its own 
properites and ...



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


Re: [fpc-devel] procedure Types

2006-03-13 Thread Amir Aavani


Any idea to call:
 BeginThread (@MyObject.F1, Pointer (S))

Michael Van Canneyt wrote:


On Sat, 4 Mar 2006, Amir Aavani wrote:

 


I have problem with procedure Types.
Look at the following code:

TProcedure= procedure (S: String);
TTest= class
MyF: TProcedure;
procedure F1 (S: String);
procedure F2 (S: String);

...
end;

TTest.constructor ;
begin
MyF:= @F1;
end;

it says it can't cast Procedure (S: String); Object to TProcedure. The
problem is clear but I don't know
(can't find) any solution to define TProcedure as a procedure of a class which
accepts one argument.
   



Try the following (note the 'of object' in the declaration):

Type
 TMyStringProc = procedure (S : String) of object;

and then
x
 MyF : TMyStringProc;

This is documented.

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




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


[fpc-devel] procedure Types

2006-03-04 Thread Amir Aavani



I have problem with procedure Types.
Look at the following code:

 TProcedure= procedure (S: String);
 TTest= class
   MyF: TProcedure;
procedure F1 (S: String);
   procedure F2 (S: String);
   
   ...
 end;

TTest.constructor ;
begin
 MyF:= @F1;
end;

it says it can't cast Procedure (S: String); Object to TProcedure. The 
problem is clear but I don't know
(can't find) any solution to define TProcedure as a procedure of a class 
which accepts one argument.


Yours
Amir

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


Re: [fpc-devel] procedure Types

2006-03-04 Thread Amir Aavani

Thanks to Michael and Christian.
It works correctly.
I think it could be usefull to put an example for this case in fpc docs.

Michael Van Canneyt wrote:


On Sat, 4 Mar 2006, Amir Aavani wrote:

 


I have problem with procedure Types.
Look at the following code:

TProcedure= procedure (S: String);
TTest= class
MyF: TProcedure;
procedure F1 (S: String);
procedure F2 (S: String);

...
end;

TTest.constructor ;
begin
MyF:= @F1;
end;

it says it can't cast Procedure (S: String); Object to TProcedure. The
problem is clear but I don't know
(can't find) any solution to define TProcedure as a procedure of a class which
accepts one argument.
   



Try the following (note the 'of object' in the declaration):

Type
 TMyStringProc = procedure (S : String) of object;

and then

 MyF : TMyStringProc;

This is documented.

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




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


[fpc-devel] Calling Web Service from Freepascal

2006-02-03 Thread Amir Aavani


Any one call a webservice (WSDL) from Freepascal. I did it using Delphi, 
but now i want to do it by freepascal/Lazarus.



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


Re: [fpc-devel] How to call (access) to an external procedure!

2006-01-31 Thread Amir Aavani




Thanks Geno 
that works, but could you tell me what should i do for an external
variable,
var environ: ppchar; cvar; external;


Geno Roupsky wrote:

  This particular function could be declared as this:

TEnvironment = class
public
  class function GetEnvironment(const Name: PChar): PChar; cdecl;
end;

class function GetEnvironment(const Name: PChar): PChar; cdecl; external
'c' name 'getenv';
  

  function TEnvironment.GetEnvironment(const Name: PChar): PChar;
cdecl; external
   'c' name 'getenv';

  
Of course this is not very useful but the idea for methods is this. Just
keep in mind that methods have a hidden parameter Self pointing to the
object. When method is declared as cdecl it is the first parameter.

Tia,

Geno Roupsky

В вт, 2006-01-31 в 10:05 +0330, Amir Aavani написа:
  
  
dear friends,
I know that if want to use an external variable/procedure in fpc, i 
should use the following code:

function GetEnvironment (const Name: PChar): PChar; cdecl; external 'c' 
name 'getenv';

but how could i add for example  GetEnvironment function to a class 
(TEnvironment)!
Is there any good (OO) way?

Is it a good idea to use a following method:

TGetEnvironmentFunction= function : PChar;
TEnvironment= class (TObject)
private
  ...
public
  GetEnvironment: TGetEnvironment;
  procedure SetGetEnvironmentFunction (AFunction: TGetEnvironmentFunction);
  ...
end;

procedure TEnvironment.SetGetEnvironmentFunction (AFunction: 
TGetEnvironmentFunction);
begin
  GetEnvironment:= AFunction;
end;



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


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




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


[fpc-devel] How to call (access) to an external procedure!

2006-01-30 Thread Amir Aavani

dear friends,
I know that if want to use an external variable/procedure in fpc, i 
should use the following code:


function GetEnvironment (const Name: PChar): PChar; cdecl; external 'c' 
name 'getenv';


but how could i add for example  GetEnvironment function to a class 
(TEnvironment)!

Is there any good (OO) way?

Is it a good idea to use a following method:

TGetEnvironmentFunction= function : PChar;
TEnvironment= class (TObject)
private
 ...
public
 GetEnvironment: TGetEnvironment;
 procedure SetGetEnvironmentFunction (AFunction: TGetEnvironmentFunction);
 ...
end;

procedure TEnvironment.SetGetEnvironmentFunction (AFunction: 
TGetEnvironmentFunction);

begin
 GetEnvironment:= AFunction;
end;



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