Sign in Join

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

Mailing lists / fpc-pascal / 2019-11

FPC cannot understand 1-char string as PChar

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

AlexeyT

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

Reply by email

Sven Barth
to AlexeyT

AlexeyT via fpc-pascal schrieb am Mo., 4.
Nov. 2019, 23:40:

Show quoted text 28 lines
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

Reply by email