[fpc-pascal] Re: Runs correctly when debugging.

Henry Vermaak henry.vermaak at gmail.com
Tue May 8 13:22:56 CEST 2012


On 08/05/12 11:52, Guillermo Martínez Jiménez wrote:
>> From: Henry Vermaak
>> Subject: Re: [fpc-pascal] Re: Runs correctly when debugging.
>>
>> It's hard to say without seeing your function/type declarations.
> 
> Actually I don't call the function that raises the SIGSEGV signal,
> since it's an internal function.  Allegro has a "driver" struct
> (RECORD) that stores a pointer to this function only if OpenGL is used
> (else it uses DirectX or something like that), then functions that
> uses or modifies the "bitmap" struct uses it.
> 
> For example, it's used by next function:
> 
>   ALLEGRO_BITMAP *al_load_bitmap(const char *filename);
> 
> The wrapper I wrote is:
> 
>   TYPE
>   (* Abstract type representing a bitmap (2D image). *)
>     ALLEGRO_BITMAPptr = POINTER;
> 
>   FUNCTION al_load_bitmap (CONST filename: STRING): ALLEGRO_BITMAPptr; CDECL;
>   EXTERNAL ALLEGRO_LIB_NAME;
> 
> I'm concerning about the "STRING" type as it may affect the stack (I
> had problems with enumerations because FPC optimised them and C
> doesn't) and use "PCHAR" instead, but manual says it's not a problem
> if using "-h" or "{$LONGSTRINGS ON}".

No, you have to use pchar.  I would also define ALLEGRO_BITMAP as an
empty record, to be clear that it's an opaque type:

{$packrecords c}
  TAllegroBitmap = record
  end;
  PAllegroBitmap = ^TAllegroBitmap;

Thus:

function al_load_bitmap(const filename: pchar): PAllegroBitmap; cdecl;
external ALLEGRO_LIB_NAME;

Make sure you use {$packrecords c}.  Use the types in unit "ctypes",
e.g. cint, cfloat, cdouble.  This will ensure the variables are the same
size and work on all architectures.

Henry



More information about the fpc-pascal mailing list