← board

Initialize() / Finalize() standard procedures (managed-type intrinsics)

Problem

FPC/Delphi define Initialize(v) / Finalize(v[, count]) standard procs: treat v (a variable of a managed type, or a record/array containing managed fields) as raw memory and set it to the initialized-empty state (Initialize), or release its managed contents (Finalize). Canonical use:

{ TLinkedListItem.GetCopy raw-Moves all instance data -> the ansistring
  field now aliases the original without a refcount bump. Reinit the field
  as if it were fresh memory, then assign properly: }
Initialize(TCmdStrListItem(Result).FPStr);
TCmdStrListItem(Result).FPStr := FPstr;

pxx has the underlying machinery (managed locals get init/final generated by the compiler) but does not expose it as callable intrinsics — grep for an Initialize builtin comes up empty.

Fix shape

Two intrinsics resolving against the argument's static type:

Gate

make test + self-host byte-identical. Regressions: Move-then-Initialize refcount pattern (mirror the cclasses idiom) leaks nothing and double-frees nothing under the ansistring refcount checks; Finalize on a record with mixed managed/unmanaged fields.