Re: [fpc-pascal] Developing a mini ERP / web based development

2019-07-03 Thread silvioprog
Hi Darius.

On Thu, Jun 27, 2019 at 1:10 PM Darius Blaszyk  wrote:

> Hi all,
>
> I have been asked to write a limited functionality / mini ERP type of
> software for an NGO that is setting up a hospital. I'm doing this in my own
> time and free of charge. The compiler and IDE of choice are of course
> FreePascal & Lazarus. I’m still thinking about the direction to go exactly
> with this and I was hoping to get some feedback/support from the community
> here as I always have gotten over the years.
>

First of all, good luck in your project! :-)

The hardware of choice is already made and will be a network of several
> Chromebooks on which all staff will be logging in the system. This made me
> think that a desktop application is less feasible and I should look at a
> web-based solution. I found some frameworks such as ExtPascal, fano, Brook,
> pas2js. Unfortunately, I don't know much about web-based applications. So
> my question is whether any of the frameworks are mature enough to create a
> database driven application as described. Possibly there are other
> frameworks available that I don't know of but are worth investigating?
>

There is an important project also for web/database purposes missing on the
above list: mORMot. You should consider to investigate it too. :-)

Regarding Brook, there are two active versions of it:

1. https://github.com/risoflora/brookframework
2. https://github.com/risoflora/brookfreepascal

Let me explain starting from option 2, BrookFreePascal, which I'm going to
reference as B4F. As Michael commented (thanks dude! :-)), it is a
long-standing FCL-based project, providing high-level features making it
easy to develop FPC/Laz web applications. It was strong influenced by Slim
Framework, also active nowadays and, like Slim, B4F uses a basic routing
concept, which triggers predefined methods named as the same HTTP verbs,
like Get, Post, Delete etc., declared in the public scope of an action
class. The few lines below illustrates it:

...
  THello = class(TBrookAction)
  public
procedure Get; override;
  end;

procedure THello.Get;
begin
  Write('Hello Darius. I'm Brook on the Chromebook! :-)');
end;

initialization
  THello.Register('/hello');
...

If you run a Brook application containing these lines above, just navigate
to "/hello" to get the message "Hello Darius. I'm Brook on the Chromebook!
:-)" on your web browser and have a lot of fun.

Now, I'm going to explain the option 1 a bit, the new Brook Framework,
under active development, projected for Free Pascal and Delphi, which will
be referenced in next lines as BF. It was entirely written from scratch
with special care for embedded systems. BF routing was and is still
inspired by projects like Express, Flask, Laravel, and its components
follows some RAD concepts adopted by DataSnap/fpWeb. For example, if you
have a console or VCL project, you can turn it into a web server
application: at design time, just drag-drop three components (
BrookLibraryLoader1, BrookHTTPServer1 and BrookHTTPRouter1) to a form or
data module, define a regular expression pattern for a route item and
implement its request event:

... [.lfm or .dfm]

  object BrookHTTPRouter1: TBrookHTTPRouter
Routes = <
  item
Pattern = '/hello/(?P[a-zA-Z]+)'
OnRequest = BrookHTTPRouter1Routes0Request
  end>
  end

... [.pas]

procedure TForm1.BrookHTTPRouter1Routes0Request(ASender: TObject;
  ARoute: TBrookHTTPRoute; ARequest: TBrookHTTPRequest;
  AResponse: TBrookHTTPResponse);
begin
  AResponse.SendFmt('Hello %s', [ARoute.Variables['name']], 'text/html',
200);
end;

...

This way, if you navigate to "/hello/Darius", the message "Hello Darius"
will be displayed on the browser, however, any other invalid value, like "
/hello/*123*", will be automatically refused, due to pattern "
/hello/(?P[a-zA-Z]+)" defined to the route item.

There are a lot of features (three threading models, data compression,
on-demand content, JIT optimizations, etc.) with focus on performance that
I couldn't detail in a single message, but the most important info: BF
loads a GNU C library which provides a low-level API containing common HTTP
features that are a good replacement for HTTP servers like Apache, Nginx,
NodeJS, Civetweb and so on. In short, you can run your application in
production and provide web services in the same (or higher) performance as
those servers, just distributing a small single-file library with your
executable, that probably will already be using other library, like the
database client one, for example.

As I am starting this endeavor I would welcome any advisory or practical
> help. If someone is willing to support in any form, please contact me via
> PM.
>
> TIA for all pointers, tips, and suggestions.
>
> Regards, Darius


I'd like to make a naive suggestion for you regarding to server side. You
mentioned about several Chromebooks logging to the system. So, beforehand,
what do you think about simulating that scenario? It is a 

Re: [fpc-pascal] Feature Announcement: Support for multiple active helpers per type

2019-05-10 Thread silvioprog
On Fri, May 10, 2019 at 4:57 PM Sven Barth via fpc-pascal <
fpc-pascal@lists.freepascal.org> wrote:

> Hello together!
>
> We are pleased to announce that Free Pascal now supports the usage of
> multiple active helper types per extended type. This feature has been
> developed by Ryan Joseph, so thank you very much Ryan.
>

awesome news.

thanks for implementing it dudes, i'm going to update my git to test it!


> To enable this feature you need to use the new modeswitch multihelpers.
> This will then result in the following code to compile:
>
> === code begin ===
>
> {$mode objfpc}
> {$modeswitch typehelpers}
> {$modeswitch multihelpers}
>
> type
>TObjectHelper1 = type helper for TObject
>  procedure Foo;
>  procedure Foobar;
>end;
>
>TObjectHelper2 = type helper for TObject
>  procedure Bar;
>  procedure Foobar;
>end;
>
> procedure TObjectHelper1.Foo;
> begin
>Writeln('Foo');
> end;
>
> procedure TObjectHelper1.Foobar;
> begin
>Writeln('Foobar1');
> end;
>
> procedure TObjectHelper2.Bar;
> begin
>Writeln('Bar');
> end;
>
> procedure TObjectHelper2.Foobar;
> begin
>Writeln('Foobar2');
> end;
>
> var
>o: TObject;
> begin
>o.Foo;
>o.Bar;
>o.Foobar; // this will call TObjectHelper2.Foobar
> end.
>
> === code end ===
>
> As can be seen in the example above if a member is present in multiple
> helpers then it will be resolved by the usual scoping rules. More common
> is however is to have helpers in different units:
>
> === code begin ===
>
> unit test1;
>
> {$mode objfpc}
> {$modeswitch typehelpers}
>
> interface
>
> type
>TObjectHelper1 = type helper for TObject
>  function Func: LongInt;
>end;
>
> implementation
>
> function TObjectHelper1.Func: LongInt;
> begin
>Result := 1;
> end;
>
> end.
>
> unit test2;
>
> {$mode objfpc}
> {$modeswitch typehelpers}
>
> interface
>
> type
>TObjectHelper2 = type helper for TObject
>  function Func: LongInt;
>end;
>
> implementation
>
> function TObjectHelper2.Func: LongInt;
> begin
>Result := 2;
> end;
>
> end.
>
> program testA;
>
> uses
>test1, test2;
>
> var
>o: TObject;
> begin
>Writeln(o.Func); // will print 2
> end.
>
> program testB;
>
> uses
>test2, test1;
>
> var
>o: TObject;
> begin
>Writeln(o.Func); // will print 1
> end.
>
> === code end ===
>
> Sidenote: yes, modeswitch typehelpers also allows "type helper" to be
> used with classes and records.
>
> Regards,
> Sven


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

Re: [fpc-pascal] [OT] Mantis offline

2019-05-10 Thread silvioprog
Thanks for checking it dudes. 

(maybe DNS issues)

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

[fpc-pascal] [OT] Mantis offline

2019-05-10 Thread silvioprog
Hello.

Could anyone check if Mantis is online? I've tried to access
http://bugs.freepascal.org now (Fri 10 May 2019 11:30:37 AM BRT), but got
"This site can’t be reached". Some hours ago it was OK.

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

Re: [fpc-pascal] Translating c records

2019-04-24 Thread silvioprog
On Wed, Apr 24, 2019 at 5:41 PM Rainer Stratmann <
rainerstratm...@t-online.de> wrote:

> struct sockaddr_ll {
>  unsigned short sll_family;
>  unsigned short sll_protocol;
>  intsll_ifindex;
>  unsigned short sll_hatype;
>  unsigned char  sll_pkttype;
>  unsigned char  sll_halen;
>  unsigned char  sll_addr[8];
>  };
>
> type
>  sockaddr_ll = record
>   sll_family : word;
>   sll_protocol : word;
>   sll_ifindex : integer;
>   sll_hatype : word;
>   sll_pkttype : byte;
>   sll_halen : byte;
>   sll_addr: array[ 0 .. 7 ] of byte;
>  end;
>
> Is this correct?


It seems OK, however, if you want portability too, you should:

uses
  ctypes;

{$PACKRECORDS C} // already commented by Michael

type
  sockaddr_ll = record
sll_family: cushort;
sll_protocol: cushort;
sll_ifindex: cint;
sll_hatype: cushort;
sll_pkttype: cuchar;
sll_halen: cuchar;
sll_addr: array[0..7] of cuchar;
 end;

cheers

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

Re: [fpc-pascal] Registers used by calling conventions

2019-03-08 Thread silvioprog
On Fri, Mar 8, 2019 at 6:34 PM Anthony Walter  wrote:

> What registers are used by default calling convention and where can I find
> more information about Free Pascal asm details?
>

For linux64 the default C.C is sysv x64. Some links with info you are
looking for:

1. https://bugs.freepascal.org/view.php?id=34743 (a low-level
Delphi-like invoke() almost done for Linux x86_64)
2. https://www3.nd.edu/~dthain/courses/cse40243/fall2017/intel-intro.html
(Introduction to X86-64 Assembly for Compiler Writers)
3. https://www.uclibc.org/docs/psABI-x86_64.pdf (System V ABI [AMD64])
4. https://wiki.osdev.org/System_V_ABI (some related links)

[]

> Also is it possible to get the Lazarus assembler to show instructions in
> Intel mode rather than AT?
>

Yes, just change the $asmmode to the syntax you want, e.g {$asmmode intel}.

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

Re: [fpc-pascal] PMake a new build tool

2019-02-27 Thread silvioprog
On Wed, Feb 27, 2019 at 7:13 PM Darius Blaszyk  wrote:

> Hi,
>

Hi Darius.


> I would like to inform everyone interested here that I just made a beta
> release (v0.0.2) of a build tool I have been developing for some of my
> projects which is called PMake.
> PMake is inspired on FPMake and CMake, but much easier in its use (as far
> as I am concerned). It compiles build "script" code into a "make" tool and
> regenerates the build tools on demand. A nice feature is autogenerating the
> build scripts, based on the files in the source tree. You can also do
> out-of-source builds and install files and package files (ZIP only for
> now). PMake parses the output of FPC to create visually more distinctive
> output.
> The basic concept are collections of unit files called libraries. These
> libraries are labelled symbolically. The labels are used to assign
> dependencies. It's also possible to create dependencies on generated output
> (revision number to source file for instance) and compiled files, then
> generating output even (some tool that generates an output file in turn).
> There even much more...
>
> The project is located here: https://github.com/daar/pmake
>

This is great news!

I'm familiar to CMake and your tool looks like a lot its script syntax. :-)

I've looked for something like this to automate the build of some projects
I'm maintaining, so I have some questions:

Could it build a Delphi-based project too? If so, does it allows to select
the build for a specific platform/config? (e.g: Win32/Release)

Could I link the build of an external 3rd party project to automate it
inside a PMake-based project? For example, supposing I have a C library
using CMake-based build, could this library be built while (before or
after) the PMake builds the Pascal project? ( something like CMake's
ExternalProject_Add() and, optionally, some alternative to
ExternalProject_Get_Property() )

Please test if you like, comment if you have an idea or ignore if you're
> not interested...
>
> Rgds, Darius
>

I liked it. (y)

It probably will help me a lot to automate the build of
interlinked projects simultaneously using two or three commands. :-)

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

Re: [fpc-pascal] How do I take the float type of a field from a record?

2018-12-13 Thread silvioprog
Oh, please ignore and sorry for noise. I found the solution as soon as I
sent the e-mail. -.-

var
  F: PManagedField;
  R: TTestRecord;
  T, T2: PTypeData;
  I: Integer;
begin
  R := Default(TTestRecord);
  T := GetTypeData(TypeInfo(R));
  F := PManagedField(PByte(@T^.TotalFieldCount) + 4);
  for I := 0 to Pred(T^.TotalFieldCount) do
  begin
if F^.TypeRef^.Kind = tkFloat then
begin
  T2 := GetTypeData(F^.TypeRef);
  WriteLn(F^.TypeRef^.Kind, ':', T2^.FloatType);
end;
Inc(F);
  end;
end;

time to go to bed.

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

Re: [fpc-pascal] How do I take the float type of a field from a record?

2018-12-13 Thread silvioprog
Oops...

On Fri, Dec 14, 2018 at 3:35 AM silvioprog  wrote:
[...]

> WriteLn(F^.TypeRef^.Kind, ':tk', F^.TypeRef^.Name);
>

I meant "':*ft*', F^.TypeRef^.Name);".

Anyway, still a very ugly workaround.

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

[fpc-pascal] How do I take the float type of a field from a record?

2018-12-13 Thread silvioprog
Hi.

Please consider the following code:

uses TypInfo;

type
  TTestRecord = record
Member1: LongInt;
Member2: Double;
Member3: string;
Member4: Extended;
  end;

var
  F: PManagedField;
  R: TTestRecord;
  T, T2: PTypeData;
  I: Integer;
begin
  R := Default(TTestRecord);
  T := GetTypeData(TypeInfo(R));
  F := PManagedField(PByte(@T^.TotalFieldCount) + 4);
  T2 := GetTypeData(F^.TypeRef);
  for I := 0 to Pred(T^.TotalFieldCount) do
  begin
if F^.TypeRef^.Kind = tkFloat then
  WriteLn(F^.TypeRef^.Kind, ':', T2^.FloatType);
Inc(F);
  end;
end.

it prints:

tkFloat:ftCurr
tkFloat:ftCurr

is there any chance to print it as below using FloatType?:

tkFloat:ftDouble
tkFloat:ftExtended

I solved it temporally using the following workaround (removing the last
four chars when the floating type is "Currency"):

WriteLn(F^.TypeRef^.Kind, ':tk', F^.TypeRef^.Name);

but I really would like to get the ordinal item instead of its name,
avoiding string handling.

Thank you!

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

Re: [fpc-pascal] Ho to convert a special format of datetime?

2018-12-13 Thread silvioprog
On Thu, Dec 13, 2018 at 5:07 PM luciano de souza 
wrote:

> Hello all,
> I'd like to convert this date "2017-01-11T17:47:22.2912317-02:00" to
> TDatetime.
>

uses restbase;

var
  d: TDateTime;
begin
  d := RFC3339ToDateTime('2017-01-11T17:47:22.2912317-02:00');
  WriteLn(DateTimeToStr(d)); // prints 11-1-17 17:47:22
end.

Anyway, I'm not sure regarding the tmz part, so take a look at Marco's
answer.

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

Re: [fpc-pascal] FPC-based http/s server

2018-12-11 Thread silvioprog
Hello dude,

On Mon, Dec 10, 2018 at 8:09 AM Michael Van Canneyt 
wrote:
[...]

> It does not support https yet, but this is planned for the near future.
> (I expect to work on it between this Christmas and new year)


Please consider support for TLS 1.3  (all
new web servers should use it).

GnuTLS  is a very good library (I've used it about
two years at company). Its API is clean, small, massively documented
, and its ABI is very stable
(about 99.83~100% between 2015-2018).

Cheers

p.s.: I made a X.509 based authentication using OpenSSL. Its API is a
little bit ugly and confuse, so I spent about three weeks working on that.
After, I did the same work using GnuTLS, so I spent just five days because
its API is better and contais this good manual
.

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

Re: [fpc-pascal] Dynamic array bug

2018-11-07 Thread silvioprog
On Thu, Nov 8, 2018 at 1:13 AM silvioprog  wrote:

> On Wed, Nov 7, 2018 at 11:06 PM Ryan Joseph 
> wrote:
>
>> I read the old thread and we need to add {$modeswitch arrayoperators} to
>> make it work. a += [4] does work now.
>>
>> Also I found the thread where Sven said he fixed the "Incompatible types:
>> got "Set Of Byte” bug in r39554 (
>> https://bugs.freepascal.org/view.php?id=34021). It is indeed fixed but
>> only for + operators.
>>
>> Do you want me to file a new bug report for := operators?
>
>
> You can temporary solve it by specializing a generic array:
>

... or forcing the compiler to get the correct type by cast:

type
  TIntArray = array of integer;

...

var
  r: TMyRec;
begin
  r := TIntArray([1, 2, 3]);
...

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

Re: [fpc-pascal] Dynamic array bug

2018-11-07 Thread silvioprog
On Wed, Nov 7, 2018 at 11:06 PM Ryan Joseph 
wrote:

> I read the old thread and we need to add {$modeswitch arrayoperators} to
> make it work. a += [4] does work now.
>
> Also I found the thread where Sven said he fixed the "Incompatible types:
> got "Set Of Byte” bug in r39554 (
> https://bugs.freepascal.org/view.php?id=34021). It is indeed fixed but
> only for + operators.
>
> Do you want me to file a new bug report for := operators?


You can temporary solve it by specializing a generic array:

program project1;

{$mode objfpc}{$H+}
{$modeswitch advancedrecords}
{$modeswitch arrayoperators}

uses sysutils;

type
  TIntArray = specialize TArray;

  TMyRec = record
a: TIntArray;
class operator := (right: TIntArray): TMyRec;
  end;

class operator TMyRec.:= (right: TIntArray): TMyRec;
begin
  result.a := right;
end;

var
  r: TMyRec;
  a: TIntArray;
begin
  r := specialize TArray.Create(1, 2, 3);
  a := [1, 2, 3];
  a += [4];
end.

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

Re: [fpc-pascal] Dynamic array bug

2018-11-07 Thread silvioprog
On Wed, Nov 7, 2018 at 12:09 PM Ryan Joseph 
wrote:

>
> > On Nov 7, 2018, at 9:31 PM, silvioprog  wrote:
> >
> > Yes, it works. But only on Delphi:
> >
>
> That’s too bad, I don’t use Delphi mode. Should be in Objfpc mode also
> right?


Oops... I meant "in Delphi compiler". ^^'

Anyway, it doesn't compile in FPC (tested in both delphi and objfpc modes).

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

Re: [fpc-pascal] Dynamic array bug

2018-11-07 Thread silvioprog
On Wed, Nov 7, 2018 at 3:39 AM Ryan Joseph 
wrote:

> Good to know. I reported this before and Sven said it was fixed in an
> update (after another user had submitted the original patch).
>
> Are you able to get a := a + [4]; to work? I’m looking Sven’s old message
> titled "Feature announcement: Dynamic array extensions” and he says +
> operator now works.


Yes, it works. But only on Delphi:

a := a + [4];
writeln(a[3]); // prints 4

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

Re: [fpc-pascal] Dynamic array bug

2018-11-06 Thread silvioprog
Hi Ryan.

On Wed, Nov 7, 2018 at 1:13 AM Ryan Joseph 
wrote:

> I finally built the trunk today (version 3.3.1) to try new dynamic array
> features and a bug fix Sven did a while ago but I’m still getting errors.
>
> Did I get the wrong version or something? I thought these things were
> working now.


Same problem here:

Error: Incompatible types: got "Set Of Byte" expected "TMyRec"
Error: Operator is not overloaded: "TIntArray" + "Set Of Byte"

It seems a bug, because the same code works fine on Delphi by changing
operator from ":=" to its respective name "Implicit".

My compiler ver: FPC 3.3.1 [2018/11/07] for x86_64 (Linux)

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

Re: [fpc-pascal] Listing the type (even as string) of the parameters and the return of a function

2018-11-03 Thread silvioprog
On Thu, Nov 1, 2018 at 2:11 AM silvioprog  wrote:
[...]

> I took a look at some System V ABI manuals to start a draft based on them,
> adapting the assembly to the InvokeKernelWin64() signature idea. The
> draft works fine for six or more arguments and returns the function value
> too, but I need to check (probably next weekend) how to pass floating-point
> values to the XMM registers (I'm looking for references/manuals about).
>

Finally, I found a awesome material to study: the GCC's X86-64 assembly for
compiler writers. And after some successful tests, I concluded that:

- floating-point types with size 8 or less (double, single etc.) must be
set in XMM registers aligned in 8;
- floating-point types larger than 8 (extended) must be pushed to the stack
aligned in 10.

This is a small example to check it (environment used in the tests: Lazarus
2.1.0 r59363 FPC 3.1.1 x86_64-linux-gtk2):

===
program project1;

{$MODE DELPHI}
{$MACRO ON}
//{$DEFINE USE_EXTENDED}
{$IFDEF USE_EXTENDED}
 {$DEFINE FLOAT_TYPE := extended} // size 10
{$ELSE}
 {$DEFINE FLOAT_TYPE := double} // size 8
{$ENDIF}

uses sysutils;

procedure test(const a, b: FLOAT_TYPE);
begin
  writeln(a:0:2, ' - ', b:0:2);
end;

procedure call_test(arr: pointer; f: codepointer); assembler; nostackframe;
asm
  { save the base pointer }
  pushq %rbp
  { set new base pointer }
  movq  %rsp, %rbp

  { save callee-saved registers }
  pushq %rbx
  pushq %r12
  pushq %r13
  pushq %r14
  pushq %r15

{$IFDEF USE_EXTENDED}
  leaq 0(%rdi), %rdx
  movq (%rdx), %rax
  movq %rax, (%rsp)
  movq 0x8(%rdx), %ax
  movq %ax, 0x8(%rsp)

  leaq 10(%rdi), %rax
  movq (%rax), %rdx
  movq %rdx, 0x10(%rsp)
  movq 0x8(%rax), %ax
  movq %ax, 0x18(%rsp)
{$ELSE}
  movq 0(%rdi), %xmm0
  movq 8(%rdi), %xmm1
{$ENDIF}

  { call the function }
  callq *%rsi

  { restore callee-saved registers }
  popq %r15
  popq %r14
  popq %r13
  popq %r12
  popq %rbx

  { reset stack to base pointer }
  movq %rbp, %rsp
  { restore the old base pointer }
  popq %rbp
  { return to caller }
  retq
end;

var
  arr: array of FLOAT_TYPE;
begin
  Writeln(IntToStr(SizeOf(FLOAT_TYPE)));
{$PUSH}{$WARN 5090 OFF}
  setlength(arr, 2);
{$POP}
  arr[0] := 12.34;
  arr[1] := 45.67;
  call_test(@arr[0], @test);
end.
===

and the results was:

//{$DEFINE USE_EXTENDED}:

===
...
8
12.34 - 45.67
===

{$DEFINE USE_EXTENDED}:

===
...
10
12.34 - 45.67
===

I'm going to clone the Free Pascal repository from Github to work on this
feature (sysv ABI for Linux 64 for now). After some functional code I'll
send it as patch to the Mantis issues. I'm very interested in rtti.invoke()
support on Linux/ARM and Win32. :-)

(P.S.: Could you check the issue #34496? I'm not sure if saving the base
pointer is best way to solve the problem, but at least fixed the AV for
extended types)

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

Re: [fpc-pascal] Listing the type (even as string) of the parameters and the return of a function

2018-10-31 Thread silvioprog
On Tue, Oct 9, 2018 at 5:56 PM Sven Barth via fpc-pascal <
fpc-pascal@lists.freepascal.org> wrote:

> The main challenge is to find the time and motivation to implement the
> whole extended RTTI shenanigans. Though I hope that after my birthday this
> weekend I'll find the time to work on this as well as finish the support
> for dynamic packages.
>

Awesome.

Late happy birthday! ^^

Feel free to contribute here. A x64 SysV variant would be welcome as well.
>

I took a look at some System V ABI manuals to start a draft based on them,
adapting the assembly to the InvokeKernelWin64() signature idea. The draft
works fine for six or more arguments and returns the function value too,
but I need to check (probably next weekend) how to pass floating-point
values to the XMM registers (I'm looking for references/manuals about).

The "attachment A" is my first draft (improvements are welcome) for SysV,
and the "attachment B" is the original SystemInvoke() with just few
adjustments to handle the first six arguments in the six general use
registers and the rest on the stack.

Regards,
> Sven
>

Attachment A:

function InvokeKernelSysV(aArgsStackLen: PtrUInt; aArgsStack, aArgsReg:
Pointer; aFunc: CodePointer): PtrUInt; assembler; nostackframe;
asm
  { save the base pointer }
  pushq %rbp
  { set new base pointer }
  movq  %rsp, %rbp

  { save callee-saved registers }
  pushq %rbx
  pushq %r12
  pushq %r13
  pushq %r14
  pushq %r15

  { check if is six of less arguments, if so ... }
  cmpq $0, %rdi
je .L2

  { iterates and push all extra arguments to the stack }
  movq %rdi, %rax
.L1:
  decq %rax
  cmpq $0, %rax
  movq (%rsi, %rax, 8), %rbx
  pushq %rbx
  jne .L1

  { ... skip the iteration above }
.L2:

  { get the stack and the function pointer }
  movq %rdx, %rbx
  movq %rcx, %rax

  { setup general purpose registers }
  movq 0(%rbx), %rdi
  movq 8(%rbx), %rsi
  movq 16(%rbx), %rdx
  movq 24(%rbx), %rcx
  movq 32(%rbx), %r8
  movq 40(%rbx), %r9

  { TODO: fill XMM0..XMM7 registers }

  { call the function }
  callq *%rax

  { restore callee-saved registers }
  popq %r15
  popq %r14
  popq %r13
  popq %r12
  popq %rbx

  { reset stack to base pointer }
  movq %rbp, %rsp
  { restore the old base pointer }
  popq %rbp
  { return to caller }
  ret
end;

Attachment B:

procedure SystemInvoke(aCodeAddress: CodePointer; const aArgs:
TFunctionCallParameterArray; aCallConv: TCallConv;
aResultType: PTypeInfo; aResultValue: Pointer; aFlags:
TFunctionCallFlags);
type
  PBoolean16 = ^Boolean16;
  PBoolean32 = ^Boolean32;
  PBoolean64 = ^Boolean64;
  PByteBool = ^ByteBool;
  PQWordBool = ^QWordBool;
var
  stackarea: array of PtrUInt;
  stackptr: Pointer;
  regs: array[0..5] of PtrUInt; // six registers
  i, regidx, stackidx: LongInt;
  val: PtrUInt;
  td: PTypeData;
  retinparam: Boolean;
  argcount, resreg: SizeInt;
begin
  if Assigned(aResultType) and not Assigned(aResultValue) then
raise EInvocationError.Create(SErrInvokeResultTypeNoValue);
  retinparam := False;
  if Assigned(aResultType) then begin
case aResultType^.Kind of
  tkSString,
  tkAString,
  tkUString,
  tkWString,
  tkInterface,
  tkDynArray:
retinparam := True;
end;
  end;

  stackidx := 0;
  regidx := 0;
  argcount := Length(aArgs);
  if retinparam then begin
if fcfStatic in aFlags then
  resreg := 0
else
  resreg := 1;
regs[resreg] := PtrUInt(aResultValue);
Inc(argcount);
  end else
resreg := -1;
  if argcount > 6 then
SetLength(stackarea, argcount - 6);
  for i := 0 to High(aArgs) do begin
if pfArray in aArgs[i].Info.ParamFlags then
  val := PtrUInt(aArgs[i].ValueRef)
else if aArgs[i].Info.ParamFlags * [pfOut, pfVar, pfConstRef] <> [] then
  val := PtrUInt(aArgs[i].ValueRef)
else begin
  td := GetTypeData(aArgs[i].Info.ParamType);
  case aArgs[i].Info.ParamType^.Kind of
tkSString,
tkMethod:
  val := PtrUInt(aArgs[i].ValueRef);
tkArray:
  if td^.ArrayData.Size in [1, 2, 4, 8] then
val := PPtrUInt(aArgs[i].ValueRef)^
  else
val := PtrUInt(aArgs[i].ValueRef);
tkRecord:
  if td^.RecSize in [1, 2, 4, 8] then
val := PPtrUInt(aArgs[i].ValueRef)^
  else
val := PtrUInt(aArgs[i].ValueRef);
{ ToDo: handle object like record? }
tkObject,
tkWString,
tkUString,
tkAString,
tkDynArray,
tkClass,
tkClassRef,
tkInterface,
tkInterfaceRaw,
tkProcVar,
tkPointer:
  val := PPtrUInt(aArgs[i].ValueRef)^;
tkInt64,
tkQWord:
  val := PInt64(aArgs[i].ValueRef)^;
tkSet: begin
  case td^.OrdType of
otUByte: begin
  case td^.SetSize of
0, 1:
  val := PByte(aArgs[i].ValueRef)^;
2:
  val := PWord(aArgs[i].ValueRef)^;
3:

Re: [fpc-pascal] Listing the type (even as string) of the parameters and the return of a function

2018-10-09 Thread silvioprog
On Mon, Oct 8, 2018 at 6:21 AM Sven Barth via fpc-pascal <
fpc-pascal@lists.freepascal.org> wrote:

> Short answer: No.
>
> Long answer: No. The extended RTTI required for that is currently only
> generated for interfaces with $M+ set.
>
> Regards,
> Sven
>

Hi Sven, thanks for replying.

What are the challenges to implement this feature? (Besides changes in the
current ABI, new types in the typinfo etc.)

I'm busy developing a library for the company, but, after that, I would
like to contribute the assembly on invoke.inc for x86/ARM (32-bit only).

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

[fpc-pascal] Listing the type (even as string) of the parameters and the return of a function

2018-10-08 Thread silvioprog
Hi.

First, thanks for the great work in the invoke.inc for win64! ☺

So, consider the following example:

uses RTTI;

type
  TFoo = class
  public
function Bar(const A: string; B: Integer): string;
  end;

function TFoo.Bar(const A: string; B: Integer): string;
begin
end;

var
  m: TRttiMethod;
  p: TRttiParameter;
begin
  m := TRttiContext.Create.GetType(TFoo.ClassInfo).GetMethod('Bar');
  Writeln('m: ', m.ReturnType.ToString);
  for p in m.GetParameters do
Writeln(' p: ', p.ParamType.ToString);
end.

in Delphi, it returns:

m: string
 p: string
 p: Integer

in the current stage of RTTI or TypInfo, is there any way to retrieve the
type (even as string) of the parameters and the return of a function
passing its name as string and only the vtypeinfo of the instance of showed
in the above example?

Thanks in advance!

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

[fpc-pascal] [FEATURE REQUEST] SysUtils.TMarshaller type

2017-12-15 Thread silvioprog
Hi.

The TMarshaller record is a high-level aid for marshalling arguments to and
from OS / native API or interfacing with external libraries APIs.

This feature request was issued as #0032835 . If this feature can be useful
for you too, please help at this link:

https://bugs.freepascal.org/view.php?id=32835

Thank you!

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

Re: [fpc-pascal] Call function in shared library from multiple threads

2017-03-31 Thread silvioprog
On Fri, Mar 31, 2017 at 1:15 PM, Henry Vermaak 
wrote:

> On Fri, Mar 31, 2017 at 08:42:24AM -0700, fredvs wrote:
> > > Z:\home\fred\uos\examples\uos.pas(7438,29) Warning: (4046)
> Constructing a
> > > class "TThread" with abstract method "Execute"
> >
> > Huh, is it Is it serious doctor?
>
> I use this:
>
> function DummyThread(param: pointer): ptrint;
> begin
>   Result := 0;
>   EndThread(Result);
> end;
>
> begin
>   BeginThread(@DummyThread);
>   ...
>   ...
> end.


What about calling TM directly? Something like this:

uses cthreads;
var
  TM: TThreadManager;
begin
  TM := Default(TThreadManager); // just hiding hint 'variable TM doesn't
seem to be initialized'
  GetThreadManager(TM);
  IsMultiThread := TM.InitManager;
...
end.

I can't test it now (I would like to debug it asap), but I think FPC offer
some option to start the TM without starting a new -- dummy -- thread. o.O

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

Re: [fpc-pascal] Hash List

2017-03-17 Thread silvioprog
You're welcome. :-)

Notice the first link I've passed is exactly showing the TDictionary,
recently added to FPC:
https://github.com/graemeg/freepascal/blob/master/packages/rtl-generics/src/inc/generics.dictionariesh.inc#L534
.

You should take a look at that. :-)

On Sat, Mar 18, 2017 at 12:54 AM, African Wild Dog 
wrote:

> Thanks for your reply Giuliano, Silvio.
>
> To be more specific, i need a generic hash map similar to the Delphi's
> TDictionary.
>
> It seems THashmap from the ghashmap unit is the most close to TDictionary.
>
> Regards
>

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

Re: [fpc-pascal] Hash List

2017-03-17 Thread silvioprog
On Fri, Mar 17, 2017 at 8:29 PM, African Wild Dog 
wrote:

> Hello,
>
> Ia there any hash list implementation in free Pascal?
>

Hello,

Please take a look at these examples:

https://github.com/graemeg/freepascal/tree/master/packages/rtl-generics/examples

and in this wiki page:

http://www.freepascal.org/docs-html/3.0.0/fcl/contnrs/tfphashlist.html


> Ghashmap has no documentation. Is it stable for production use?
>

Some info: https://www.mii.lt/olympiads_in_informatics/pdf/INFOL101.pdf

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

Re: [fpc-pascal] Feature announcement: Interface RTTI

2017-01-28 Thread silvioprog
On Sat, Jan 28, 2017 at 9:29 AM, Sven Barth 
wrote:

> Hello together!
>
> I'm pleased to finally announce the addition of Interface RTTI to Free
> Pascal.
>
> Interface RTTI essentially provides a list of all methods available in
> an interface if it's declared is parsed with $M+ or has such an
> interface as parent.


Great news. Finally I'm going to make some my RTTI layer written in Delphi
compatible with Free Pascal. Thank you for making it even better!

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

Re: [fpc-pascal] Pipe vs Memory buffer.

2017-01-26 Thread silvioprog
On Thu, Jan 26, 2017 at 11:52 PM, fredvs  wrote:

> Hello Silvio:
>
> Yes, we are on the good way.
>

Awesome. :-)


> Following your advice, here from https-url-opus the result of :
>
> var
>   BufferURL: tbytes;
>
>   setlength(BufferURL, PipeBufferSize);
>   CreatePipeHandles(InHandle, OutHandle, PipeBufferSize);
>   InPipe := TInputPipeStream.Create(InHandle);
>   OutPipe := TOutputPipeStream.Create(OutHandle);
>   httpget := TThreadHttpGetter.Create(url, OutPipe);
>   InPipe.Read(BufferURL[0],PipeBufferSize);
>
>   writeln(tencoding.utf8.getstring(BufferURL));
>
> ==>
>
> Lavf57.57.100  encoder=Lavc57.65.100 libopus title=Be Thankful%artist=For
> What You GotWilliam De Vau$album=Blaxploitation Vol.3 The Payba
> date=1997TRACKNUMBER=11OggS

[...]

Some streams requires you set its cursor to 0 before writing/reading
buffer, so you need to check it:

  CreatePipeHandles(InHandle, OutHandle, PipeBufferSize);
  InPipe := TInputPipeStream.Create(InHandle);
  OutPipe := TOutputPipeStream.Create(OutHandle);
  httpget := TThreadHttpGetter.Create(url, OutPipe);
  OutPipe.Seek(0, soBeginning);
  InPipe.Seek(0, soBeginning);
  InPipe.Read(BufferURL[0],PipeBufferSize);

Notice tencoding was just for testing. :-)

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

Re: [fpc-pascal] Pipe vs Memory buffer.

2017-01-26 Thread silvioprog
On Thu, Jan 26, 2017 at 8:20 PM, fredvs  wrote:

> Hello.
>
> Some news from the front:
>
> var
> BufferURL : array of float;
>
> .
>
> PipeBufferSize := $4000 ;
>
> CreatePipeHandles(InHandle, OutHandle, PipeBufferSize);
>
> InPipe := TInputPipeStream.Create(InHandle);
> OutPipe := TOutputPipeStream.Create(OutHandle);
> httpget := TThreadHttpGetter.Create(opus_url,OutPipe);
>
> setlength(BufferURL, PipeBufferSize);
>
> // This to have the buffer as parameter ???
> InPipe.Read(BufferURL,PipeBufferSize);
>
> op_test_memory(BufferURL,PipeBufferSize, Err);
>
> => Gives as error:  -133 =>
> A required header packet was not properly formatted, contained illegal
> values, or was missing altogether.
>
> So it seems that the buffer was accepted, only miss the header ?
>
> Difficult to explore when there is no documentation how to do nor examples.
>

I had never tried pipes before, but it seems FPC has a unit to handle that:
`iostream`, so today I played a very simple test:

program project1;
uses sysutils, iostream;
const buf_sz = 1024;
var
  buf: tbytes;
  sz: longint;
  stdin: tiostream;
begin
  stdin := tiostream.create(iosinput);
  try
setlength(buf, buf_sz);
// it is just a test, so I limited it to 1024 bytes, please read the
entire content by yourself! :-)
sz := stdin.read(buf[0], buf_sz);
if sz < buf_sz then
  setlength(buf, sz);
writeln(tencoding.utf8.getstring(buf));
  finally
stdin.free;
  end;
end.

in my terminal:

$ echo "Yes" | ./project1
Yes

However, I don't know if you are searching exactly that, anyway you can
check the iosinput sources. :-)

Any idea is highly welcome.
>
> Fe;D
>
> -
> Many thanks ;-)


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

Re: [fpc-pascal] Array as result in function.

2017-01-21 Thread silvioprog
On Sat, Jan 21, 2017 at 11:11 AM, fredvs  wrote:

> Hello everybody.
>
> Do you agree with this ? :
>
> type
>   TOggOpusFile = ^OggOpusFile;
>   OggOpusFile = record
>   end;
>
> op_read: function(OpusFile: TOggOpusFile; pcm : pcfloat; SampleCount:
> Integer; li: pointer): Integer;
>

It's almost there. :-)

Notice my message regarding the op_read's pcm and li parameters type ...

op_read_float: function(OpusFile: TOggOpusFile; pcm : pcfloat; SampleCount:
> Integer; li: pointer): Integer;
> op_read_stereo: function(OpusFile: TOggOpusFile; pcm : pcfloat;
> SampleCount:
> Integer): Integer;
> op_read_float_stereo: function(OpusFile: TOggOpusFile; pcm : pcfloat;
> SampleCount: Integer): Integer;
>
> Fre;D
>
> -
> Many thanks ;-)


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

Re: [fpc-pascal] Array as result in function.

2017-01-20 Thread silvioprog
On Fri, Jan 20, 2017 at 9:06 PM, silvioprog <silviop...@gmail.com> wrote:
[...]

> `_pcm` on original code is an `int16` buffer... consider to using `cint16`:
>

Damn Gmail's Ctrl+Enter. -.-'

I meant: "`_pcm` on original code is an `int16` buffer... consider to using
`*pcint16*`:"

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

Re: [fpc-pascal] Array as result in function.

2017-01-20 Thread silvioprog
On Fri, Jan 20, 2017 at 7:36 PM, fredvs  wrote:

> Re-hello.
>
> Ok, thanks Silvio, I will take this one from your advice, it works like
> charm:
>
> type
>   TOggOpusFile = THandle;
>

Hm... you should keep the same C data types. :-) I took a look at
`OggOpusFile` type, it is a struct:

https://github.com/gcp/opusfile/blob/9a9825df0319138fe845cbb19c250b642965c4b1/include/opusfile.h#L133

so on Pascal it makes more sense declared as:

type
  POggOpusFile = ^OggOpusFile;
  OggOpusFile = record
  end;

and finally:

op_read: function(OpusFile: POggOpusFile; ...

`PDArFloat` seems OK to `op_read_float`, but notice last comment regarding
`_pcm`.

"li: pointer" should be "li: pcint" in both funcs.

go slowly: these changes can raise new errors on your code. :-)

  TDArFloat = array of cfloat;
>   PDArFloat = ^TDArFloat;
>
> op_read: function(OpusFile: TOggOpusFile; pcm : PDArFloat; SampleCount:
> Integer; li: pointer): Integer;
>

`_pcm` on original code is an `int16` buffer... consider to using `cint16`:

https://github.com/gcp/opusfile/blob/9a9825df0319138fe845cbb19c250b642965c4b1/include/opusfile.h#L1873

op_read_float: function(OpusFile: TOggOpusFile; pcm : PDArFloat;
> SampleCount: Integer; li: pointer): Integer;
>
> Many thanks.
>
> Fre;D


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

Re: [fpc-pascal] Array as result in function.

2017-01-20 Thread silvioprog
On Fri, Jan 20, 2017 at 7:11 PM, fredvs  wrote:

> Hello Silvio.
>
> Wow, thanks, I will study it deep.
>
> By the way, the Opus Pascal wrappers are working.
> You may listen, seek, saving to file, apply dsp,.. to Opus files.
> You may try SimplePlayer demo in uos (all libraries and Opus-audiofile
> included):
>
> https://github.com/fredvs/uos
>
> PS: BufferIn is working only if it is a array of cfloat (from ctypes.pas).
> With array of double, array of float,.. it does not work.


Yes, because C `float`'s size is 4, and Pascal `double`'s, 8. Pascal
`cfloat` is just a alias to `single`, 4. :-) Try two tests:

$ echo -e '#include \nint main(){printf("size of float: %zu\\n",
sizeof(float));return 0;}' > fredvs.c && gcc -o fredvs fredvs.c && clear &&
./fredvs # it prints "size of float: 4" on your terminal

and:

$ echo "program fredvs;begin writeln('sizeof double: ',
sizeof(double));writeln('size of single: ', sizeof(single));end." >
fredvs.pp && fpc fredvs.pp && clear && ./fredvs # it prints "sizeof double:
8" and "size of single: 4" on your terminal

Some useful links:

FPC Real types:
http://freepascal.org/docs-html/ref/refsu6.html#x28-310003.1.2
C - Data Types: https://www.tutorialspoint.com/cprogramming/c_data_types.htm
Delphi to C++ types mapping:
http://docwiki.embarcadero.com/RADStudio/Berlin/en/Delphi_to_C%2B%2B_types_mapping

Fre;D
>
> -
> Many thanks ;-)


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

Re: [fpc-pascal] Array as result in function.

2017-01-20 Thread silvioprog
On Fri, Jan 20, 2017 at 5:14 PM, silvioprog <silviop...@gmail.com> wrote:
[...]
>
> It seems that function just increment the address of a (float) buffer, so:
>

I meant "It seems that function just fill a (float) buffer". ^^'

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

Re: [fpc-pascal] Array as result in function.

2017-01-20 Thread silvioprog
On Fri, Jan 20, 2017 at 3:45 PM, fredvs  wrote:
>
> Here, for example from OpusFile.h =>
>
> OP_WARN_UNUSED_RESULT int op_read_float(OggOpusFile *_of,
>  float *_pcm,int _buf_size,int *_li) OP_ARG_NONNULL(1);
>
> Translated in fpc with:
>
> op_read: function(OpusFile: TOggOpusFile; var pcm; SampleCount: Integer;
> li:
> pointer): Integer;
>
> And used like this:
> BufferIn : array of cfloat;
>
> outframes := op_read_float(HandleOF,BufferIn[0],Wantframes *Channels,
> nil);
>

You should keep the Pascal code syntax closest to the C one, something like
this:

uses ctypes;

POggOpusFile = ^TOggOpusFile
TOggOpusFile = record // please check if original C struct uses some
alignment ...
end;

function op_read_float(_of: POggOpusFile; _pcm: Pcfloat; _buf_size: cint;
_li: pcint): cint; cdecl; ... blah blah blah
// or dynamic loading like you showed (on Delphi you can use the `delayed`
keyword instead of declaring `GetProcedureAddress` by hand :-) )

{$MACRO ON}
{$DEFINE OP_ARG_NONNULL := op_read_float}

It is useful when we need to translate the examples.

It seems that function just increment the address of a (float) buffer, so:

var
...
  buf: pcfloat;
begin
  ... HandleOF/buf initialization etc. ...
  outframes := OP_ARG_NONNULL(HandleOF, buf, Wantframes * Channels, nil);
... code ...
  buf += (Wantframes * Channels) * sizeof(cfloat) // or inc(buf,
(Wantframes * Channels) * sizeof(cfloat));

( you can try "buf += Wantframes * Channels; // or inc(buf, Wantframes *
Channels);" too )

I'm not sure if it works, but you can check it by yourself. :-)


> The nice thing is that BufferIn can be used for portaudio, soundfile,
> mpg123, aac buffers and is working like charm.


Awesome. :-)

Fre;D
>
> -
> Many thanks ;-)


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

Re: [fpc-pascal] Array as result in function.

2017-01-20 Thread silvioprog
On Fri, Jan 20, 2017 at 1:12 PM, fredvs  wrote:
[...]

Please look at Sven's warn regarding Pascal arrays mixed with C arrays.

Could you show us the original C function?

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

Re: [fpc-pascal] Array as result in function.

2017-01-19 Thread silvioprog
On Thu, Jan 19, 2017 at 6:50 PM, fredvs  wrote:

> Hello.
>
> With this code, the result of the function does not have same format as the
> array input:
>
> Why ?
>
> type
>   TArFloat = array of cfloat;
>
> function array_in_out(arrayin: TArFloat): TArFloat;
> begin
> result := arrayin;
> end;
>

It works fine here. Eg:

=== begin code ===

type
  TArFloat = array of cfloat;

function array_in_out(arrayin: TArFloat): TArFloat;
var
  i: byte;
begin
  for i := low(arrayin) to high(arrayin) do
arrayin[i] *= 10;
  Result := arrayin;
end;

...

var
  item: cfloat;
  thebuffer: TArFloat;
begin
  SetLength(thebuffer, 3);
  thebuffer[0] := 1;
  thebuffer[1] := 2;
  thebuffer[2] := 3;
  WriteLn('before');
  for item in thebuffer do
WriteLn(item.ToString);
  thebuffer := array_in_out(thebuffer);
  WriteLn('after x10');
  for item in thebuffer do
WriteLn(item.ToString);
end;

// output:

before
1
2
3
after x10
10
20
30

=== end code ===


> Some more explaination.
>
> If in a code I use:
> var
> thebuffer: TArFloat;
>
> // thebuffer was filled with some float-samples
>
> thebuffer := array_in_out(thebuffer);
>
> It is not neutral, the data are affected (in audio the data are noisy).
>
> What is wrong ?
>

Are you using that function as callback with some (C/C++) library? If so,
check its parameter calling convention, declaring it as `function
array_in_out(arrayin: TArFloat): TArFloat; cdecl;`.


> Thanks.
>
> Fre;D


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

Re: [fpc-pascal] Missing messages

2016-11-03 Thread silvioprog
On Thu, Nov 3, 2016 at 7:01 PM, Bo Berglund <bo.bergl...@gmail.com> wrote:

> On Tue, 1 Nov 2016 23:44:09 -0300, silvioprog
> <silviop...@gmail.com> wrote:
>
> >-begin off-
> >Oh my, I remember a big problem I had in my email months ago... trying to
> >reduce receiving spams, I tried clients like Thunderbird, however, I
> forgot
> >to check the option 'keep the emails on the server', losing all mails from
> >client and server, not knowing if someone had contacted me at that time.
> x(
> >-end off-
> As a client you cannot lose the messages in an NNTP scenario, they are
> always available on the server
>
> --
> Bo Berglund
> Developer in Sweden


Yes, but I've used IMAP in my personal email (this one receiving this
message). :-/

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

Re: [fpc-pascal] Missing messages

2016-11-01 Thread silvioprog
On Sun, Oct 30, 2016 at 12:43 PM, José Mejuto  wrote:

>

> Hello,
>
> Today I had detected that some emails does not reach me in this mailing
list, in fact the last ones from "leledumbo" about JSON parsing, but Graeme
and Michael ones arrive successfully

I've had the same problem (I'm using Gmail client on Google Chrome) for
months. Unfortunately, all Sven's/leledumbo's mails still arrive to spam
folder, even after I mark them as trusted senders. :-/

-begin off-
Oh my, I remember a big problem I had in my email months ago... trying to
reduce receiving spams, I tried clients like Thunderbird, however, I forgot
to check the option 'keep the emails on the server', losing all mails from
client and server, not knowing if someone had contacted me at that time. x(
-end off-

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

Re: [fpc-pascal] Does MACRO work in this case?

2016-09-18 Thread silvioprog
On Thu, Sep 8, 2016 at 6:27 PM, David Emerson <dle...@angelbase.com> wrote:

> On 09/08/2016 10:08 AM, silvioprog wrote:
>
>> Hello,
>>
>> Looking an alternative to solve the problem I've talked at this topic
>> <http://lists.freepascal.org/pipermail/fpc-pascal/2016-August/048635.html
>> >,
>> I've tried to solve it declaring a macro named "TIStringComparer.Ordinal":
>>
>
> Macros can only replace identifiers, the dot breaks it.
>
> I would make something like,
>
> _TIStringComparer_dot_Ordinal
>
> and then you can use the definition you proposed.
>
> I'm in the habit of naming macros with a leading underscore, as I don't
> name anything else that way and it makes it easy to identify them.


Thanks for sharing this info regarding macros. :-)

I've declared a macro trying to keep the Delphi syntax, so unfortunately I
can't declare it as _TIStringComparer_dot_Ordinal instead of
TIStringComparer.Ordinal, hence I've temporally declared it as:

class constructor TFoo.Bar;
begin
...
  GVariables := TDictionary<string, string>.Create(
{$IFDEF FPC}
// see http://lists.freepascal.org/pipermail/fpc-pascal/2016-
August/048635.html
TEqualityComparer.Construct(EqualityComparison, ExtendedHasher)
{$ELSE}
TIStringComparer.Ordinal
{$ENDIF});
end;

but I will remove the implementation above as soon as rtl-generics allow to
use TIStringComparer.Ordinal without workarounds.

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

[fpc-pascal] Does MACRO work in this case?

2016-09-08 Thread silvioprog
Hello,

Looking an alternative to solve the problem I've talked at this topic
,
I've tried to solve it declaring a macro named "TIStringComparer.Ordinal":

=== begin code ===

{$IFDEF FPC}

function EqualityComparison(constref ALeft, ARight: string): Boolean;
begin
  Result := CompareText(ALeft, ARight) = 0;
end;

function ExtendedHasher(constref AValue: string): UInt32;
var
  S: string;
begin
  S := LowerCase(AValue);
  Result := TDefaultHashFactory.GetHashCode(Pointer(S), Length(S) *
SizeOf(Char), 0);
end;

// see http://lists.freepascal.org/pipermail/fpc-pascal/2016-August
/048635.html
{$MACRO ON}
{$DEFINE TIStringComparer.Ordinal :=
TEqualityComparer.Construct(EqualityComparison,
ExtendedHasher) }

{$ENDIF}

=== end code ===

The macro is just for retro-compatibility with Delphi, allowing to use this
syntax:

GVariables := TDictionary.Create(TIStringComparer.Ordinal);
// the macro should replace it, but ...

However, it seems the macro can't replace the original
"TIStringComparer.Ordinal" to my
"TEqualityComparer.Construct(EqualityComparison,
ExtendedHasher)" definition.

So, is macro indicated to solve this kind of problem?

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

Re: [fpc-pascal] Could someone explain me which the correct triggering of the BeforeDestruction method?

2016-09-06 Thread silvioprog
On Tue, Sep 6, 2016 at 5:10 PM, silvioprog <silviop...@gmail.com> wrote:

> On Tue, Sep 6, 2016 at 5:18 AM, Maciej Izak <hnb.c...@gmail.com> wrote:
>
>>
>> 2016-09-05 17:56 GMT+02:00 silvioprog <silviop...@gmail.com>:
>>
>>> FPC triggers 132, Delphi 1342. :-/
>>
>>
>> Please report on bug tracker. IMO in presented context - definitely bug.
>>
>
> Sweet, I'm going to do it tonight. :-)
>

Done: http://bugs.freepascal.org/view.php?id=30570 .

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

Re: [fpc-pascal] Could someone explain me which the correct triggering of the BeforeDestruction method?

2016-09-06 Thread silvioprog
On Tue, Sep 6, 2016 at 5:18 AM, Maciej Izak <hnb.c...@gmail.com> wrote:

>
> 2016-09-05 17:56 GMT+02:00 silvioprog <silviop...@gmail.com>:
>
>> FPC triggers 132, Delphi 1342. :-/
>
>
> Please report on bug tracker. IMO in presented context - definitely bug.
>

Sweet, I'm going to do it tonight. :-)

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

Re: [fpc-pascal] Could someone explain me which the correct triggering of the BeforeDestruction method?

2016-09-05 Thread silvioprog
On Sun, Sep 4, 2016 at 5:23 PM, Luiz Americo Pereira Camara <
luizameri...@gmail.com> wrote:

> Seems that Delphi considers that the object is already created at the time
> AfterConstruction is called, so it understands that when it gets into
> AfterConstruction is sucessfully created. Semantically makes sense.
>
> The counter proof is see if AfterConstruction is called when a exception
> occurs in constructor
>
And I'm even still not sure about BeforeDestruction triggering, FPC
triggers 132, Delphi 1342. :-/

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

Re: [fpc-pascal] GZip - Stream decompress only in memory

2016-09-05 Thread silvioprog
On Mon, Sep 5, 2016 at 2:50 AM, Michael Van Canneyt 
wrote:
[...]

> As far as I know these things can be done with all the FPC classes as well
> ?
> The implementation in base64 unit can perfectly do everything in memory.
> And ZUncompressStream can be done with TDecompressionStream ?
>

Perfect! :-)


> Var
>   Dest : TFileStream;
>   B : TBase64DecodingStream;
>   Z : TDecompressionStream;

[...]

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

Re: [fpc-pascal] GZip - Stream decompress only in memory

2016-09-04 Thread silvioprog
On Sep 4, 2016 5:29 PM, "Marcos Douglas"  wrote:
>
> Ok, it works now.

Great!

> For the records, I've used the lib http://www.gocher.me/GZIP (Silvio's
> tip) and the function Base64Decode from WST framework
> http://svn.code.sf.net/p/lazarus-ccr/svn/wst/trunk/
>
> For some reason the function DecodeBase64 from Synapse doesn't work.
> It receives an AnsiString. Instead, the Base64Decode function receives
> a TByteDynArray.
>
> The TDataStream class doesn't matter...
>
> So, the code below is ugly, but shows how it works now (before the
refactoring).
>
> Thank you all for the help.
>
> === begin ===
>
> procedure TMainForm.Button2Click(Sender: TObject);
> var
>   Buf,Buf2: TMemoryStream;
>   B: TByteDynArray;
> begin
>   Buf := TMemoryStream.Create;
>   Buf2 := TMemoryStream.Create;
>   try
> Buf.LoadFromFile('result.txt');
> B := Base64Decode(TDataStream.New(Buf).AsString,
> [xoDecodeIgnoreIllegalChar]);
> Buf.SaveToFile('bytes.txt');
> Buf.Clear;
> Buf.WriteBuffer(Pointer(B)^, Length(B));

I'm on the phone, but looking this part it seems that base64 unconversion
can be done directly in memory too. I can try it after...

> if ZUncompressStream(Buf, Buf2) then
>   Buf2.SaveToFile('content.txt');
>   finally
> Buf.Free;
> Buf2.Free;
>   end;
> end;
>
> === end ===
>
> Best regards,
> Marcos Douglas

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

[fpc-pascal] Could someone explain me which the correct triggering of the BeforeDestruction method?

2016-09-03 Thread silvioprog
Hello,

My question at title seems stupid, but the reason why I've get this doubt
is just because it get different results between Free Pascal and Delphi in
the following example:

=== begin code ===

program project1;

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$IFDEF MSWINDOWS}
  {$APPTYPE CONSOLE}
{$ENDIF}

uses SysUtils;

type
  TSomeClass = class
  public
procedure LoadSomething;
  end;

  TA = class
  private
FSomeObject: TSomeClass;
  public
constructor Create; virtual;
destructor Destroy; override;
procedure AfterConstruction; override;
procedure BeforeDestruction; override;
property SomeObject: TSomeClass read FSomeObject;
  end;

procedure TSomeClass.LoadSomething;
begin
  raise Exception.Create('An exception loading something');
end;

constructor TA.Create;
begin
  WriteLn(1);
  inherited Create;
end;

destructor TA.Destroy;
begin
  WriteLn(2);
  inherited Destroy;
end;

procedure TA.AfterConstruction;
begin
  WriteLn(3);
  FSomeObject := TSomeClass.Create;
  FSomeObject.LoadSomething;
end;

procedure TA.BeforeDestruction;
begin
  WriteLn(4);
  FSomeObject.Free;
end;

var
  VA: TA;
begin
  VA := TA.Create;
  try
  finally
VA.Free;
  end;
end.

=== end code ===

I've compiled it in Free Pascal from trunk (version 3.1.1 [2016/08/26] for
x86_64) installed on a Xubuntu 16.04 64 bits, and got the following log:

$ ./project1
1
3
2
An unhandled exception occurred at $004001CD:
Exception: An exception loading something
  $004001CD  LOADSOMETHING,  line 30 of project1.lpr
  $0040045A  AFTERCONSTRUCTION,  line 50 of project1.lpr
  $004002CC  CREATE,  line 38 of project1.lpr
  $004004FA  main,  line 62 of project1.lpr

and I've compiled the same code in an original version of Delphi Pro
(version 10.1 Berlin 24.0.22858.6822), on a Windows 10 64 bits, and I got
the log below and a critical exception (notice the result numbers, they are
different from similar test compiled in Free Pascal):

Win32\Debug>Project1.exe
1
3
4
2
^C

(I need to kill the app by Ctrl+C within terminal)

the critical exception was the known:

[Main Instruction]
Project1.exe has stopped working

[Content]
Windows is checking for a solution to the problem...

So, is it a bug? If so, in which compiler?! Even after reading some
documents about BeforeDestruction I still have doubt about which is the
correct triggering of this method, and I would be glad if someone could
help me to solve it.

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

Re: [fpc-pascal] Doubt related to the issue #30498

2016-08-23 Thread silvioprog
On Tue, Aug 23, 2016 at 2:57 AM, Sven Barth 
wrote:
[...]

> See here: http://bugs.freepascal.org/view.php?id=30503
>
> Regards,
> Sven
>
Thank you! :-)

I did:

...
{$IFDEF FPC}
var
  VPairs: TArray>;
{$ENDIF}
begin
...
{$IFDEF FPC}
  // issues #30503 and #30498
  SetLength(VPairs, 2);
  VPairs[0] := TPair.Create(TMyObject, 'my qualifier');
  VPairs[1] := TPair.Create(TMySerializable,
TMySerializable.QualifiedClassName);
  TClassRegistry.Register(VPairs);
{$ELSE}
  TClassRegistry.Register([TPair.Create(TMyObject, 'my
qualifier'),
TPair.Create(TMySerializable, TMySerializable.
QualifiedClassName)]);
{$ENDIF}
...

and now my test-case compiles fine.

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

Re: [fpc-pascal] Free Delphi 10.1 Berlin Starter Edition

2016-08-23 Thread silvioprog
On Tue, Aug 23, 2016 at 6:43 AM, Maciej Izak  wrote:

>

> Hi,
>
> finally we have simple way to test new syntax to improve FPC quality /
$MODE DELPHI without spending $ on Delphi :)
>
> Probably limited time offer:
>
> https://www.embarcadero.com/products/delphi/starter/promotional-download


Great news.

Thank you! (y)

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

[fpc-pascal] Doubt related to the issue #30498

2016-08-22 Thread silvioprog
Hello,

A possible inline way (without declaring specialized local variables) to
compile the attached test at the issue #30498
 is:

...
  procedure Test(const AItems: TArray);
  begin
  end;

begin
  // Test(['foo', 'bar']); issue #30498
  Test(TArray.Create('foo', 'bar'));
...

However, how to do something like this in the following declaration?:

...
procedure Test(const AItems: TArray>);
...

I've tried:

...
  procedure Test(const AItems: TArray>);
  begin
  end;

begin
  Test(TArray>.Create(TPair.Create('foo', 'bar')));
...

Got:

project1.dpr(18,37) Error: Illegal expression
project1.dpr(18,38) Fatal: Syntax error, ")" expected but "identifier
CREATE" found

Thank you!

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

Re: [fpc-pascal] rtl-generics: TIStringComparer.Ordinal -> Access violation

2016-08-17 Thread silvioprog
On Wed, Aug 17, 2016 at 12:20 PM, Maciej Izak <hnb.c...@gmail.com> wrote:

>
> 2016-08-17 16:05 GMT+02:00 silvioprog <silviop...@gmail.com>:
>
>> I need to find the values using case-insensitive keys (I'm using it in a
>> class registry of my app), so unfortunately this bug doesn't let me to use
>> TDictionary on FPC yet. :-(
>
>
> There is simple workaround:
>
> === begin code ===
>
> function EqualityComparison(constref ALeft, ARight: string): Boolean;
> begin
>   Result := LowerCase(ALeft) = LowerCase(ARight);
> end;
>
> procedure ExtendedHasher(constref AValue: string; AHashList: PUInt32);
> begin
>   TDefaultHashFactory.GetHashList(Pointer(AValue), Length(AValue) *
> SizeOf(Char), AHashList);
> end;
>
> var
>   list: TDictionary<string, string>;
> begin
>   list := TDictionary<string, string>.Create(TEqualityCompar
> er.Construct(EqualityComparison, ExtendedHasher));
>
> === end code ===
>

I changed it to a function:

  function ExtendedHasher(constref AValue: string): UInt32;
  begin
TDefaultHashFactory.GetHashList(Pointer(AValue),
  Length(AValue) * SizeOf(Char), @Result);
  end;

because the "Error: Incompatible type for arg no. 2: Got
"ExtendedHasher(constref AnsiString;PDWord);", expected """.

Anyway, thanks for the workaround, it can fix the FPC version of my tests.
:-)

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

Re: [fpc-pascal] rtl-generics: TIStringComparer.Ordinal -> Access violation

2016-08-17 Thread silvioprog
On Wed, Aug 17, 2016 at 3:04 AM, Maciej Izak <hnb.c...@gmail.com> wrote:

>
> 2016-08-17 7:05 GMT+02:00 silvioprog <silviop...@gmail.com>:
>
>> Just try it:
>>
>
> related to
>
> http://bugs.freepascal.org/view.php?id=28911
>
> Sven comment: "I won't change the current implementation for now, because
> once I'm going to fix this I'm going to fix this correctly for all cases,
> including packages, everything else is merely a workaround. But for that I
> first need to finish my work on packages."
>
> btw, already reported: http://bugs.freepascal.org/view.php?id=30433
>

Indeed. After some debug I found where the exception is raised:

...
function TOpenAddressingLP.FindBucketIndex(constref
AItems: TArray;
  constref AKey: TKey; out AHash: UInt32): SizeInt;
var
  LItem: {TOpenAddressing.}_TItem; // for
workaround Lazarus bug #25613
  LLengthMask: SizeInt;
  i, m: SizeInt;
  LHash: UInt32;
begin
  m := Length(AItems);
  LLengthMask := m - 1;

  LHash := FEqualityComparer.GetHashCode(AKey); // << here
...

but I can't step into FEqualityComparer.GetHashCode to check why it
happens, so I'll wait for Sven too. ^^

I need to find the values using case-insensitive keys (I'm using it in a
class registry of my app), so unfortunately this bug doesn't let me to use
TDictionary on FPC yet. :-(

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

[fpc-pascal] rtl-generics: TIStringComparer.Ordinal -> Access violation

2016-08-16 Thread silvioprog
Hello,

Just try it:

var
  list: TDictionary;
begin
  list := TDictionary.Create(TIStringComparer.Ordinal);

Error:

An unhandled exception occurred at $0043A2F8:
EAccessViolation: Access violation
  $0043A2F8
  $004084B3  DOADD,  line 277 of inc/generics.dictionaries.inc
  $004099AB  main,  line 14 of project1.lpr

---

Trace:

#0
GENERICS.DEFAULTS$_$TGORDINALISTRINGCOMPARER$2$CRC09680922_$__$$_GETHASHCODE$ANSISTRING$$LONGWORD
at :0
#1 ?? at :0

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

Re: [fpc-pascal] Does FPC supports the `delayed` directive?

2016-08-13 Thread silvioprog
On Sat, Aug 13, 2016 at 2:31 PM, Sven Barth <pascaldra...@googlemail.com>
wrote:

> On 13.08.2016 18:38, silvioprog wrote:
> > My test ({$mode delphi}; FPC from trunk):
> >
> >   procedure foo(); cdecl; external 'foo' name 'foo' delayed;
> >
> > The compiler error:
> >
> > "Fatal: Syntax error, ";" expected but "identifier DELAYED" found".
>
> http://bugs.freepascal.org/view.php?id=23637


Great. Do you know if it was successfully accepted as a feature to be
implemented?
-- 
Silvio Clécio
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Does FPC supports the `delayed` directive?

2016-08-13 Thread silvioprog
Oops, I meant: "Does FPC support the `delayed` directive?". ^^'

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

[fpc-pascal] Does FPC supports the `delayed` directive?

2016-08-13 Thread silvioprog
Hello,

Firstly, a quot from Dr.Bob's site:

The basic idea of the solution is the fact that the DLL will not be loaded
> right away (which is the case for implicit linking), but only when needed.
> So potentially “delayed”, and hence the name “delay loading”.


The main idea is the similar to the traditional dynamic loading library
using LoadLibrary(), however, this directive ensures the compiler to handle
it automatically for us.

Another quot:

The delayed directive is useful in the case where the imported routines do
> not exist on the target operating system on which the application is run.
> Statically imported routines require that the operating system find and
> load the library when the application is started. If the routine is not
> found in the loaded library, or the library does not exist, the Operating
> System halts the execution of the application. Using the delayed directive
> enables you to check, at run time, whether the Operating System supports
> the required APIs; only then you can call the imported routines.


And the useful sources:

docwiki -
http://docwiki.embarcadero.com/CodeExamples/Berlin/en/DelayedLoading_(Delphi)

Dr.Bob - http://www.drbob42.com/examines/examinc1.htm

docwiki -
http://docwiki.embarcadero.com/RADStudio/Berlin/en/Libraries_and_Packages_(Delphi)

My test ({$mode delphi}; FPC from trunk):

  procedure foo(); cdecl; external 'foo' name 'foo' delayed;

The compiler error:

"Fatal: Syntax error, ";" expected but "identifier DELAYED" found".

Thank you!

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

Re: [fpc-pascal] rtl-generics: Suggestion and question

2016-08-12 Thread silvioprog
On Fri, Aug 12, 2016 at 5:03 PM, silvioprog <silviop...@gmail.com> wrote:

> On Fri, Aug 12, 2016 at 3:51 PM, Maciej Izak <hnb.c...@gmail.com> wrote:
> [...]
>
>> Using WARN OFF for whole module is rather bad, but might be (temporary)
>> the only solution. IIRC FPC has many bugs for switching off warnings /
>> hints especially for generics. Compiler likes to report warnings/hints in
>> specialization place/module (which each of reported warnings was disabled
>> in structure declaration).
>>
>
> IIRC FPC has the {$PUSH}/{$POP} switches allowing to enable/disable
> switches, I would be happy if someone could confirm that.
>

Oh, I'm wrong about  POP/PUSH switches ^^' :

http://www.freepascal.org/docs-html/prog/progsu62.html#x69-680001.2.62

http://www.freepascal.org/docs-html/prog/progsu63.html#x70-690001.2.63

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

Re: [fpc-pascal] rtl-generics: Suggestion and question

2016-08-12 Thread silvioprog
On Fri, Aug 12, 2016 at 3:51 PM, Maciej Izak  wrote:
[...]

> Using WARN OFF for whole module is rather bad, but might be (temporary)
> the only solution. IIRC FPC has many bugs for switching off warnings /
> hints especially for generics. Compiler likes to report warnings/hints in
> specialization place/module (which each of reported warnings was disabled
> in structure declaration).
>

IIRC FPC has the {$PUSH}/{$POP} switches allowing to enable/disable
switches, I would be happy if someone could confirm that.

TDictionary is very stable and well tested. Feel free to use that structure
> it definitely should stay without many modifications (generally public
> interface is stable - compatibility with Delphi).
>

Awesome, I'm going to do it! :-)


> the only candidate to remove is :
>
> procedure GetMemoryLayout(const AOnGetMemoryLayoutKeyPosition:
> TOnGetMemoryLayoutKeyPosition);
>
which was used only for testing purposes, thanks to GetMemoryLayout you can
> see how looks memory layout for each kind of dictionary (we have many
> memory layouts, even more - we have unique de-amortized cuckoo hashing -
> http://arxiv.org/abs/0903.0391 declared as THashMap/TFastHashMap).
>

Great. Does TDictionary descendant from one of those classes?

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

[fpc-pascal] rtl-generics: Suggestion and question

2016-08-12 Thread silvioprog
Hello,

I've spend some time adapting my beta project to use the new rtl-generics
classes, however, I have some issues regarding to TDictionary class. Let's
go to a test using the example below:

=== begin code ===

var
  hash: TDictionary;
begin
  hash := TDictionary.Create;
end

=== end code ===

You may get the following compiler log:

=== begin log ===

generics.dictionariesh.inc(231,33) Hint: Parameter "AFrom" not used
generics.dictionariesh.inc(231,40) Hint: Parameter "ATo" not used
generics.dictionariesh.inc(54,27) Hint: Parameter "ACapacity" not used
generics.dictionariesh.inc(58,32) Hint: Parameter "AValue" not used
generics.dictionariesh.inc(69,28) Hint: Parameter "APair" not used
generics.dictionariesh.inc(87,36) Hint: Parameter "ASize" not used
generics.dictionariesh.inc(155,39) Hint: Parameter "AItems" not used
generics.dictionariesh.inc(155,71) Hint: Parameter "AKey" not used
generics.dictionariesh.inc(155,87) Hint: Parameter "AHash" not used
generics.defaults.pas(47,31) Hint: Parameter "ALeft" not used
generics.defaults.pas(47,38) Hint: Parameter "ARight" not used
generics.defaults.pas(69,35) Hint: Parameter "AValues" not used
generics.defaults.pas(69,56) Hint: Parameter "ALeft" not used
generics.defaults.pas(69,63) Hint: Parameter "ARight" not used
generics.defaults.pas(69,86) Hint: Parameter "AComparer" not used
generics.defaults.pas(78,42) Hint: Parameter "AValues" not used
generics.defaults.pas(78,72) Hint: Parameter "AItem" not used
generics.defaults.pas(79,11) Hint: Parameter "AFoundIndex" not used
generics.defaults.pas(79,39) Hint: Parameter "AComparer" not used
generics.defaults.pas(80,7) Hint: Parameter "AIndex" not used
generics.defaults.pas(80,15) Hint: Parameter "ACount" not used
generics.defaults.pas(143,27) Hint: Parameter "AValue" not used
generics.defaults.pas(47,31) Hint: Parameter "ALeft" not used
generics.defaults.pas(47,38) Hint: Parameter "ARight" not used
generics.defaults.pas(69,35) Hint: Parameter "AValues" not used
generics.defaults.pas(69,56) Hint: Parameter "ALeft" not used
generics.defaults.pas(69,63) Hint: Parameter "ARight" not used
generics.defaults.pas(69,86) Hint: Parameter "AComparer" not used
generics.defaults.pas(78,42) Hint: Parameter "AValues" not used
generics.defaults.pas(78,72) Hint: Parameter "AItem" not used
generics.defaults.pas(79,11) Hint: Parameter "AFoundIndex" not used
generics.defaults.pas(79,39) Hint: Parameter "AComparer" not used
generics.defaults.pas(80,7) Hint: Parameter "AIndex" not used
generics.defaults.pas(80,15) Hint: Parameter "ACount" not used
generics.collections.pas(143,27) Hint: Parameter "AValue" not used
generics.defaults.pas(767,30) Hint: Parameter "ALeft" not used
generics.defaults.pas(767,37) Hint: Parameter "ARight" not used
generics.defaults.pas(768,35) Hint: Parameter "AValue" not used

=== end log ===

Those hints can be a problem when we also need to check the log from other
classes, because it pollute the windows messages, so a suggestion is just
to declare the "{$WARN 5024 OFF : Parameter "$1" not used}" in the
rtl-generics units.

The question is regarding to TDictionary, because I'm not sure if it is a
concrete class on its actual implementation stage (I'm using FPC from
trunk). See the warnings below:

=== begin warns ===

generics.dictionaries.inc(158,92) Warning: Constructing a class
"TCustomDictionaryEnumerator$4$crc7DF95A99" with abstract method
"DoMoveNext"
generics.dictionaries.inc(158,92) Warning: Constructing a class
"TCustomDictionaryEnumerator$4$crc7DF95A99" with abstract method
"GetCurrent"
generics.dictionaries.inc(158,92) Warning: Constructing a class
"TCustomDictionaryEnumerator$4$crc7DF95A99" with abstract method
"DoMoveNext"
generics.dictionaries.inc(158,92) Warning: Constructing a class
"TCustomDictionaryEnumerator$4$crc7DF95A99" with abstract method
"GetCurrent"

=== end warns ===

I want to use the TDictionary in a beta project, but I'm not sure if today
it is only for experimental purposes. :-/

Thank you!

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

Re: [fpc-pascal] Are the TEncoding singletons thread-safe?

2016-08-11 Thread silvioprog
On Thu, Aug 11, 2016 at 3:33 PM, Jonas Maebe <jonas.ma...@elis.ugent.be>
wrote:

> On 11/08/16 20:25, silvioprog wrote:
>
>> But now I have a question: many Free Pascal programmers are Delphi
>> programmers too, having code that can be compiled in both compilers, and
>> sometimes they need to debug deeply, entering into the compiler code and
>> looking at it, so, can't a programmer contribute with Free Pascal in
>> that situation? If so, I have no more questions.
>>
>
> The compiler code is no problem, since the Delphi compiler code is not
> open source. For the RTL: if they looked at parts of the Delphi RTL source
> code, then they cannot contribute to the same functionality in the FPC RTL.


Hm... now I understood and fully agreed. Since Delphi's TEncoding is part
of its RTL and I've looked at its implementation to understand why I can't
get leaks compiling my code using it, and there is no definition in
copyright of when exactly a work is independent and when it is derivative,
so anything I do can be understood as rewrite.

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

Re: [fpc-pascal] Are the TEncoding singletons thread-safe?

2016-08-11 Thread silvioprog
On Thu, Aug 11, 2016 at 12:54 PM, Jonas Maebe 
wrote:
>
> Yes, but we cannot integrate any code that has been written by you based
> on the Delphi code you looked at, because the license does not allow you to
> rewrite that code into something that is licensed under the GPLv2 or later.
>
While in theory the issue is not as black and white (there is no definition
> in copyright of when exactly a work is independent and when it is
> derivative), to be on the safe side we do not accept code that has been
> written by someone after they looked at the Delphi code for the same
> functionality.


I understood and agreed.

But now I have a question: many Free Pascal programmers are Delphi
programmers too, having code that can be compiled in both compilers, and
sometimes they need to debug deeply, entering into the compiler code and
looking at it, so, can't a programmer contribute with Free Pascal in that
situation? If so, I have no more questions.

Well, to avoid more confusion I'll not send more patches to solve this
>> problem and I'm going to close my issue.
>>
>
> I have simply removed your code from the bug report, that is enough. Your
> description of how to fix it does not pose any problems.


No problem. Thank you!

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

Re: [fpc-pascal] Are the TEncoding singletons thread-safe?

2016-08-11 Thread silvioprog
On Thu, Aug 11, 2016 at 11:07 AM, Jonas Maebe <jonas.ma...@elis.ugent.be>
wrote:

> On 11/08/16 15:38, silvioprog wrote:
>
>> No, I didn't. Sorry if I made some misunderstood, I look at Delphi
>> source just for check why it doesn't raise memory leak, I'm fully
>> against piracy! I look at other sources from another languages too, like
>> DotGNU Encoding, but just for analysis. The proposed possible patch is
>> 100% genuine FPC implementation, and unlike Delphi, I've used a plain
>> critical section for cross platform purposes.
>>
>
> How do you know that Delphi doesn't use a critical section if you did not
> look at its source code?


Now I understand what you meant. When you asked me if I looked at Delphi's
code I thought you were suggesting that I had written the patch based on it
to make a kind of copy, if so, I haven't. But if the question is about
looking at Delphi code, yes, I do, I bought a professional Delphi copy and
its license allows me to see any unit that they've sent me. Finally, I can
analyse any code of any tool if its license allows me, can't I?

Well, to avoid more confusion I'll not send more patches to solve this
problem and I'm going to close my issue.

Thank you!

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

Re: [fpc-pascal] Are the TEncoding singletons thread-safe?

2016-08-11 Thread silvioprog
On Thu, Aug 11, 2016 at 10:21 AM, Jonas Maebe <jonas.ma...@elis.ugent.be>
wrote:

> On 11/08/16 15:17, silvioprog wrote:
>
>> I've opened a new issue sending a possible
>> patch: http://bugs.freepascal.org/view.php?id=30462
>> <http://bugs.freepascal.org/view.php?id=30462>.
>>
>
> Did you look at the Delphi source code for TEncoding?


No, I didn't. Sorry if I made some misunderstood, I look at Delphi source
just for check why it doesn't raise memory leak, I'm fully against piracy!
I look at other sources from another languages too, like DotGNU Encoding,
but just for analysis. The proposed possible patch is 100% genuine FPC
implementation, and unlike Delphi, I've used a plain critical section for
cross platform purposes.

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

Re: [fpc-pascal] Are the TEncoding singletons thread-safe?

2016-08-11 Thread silvioprog
On Thu, Aug 11, 2016 at 5:02 AM, Jonas Maebe <jonas.ma...@elis.ugent.be>
wrote:

> Bart wrote:
> > On 8/11/16, silvioprog <silviop...@gmail.com> wrote:
> >
> >> ... so I decided to research how Delphi
> >> implements it, because I can't get any error on it, and I've seen it
> >> implements a "lock-free initialization" technique
> >> <http://stackoverflow.com/a/24657705/3268398> using the XE's
> >> AtomicCmpExchange() function before return any TEncoding global
> instance.
> > ..
> >> I could send a patch to solve it,
> >
> > I hope you did not look at the Delphi sourcecode to see how it was
> > implemented, because that would now make a "clean room" implementation
> > on our side almost impossible.
>
> It would make a clean room implementation by Silvio himself impossible,
> but anyone that reads his description and writes code based on that
> description is still clean (as long as they did not also look at the
> Delphi source code).


I've opened a new issue sending a possible patch: http://bugs.freepascal.
org/view.php?id=30462.

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

[fpc-pascal] Are the TEncoding singletons thread-safe?

2016-08-10 Thread silvioprog
Hello,

I've used the useful singletons available in the TEncoding class, and I
don't get any problem with them, unless using threads.

I have an application that does many tests in a code compilable in FPC and
Delphi, however, the FPC's tests raise memory leak at the finalization
tests. The problem can be a little bit hard to be reproduce, but I think
the code below can do that:

=== begin code [project1.dpr] ===

program project1;

{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$IFDEF MSWINDOWS}
{$APPTYPE CONSOLE}
{$ENDIF}

uses
//  HeapTrc, the FPC staff recomends to enable HeapTrc in the lpi or
passing the -gh compiler parameter
{$IFDEF UNIX}
  CThreads,
{$ENDIF} SysUtils, Classes;

type
  TTestThread = class(TThread)
  public
constructor Create;
procedure Execute; override;
  end;

  constructor TTestThread.Create;
  begin
inherited Create(True);
FreeOnTerminate := False;
  end;

  procedure TTestThread.Execute;
  begin
WriteLn(TEncoding.Default.GetString(TBytes.Create(65, 66, 67)));
  end;

var
  VThread1, VThread2: TTestThread;
begin
{$IFNDEF FPC}
  ReportMemoryLeaksOnShutdown := True;
{$ENDIF}
  VThread1 := TTestThread.Create;
  VThread2 := TTestThread.Create;
  try
Sleep(1000);
VThread1.Start;
VThread2.Start;
VThread1.WaitFor;
VThread2.WaitFor;
  finally
VThread1.Free;
VThread2.Free;
  end;
end.

=== end code ===

If you compile and run the code above, you may get the following trace:

=== begin log ===

ABC
ABC
Heap dump by heaptrc unit
44 memory blocks allocated : 2119/2144
43 memory blocks freed : 2087/2112
1 unfreed memory blocks : 32
True heap size : 131072
True free heap : 131072
Should be : 130912
Call trace for block $77FAB0C0 size 32

=== end log ===

Researching the FPC's TEncoding implementation, I think it doesn't do any
lock before instantiate its singletons, so I decided to research how Delphi
implements it, because I can't get any error on it, and I've seen it
implements a "lock-free initialization" technique
 using the XE's
AtomicCmpExchange() function before return any TEncoding global instance.

That memory leak can be really a problem, because I can't prevent how many
threads will call the TEncoding's singletons at same time, I could
initialize the TEncoding before starting any thread of my application, but
it doesn't sound good, because I can't prevent if the threads will
instantiate the ANSI or UTF8 singleton. The best way to solve this problem
would be making the TEncoding become thread-safe. I could send a patch to
solve it, but I don't know if FPC provides some global locker like
AtomicCmpExchange.

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

Re: [fpc-pascal] TArray.Sort(array) returns 'Error: Identifier not found "TArray" '

2016-08-07 Thread silvioprog
On Aug 4, 2016 3:08 AM, "Maciej Izak" <hnb.c...@gmail.com> wrote:
>
> 2016-08-04 3:16 GMT+02:00 silvioprog <silviop...@gmail.com>:
>>
>> So, is this the best way to solve this problem?
>
> TArrayHelper is marked as experimental structure and exist only temporary
for bug workaround (see page 1 of
https://github.com/dathox/generics.collections/blob/master/GenericsCompatibilityMatrix.pdf
).

Awesome.

Will you keep the sparta-generics package at Lazarus sources?

Thanks for sharing the PDF, it will help me a lot to migrate my code from
FGL to Generics.Collections.

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

Re: [fpc-pascal] TArray.Sort(array) returns 'Error: Identifier not found "TArray" '

2016-08-07 Thread silvioprog
On Thu, Aug 4, 2016 at 3:07 AM, Sven Barth <pascaldra...@googlemail.com>
wrote:

>

> Am 04.08.2016 03:17 schrieb "silvioprog" <silviop...@gmail.com>:
> > So, is this the best way to solve this problem?
>
> For now, yes. Maciej still needs to adjust the code to make use of the
features added in trunk.

Great. Added as reminder in my TODO list. :-)

Thank you!

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

[fpc-pascal] TArray.Sort(array) returns 'Error: Identifier not found "TArray" '

2016-08-03 Thread silvioprog
Hello,

First, thanks a lot for the rtl-generics units, this really was a
great contribution to the Free Pascal community!

So, sometimes, I need to sort the values of a specialized key/value list,
but I can't compile the adapted Delphi XE code below (I'm using MODE
DELPHI):

=== begin code ===

var
  key: string;
  ordkeys: TArray;
  list: TDictionary;
begin
  list := TDictionary.Create;
  try
list.Add('a', 'aaa');
list.Add('b', 'bbb');
list.Add('c', 'ccc');
ordkeys := list.Keys.ToArray;
TArray.Sort(ordkeys);
for key in ordkeys do
  WriteLn(key, ' - ', list[key]);
  finally
list.Free;
  end;
end.

=== end code ===

I got:

'Error: Identifier not found "TArray"'

So I've fixed it with:

=== begin code ===

...

{$IFDEF FPC}
TArrayHelper.Sort(ordkeys);
{$ELSE}
TArray.Sort(ordkeys);
{$ENDIF}

...

=== end code ===

So, is this the best way to solve this problem?

Thank you!

P.S.: You should remove the {$H+} from the generics.* units, the mode
Delphi already enables the long strings
.

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

Re: [fpc-pascal] FCL maskutils incompatible with Delphi

2016-04-19 Thread silvioprog
On Tue, Apr 19, 2016 at 4:14 PM, Bart <bartjun...@gmail.com> wrote:

> On 4/19/16, silvioprog <silviop...@gmail.com> wrote:
>
> > The expected value: H1H357-K808K-44616-YK8720.
> >
> > The returned value: H1H357-K808K-44616-**.
> >
> > If you uncomment the code in the last writeln, it will raise the generic
> > "FormatMaskText function failed!" error.
> >
>
> The issue you describe looks like
> http://bugs.freepascal.org/view.php?id=30020
>
> There is also a bugreport about crashes in FormatMaskText.
> http://bugs.freepascal.org/view.php?id=28201
>
> And there is also a thread in this ML about a new implementation of
> the MaskUtils unit.
>

Yes, he (Handlei) reported it at Brazillian group, but he didn't tell us
that had already reported that at bugtracker.

The patch was sent from another member, and he told us that it fix the
current maskutils.pp unit, I just sent it here as they asked me.

Can I send this patch to #30020 or just wait for new MaskUtils
implementation?

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

[fpc-pascal] STATIC can only be used on non-virtual class methods

2016-04-15 Thread silvioprog
Hello,

Consider the following code:

=== test begin ===

{$MODE DELPHI}

  TStaticVirtualTest = class sealed(TObject)
  public
class procedure Test; virtual; static;
  end;

class procedure TStaticVirtualTest.Test;
begin
end;

=== test end ===

You can compile it in FPC (trunk), but, when you try to compile it on
Delphi (Seattle):

=== error begin ===

E2376 STATIC can only be used on non-virtual class methods

=== error end ===

Is this a FPC bug?

Thank you!

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

[fpc-pascal] Any chance to add the TStringBuilder to FCL?

2016-04-14 Thread silvioprog
Hello,

Is there any chance to add a class like Delphi's TStringBuilder

to FCL? It would be very useful to port Delphi code libraries to Free
Pascal.

Thank you!

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

[fpc-pascal] TStringHelper with SysUtils functions

2016-04-12 Thread silvioprog
Hello,

How do I use the TStringHelper with SysUtils functions?

When I've tried to compile this code:

=== code ===

program Project1;

{$mode objfpc}{$H+}

uses
  SysUtils;

begin
  WriteLn(ExtractFileExt(ParamStr(0)).Substring(1));
  ReadLn;
end.

=== /code ===

I've got:

project1.lpr(9,39) Error: Illegal qualifier

A possible fix would be changing the TStringHelper declaration from
"TStringHelper = Type Helper for AnsiString" to "TStringHelper = Type
Helper for string" keeping it Delphi compatible.

Thank you!

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

Re: [fpc-pascal] Class constructor called unconditionally

2016-03-31 Thread silvioprog
On Thu, Mar 31, 2016 at 11:28 AM, Michael Van Canneyt <
mich...@freepascal.org> wrote:
[...]

> I suspect the problem is not in the mode, but in detecting whether a class
> is used
> or not in a program. It becomes very complicated when you use e.g.
> run-time packages.
>

Hm... so FPC class constructor (or class initialization) works like unit
initialization.


> Delphi itself is buggy in this regard, and has been since at least D7.
> For this reason, in general I advise against extensive use of
> initialization sections etc...


Thanks for sharing this information.

It's hard to make test-case when the code has an extensive use of
initialization sections, so currently I'm avoiding it too. However, I need
to register some classes in a class list, so I'm changing my code to do it
in some place like application initialization.

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

Re: [fpc-pascal] Class constructor called unconditionally

2016-03-31 Thread silvioprog
On Thu, Mar 31, 2016 at 10:58 AM, Vojtěch Čihák 
wrote:

> IMO compilers should be dogmatic otherwise one cannot rely on them. This
> looks to me like advocating wrong optimization.
>
>
>
> Blaazen
>

Thanks for reply Vojtěch, but are you referring to Delphi or FPC
optimization?

I think that FPC should keep the Delphi class constructor behaviour in MODE
DELPHI, allowing the programmers to port Delphi libraries to FPC, but ...

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

Re: [fpc-pascal] Class constructor called unconditionally

2016-03-31 Thread silvioprog
On Thu, Mar 31, 2016 at 10:49 AM, Sven Barth <pascaldra...@googlemail.com>
wrote:

> Am 31.03.2016 15:33 schrieb "silvioprog" <silviop...@gmail.com>:
> > After read this explanations, is there some compiler option to make FPC
> with this same Delphi behaviour? I'm using MODE DELPHI.
>
> No, there is not. Currently class constructors (and destructors) are
> called always.
>
> Regards,
> Sven
>
OK. So I can't use class constructor in FPC.

Thank you!

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

[fpc-pascal] Class constructor called unconditionally

2016-03-31 Thread silvioprog
Hello,

First, take a look at this small project:

=== code ===

program Project1;

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$IFDEF MSWINDOWS}
  {$APPTYPE CONSOLE}
{$ENDIF}

type
  TFoo = class
  public
class constructor Create;
  end;

  class constructor TFoo.Create;
  begin
Writeln('TFoo.Create called');
  end;

begin
  Writeln('Program start');
  Readln;
end.

=== /code ===

When you compile and run it in FPC, the result is:

=== result ===

TFoo.Create called
Program start

=== /result ===

But, if you compile and run this same code in Delphi (I'm using Seattle),
the result is:

=== result ===

Program start

=== /result ===

Googling about this problem, I found this link at StackOverflow:

http://stackoverflow.com/questions/6231871/class-constructor-not-called-when-class-registration-is-done-in-that-class-const

With this comment:

"Uwe Raabe answered Jun 3 '11 at 19:55: As long as you don't use the class
anywhere outside the class itself, the compiler takes this as the class not
used at all and hence won't call the class constructor. So I guess you have
to use the intialization section instead of tweaking the code to fool the
compiler. Take the pragmatic approach instead of the dogmatic one. It will
be more readable anyway."

After read this explanations, is there some compiler option to make FPC
with this same Delphi behaviour? I'm using MODE DELPHI.

Thank you!

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

Re: [fpc-pascal] Codepage + class helper raises "Error identifier idents no member ..."

2016-03-19 Thread silvioprog
On Wed, Mar 16, 2016 at 8:53 PM, Bart  wrote:
[...]

> @Silvio: Sven fixed it in trunk.
> Can you test and report back in
> http://bugs.freepascal.org/view.php?id=29745
> (I don't have fpc trunk)


Now it is working like a charm. Thank you Bart and Sven! :-D

(you can close the issue ^^ )

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

Re: [fpc-pascal] How do I test the testfppdf on Windows?

2016-03-18 Thread silvioprog
On Tue, Mar 15, 2016 at 4:38 AM, Michael Van Canneyt  wrote:
[...]

> I have (hopefully) fixed this. rev. 33255.


The crash was fixed after upgrade my FPC. But it still generating five
empty pages even applying the Jesus Reyes' patch. :-/

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

Re: [fpc-pascal] How do I test the testfppdf on Windows?

2016-03-14 Thread silvioprog
On Fri, Mar 11, 2016 at 4:35 AM, Michael Van Canneyt <mich...@freepascal.org
> wrote:
>
> On Thu, 10 Mar 2016, silvioprog wrote:
>
> On Sat, Mar 5, 2016 at 3:38 PM, silvioprog <silviop...@gmail.com> wrote:
>> [...]
>>
>> ... however, when I try to run the project, I get a SIGSEGV:
>>>
>>>
>> This patch (by Gilson Nunes) fix the SIGSEGV:
>> http://bugs.freepascal.org/view.php?id=29812.
>>
>
> Improved and applied, thank you.
>
>
>> However, the example still making empty pages on Windows. (I'll ask Gilson
>> to help us to fix this problem ...)
>>
>
> Did you try the patch by Jesus Reyes ?


Not yet, because I get a new error:

An unhandled exception occurred at $0041EECF:
EListError: List index (0) out of bounds
  $0041EECF
  $00432EAA  TPDFDOCUMENT__INDEXOFGLOBALXREF,  line 2746 of
C:/dev/git/freepascal/packages/fcl-pdf/src/fppdf.pp
  $00432F15  TPDFDOCUMENT__FINDGLOBALXREF,  line 2759 of
C:/dev/git/freepascal/packages/fcl-pdf/src/fppdf.pp
  $004348A5  TPDFDOCUMENT__GLOBALXREFBYNAME,  line 3212 of
C:/dev/git/freepascal/packages/fcl-pdf/src/fppdf.pp
  $0043341A  TPDFDOCUMENT__CREATEPREFERENCESENTRY,  line 2858 of
C:/dev/git/freepascal/packages/fcl-pdf/src/fppdf.pp
  $00434B42  TPDFDOCUMENT__STARTDOCUMENT,  line 3242 of
C:/dev/git/freepascal/packages/fcl-pdf/src/fppdf.pp
  $0040177F  SETUPDOCUMENT,  line 22 of testfppdf.lpr
  $00402BF4  main,  line 427 of testfppdf.lpr

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

Re: [fpc-pascal] Primitive Record Wrappers

2016-03-10 Thread silvioprog
On Sun, Mar 6, 2016 at 7:21 PM, Mazola Winstrol 
wrote:
[...]

> Please see the code in attachments and send your suggestions / remarks.
>

Thanks for share.

How do I use the the NullableTypes.String unit?

Tried:

program project1;

{$mode objfpc}{$H+}

uses NullableTypes.String;

begin
end.

Got:

Fatal: Syntax error, "identifier" expected but "STRING" found

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

Re: [fpc-pascal] CMem issue?

2016-03-10 Thread silvioprog
On Tue, Mar 8, 2016 at 12:10 PM, Michael Van Canneyt <mich...@freepascal.org
> wrote:

> On Tue, 8 Mar 2016, silvioprog wrote:
>
>> On Tue, Mar 8, 2016 at 9:29 AM, Bart <bartjun...@gmail.com> wrote:
>>
>> On 3/8/16, silvioprog <silviop...@gmail.com> wrote:
>>>
>>> (my environment: Lazarus 1.7 rUnknown FPC 3.1.1 i386-win32-win32/win64)
>>>>
>>>
>>> I can run simple Lazarus GUI program that uses CMem.
>>> Lazarus 1.7 r51837 FPC 3.0.0 i386-win32-win32/win64.
>>> (32-bit)
>>>
>>
>> Can you test this attached program?
>>
>
> Runs fine on Linux, 64 bit, built both with lazbuild, and with fpc on
> command-line.


Strange, I got same error on my Xubuntu 64 bits:

http://ctrlv.in/725502 (SIGSEGV)

http://ctrlv.in/725503 (Assembler)

FPC 3.1.1 from trunk compiled tonight.

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

Re: [fpc-pascal] CMem issue?

2016-03-10 Thread silvioprog
On Tue, Mar 8, 2016 at 1:12 PM, Bart <bartjun...@gmail.com> wrote:

> On 3/8/16, silvioprog <silviop...@gmail.com> wrote:
> > Can you test this attached program?
>
> Builds and runs fine, both 64 and 32 bit, inside and outside the debugger.
> Tested on Win7-64.


Strange. I got it on my Windows:

http://ctrlv.in/725499

http://ctrlv.in/725501

I use this batch to build my FPC from trunk on Windows:

http://pastebin.com/V1mZdPvK

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

Re: [fpc-pascal] How do I test the testfppdf on Windows?

2016-03-10 Thread silvioprog
On Sat, Mar 5, 2016 at 3:38 PM, silvioprog <silviop...@gmail.com> wrote:
[...]

> ... however, when I try to run the project, I get a SIGSEGV:
>

This patch (by Gilson Nunes) fix the SIGSEGV:
http://bugs.freepascal.org/view.php?id=29812.

However, the example still making empty pages on Windows. (I'll ask Gilson
to help us to fix this problem ...)

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

Re: [fpc-pascal] TStringHelper.Split() issue?

2016-03-08 Thread silvioprog
On Tue, Mar 8, 2016 at 12:09 PM, Michael Van Canneyt  wrote:
[...]

> Please report a bug !


Done as #29798 .

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

Re: [fpc-pascal] TStringHelper.Split() issue?

2016-03-08 Thread silvioprog
On Tue, Mar 8, 2016 at 12:03 PM, Michael Van Canneyt  wrote:
[...]
>
> Yes. Quite strange, because I have testcases for this ?


It happens only when the second part of string has only one character, two
or more (eg "content: string = 'x:yy'") it works.

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

Re: [fpc-pascal] CMem issue?

2016-03-08 Thread silvioprog
On Tue, Mar 8, 2016 at 9:48 AM, Michael Van Canneyt 
wrote:
[...]

> Linux, 64 bit.


I'll check it on my Xubuntu ...

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

[fpc-pascal] TStringHelper.Split() issue?

2016-03-08 Thread silvioprog
Hello,

Just test this code below:

=== code ===

program Project1;

{$mode delphi}

uses
  SysUtils;

var
  content: string = 'x:y';
  splited: TArray;
begin
  splited := content.Split([':']);
  WriteLn(Length(splited));
  ReadLn;
end.

=== /code ===

On FPC, it returns 1, on Delphi, it returns 2. And debuging the "splited"
variable, on FPC I get only and "x" value, Delphi "x" and "y".

Is this a bug?

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

Re: [fpc-pascal] How do I test the testfppdf on Windows?

2016-03-08 Thread silvioprog
On Sun, Mar 6, 2016 at 6:30 AM, Luca Olivetti  wrote:

> El 06/03/16 a les 10:15, Michael Van Canneyt ha escrit:
>
>> Strange, because if I recall correctly it was tested with Cyrillic, and
>> that worked ?
>>
>> Later I will try with other readers.
>>>
>>
>> Please do, I'd welcome any hints as to what could be wrong !
>>
>> (evince is one of the readers that was used to test, BTW)
>>
>
> With okular I see this at the bottom of the first page
>
>
> http://ctrlv.in/722862
>
>
> These are the details of my okular:
> versió 0.23.2
> S'utilitza la «KDE Development Platform» 4.14.15


Same problem here.

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

Re: [fpc-pascal] CMem issue?

2016-03-08 Thread silvioprog
On Tue, Mar 8, 2016 at 8:42 AM, Michael Van Canneyt 
wrote:
[...]

> I tried that and the code runs fine on my system.


Linux?

(my environment: Lazarus 1.7 rUnknown FPC 3.1.1 i386-win32-win32/win64)

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

Re: [fpc-pascal] CMem issue?

2016-03-08 Thread silvioprog
On Tue, Mar 8, 2016 at 5:54 AM, Michael Van Canneyt 
wrote:
[...]

> First paragraph.
>
> http://freepascal.org/docs-html/current/rtl/cmem/index.html


This Sven explanation below should be added there too:

'Also don't use -gh with alternate memory managers. They are *both* memory
managers and thus will lead to conflicting situations.'

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

Re: [fpc-pascal] CMem issue?

2016-03-08 Thread silvioprog
On Tue, Mar 8, 2016 at 4:02 AM, Sven Barth <pascaldra...@googlemail.com>
wrote:
[...]

> *Always* put an alternate memory manager as the first unit. I think that
> requirement is even documented somewhere...
>
Thanks for share this information.

> Also don't use -gh with alternate memory managers. They are *both* memory
> managers and thus will lead to conflicting situations.
>
H... I didn't know about this conflicting, thanks again! :-)

Is there some way to report possible memory leaks when my memory manager is
the cmem?

Now I omitted the -gh and declared the units as:

=== code ===

uses
  cmem, Classes, SysUtils;

=== /code ===

And the problem was:

=== error ===

C:\Users\silvioprog\Desktop\av>project1.exe
An unhandled exception occurred at $0040B8E2:
EAccessViolation: Access violation
  $0040B8E2

=== /error ===

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

Re: [fpc-pascal] CMem issue?

2016-03-08 Thread silvioprog
On Mon, Mar 7, 2016 at 10:09 PM, Bart <bartjun...@gmail.com> wrote:

> On 3/8/16, silvioprog <silviop...@gmail.com> wrote:
> > I got an AV in the CMem unit. To reproduce the problem just compile and
> run
> > this code below:
> >
> > === code ===
> >
> > program project1;
> >
> > {$mode delphi}
> >
> > uses
> >   Classes, SysUtils, cmem;
>
> 1. Shouldn't Cmem be the first unit in your program's uses clause?
> 2. Maybe http://bugs.freepascal.org/view.php?id=29759


Now I declared it as first unit in my program, and the problem was:

=== error ===

C:\Users\silvioprog\Desktop\av>project1.exe
An unhandled exception occurred at $0040B8E2:
EAccessViolation: Access violation
  $0040B8E2

=== /error ===

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

[fpc-pascal] CMem issue?

2016-03-07 Thread silvioprog
Hello,

I got an AV in the CMem unit. To reproduce the problem just compile and run
this code below:

=== code ===

program project1;

{$mode delphi}

uses
  Classes, SysUtils, cmem;

var
  VBuffer: TBytes;
  VStream: TStream;
begin
  VStream := TBytesStream.Create;
  try
VBuffer := TEncoding.UTF8.GetBytes('abc');
VStream.WriteBuffer(VBuffer[0], Length(VBuffer));
  finally
VStream.Free;
  end;
end.

=== /code ===

=== error ===

C:\Users\silvioprog\Desktop\av>project1.exe
An unhandled exception occurred at $00410479:
EAccessViolation: Access violation
  $00410479
  $00410542

Heap dump by heaptrc unit
70 memory blocks allocated : 1972/2104
67 memory blocks freed : 1792/1920
3 unfreed memory blocks : 180
True heap size : 262144 (96 used in System startup)
True free heap : 261632
Should be : 261672
Call trace for block $015C8480 size 64
  $00409B9C
  $004169A7
  $0040AACE
  $00410542
Call trace for block $015C0478 size 24
  $00409B9C
  $004169A7
  $0040AACE
  $00410542
Call trace for block $015B8470 size 92
  $0041687F
  $0040AACE
  $00410542
  $0077006F
  $005C0073
  $00790073
  $00740073
  $006D0065

=== /error ===

The project was compiled with -gh option. If you comment the "cmem"
declaration, the problem is over.

To fix my problem I declared the functions Malloc() and Free() directly in
my project, but even so I thought it was interesting to report this error.

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

Re: [fpc-pascal] How do I test the testfppdf on Windows?

2016-03-05 Thread silvioprog
On Sat, Mar 5, 2016 at 5:24 PM, Ralf Quint  wrote:

> On 3/5/2016 12:03 PM, Michael Van Canneyt wrote:
>
>>
>> This is what I get with the normal test font:
>> http://www.freepascal.org/~michael/test.pdf
>>
>> FYI,
>
> Opening up this document with the latest Adobe Reader DC
> (15.10.20059.40980, on Windows 8.1/64), I get an error message saying
>
> "The font 'Times' contains a bad /BBox"...


Same problem here too. :-/

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

Re: [fpc-pascal] How do I test the testfppdf on Windows?

2016-03-05 Thread silvioprog
On Sat, Mar 5, 2016 at 5:03 PM, Michael Van Canneyt <mich...@freepascal.org>
wrote:
>
> On Sat, 5 Mar 2016, silvioprog wrote:
>
> Hm. I tried many PDF readers on the file. All unix based (okular,
>>> openoffice), but also the Google docs PDF viewer and Firefox PDF reader.
>>> All displayed the PDF just fine.
>>>
>>>
>> Now I tried on Google PDF viewer, no errors, but:
>>
>> https://dl.dropboxusercontent.com/u/135304375/print.png
>>
>> (sent a print just to you see how it is showed for me)
>>
>
> Hm. Strange.
>
>
>>
>> Can you send me the PDF you got ?
>>>
>>
>>
>> It's a pleasure :-)
>>
>> https://dl.dropboxusercontent.com/u/135304375/test.pdf
>>
>
> Seems empty here too.
>
> This is what I get with the normal test font:
> http://www.freepascal.org/~michael/test.pdf


It open fine on Chrome, but on Adobe Reader:

"The font 'Times' contains a bad /BBox."

Can you please try with the original font too, please ?
> (freesans is freely available)
>

Yes. Do you downloaded it from
http://ftp.gnu.org/gnu/freefont/freefont-ttf.zip ?

If so, even using this file above I get same problem (Windows 7 64 bits).
:-/


> If that works, it would mean there is something wrong with the Arial font
> handling.


Same problem, and it persists even after install the font in my system. :-(

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

Re: [fpc-pascal] How do I test the testfppdf on Windows?

2016-03-05 Thread silvioprog
On Sat, Mar 5, 2016 at 3:58 PM, Michael Van Canneyt <mich...@freepascal.org>
wrote:

> On Sat, 5 Mar 2016, silvioprog wrote:
>
>> On Sat, Mar 5, 2016 at 3:38 PM, silvioprog <silviop...@gmail.com> wrote:
>>
>>> Hello,
>>>
>>> I just created the folder "fonts" and copied the
>>> "C:\Windows\Fonts\arial.ttf" into that, so I changed the line
>>> "D.AddFont('FreeSans.ttf', 'FreeSans-12' to "D.AddFont('arial.ttf',
>>> 'Arial", however, when I try to run the project, I get a SIGSEGV:
>>>
>>>
>> To fix the SIGSEGV, I just disabled the heap (-gh) unit.
>>
>
> Hehe =-)
>
>
>> Now I put all freetype binaries into my example folder, and after run the
>> test, I got a "test.pdf" file about 654KB, but I can't open it on my Adobe
>> Reader XI (latest version):
>>
>> "An error exists on this page. Acrobat may not display the page correctly.
>> Please contact the person who created the PDF document to correct the
>> problem."
>>
>> And got five empty pages.
>>
>
> Hm. I tried many PDF readers on the file. All unix based (okular,
> openoffice), but also the Google docs PDF viewer and Firefox PDF reader.
> All displayed the PDF just fine.
>

Now I tried on Google PDF viewer, no errors, but:

https://dl.dropboxusercontent.com/u/135304375/print.png

(sent a print just to you see how it is showed for me)


> Can you send me the PDF you got ?


It's a pleasure :-)

https://dl.dropboxusercontent.com/u/135304375/test.pdf .

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

Re: [fpc-pascal] How do I test the testfppdf on Windows?

2016-03-05 Thread silvioprog
On Sat, Mar 5, 2016 at 3:56 PM, Michael Van Canneyt <mich...@freepascal.org>
wrote:
>
> On Sat, 5 Mar 2016, silvioprog wrote:
>
>> Hello,
>>
>> I just created the folder "fonts" and copied the
>> "C:\Windows\Fonts\arial.ttf" into that, so I changed the line
>> "D.AddFont('FreeSans.ttf', 'FreeSans-12' to "D.AddFont('arial.ttf',
>> 'Arial", however, when I try to run the project, I get a SIGSEGV:
>>
>> #0
>>
>> WRPR_$SYSTEM_$$_TINTERFACEDOBJECT_$_IUNKNOWN_$_2_$_SYSTEM$_$TINTERFACEDOBJECT_$__$$__RELEASE$$LONGINT
>> at :0
>> #1 ?? at :0
>> #2 ?? at :0
>> #3 ?? at :0
>> #4
>>
>> WRPR_$SYSTEM_$$_TINTERFACEDOBJECT_$_IUNKNOWN_$_2_$_SYSTEM$_$TINTERFACEDOBJECT_$__$$__RELEASE$$LONGINT
>> at :0
>> #5 ?? at :0
>>
>> I also get some warnings and hints in the compilation:
>>
>
> Hm. This is strange, the code does not use interfaces at all.
> The compilation hints/warnings do not really present me with a hint as to
> what could be wrong.
>

Attached patch to fix warns/hints. (need to test it with FPC 2.6, I tested
only in 3.0)


> Any chance to get a better stack backtrace ?


Yes. I'm trying to get that, it seems more related to the TComponent class,
that uses interfaces.

-- 
Silvio Clécio


0001-Remove-warnings-and-hints.patch
Description: Binary data
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] How do I test the testfppdf on Windows?

2016-03-05 Thread silvioprog
On Sat, Mar 5, 2016 at 3:38 PM, silvioprog <silviop...@gmail.com> wrote:

> Hello,
>
> I just created the folder "fonts" and copied the
> "C:\Windows\Fonts\arial.ttf" into that, so I changed the line
> "D.AddFont('FreeSans.ttf', 'FreeSans-12' to "D.AddFont('arial.ttf',
> 'Arial", however, when I try to run the project, I get a SIGSEGV:
>

To fix the SIGSEGV, I just disabled the heap (-gh) unit.

Now I put all freetype binaries into my example folder, and after run the
test, I got a "test.pdf" file about 654KB, but I can't open it on my Adobe
Reader XI (latest version):

"An error exists on this page. Acrobat may not display the page correctly.
Please contact the person who created the PDF document to correct the
problem."

And got five empty pages.

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

[fpc-pascal] How do I test the testfppdf on Windows?

2016-03-05 Thread silvioprog
Hello,

I just created the folder "fonts" and copied the
"C:\Windows\Fonts\arial.ttf" into that, so I changed the line
"D.AddFont('FreeSans.ttf', 'FreeSans-12' to "D.AddFont('arial.ttf',
'Arial", however, when I try to run the project, I get a SIGSEGV:

#0
WRPR_$SYSTEM_$$_TINTERFACEDOBJECT_$_IUNKNOWN_$_2_$_SYSTEM$_$TINTERFACEDOBJECT_$__$$__RELEASE$$LONGINT
at :0
#1 ?? at :0
#2 ?? at :0
#3 ?? at :0
#4
WRPR_$SYSTEM_$$_TINTERFACEDOBJECT_$_IUNKNOWN_$_2_$_SYSTEM$_$TINTERFACEDOBJECT_$__$$__RELEASE$$LONGINT
at :0
#5 ?? at :0

I also get some warnings and hints in the compilation:

Compile Project, Target: testfppdf.exe: Success, Warnings: 5, Hints: 10
fpparsettf.pp(768,45) Hint: Converting the operands to "Int64" before doing
the subtract could prevent overflow errors.
fpparsettf.pp(846,25) Hint: Local variable "N" does not seem to be
initialized
fpparsettf.pp(858,21) Hint: Converting the operands to "Int64" before doing
the add could prevent overflow errors.
fpparsettf.pp(866,19) Warning: Implicit string type conversion with
potential data loss from "WideString" to "AnsiString"
fpparsettf.pp(831,3) Note: Local variable "FMT" is assigned but never used
fppdf.pp(1003,28) Hint: Local variable "Buffer" does not seem to be
initialized
fppdf.pp(982,3) Note: Local variable "I" not used
fppdf.pp(2008,3) Note: Local variable "cs" not used
fppdf.pp(2054,44) Warning: Implicit string type conversion with potential
data loss from "UnicodeString" to "AnsiString"
fppdf.pp(2641,3) Note: Local variable "lFontIndex" not used
fppdf.pp(3001,5) Note: User defined: The 1000 value is a work-around until
I can figure out the character spacing problem.
fppdf.pp(3006,31) Warning: Implicit string type conversion from
"AnsiString" to "WideString"
fppdf.pp(3007,35) Warning: Implicit string type conversion from
"AnsiString" to "WideString"
fppdf.pp(3092,37) Warning: Implicit string type conversion with potential
data loss from "WideString" to "AnsiString"
testfppdf.lpr(46,11) Hint: Local proc "EmptyPage" is not used

Lazarus 1.7 rUnknown FPC 3.1.1 i386-win32-win32/win64

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

Re: [fpc-pascal] Access violation in an empty project declaring heaptrc

2016-03-03 Thread silvioprog
On Thu, Mar 3, 2016 at 4:05 AM, Sven Barth 
wrote:
[...]

> That is the memory that had been used before the memory manager of the
> heaptrc unit had been setup. Remember that there's first the System unit
> initialization and only then the initialization of the heaptrc unit.
>
Indeed. About the AV, I'm not sure if it is related to #29558
, because it happens even
with a empty project just declaring the heap unit.

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

Re: [fpc-pascal] Primitive Record Wrappers

2016-03-03 Thread silvioprog
On Thu, Mar 3, 2016 at 10:16 AM, Mazola Winstrol <mazofei...@gmail.com>
wrote:

> 2016-03-02 23:12 GMT-03:00 silvioprog <silviop...@gmail.com>:
>
>> On Tue, Mar 1, 2016 at 12:08 AM, Mazola Winstrol <mazofei...@gmail.com>
>> wrote:
>> [...]
>>>
>>> I apologize, it works.
>>>
>>
>> Do you have plan to share it in some place like Github, Lazarus-CCR or as
>> Lazarus generics demo? Just a idea, because this implementation sounds good.
>>
>>
> Yes, sure! I dont know where to place yet. What you suggests?
>
> I will send to list the final version in the next days for discussion.
>

I can ask FPC/Lazarus team to distribute it as a FPC, Lazarus or
Lazarus-CCR generics demo, otherwise you can send it to Github, something
like "github.com/mazofeifer/fpc-prw". :-)

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

  1   2   3   4   5   6   >