TMarshal & TMarshaller.
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
TMarshalandTMarshallerbelong to SysUtils because my FPCUpDeluxe does not compilegeneric procedures insystem. >_<
Conscious changes from Delphi:
- Memory-themed arguments are
SizeInts instead ofIntegers.
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
unicodestringby 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 bytes82 A0 82 A9; converting first 3 bytes withWideStringManager.Ansi2UnicodeMoveProcgivesあ・; Delphi gives singleあ, because underlying APIs are able to do that; but with FPC wrappers fromWideStringManager, 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 inWideStringManager, e.g. by having more direct equivalents toWideCharToMultiByte/MultiByteToWideCharthan currently available ones. -
TMarshalleruses 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 preparingTMarshalleras a local variable and then saving it into a field, or some such nonsense.