FPC cannot understand 1-char string as PChar

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

FPC cannot understand 1-char string as PChar

Free Pascal - General mailing list
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;

--
Regards,
Alexey

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FPC cannot understand 1-char string as PChar

Free Pascal - General mailing list
AlexeyT via fpc-pascal <[hidden email]> 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 

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal