Skip to content

TMarshal & TMarshaller.

Rika requested to merge runewalsh/source:marsh into main

These are classes from Delphi (XE3+), I still have no idea what problem they are supposed to solve... However I made a test tests/test/units/sysutils/tmarshaller.pp, and it can be run both from FPC and Delphi (that’s its whole point). Another thing that bothers me is that I found a lot of XE3 bugs, many of these functions are unusable in XE3, for example, TMarshaller.ReallocMem that changed the pointer value leads to calling a nil procedural variable in the future TMarshaller.Flush. Enable {$define test_things_broken_in_xe3} to test on newer versions if you want.

TEMPORARY MEASURES:

  • Both TMarshal and TMarshaller belong to SysUtils because my FPCUpDeluxe does not compile generic procedures in system. >_<

Conscious changes from Delphi:

  • Memory-themed arguments are SizeInts instead of Integers.

Various notes:

  • Unlike Delphi, string functions with length limit can leave the last multi-byte character unfinished (when reading or writing). In some cases this could be worked around in a very slow and complex way (like: shrink the input unicodestring by 1 character at a time, stop when its conversion to ANSI fits into the limit... or do a binary search... or come up with something more clever but even more hacky and complex), but sometimes the workaround is close to impossible (あか in Shift-JIS is 4 bytes 82 A0 82 A9; converting first 3 bytes with WideStringManager.Ansi2UnicodeMoveProc gives あ・; Delphi gives single , because underlying APIs are able to do that; but with FPC wrappers from WideStringManager, how are you supposed to reliably detect that, and what will you do next?..). I think that, if this is an issue, it must be resolved in WideStringManager, e.g. by having more direct equivalents to WideCharToMultiByte/MultiByteToWideChar than currently available ones.

  • TMarshaller uses an interface (could use a managed record with manual reference counting, to the same effect and more code) because Delphi version can, in theory, be copied; imagine preparing TMarshaller as a local variable and then saving it into a field, or some such nonsense.

Edited by Rika

Merge request reports