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
TMarshal
andTMarshaller
belong to SysUtils because my FPCUpDeluxe does not compilegeneric procedure
s insystem
. >_<
Conscious changes from Delphi:
- Memory-themed arguments are
SizeInt
s instead ofInteger
s.
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 bytes82 A0 82 A9
; converting first 3 bytes withWideStringManager.Ansi2UnicodeMoveProc
givesあ・
; 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/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 preparingTMarshaller
as a local variable and then saving it into a field, or some such nonsense.