Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-05

Gecko / Firefox / XPCOM

9 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Henrik Genssen

Hi,

I am trying to use the gecko libs from http://sourceforge.net/projects/d-gecko with lazarus.

i get the following errors:
Hint: Start of reading config file c:\lazarus\fpc\2.2.2\bin\i386-win32\fpc.cfg Hint: End of reading config file c:\lazarus\fpc\2.2.2\bin\i386-win32\fpc.cfg Free Pascal Compiler version 2.2.2 [2008/10/05] for i386 Copyright (c) 1993-2008 by Florian Klaempfl
Target OS: Win32 for i386
Compiling project1.lpr
Compiling SimpleDownloadForm.pas
Compiling nsGeckoStrings.pas
Compiling nsInit.pas
nsInit.pas(55,15) Hint: Type "PLongBool" redefinition nsInit.pas(104,1) Hint: C arrays are passed by reference nsInit.pas(233,27) Hint: Type "PGREVersionRangeArray" redefinition nsInit.pas(241,23) Hint: Type "PGREPropertyArray" redefinition Compiling nsMemory.pas
nsMemory.pas(155,13) Warning: Some fields coming before "GetMem" weren't initialized nsMemory.pas(157,17) Warning: Some fields coming before "ReallocMem" weren't initialized nsMemory.pas(157,17) Error: Incompatible types: got "Realloc(Pointer, LongInt):^untyped" expected "<procedure variable type of function(var Pointer, LongInt):^untyped;Register>" nsMemory.pas(165) Fatal: There were 1 errors compiling module, stopping

for the following costruct - stopping at the line ReallocMem:

const
  memmgr: TMemoryManager = (
    GetMem: Alloc;
    FreeMem: Free;
    ReallocMem: Realloc;
  );
procedure SetToMemoryManager;
begin
  SetMemoryManager(memmgr);
end;

how can that be done in FPC?

regards

Hinnack

Reply by email

Flávio Etrusco
to Henrik Genssen
Henrik Genssen wrote 24 lines
(...) nsMemory.pas(155,13) Warning: Some fields coming before "GetMem" weren't initialized nsMemory.pas(157,17) Warning: Some fields coming before "ReallocMem" weren't initialized nsMemory.pas(157,17) Error: Incompatible types: got "Realloc(Pointer, LongInt):^untyped" expected "<procedure variable type of function(var Pointer, LongInt):^untyped;Register>" nsMemory.pas(165) Fatal: There were 1 errors compiling module, stopping for the following costruct - stopping at the line ReallocMem: const  memmgr: TMemoryManager = (    GetMem: Alloc;    FreeMem: Free;    ReallocMem: Realloc;  ); procedure SetToMemoryManager; begin  SetMemoryManager(memmgr); end; how can that be done in FPC? regards Hinnack

You must either set Delphi compiler mode - {$mode Delphi} - or get a reference/pointer to the functions Alloc, Free and Realloc (prefix them with the @ operator).
BTW, it looks like you're accessing the TMemoryManager declaration from System.pp/SysInit (? heaph.inc), is it what you intended?

Best regards,
Flávio

Reply by email

Henrik Genssen
to Flávio Etrusco
Show quoted text 21 lines
> (...) > nsMemory.pas(155,13) Warning: Some fields coming before "GetMem" weren't initialized > nsMemory.pas(157,17) Warning: Some fields coming before "ReallocMem" weren't initialized > nsMemory.pas(157,17) Error: Incompatible types: got "Realloc(Pointer, LongInt):^untyped" expected "<procedure variable type of function(var Pointer, LongInt):^untyped;Register>" > nsMemory.pas(165) Fatal: There were 1 errors compiling module, stopping > > for the following costruct - stopping at the line ReallocMem: > > const > memmgr: TMemoryManager = ( > GetMem: Alloc; > FreeMem: Free; > ReallocMem: Realloc; > ); > procedure SetToMemoryManager; > begin > SetMemoryManager(memmgr); > end; You must either set Delphi compiler mode - {$mode Delphi} - or get a reference/pointer to the functions Alloc, Free and Realloc (prefix them with the @ operator).

I have already set the compilermode to Delphi - any other idea?

BTW, it looks like you're accessing the TMemoryManager declaration from System.pp/SysInit (? heaph.inc), is it what you intended?

in Delphi system.pas is used:

  PMemoryManager = ^TMemoryManager;
  TMemoryManager = record
    GetMem: function(Size: Integer): Pointer;
    FreeMem: function(P: Pointer): Integer;
    ReallocMem: function(P: Pointer; Size: Integer): Pointer;
  end;

what shell I use with FPC?

regards

Hinnack

Reply by email

Jonas Maebe
to Henrik Genssen: I am trying to use the gecko libs from http://sourceforge.net/projects/d-gecko with…
Henrik Genssen wrote
nsMemory.pas(157,17) Error: Incompatible types: got "Realloc(Pointer, LongInt):^untyped" expected "<procedure variable type of function(var Pointer, LongInt):^untyped;Register>"

As the error message says: the compiler expects the first parameter of realloc to be a "var" parameter, while the declaration of realloc apparently uses a value parameter.

Jonas

Reply by email

Flávio Etrusco
to Jonas Maebe: As the error message says: the compiler expects the first parameter of realloc to be a…
Jonas Maebe wrote 13 lines
On 21 May 2009, at 22:34, Henrik Genssen wrote: > nsMemory.pas(157,17) Error: Incompatible types: got "Realloc(Pointer, > LongInt):^untyped" expected "<procedure variable type of function(var > Pointer, LongInt):^untyped;Register>" As the error message says: the compiler expects the first parameter of realloc to be a "var" parameter, while the declaration of realloc apparently uses a value parameter. Jonas

Oops. I guess I assumed the code was the other way around: that the gecko runtime accepted an application-provided mem-allocation routines, and barely read the message :-$
BTW, regarding the remaining Warnings from the OP: is there any optional member in TMemoryManager or do all of them need to be setup?

-Flávio

Reply by email

Henrik Genssen
to Den Jean: in case you didn't know http://lists.lazarus.freepascal.org/pipermail/qt/2009-May/001212.h…

no, I did not know that.
Thanx for the hint - but its stuck to QT :-(

therefor I am more interested in gecko...

Show quoted text 16 lines
reply to message: date: 24.05.2009 15:15:50 from: "Den Jean" to: "FPC-Pascal users discussions" subject: Re: [fpc-pascal] Gecko / Firefox / XPCOM On Thursday 21 May 2009 22:34:52 Henrik Genssen wrote: > I am trying to use the gecko libs from > http://sourceforge.net/projects/d-gecko with lazarus. in case you didn't know http://lists.lazarus.freepascal.org/pipermail/qt/2009-May/001212.html _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Henrik Genssen
to Flávio Etrusco: Oops. I guess I assumed the code was the other way around: that the gecko runtime…

so how can this unit be converted to FPC,
as the Memorymanager of FPC seems to differ from delphi...

unit nsMemory;
{$MODE Delphi}
interface
uses
  nsXPCOM;
const
  NS_MEMORY_CONTRACTID = '@mozilla.org/xpcom/memory-service;1';
  NS_MEMORY_CLASSNAME = 'Global Memory Service';
  NS_MEMORY_CID: TGUID = '{30a04e40-38e7-11d4-8cf5-0060b0fc14a3}';
function Alloc(size: Integer): Pointer;
function Realloc(ptr: Pointer; size: Integer): Pointer;
function Free(ptr: Pointer): Integer;
function HeapMinimize(aImmediate: Boolean): Longword;
function Clone(Ptr: Pointer; size: Longword): Pointer;
function GetGlobalMemoryService: nsIMemory;
function GlueStartupMemory: Longword;
procedure GlueShutdownMemory;
procedure SetToMemoryManager;
implementation
uses
  nsError, nsInit;
var
  gMemory: nsIMemory;
procedure FreeGlobalMemory;
begin
  gMemory := nil;
end;
function SetupGlobalMemory: nsIMemory;
begin
  if Assigned(gMemory) then Exit;
  nsInit.NS_GetMemoryManager(gMemory);
  if not Assigned(gMemory) then Exit;
  Result := gMemory;
end;
function GlueStartupMemory: Longword;
begin
  Result := NS_ERROR_FAILURE;
  if Assigned(gMemory) then Exit;
  nsInit.NS_GetMemoryManager(gMemory);
  if not Assigned(gMemory) then Exit;
  Result := NS_OK;
end;
procedure GlueShutdownMemory;
begin
  gMemory := nil;
end;
function ENSURE_ALLOCATOR: Boolean;
begin
  Result := True;
  if not Assigned(gMemory) and not Assigned(SetupGlobalMemory()) then
    Result := False;
end;
function Alloc(size: Integer): Pointer;
begin
  Result := nil;
  if ENSURE_ALLOCATOR then
    Result := gMemory.Alloc(size);
end;
function Realloc(ptr: Pointer; size: Integer): Pointer;
begin
  Result := nil;
  if ENSURE_ALLOCATOR then
    Result := gMemory.Realloc(ptr, size);
end;
function Free(ptr: Pointer): Integer;
begin
  Result := NS_OK;
  if ENSURE_ALLOCATOR then gMemory.Free(ptr)
  else
    Result := Integer(NS_ERROR_UNEXPECTED);
end;
function HeapMinimize(aImmediate: Boolean): Longword;
begin
  Result := NS_ERROR_FAILURE;
  if ENSURE_ALLOCATOR then
  try
    Result := NS_OK;
    gMemory.HeapMinimize(aImmediate);
  except
    Result := NS_ERROR_FAILURE;
  end;
end;
function Clone(ptr: Pointer; size: Longword): Pointer;
begin
  Result := nil;
  if ENSURE_ALLOCATOR then
    Result := Clone(Ptr, size);
end;
function GetGlobalMemoryService: nsIMemory;
begin
  Result := nil;
  if not ENSURE_ALLOCATOR then Exit;
  Result := gMemory;
end;
const
  memmgr: TMemoryManager = (
    GetMem: Alloc;
    FreeMem: Free;
    ReallocMem: Realloc;
  );
procedure SetToMemoryManager;
begin
  SetMemoryManager(memmgr);
end;
end.
Show quoted text 33 lines
reply to message: date: 24.05.2009 18:28:19 from: "Flávio Etrusco" to: "FPC-Pascal users discussions" subject: Re: [fpc-pascal] Gecko / Firefox / XPCOM On Sun, May 24, 2009 at 9:30 AM, Jonas Maebe wrote: > > On 21 May 2009, at 22:34, Henrik Genssen wrote: > >> nsMemory.pas(157,17) Error: Incompatible types: got "Realloc(Pointer, >> LongInt):^untyped" expected "<procedure variable type of function(var >> Pointer, LongInt):^untyped;Register>" > > As the error message says: the compiler expects the first parameter of > realloc to be a "var" parameter, while the declaration of realloc apparently > uses a value parameter. > > > Jonas Oops. I guess I assumed the code was the other way around: that the gecko runtime accepted an application-provided mem-allocation routines, and barely read the message :-$ BTW, regarding the remaining Warnings from the OP: is there any optional member in TMemoryManager or do all of them need to be setup? -Flávio _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email