rtti.inc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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. { Get element info, hacky, but what else can we do? }
  120. typeInfo:=AlignTypeData(Pointer(@PRecordInfoInit(typeInfo)^.Count)+SizeOf(PRecordInfoInit(typeInfo)^.Count));
  121. { Process elements }
  122. for i:=1 to count Do
  123. begin
  124. rttiproc(Data+PRecordElement(typeInfo)^.Offset,PRecordElement(typeInfo)^.TypeInfo{$ifndef VER3_0}^{$endif});
  125. Inc(PRecordElement(typeInfo));
  126. end;
  127. end;
  128. {$ifndef VER3_0}
  129. function RTTIRecordMopInitTable(ti: Pointer): PRTTIRecordOpOffsetTable;
  130. begin
  131. ti:=aligntoqword(ti+2+PByte(ti)[1]);
  132. Result:=PRecordInfoInit(ti)^.InitRecordOpTable;
  133. end;
  134. {$endif VER3_0}
  135. { if you modify this procedure, fpc_copy must be probably modified as well }
  136. {$ifdef VER2_6}
  137. procedure ArrayRTTI(Data,TypeInfo:Pointer;rttiproc:TRTTIProc);
  138. var
  139. i: SizeInt;
  140. begin
  141. {$ifdef VER3_0}
  142. typeInfo:=aligntoptr(typeInfo+2+PByte(typeInfo)[1]);
  143. {$else VER3_0}
  144. typeInfo:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  145. {$endif VER3_0}
  146. { Process elements }
  147. for I:=0 to PArrayInfo(typeInfo)^.ElCount-1 do
  148. rttiproc(Data+(I*PArrayInfo(typeInfo)^.Size),PArrayInfo(typeInfo)^.ElInfo);
  149. end;
  150. {$else}
  151. procedure ArrayRTTI(Data,TypeInfo:Pointer;rttiproc:TRTTIProc);
  152. var
  153. i,Count,ElSize: SizeInt;
  154. Info: Pointer;
  155. begin
  156. {$ifdef VER3_0}
  157. typeInfo:=aligntoptr(typeInfo+2+PByte(typeInfo)[1]);
  158. {$else VER3_0}
  159. typeInfo:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  160. {$endif VER3_0}
  161. Count:=PArrayInfo(typeInfo)^.ElCount;
  162. { no elements to process => exit }
  163. if Count = 0 then
  164. Exit;
  165. ElSize:=PArrayInfo(typeInfo)^.Size div Count;
  166. Info:=PArrayInfo(typeInfo)^.ElInfo{$ifndef VER3_0}^{$endif};
  167. { Process elements }
  168. for I:=0 to Count-1 do
  169. rttiproc(Data+(I*ElSize),Info);
  170. end;
  171. {$endif}
  172. Procedure fpc_Initialize (Data,TypeInfo : pointer);[Public,Alias : 'FPC_INITIALIZE']; compilerproc;
  173. begin
  174. case PTypeKind(TypeInfo)^ of
  175. {$ifdef FPC_HAS_FEATURE_DYNARRAYS}
  176. tkDynArray,
  177. {$endif FPC_HAS_FEATURE_DYNARRAYS}
  178. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  179. tkAstring,
  180. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  181. {$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
  182. tkWstring,tkUString,
  183. {$endif FPC_HAS_FEATURE_WIDESTRINGS}
  184. tkInterface:
  185. PPchar(Data)^:=Nil;
  186. tkArray:
  187. arrayrtti(data,typeinfo,@int_initialize);
  188. {$ifdef FPC_HAS_FEATURE_OBJECTS}
  189. tkObject,
  190. {$endif FPC_HAS_FEATURE_OBJECTS}
  191. tkRecord:
  192. {$ifndef VER3_0}
  193. { if possible try to use more optimal initrtti }
  194. with RTTIRecordOp(typeinfo, typeinfo)^ do
  195. begin
  196. recordrtti(data,typeinfo,@int_initialize);
  197. if Assigned(recordop) and Assigned(recordop^.Initialize) then
  198. recordop^.Initialize(data);
  199. end;
  200. {$else VER3_0}
  201. begin
  202. typeinfo:=RTTIRecordRttiInfoToInitInfo(typeinfo);
  203. recordrtti(data,typeinfo,@int_initialize);
  204. end;
  205. {$endif VER3_0}
  206. {$ifdef FPC_HAS_FEATURE_VARIANTS}
  207. tkVariant:
  208. variant_init(PVarData(Data)^);
  209. {$endif FPC_HAS_FEATURE_VARIANTS}
  210. end;
  211. end;
  212. Procedure fpc_finalize (Data,TypeInfo: Pointer);[Public,Alias : 'FPC_FINALIZE']; compilerproc;
  213. begin
  214. case PTypeKind(TypeInfo)^ of
  215. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  216. tkAstring :
  217. fpc_AnsiStr_Decr_Ref(PPointer(Data)^);
  218. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  219. {$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
  220. tkUstring :
  221. fpc_UnicodeStr_Decr_Ref(PPointer(Data)^);
  222. {$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
  223. tkWstring :
  224. fpc_WideStr_Decr_Ref(PPointer(Data)^);
  225. {$endif FPC_WIDESTRING_EQUAL_UNICODESTRING}
  226. {$endif FPC_HAS_FEATURE_WIDESTRINGS}
  227. tkArray :
  228. arrayrtti(data,typeinfo,@int_finalize);
  229. {$ifdef FPC_HAS_FEATURE_OBJECTS}
  230. tkObject,
  231. {$endif FPC_HAS_FEATURE_OBJECTS}
  232. tkRecord:
  233. {$ifndef VER3_0}
  234. { if possible try to use more optimal initrtti }
  235. with RTTIRecordOp(typeinfo, typeinfo)^ do
  236. begin
  237. if Assigned(recordop) and Assigned(recordop^.Finalize) then
  238. recordop^.Finalize(data);
  239. recordrtti(data,typeinfo,@int_finalize);
  240. end;
  241. {$else VER3_0}
  242. begin
  243. typeinfo:=RTTIRecordRttiInfoToInitInfo(typeinfo);
  244. recordrtti(data,typeinfo,@int_finalize);
  245. end;
  246. {$endif VER3_0}
  247. {$ifdef FPC_HAS_FEATURE_CLASSES}
  248. tkInterface:
  249. Intf_Decr_Ref(PPointer(Data)^);
  250. {$endif FPC_HAS_FEATURE_CLASSES}
  251. {$ifdef FPC_HAS_FEATURE_DYNARRAYS}
  252. tkDynArray:
  253. fpc_dynarray_clear(PPointer(Data)^,TypeInfo);
  254. {$endif FPC_HAS_FEATURE_DYNARRAYS}
  255. {$ifdef FPC_HAS_FEATURE_VARIANTS}
  256. tkVariant:
  257. variant_clear(PVarData(Data)^);
  258. {$endif FPC_HAS_FEATURE_VARIANTS}
  259. end;
  260. end;
  261. Procedure fpc_Addref (Data,TypeInfo : Pointer); [Public,alias : 'FPC_ADDREF']; compilerproc;
  262. begin
  263. case PTypeKind(TypeInfo)^ of
  264. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  265. tkAstring :
  266. fpc_AnsiStr_Incr_Ref(PPointer(Data)^);
  267. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  268. {$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
  269. {$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
  270. tkWstring :
  271. fpc_WideStr_Incr_Ref(PPointer(Data)^);
  272. {$endif FPC_WIDESTRING_EQUAL_UNICODESTRING}
  273. tkUstring :
  274. fpc_UnicodeStr_Incr_Ref(PPointer(Data)^);
  275. {$endif FPC_HAS_FEATURE_WIDESTRINGS}
  276. tkArray :
  277. arrayrtti(data,typeinfo,@int_addref);
  278. {$ifdef FPC_HAS_FEATURE_OBJECTS}
  279. tkobject,
  280. {$endif FPC_HAS_FEATURE_OBJECTS}
  281. tkrecord :
  282. {$ifndef VER3_0}
  283. { find init table }
  284. with RTTIRecordOp(typeinfo, typeinfo)^ do
  285. begin
  286. recordrtti(data,typeinfo,@int_addref);
  287. if Assigned(recordop) and Assigned(recordop^.AddRef) then
  288. recordop^.AddRef(Data);
  289. end;
  290. {$else VER3_0}
  291. begin
  292. typeinfo:=RTTIRecordRttiInfoToInitInfo(typeinfo);
  293. recordrtti(data,typeinfo,@int_addref);
  294. end;
  295. {$endif VER3_0}
  296. {$ifdef FPC_HAS_FEATURE_DYNARRAYS}
  297. tkDynArray:
  298. fpc_dynarray_incr_ref(PPointer(Data)^);
  299. {$endif FPC_HAS_FEATURE_DYNARRAYS}
  300. {$ifdef FPC_HAS_FEATURE_CLASSES}
  301. tkInterface:
  302. Intf_Incr_Ref(PPointer(Data)^);
  303. {$endif FPC_HAS_FEATURE_CLASSES}
  304. {$ifdef FPC_HAS_FEATURE_VARIANTS}
  305. tkVariant:
  306. variant_addref(pvardata(Data)^);
  307. {$endif FPC_HAS_FEATURE_DYNARRAYS}
  308. end;
  309. end;
  310. { define alias for internal use in the system unit }
  311. Function fpc_Copy_internal (Src, Dest, TypeInfo : Pointer) : SizeInt;[external name 'FPC_COPY'];
  312. Function fpc_Copy (Src, Dest, TypeInfo : Pointer) : SizeInt;[Public,alias : 'FPC_COPY']; compilerproc;
  313. var
  314. Temp: pbyte;
  315. copiedsize,
  316. expectedoffset,
  317. EleCount,
  318. offset,
  319. i: SizeInt;
  320. info: pointer;
  321. begin
  322. result:=sizeof(pointer);
  323. case PTypeKind(TypeInfo)^ of
  324. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  325. tkAstring:
  326. fpc_AnsiStr_Assign(PPointer(Dest)^,PPointer(Src)^);
  327. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  328. {$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
  329. {$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
  330. tkWstring:
  331. fpc_WideStr_Assign(PPointer(Dest)^,PPointer(Src)^);
  332. {$endif FPC_WIDESTRING_EQUAL_UNICODESTRING}
  333. tkUstring:
  334. fpc_UnicodeStr_Assign(PPointer(Dest)^,PPointer(Src)^);
  335. {$endif FPC_HAS_FEATURE_WIDESTRINGS}
  336. tkArray:
  337. begin
  338. {$ifdef VER3_0}
  339. Temp:=aligntoptr(typeInfo+2+PByte(typeInfo)[1]);
  340. {$else VER3_0}
  341. Temp:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  342. {$endif VER3_0}
  343. {$ifdef VER2_6}
  344. { Process elements }
  345. for I:=0 to PArrayInfo(Temp)^.ElCount-1 do
  346. fpc_Copy_internal(Src+(I*PArrayInfo(Temp)^.Size),Dest+(I*PArrayInfo(Temp)^.Size),PArrayInfo(Temp)^.ElInfo);
  347. Result:=PArrayInfo(Temp)^.Size*PArrayInfo(Temp)^.ElCount;
  348. {$else}
  349. Result:=PArrayInfo(Temp)^.Size;
  350. EleCount:=PArrayInfo(Temp)^.ElCount;
  351. { no elements to process => exit }
  352. if EleCount = 0 then
  353. Exit;
  354. Info:=PArrayInfo(Temp)^.ElInfo{$ifndef VER3_0}^{$endif};
  355. copiedsize:=Result div EleCount;
  356. Offset:=0;
  357. { Process elements }
  358. for I:=1 to EleCount do
  359. begin
  360. fpc_Copy_internal(Src+Offset,Dest+Offset,Info);
  361. inc(Offset,copiedsize);
  362. end;
  363. {$endif}
  364. end;
  365. {$ifdef FPC_HAS_FEATURE_OBJECTS}
  366. tkobject,
  367. {$endif FPC_HAS_FEATURE_OBJECTS}
  368. tkrecord:
  369. {$ifndef VER3_0}
  370. { find init table }
  371. with RTTIRecordOp(typeinfo, typeinfo)^ do
  372. {$endif VER3_0}
  373. begin
  374. {$ifdef VER3_0}
  375. typeInfo:=RTTIRecordRttiInfoToInitInfo(typeInfo);
  376. Temp:=aligntoptr(typeInfo+2+PByte(typeInfo)[1]);
  377. {$else VER3_0}
  378. Temp:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  379. {$endif VER3_0}
  380. {$ifndef VER3_0}
  381. if Assigned(recordop) and Assigned(recordop^.Copy) then
  382. recordop^.Copy(Src,Dest)
  383. else
  384. begin
  385. Result:=PRecordInfoInit(Temp)^.Size;
  386. EleCount:=PRecordInfoInit(Temp)^.Count;
  387. { Get element info, hacky, but what else can we do? }
  388. Temp:=AlignTypeData(Pointer(@PRecordInfoInit(Temp)^.Count)+SizeOf(PRecordInfoInit(Temp)^.Count));
  389. {$else VER3_0}
  390. Result:=PRecordInfoFull(Temp)^.Size;
  391. EleCount:=PRecordInfoFull(Temp)^.Count;
  392. { Get element info, hacky, but what else can we do? }
  393. Temp:=Pointer(@PRecordInfoFull(Temp)^.Count)+SizeOf(PRecordInfoFull(Temp)^.Count);
  394. {$endif VER3_0}
  395. expectedoffset:=0;
  396. { Process elements with rtti }
  397. for i:=1 to EleCount Do
  398. begin
  399. Info:=PRecordElement(Temp)^.TypeInfo{$ifndef VER3_0}^{$endif};
  400. Offset:=PRecordElement(Temp)^.Offset;
  401. Inc(PRecordElement(Temp));
  402. if Offset>expectedoffset then
  403. move((Src+expectedoffset)^,(Dest+expectedoffset)^,Offset-expectedoffset);
  404. copiedsize:=fpc_Copy_internal(Src+Offset,Dest+Offset,Info);
  405. expectedoffset:=Offset+copiedsize;
  406. end;
  407. { elements remaining? }
  408. if result>expectedoffset then
  409. move((Src+expectedoffset)^,(Dest+expectedoffset)^,Result-expectedoffset);
  410. {$ifndef VER3_0}
  411. end;
  412. {$endif VER3_0}
  413. end;
  414. {$ifdef FPC_HAS_FEATURE_DYNARRAYS}
  415. tkDynArray:
  416. fpc_dynarray_assign(PPointer(Dest)^,PPointer(Src)^,typeinfo);
  417. {$endif FPC_HAS_FEATURE_DYNARRAYS}
  418. {$ifdef FPC_HAS_FEATURE_CLASSES}
  419. tkInterface:
  420. fpc_intf_assign(PPointer(Dest)^,PPointer(Src)^);
  421. {$endif FPC_HAS_FEATURE_CLASSES}
  422. {$ifdef FPC_HAS_FEATURE_VARIANTS}
  423. tkVariant:
  424. begin
  425. VarCopyProc(pvardata(dest)^,pvardata(src)^);
  426. result:=sizeof(tvardata);
  427. end;
  428. {$endif FPC_HAS_FEATURE_VARIANTS}
  429. end;
  430. end;
  431. { For internal use by the compiler, because otherwise $x- can cause trouble. }
  432. { Generally disabling extended syntax checking for all compilerprocs may }
  433. { have unintended side-effects }
  434. procedure fpc_Copy_proc (Src, Dest, TypeInfo : Pointer);compilerproc; inline;
  435. begin
  436. fpc_copy_internal(src,dest,typeinfo);
  437. end;
  438. procedure fpc_initialize_array(data,typeinfo : pointer;count : SizeInt); [public,alias:'FPC_INITIALIZE_ARRAY']; compilerproc;
  439. var
  440. i, size : SizeInt;
  441. {$ifndef VER3_0}
  442. hasManagementOp: boolean;
  443. begin
  444. size:=RTTISizeAndOp(typeinfo, rotInitialize, hasManagementOp);
  445. if (size>0) or hasManagementOp then
  446. {$else VER3_0}
  447. begin
  448. size:=RTTISize(typeInfo);
  449. if size>0 then
  450. {$endif VER3_0}
  451. for i:=0 to count-1 do
  452. int_initialize(data+size*i,typeinfo);
  453. end;
  454. procedure fpc_finalize_array(data,typeinfo : pointer;count : SizeInt); [Public,Alias:'FPC_FINALIZE_ARRAY']; compilerproc;
  455. var
  456. i, size: SizeInt;
  457. {$ifndef VER3_0}
  458. hasManagementOp: boolean;
  459. begin
  460. size:=RTTISizeAndOp(typeinfo, rotFinalize, hasManagementOp);
  461. if (size>0) or hasManagementOp then
  462. {$else VER3_0}
  463. begin
  464. size:=RTTISize(typeInfo);
  465. if size>0 then
  466. {$endif VER3_0}
  467. for i:=0 to count-1 do
  468. int_finalize(data+size*i,typeinfo);
  469. end;
  470. procedure fpc_addref_array(data,typeinfo: pointer; count: SizeInt); [public,alias:'FPC_ADDREF_ARRAY']; compilerproc;
  471. var
  472. i, size: SizeInt;
  473. {$ifndef VER3_0}
  474. hasManagementOp: boolean;
  475. begin
  476. size:=RTTISizeAndOp(typeinfo, rotAddRef, hasManagementOp);
  477. if (size>0) or hasManagementOp then
  478. {$else VER3_0}
  479. begin
  480. size:=RTTISize(typeInfo);
  481. if size>0 then
  482. {$endif VER3_0}
  483. for i:=0 to count-1 do
  484. int_addref(data+size*i,typeinfo);
  485. end;
  486. { The following two procedures are now obsolete, needed only for bootstrapping }
  487. procedure fpc_decref (Data, TypeInfo : Pointer);[Public,alias : 'FPC_DECREF']; compilerproc;
  488. begin
  489. int_finalize(Data,TypeInfo);
  490. end;
  491. procedure fpc_decref_array(data,typeinfo: pointer; count: SizeInt); [public,alias:'FPC_DECREF_ARRAY']; compilerproc;
  492. begin
  493. int_finalizeArray(data,typeinfo,count);
  494. end;
  495. procedure InitializeArray(p, typeInfo: Pointer; count: SizeInt);
  496. external name 'FPC_INITIALIZE_ARRAY';
  497. procedure FinalizeArray(p, typeInfo: Pointer; count: SizeInt);
  498. external name 'FPC_FINALIZE_ARRAY';
  499. procedure CopyArray(dest, source, typeInfo: Pointer; count: SizeInt);
  500. var
  501. i, size: SizeInt;
  502. {$ifndef VER3_0}
  503. hasManagementOp: boolean;
  504. begin
  505. size:=RTTISizeAndOp(typeinfo, rotCopy, hasManagementOp);
  506. if (size>0) or hasManagementOp then
  507. {$else VER3_0}
  508. begin
  509. size:=RTTISize(typeInfo);
  510. if size>0 then
  511. {$endif VER3_0}
  512. for i:=0 to count-1 do
  513. fpc_Copy_internal(source+size*i, dest+size*i, typeInfo);
  514. end;