Re: [fpc-pascal] fpc-pascal Digest, Vol 175, Issue 31

2019-01-24 Thread MARCOU Gilles
Hi,

I am not sure that I can help, but this is an interesting topic and I am 
curious if you find a solution.

I can only assume that maybe you did not link to gcc and c libraries. Inside 
Common.pas, you should try to add {$link c} and {$link gcc}. You may check also 
that the symbol of your function looks as you assume it is. Use the command 
’nm’ on Cygwin. On DOS you can also use vcvarsall.bat or dumpbin.exe.

Ciao,
Gilles Marcou

> Le 24 janv. 2019 à 12:00, fpc-pascal-requ...@lists.freepascal.org a écrit :
> 
> Send fpc-pascal mailing list submissions to
>   fpc-pascal@lists.freepascal.org
> 
> To subscribe or unsubscribe via the World Wide Web, visit
>   http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
> or, via email, send a message with subject or body 'help' to
>   fpc-pascal-requ...@lists.freepascal.org
> 
> You can reach the person managing the list at
>   fpc-pascal-ow...@lists.freepascal.org
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of fpc-pascal digest..."
> 
> 
> Today's Topics:
> 
>   1.  trying to use C code in .pas on WIN32 (conlin664)
> 
> 
> --
> 
> Message: 1
> Date: Wed, 23 Jan 2019 14:30:38 -0700 (MST)
> From: conlin664 
> To: fpc-pascal@lists.freepascal.org
> Subject: [fpc-pascal] trying to use C code in .pas on WIN32
> Message-ID: <1548279038991-0.p...@n5.nabble.com>
> Content-Type: text/plain; charset=us-ascii
> 
> I've done research, but am just missing something.
> my .pas code links just fine, but doesn't RUN.
> ( first writeln never appears )
> If I remove the  external call to C code, then the writeln works as normal.
> 
> Problem:
> 
> I have c code, which I'm compiling on a WIN32 machine ( yes the horror )
> using  GCC 4.5.2  target mingw32
> 
> It generates .o files which i grouped together with ar  into common.a
> I then renamed common.a to be libcommon.a
> 
> Then I have a 
> 
> Common.pas file:
> 
> unit Common;
> interface
> 
> uses
> sysutils, dos, CTypes;
> 
> {$linklib libcommon.a }
> 
> procedure CutilInit;  cdecl; external 'CutilInit';
> 
> implementation
> 
> end.
> 
> 
> the a CommonTest.pp file:
> 
> Program commonTest;
> uses
> Common;
> 
> begin
>  writeln('got here');
>  CutilInit();
> end.
> 
> 
> fpc.exe -TWin32 -Mdelphi -vw -Sg  -Ci -O1 -Cp386 -XS -gl -p- -b-
> 
> is the relevant way I'm invoking fpc
> 
> It links, but then does nothing on execution.
> 
> If I change the C line to be:
> 
> procedure CutilInit;  cdecl; external;
> 
> I think get a link error
> Undefined Symbol: _CutilInit
> 
> Any ideas ?
> 
> Does the linklib define need to be below where I declare the C routines ?
> Is it something to do with WINDOWS.. ( aka the _ in the name )
> 
> Maybe I need different options on the C compile..
> 
> 
> 
> 
> 
> 
> --
> Sent from: http://free-pascal-general.1045716.n5.nabble.com/
> 
> 
> --
> 
> Subject: Digest Footer
> 
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
> 
> --
> 
> End of fpc-pascal Digest, Vol 175, Issue 31
> ***

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

Re: [fpc-pascal] Array clearing

2017-04-13 Thread MARCOU Gilles
Regarding this code:

> SetLength(Array,Length(Array)+1);
> Array[High(Array)] := …

as I understood from (http://wiki.freepascal.org/Dynamic_array 
), SetLength will create a copy of 
the array and free the memory of the shorter array. In this case, a lot of 
memory operations and copy operations are performed thus degrading the 
performances of the code. Then it would be unwise to use such strategy: better 
allocate the size of the array correctly at the beginning of the run, or resize 
the array by block, to decrease the frequency of such operation:

> SetLength(Array,Length(Array)+N);

Can somebody confirm (or invalidate) this?

Ciao,
Gilles Marcou___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] AnsiCompareStr question (again...)

2016-03-08 Thread MARCOU Gilles
Sorry for my last post, I missed some reply. I think that I understood now the 
problem. Using TStringList.Sort, it uses AnsiCompareStr which needs a specific 
widestring manager to be defined. This is done adding the unit cwstring in the 
program unit (the .lpr using Lazarus). A better option, if executable size is 
not a concern, is to use fpwidestring, but it requires fpc 2.7.1 or more. 
Basically, the widestring support international characters, however this 
support affects characters that could be thought of as Char such as the sign « 
= «. A good help page is there: 
http://wiki.freepascal.org/Character_and_string_types 
. Please correct if I’m 
wrong.

I thank you all again for your kind help,
Gilles Marcou___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] AnsiCompareStr question (again...)

2016-03-07 Thread Marcou Gilles
Thanks for your answer Jonas.

> One probably includes cwstring, while the other one doesn't. 
> AnsiCompareStr can be intercepted/replaced by widestring manages such as 
> cwstring.

Is it what is meant into the manual by: "A widestring manager must be
installed in order for this function to work correctly with various
character sets"? Frankly I don't understand what is a widestring manager
in the first place and how do I know if one is installed in the second.
Somebody can explain?

Another question is: do the cwstring unit call a system library
(.dll/.o/.so)? In that case, maybe my problem was due to a memory
management problem. Is it possible that a memory leak problem could
interfere with a system library?

Thanks for your help,
Gilles Marcou
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] AnsiCompareStr question (again...)

2016-03-05 Thread Marcou Gilles
Thanks Bart,

this is strange. Using you example I got the value -16. I am using fpc
2.6.4 on a Linux 64 bits machine. I do not get why I got a different
value than you. And in my case, the strange behavior is that
AnsiCompareStr in the same unit but in two different application gave
two different results. I wonder if somebody else got observed this?

I also noticed that using CompareStr, I got the value -16 and the
funtion give the same result on both application. The code where I
observe this are rather large, so it is difficult to share. But if I
manage to recreate this situation in a more simple context, I'll post a
bug report.

Thanks again for your help,
Gilles Marcou

Le samedi 05 mars 2016 à 13:01 +0100, Bart a écrit :
> On 3/5/16, Marcou Gilles <g.mar...@unistra.fr> wrote:
> 
> 
> > I checked the AnsiCompareStr value between these two string and found
> > that the same unit compiled into one application give the value 16 and
> > compiled into the other application, it return the value -28.
> 
> {$apptype console}
> {$ifdef fpc}
> {$mode objfpc}
> {$h+}
> //{$codepage utf8}
> {$endif}
> 
> uses SysUtils;
> var
>   S1,S2: AnsiString;
> 
> begin
>   S1 := 'C-C';
>   S2 := 'C=C';
>   writeln('AnsiCompareStr(''C-C'',''C=C'') = ',ansicomparestr(S1,S2));
> end.
> 
> 
> C:\Users\Bart\LazarusProjecten\ConsoleProjecten>fpc test.pas
> Free Pascal Compiler version 3.0.0 [2015/11/16] for i386
> Copyright (c) 1993-2015 by Florian Klaempfl and others
> Target OS: Win32 for i386
> Compiling test.pas
> Linking test.exe
> 16 lines compiled, 2.5 sec, 64048 bytes code, 4052 bytes data
> 
> C:\Users\Bart\LazarusProjecten\ConsoleProjecten>test
> AnsiCompareStr('C-C','C=C') = 1
> 
> (Same result with fpc 2.6.4)
> 
> Bart
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] AnsiCompareStr question (again...)

2016-03-05 Thread Marcou Gilles
Hi,

in an application, I use a TStringList.Sort to sort a list of these two
words "(C-C)" and "(C=C)". When I use the same unit in another project,
the Sort function sort those two strings in revert order (on the same
computer, same system).

I checked the AnsiCompareStr value between these two string and found
that the same unit compiled into one application give the value 16 and
compiled into the other application, it return the value -28.

I am really puzzled. Does it has something to do with the
WideStringManager? I don't understand how to fix this to guarantee the
same behavior of this function at any time on any system.

Thanks in advance,
Gilles Marcou
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal