[fpc-pascal] FPC cannot understand 1-char string as PChar

Sven Barth pascaldragon at googlemail.com
Tue Nov 5 07:51:18 CET 2019


AlexeyT via fpc-pascal <fpc-pascal at lists.freepascal.org> schrieb am Mo., 4.
Nov. 2019, 23:40:

> FPC 3.3.1-r43022 [2019/09/16] for Linux x64. This code crashes, because
> fpc sees 'x', 'y' wrong:
>
>    Py_BuildValue('{sLsisisisisisisOsOsOsisisisisisO}',
>      'tag',
>      Mark.Tag,
>      'x',
>      Mark.PosX,
>      'y',
>      Mark.PosY,
>      'len',
>      Mark.LenX,
>
> I must change it to this, it works ok:
>    Py_BuildValue('{sLsisisisisisisOsOsOsisisisisisO}',
>      'tag',
>      Mark.Tag,
>      PChar(string('x')),
>      Mark.PosX,
>      PChar(string('y')),
>      Mark.PosY,
>      'len',
>      Mark.LenX,
>
> Py_BuildValue is from Python-for-Lazarus package.
>      Py_BuildValue:      function( format: PAnsiChar {;...}): PPyObject;
> cdecl varargs;
>

What did you expect? With varargs the compiler can't do any checks, thus
the types are inserted as is and 'x' *is* a char or maybe a Pascal string,
but by itself *never* a PChar. So the cast is the correct way.

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20191105/5ed3e5a7/attachment.html>


More information about the fpc-pascal mailing list