rtti.inc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Michael Van Canneyt
  4. member of the Free Pascal development team
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. { Run-Time type information routines }
  12. function RTTIArraySize(typeInfo: Pointer): SizeInt;
  13. begin
  14. {$ifdef VER3_0}
  15. typeInfo:=aligntoptr(typeInfo+2+PByte(typeInfo)[1]);
  16. {$else VER3_0}
  17. typeInfo:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  18. {$endif VER3_0}
  19. {$ifdef VER2_6}
  20. result:=PArrayInfo(typeInfo)^.Size*PArrayInfo(typeInfo)^.ElCount;
  21. {$else}
  22. result:=PArrayInfo(typeInfo)^.Size;
  23. {$endif}
  24. end;
  25. function RTTIRecordSize(typeInfo: Pointer): SizeInt;
  26. begin
  27. {$ifdef VER3_0}
  28. typeInfo:=aligntoptr(typeInfo+2+PByte(typeInfo)[1]);
  29. {$else VER3_0}
  30. typeInfo:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  31. {$endif VER3_0}
  32. { for size field init table is compatible with rtti table }
  33. result:=PRecordInfoFull(typeInfo)^.Size;
  34. end;
  35. {$ifndef VER3_0}
  36. function RTTIRecordOp(typeInfo: Pointer; var initrtti: Pointer): PRecordInfoInit; inline;
  37. begin
  38. { find init table and management operators }
  39. typeInfo:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  40. result:=typeInfo;
  41. { check terminator, maybe we are already in init table }
  42. if Assigned(result^.Terminator) then
  43. begin
  44. { point to more optimal initrtti }
  45. initrtti:=PRecordInfoFull(result)^.InitTable;
  46. { and point to management operators in our init table }
  47. result:=aligntoqword(initrtti+2+PByte(initrtti)[1]);
  48. end
  49. end;
  50. {$else VER3_0}
  51. function RTTIRecordRttiInfoToInitInfo(typeInfo: Pointer): Pointer; inline;
  52. begin
  53. result:=typeInfo;
  54. {$ifndef VER3_0}
  55. { find init table }
  56. typeInfo:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  57. { check terminator, maybe we are already in init table }
  58. if Assigned(PRecordInfoInit(typeInfo)^.Terminator) then
  59. { point to more optimal initrtti }
  60. result:=PRecordInfoFull(typeInfo)^.InitTable;
  61. {$endif VER3_0}
  62. end;
  63. {$endif VER3_0}
  64. {$ifndef VER3_0}
  65. function RTTISizeAndOp(typeInfo: Pointer;
  66. const expectedManagementOp: TRTTIRecOpType; out hasManagementOp: boolean): SizeInt;
  67. begin
  68. hasManagementOp:=false;
  69. {$else VER3_0}
  70. function RTTISize(typeInfo: Pointer): SizeInt;
  71. begin
  72. {$endif VER3_0}
  73. case PTypeKind(typeinfo)^ of
  74. tkAString,tkWString,tkUString,
  75. tkInterface,tkDynarray:
  76. result:=sizeof(Pointer);
  77. {$ifdef FPC_HAS_FEATURE_VARIANTS}
  78. tkVariant:
  79. result:=sizeof(TVarData);
  80. {$endif FPC_HAS_FEATURE_VARIANTS}
  81. tkArray:
  82. result:=RTTIArraySize(typeinfo);
  83. {$ifndef VER3_0}
  84. tkObject:
  85. result:=RTTIRecordSize(typeinfo);
  86. tkRecord:
  87. with RTTIRecordOp(typeInfo,typeInfo)^ do
  88. begin
  89. result:=Size;
  90. hasManagementOp := Assigned(RecordOp);
  91. if hasManagementOp then
  92. case expectedManagementOp of
  93. rotInitialize: hasManagementOp:=Assigned(RecordOp^.Initialize);
  94. rotFinalize: hasManagementOp:=Assigned(RecordOp^.Finalize);
  95. rotAddRef: hasManagementOp:=Assigned(RecordOp^.AddRef);
  96. rotCopy: hasManagementOp:=Assigned(RecordOp^.Copy);
  97. end;
  98. end;
  99. {$else VER3_0}
  100. tkObject,tkRecord:
  101. result:=RTTIRecordSize(typeinfo);
  102. {$endif VER3_0}
  103. else
  104. result:=-1;
  105. end;
  106. end;
  107. { if you modify this procedure, fpc_copy must be probably modified as well }
  108. procedure RecordRTTI(Data,TypeInfo:Pointer;rttiproc:TRTTIProc);
  109. var
  110. count,
  111. i : longint;
  112. begin
  113. {$ifdef VER3_0}
  114. typeInfo:=aligntoptr(typeInfo+2+PByte(typeInfo)[1]);
  115. {$else VER3_0}
  116. typeInfo:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  117. {$endif VER3_0}
  118. Count:=PRecordInfoInit(typeInfo)^.Count;
  119. Inc(PRecordInfoInit(typeInfo));
  120. { Process elements }
  121. for i:=1 to count Do
  122. begin
  123. rttiproc(Data+PRecordElement(typeInfo)^.Offset,PRecordElement(typeInfo)^.TypeInfo{$ifndef VER3_0}^{$endif});
  124. Inc(PRecordElement(typeInfo));
  125. end;
  126. end;
  127. {$ifndef VER3_0}
  128. function RTTIRecordMopInitTable(ti: Pointer): PRTTIRecordOpOffsetTable;
  129. begin
  130. ti:=aligntoqword(ti+2+PByte(ti)[1]);
  131. Result:=PRecordInfoInit(ti)^.InitRecordOpTable;
  132. end;
  133. {$endif VER3_0}
  134. { if you modify this procedure, fpc_copy must be probably modified as well }
  135. {$ifdef VER2_6}
  136. procedure ArrayRTTI(Data,TypeInfo:Pointer;rttiproc:TRTTIProc);
  137. var
  138. i: SizeInt;
  139. begin
  140. {$ifdef VER3_0}
  141. typeInfo:=aligntoptr(typeInfo+2+PByte(typeInfo)[1]);
  142. {$else VER3_0}
  143. typeInfo:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  144. {$endif VER3_0}
  145. { Process elements }
  146. for I:=0 to PArrayInfo(typeInfo)^.ElCount-1 do
  147. rttiproc(Data+(I*PArrayInfo(typeInfo)^.Size),PArrayInfo(typeInfo)^.ElInfo);
  148. end;
  149. {$else}
  150. procedure ArrayRTTI(Data,TypeInfo:Pointer;rttiproc:TRTTIProc);
  151. var
  152. i,Count,ElSize: SizeInt;
  153. Info: Pointer;
  154. begin
  155. {$ifdef VER3_0}
  156. typeInfo:=aligntoptr(typeInfo+2+PByte(typeInfo)[1]);
  157. {$else VER3_0}
  158. typeInfo:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  159. {$endif VER3_0}
  160. Count:=PArrayInfo(typeInfo)^.ElCount;
  161. { no elements to process => exit }
  162. if Count = 0 then
  163. Exit;
  164. ElSize:=PArrayInfo(typeInfo)^.Size div Count;
  165. Info:=PArrayInfo(typeInfo)^.ElInfo{$ifndef VER3_0}^{$endif};
  166. { Process elements }
  167. for I:=0 to Count-1 do
  168. rttiproc(Data+(I*ElSize),Info);
  169. end;
  170. {$endif}
  171. Procedure fpc_Initialize (Data,TypeInfo : pointer);[Public,Alias : 'FPC_INITIALIZE']; compilerproc;
  172. begin
  173. case PTypeKind(TypeInfo)^ of
  174. {$ifdef FPC_HAS_FEATURE_DYNARRAYS}
  175. tkDynArray,
  176. {$endif FPC_HAS_FEATURE_DYNARRAYS}
  177. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  178. tkAstring,
  179. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  180. {$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
  181. tkWstring,tkUString,
  182. {$endif FPC_HAS_FEATURE_WIDESTRINGS}
  183. tkInterface:
  184. PPchar(Data)^:=Nil;
  185. tkArray:
  186. arrayrtti(data,typeinfo,@int_initialize);
  187. {$ifdef FPC_HAS_FEATURE_OBJECTS}
  188. tkObject,
  189. {$endif FPC_HAS_FEATURE_OBJECTS}
  190. tkRecord:
  191. {$ifndef VER3_0}
  192. { if possible try to use more optimal initrtti }
  193. with RTTIRecordOp(typeinfo, typeinfo)^ do
  194. begin
  195. recordrtti(data,typeinfo,@int_initialize);
  196. if Assigned(recordop) and Assigned(recordop^.Initialize) then
  197. recordop^.Initialize(data);
  198. end;
  199. {$else VER3_0}
  200. begin
  201. typeinfo:=RTTIRecordRttiInfoToInitInfo(typeinfo);
  202. recordrtti(data,typeinfo,@int_initialize);
  203. end;
  204. {$endif VER3_0}
  205. {$ifdef FPC_HAS_FEATURE_VARIANTS}
  206. tkVariant:
  207. variant_init(PVarData(Data)^);
  208. {$endif FPC_HAS_FEATURE_VARIANTS}
  209. end;
  210. end;
  211. Procedure fpc_finalize (Data,TypeInfo: Pointer);[Public,Alias : 'FPC_FINALIZE']; compilerproc;
  212. begin
  213. case PTypeKind(TypeInfo)^ of
  214. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  215. tkAstring :
  216. fpc_AnsiStr_Decr_Ref(PPointer(Data)^);
  217. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  218. {$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
  219. tkUstring :
  220. fpc_UnicodeStr_Decr_Ref(PPointer(Data)^);
  221. {$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
  222. tkWstring :
  223. fpc_WideStr_Decr_Ref(PPointer(Data)^);
  224. {$endif FPC_WIDESTRING_EQUAL_UNICODESTRING}
  225. {$endif FPC_HAS_FEATURE_WIDESTRINGS}
  226. tkArray :
  227. arrayrtti(data,typeinfo,@int_finalize);
  228. {$ifdef FPC_HAS_FEATURE_OBJECTS}
  229. tkObject,
  230. {$endif FPC_HAS_FEATURE_OBJECTS}
  231. tkRecord:
  232. {$ifndef VER3_0}
  233. { if possible try to use more optimal initrtti }
  234. with RTTIRecordOp(typeinfo, typeinfo)^ do
  235. begin
  236. if Assigned(recordop) and Assigned(recordop^.Finalize) then
  237. recordop^.Finalize(data);
  238. recordrtti(data,typeinfo,@int_finalize);
  239. end;
  240. {$else VER3_0}
  241. begin
  242. typeinfo:=RTTIRecordRttiInfoToInitInfo(typeinfo);
  243. recordrtti(data,typeinfo,@int_finalize);
  244. end;
  245. {$endif VER3_0}
  246. tkInterface:
  247. Intf_Decr_Ref(PPointer(Data)^);
  248. {$ifdef FPC_HAS_FEATURE_DYNARRAYS}
  249. tkDynArray:
  250. fpc_dynarray_clear(PPointer(Data)^,TypeInfo);
  251. {$endif FPC_HAS_FEATURE_DYNARRAYS}
  252. {$ifdef FPC_HAS_FEATURE_VARIANTS}
  253. tkVariant:
  254. variant_clear(PVarData(Data)^);
  255. {$endif FPC_HAS_FEATURE_VARIANTS}
  256. end;
  257. end;
  258. Procedure fpc_Addref (Data,TypeInfo : Pointer); [Public,alias : 'FPC_ADDREF']; compilerproc;
  259. begin
  260. case PTypeKind(TypeInfo)^ of
  261. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  262. tkAstring :
  263. fpc_AnsiStr_Incr_Ref(PPointer(Data)^);
  264. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  265. {$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
  266. {$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
  267. tkWstring :
  268. fpc_WideStr_Incr_Ref(PPointer(Data)^);
  269. {$endif FPC_WIDESTRING_EQUAL_UNICODESTRING}
  270. tkUstring :
  271. fpc_UnicodeStr_Incr_Ref(PPointer(Data)^);
  272. {$endif FPC_HAS_FEATURE_WIDESTRINGS}
  273. tkArray :
  274. arrayrtti(data,typeinfo,@int_addref);
  275. {$ifdef FPC_HAS_FEATURE_OBJECTS}
  276. tkobject,
  277. {$endif FPC_HAS_FEATURE_OBJECTS}
  278. tkrecord :
  279. {$ifndef VER3_0}
  280. { find init table }
  281. with RTTIRecordOp(typeinfo, typeinfo)^ do
  282. begin
  283. recordrtti(data,typeinfo,@int_addref);
  284. if Assigned(recordop) and Assigned(recordop^.AddRef) then
  285. recordop^.AddRef(Data);
  286. end;
  287. {$else VER3_0}
  288. begin
  289. typeinfo:=RTTIRecordRttiInfoToInitInfo(typeinfo);
  290. recordrtti(data,typeinfo,@int_addref);
  291. end;
  292. {$endif VER3_0}
  293. {$ifdef FPC_HAS_FEATURE_DYNARRAYS}
  294. tkDynArray:
  295. fpc_dynarray_incr_ref(PPointer(Data)^);
  296. {$endif FPC_HAS_FEATURE_DYNARRAYS}
  297. tkInterface:
  298. Intf_Incr_Ref(PPointer(Data)^);
  299. {$ifdef FPC_HAS_FEATURE_VARIANTS}
  300. tkVariant:
  301. variant_addref(pvardata(Data)^);
  302. {$endif FPC_HAS_FEATURE_DYNARRAYS}
  303. end;
  304. end;
  305. { define alias for internal use in the system unit }
  306. Function fpc_Copy_internal (Src, Dest, TypeInfo : Pointer) : SizeInt;[external name 'FPC_COPY'];
  307. Function fpc_Copy (Src, Dest, TypeInfo : Pointer) : SizeInt;[Public,alias : 'FPC_COPY']; compilerproc;
  308. var
  309. Temp: pbyte;
  310. copiedsize,
  311. expectedoffset,
  312. count,
  313. offset,
  314. i: SizeInt;
  315. info: pointer;
  316. begin
  317. result:=sizeof(pointer);
  318. case PTypeKind(TypeInfo)^ of
  319. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  320. tkAstring:
  321. fpc_AnsiStr_Assign(PPointer(Dest)^,PPointer(Src)^);
  322. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  323. {$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
  324. {$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
  325. tkWstring:
  326. fpc_WideStr_Assign(PPointer(Dest)^,PPointer(Src)^);
  327. {$endif FPC_WIDESTRING_EQUAL_UNICODESTRING}
  328. tkUstring:
  329. fpc_UnicodeStr_Assign(PPointer(Dest)^,PPointer(Src)^);
  330. {$endif FPC_HAS_FEATURE_WIDESTRINGS}
  331. tkArray:
  332. begin
  333. {$ifdef VER3_0}
  334. Temp:=aligntoptr(typeInfo+2+PByte(typeInfo)[1]);
  335. {$else VER3_0}
  336. Temp:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  337. {$endif VER3_0}
  338. {$ifdef VER2_6}
  339. { Process elements }
  340. for I:=0 to PArrayInfo(Temp)^.ElCount-1 do
  341. fpc_Copy_internal(Src+(I*PArrayInfo(Temp)^.Size),Dest+(I*PArrayInfo(Temp)^.Size),PArrayInfo(Temp)^.ElInfo);
  342. Result:=PArrayInfo(Temp)^.Size*PArrayInfo(Temp)^.ElCount;
  343. {$else}
  344. Result:=PArrayInfo(Temp)^.Size;
  345. Count:=PArrayInfo(Temp)^.ElCount;
  346. { no elements to process => exit }
  347. if Count = 0 then
  348. Exit;
  349. Info:=PArrayInfo(Temp)^.ElInfo{$ifndef VER3_0}^{$endif};
  350. copiedsize:=Result div Count;
  351. Offset:=0;
  352. { Process elements }
  353. for I:=1 to Count do
  354. begin
  355. fpc_Copy_internal(Src+Offset,Dest+Offset,Info);
  356. inc(Offset,copiedsize);
  357. end;
  358. {$endif}
  359. end;
  360. {$ifdef FPC_HAS_FEATURE_OBJECTS}
  361. tkobject,
  362. {$endif FPC_HAS_FEATURE_OBJECTS}
  363. tkrecord:
  364. {$ifndef VER3_0}
  365. { find init table }
  366. with RTTIRecordOp(typeinfo, typeinfo)^ do
  367. {$endif VER3_0}
  368. begin
  369. {$ifdef VER3_0}
  370. typeInfo:=RTTIRecordRttiInfoToInitInfo(typeInfo);
  371. Temp:=aligntoptr(typeInfo+2+PByte(typeInfo)[1]);
  372. {$else VER3_0}
  373. Temp:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  374. {$endif VER3_0}
  375. {$ifndef VER3_0}
  376. if Assigned(recordop) and Assigned(recordop^.Copy) then
  377. recordop^.Copy(Src,Dest)
  378. else
  379. begin
  380. Result:=Size;
  381. Inc(PRecordInfoInit(Temp));
  382. {$else VER3_0}
  383. Result:=PRecordInfoFull(Temp)^.Size;
  384. Count:=PRecordInfoFull(Temp)^.Count;
  385. Inc(PRecordInfoFull(Temp));
  386. {$endif VER3_0}
  387. expectedoffset:=0;
  388. { Process elements with rtti }
  389. for i:=1 to Count Do
  390. begin
  391. Info:=PRecordElement(Temp)^.TypeInfo{$ifndef VER3_0}^{$endif};
  392. Offset:=PRecordElement(Temp)^.Offset;
  393. Inc(PRecordElement(Temp));
  394. if Offset>expectedoffset then
  395. move((Src+expectedoffset)^,(Dest+expectedoffset)^,Offset-expectedoffset);
  396. copiedsize:=fpc_Copy_internal(Src+Offset,Dest+Offset,Info);
  397. expectedoffset:=Offset+copiedsize;
  398. end;
  399. { elements remaining? }
  400. if result>expectedoffset then
  401. move((Src+expectedoffset)^,(Dest+expectedoffset)^,Result-expectedoffset);
  402. {$ifndef VER3_0}
  403. end;
  404. {$endif VER3_0}
  405. end;
  406. {$ifdef FPC_HAS_FEATURE_DYNARRAYS}
  407. tkDynArray:
  408. fpc_dynarray_assign(PPointer(Dest)^,PPointer(Src)^,typeinfo);
  409. {$endif FPC_HAS_FEATURE_DYNARRAYS}
  410. tkInterface:
  411. fpc_intf_assign(PPointer(Dest)^,PPointer(Src)^);
  412. {$ifdef FPC_HAS_FEATURE_VARIANTS}
  413. tkVariant:
  414. begin
  415. VarCopyProc(pvardata(dest)^,pvardata(src)^);
  416. result:=sizeof(tvardata);
  417. end;
  418. {$endif FPC_HAS_FEATURE_VARIANTS}
  419. end;
  420. end;
  421. { For internal use by the compiler, because otherwise $x- can cause trouble. }
  422. { Generally disabling extended syntax checking for all compilerprocs may }
  423. { have unintended side-effects }
  424. procedure fpc_Copy_proc (Src, Dest, TypeInfo : Pointer);compilerproc; inline;
  425. begin
  426. fpc_copy_internal(src,dest,typeinfo);
  427. end;
  428. procedure fpc_initialize_array(data,typeinfo : pointer;count : SizeInt); [public,alias:'FPC_INITIALIZE_ARRAY']; compilerproc;
  429. var
  430. i, size : SizeInt;
  431. {$ifndef VER3_0}
  432. hasManagementOp: boolean;
  433. begin
  434. size:=RTTISizeAndOp(typeinfo, rotInitialize, hasManagementOp);
  435. if (size>0) or hasManagementOp then
  436. {$else VER3_0}
  437. begin
  438. size:=RTTISize(typeInfo);
  439. if size>0 then
  440. {$endif VER3_0}
  441. for i:=0 to count-1 do
  442. int_initialize(data+size*i,typeinfo);
  443. end;
  444. procedure fpc_finalize_array(data,typeinfo : pointer;count : SizeInt); [Public,Alias:'FPC_FINALIZE_ARRAY']; compilerproc;
  445. var
  446. i, size: SizeInt;
  447. {$ifndef VER3_0}
  448. hasManagementOp: boolean;
  449. begin
  450. size:=RTTISizeAndOp(typeinfo, rotFinalize, hasManagementOp);
  451. if (size>0) or hasManagementOp then
  452. {$else VER3_0}
  453. begin
  454. size:=RTTISize(typeInfo);
  455. if size>0 then
  456. {$endif VER3_0}
  457. for i:=0 to count-1 do
  458. int_finalize(data+size*i,typeinfo);
  459. end;
  460. procedure fpc_addref_array(data,typeinfo: pointer; count: SizeInt); [public,alias:'FPC_ADDREF_ARRAY']; compilerproc;
  461. var
  462. i, size: SizeInt;
  463. {$ifndef VER3_0}
  464. hasManagementOp: boolean;
  465. begin
  466. size:=RTTISizeAndOp(typeinfo, rotAddRef, hasManagementOp);
  467. if (size>0) or hasManagementOp then
  468. {$else VER3_0}
  469. begin
  470. size:=RTTISize(typeInfo);
  471. if size>0 then
  472. {$endif VER3_0}
  473. for i:=0 to count-1 do
  474. int_addref(data+size*i,typeinfo);
  475. end;
  476. { The following two procedures are now obsolete, needed only for bootstrapping }
  477. procedure fpc_decref (Data, TypeInfo : Pointer);[Public,alias : 'FPC_DECREF']; compilerproc;
  478. begin
  479. int_finalize(Data,TypeInfo);
  480. end;
  481. procedure fpc_decref_array(data,typeinfo: pointer; count: SizeInt); [public,alias:'FPC_DECREF_ARRAY']; compilerproc;
  482. begin
  483. int_finalizeArray(data,typeinfo,count);
  484. end;
  485. procedure InitializeArray(p, typeInfo: Pointer; count: SizeInt);
  486. external name 'FPC_INITIALIZE_ARRAY';
  487. procedure FinalizeArray(p, typeInfo: Pointer; count: SizeInt);
  488. external name 'FPC_FINALIZE_ARRAY';
  489. procedure CopyArray(dest, source, typeInfo: Pointer; count: SizeInt);
  490. var
  491. i, size: SizeInt;
  492. {$ifndef VER3_0}
  493. hasManagementOp: boolean;
  494. begin
  495. size:=RTTISizeAndOp(typeinfo, rotCopy, hasManagementOp);
  496. if (size>0) or hasManagementOp then
  497. {$else VER3_0}
  498. begin
  499. size:=RTTISize(typeInfo);
  500. if size>0 then
  501. {$endif VER3_0}
  502. for i:=0 to count-1 do
  503. fpc_Copy_internal(source+size*i, dest+size*i, typeInfo);
  504. end;