rtti.inc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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. tkInterface:
  248. Intf_Decr_Ref(PPointer(Data)^);
  249. {$ifdef FPC_HAS_FEATURE_DYNARRAYS}
  250. tkDynArray:
  251. fpc_dynarray_clear(PPointer(Data)^,TypeInfo);
  252. {$endif FPC_HAS_FEATURE_DYNARRAYS}
  253. {$ifdef FPC_HAS_FEATURE_VARIANTS}
  254. tkVariant:
  255. variant_clear(PVarData(Data)^);
  256. {$endif FPC_HAS_FEATURE_VARIANTS}
  257. end;
  258. end;
  259. Procedure fpc_Addref (Data,TypeInfo : Pointer); [Public,alias : 'FPC_ADDREF']; compilerproc;
  260. begin
  261. case PTypeKind(TypeInfo)^ of
  262. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  263. tkAstring :
  264. fpc_AnsiStr_Incr_Ref(PPointer(Data)^);
  265. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  266. {$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
  267. {$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
  268. tkWstring :
  269. fpc_WideStr_Incr_Ref(PPointer(Data)^);
  270. {$endif FPC_WIDESTRING_EQUAL_UNICODESTRING}
  271. tkUstring :
  272. fpc_UnicodeStr_Incr_Ref(PPointer(Data)^);
  273. {$endif FPC_HAS_FEATURE_WIDESTRINGS}
  274. tkArray :
  275. arrayrtti(data,typeinfo,@int_addref);
  276. {$ifdef FPC_HAS_FEATURE_OBJECTS}
  277. tkobject,
  278. {$endif FPC_HAS_FEATURE_OBJECTS}
  279. tkrecord :
  280. {$ifndef VER3_0}
  281. { find init table }
  282. with RTTIRecordOp(typeinfo, typeinfo)^ do
  283. begin
  284. recordrtti(data,typeinfo,@int_addref);
  285. if Assigned(recordop) and Assigned(recordop^.AddRef) then
  286. recordop^.AddRef(Data);
  287. end;
  288. {$else VER3_0}
  289. begin
  290. typeinfo:=RTTIRecordRttiInfoToInitInfo(typeinfo);
  291. recordrtti(data,typeinfo,@int_addref);
  292. end;
  293. {$endif VER3_0}
  294. {$ifdef FPC_HAS_FEATURE_DYNARRAYS}
  295. tkDynArray:
  296. fpc_dynarray_incr_ref(PPointer(Data)^);
  297. {$endif FPC_HAS_FEATURE_DYNARRAYS}
  298. tkInterface:
  299. Intf_Incr_Ref(PPointer(Data)^);
  300. {$ifdef FPC_HAS_FEATURE_VARIANTS}
  301. tkVariant:
  302. variant_addref(pvardata(Data)^);
  303. {$endif FPC_HAS_FEATURE_DYNARRAYS}
  304. end;
  305. end;
  306. { define alias for internal use in the system unit }
  307. Function fpc_Copy_internal (Src, Dest, TypeInfo : Pointer) : SizeInt;[external name 'FPC_COPY'];
  308. Function fpc_Copy (Src, Dest, TypeInfo : Pointer) : SizeInt;[Public,alias : 'FPC_COPY']; compilerproc;
  309. var
  310. Temp: pbyte;
  311. copiedsize,
  312. expectedoffset,
  313. EleCount,
  314. offset,
  315. i: SizeInt;
  316. info: pointer;
  317. begin
  318. result:=sizeof(pointer);
  319. case PTypeKind(TypeInfo)^ of
  320. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  321. tkAstring:
  322. fpc_AnsiStr_Assign(PPointer(Dest)^,PPointer(Src)^);
  323. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  324. {$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
  325. {$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
  326. tkWstring:
  327. fpc_WideStr_Assign(PPointer(Dest)^,PPointer(Src)^);
  328. {$endif FPC_WIDESTRING_EQUAL_UNICODESTRING}
  329. tkUstring:
  330. fpc_UnicodeStr_Assign(PPointer(Dest)^,PPointer(Src)^);
  331. {$endif FPC_HAS_FEATURE_WIDESTRINGS}
  332. tkArray:
  333. begin
  334. {$ifdef VER3_0}
  335. Temp:=aligntoptr(typeInfo+2+PByte(typeInfo)[1]);
  336. {$else VER3_0}
  337. Temp:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  338. {$endif VER3_0}
  339. {$ifdef VER2_6}
  340. { Process elements }
  341. for I:=0 to PArrayInfo(Temp)^.ElCount-1 do
  342. fpc_Copy_internal(Src+(I*PArrayInfo(Temp)^.Size),Dest+(I*PArrayInfo(Temp)^.Size),PArrayInfo(Temp)^.ElInfo);
  343. Result:=PArrayInfo(Temp)^.Size*PArrayInfo(Temp)^.ElCount;
  344. {$else}
  345. Result:=PArrayInfo(Temp)^.Size;
  346. EleCount:=PArrayInfo(Temp)^.ElCount;
  347. { no elements to process => exit }
  348. if EleCount = 0 then
  349. Exit;
  350. Info:=PArrayInfo(Temp)^.ElInfo{$ifndef VER3_0}^{$endif};
  351. copiedsize:=Result div EleCount;
  352. Offset:=0;
  353. { Process elements }
  354. for I:=1 to EleCount do
  355. begin
  356. fpc_Copy_internal(Src+Offset,Dest+Offset,Info);
  357. inc(Offset,copiedsize);
  358. end;
  359. {$endif}
  360. end;
  361. {$ifdef FPC_HAS_FEATURE_OBJECTS}
  362. tkobject,
  363. {$endif FPC_HAS_FEATURE_OBJECTS}
  364. tkrecord:
  365. {$ifndef VER3_0}
  366. { find init table }
  367. with RTTIRecordOp(typeinfo, typeinfo)^ do
  368. {$endif VER3_0}
  369. begin
  370. {$ifdef VER3_0}
  371. typeInfo:=RTTIRecordRttiInfoToInitInfo(typeInfo);
  372. Temp:=aligntoptr(typeInfo+2+PByte(typeInfo)[1]);
  373. {$else VER3_0}
  374. Temp:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  375. {$endif VER3_0}
  376. {$ifndef VER3_0}
  377. if Assigned(recordop) and Assigned(recordop^.Copy) then
  378. recordop^.Copy(Src,Dest)
  379. else
  380. begin
  381. Result:=PRecordInfoInit(Temp)^.Size;
  382. EleCount:=PRecordInfoInit(Temp)^.Count;
  383. { Get element info, hacky, but what else can we do? }
  384. Temp:=AlignTypeData(Pointer(@PRecordInfoInit(Temp)^.Count)+SizeOf(PRecordInfoInit(Temp)^.Count));
  385. {$else VER3_0}
  386. Result:=PRecordInfoFull(Temp)^.Size;
  387. EleCount:=PRecordInfoFull(Temp)^.Count;
  388. { Get element info, hacky, but what else can we do? }
  389. Temp:=Pointer(@PRecordInfoFull(Temp)^.Count)+SizeOf(PRecordInfoFull(Temp)^.Count);
  390. {$endif VER3_0}
  391. expectedoffset:=0;
  392. { Process elements with rtti }
  393. for i:=1 to EleCount Do
  394. begin
  395. Info:=PRecordElement(Temp)^.TypeInfo{$ifndef VER3_0}^{$endif};
  396. Offset:=PRecordElement(Temp)^.Offset;
  397. Inc(PRecordElement(Temp));
  398. if Offset>expectedoffset then
  399. move((Src+expectedoffset)^,(Dest+expectedoffset)^,Offset-expectedoffset);
  400. copiedsize:=fpc_Copy_internal(Src+Offset,Dest+Offset,Info);
  401. expectedoffset:=Offset+copiedsize;
  402. end;
  403. { elements remaining? }
  404. if result>expectedoffset then
  405. move((Src+expectedoffset)^,(Dest+expectedoffset)^,Result-expectedoffset);
  406. {$ifndef VER3_0}
  407. end;
  408. {$endif VER3_0}
  409. end;
  410. {$ifdef FPC_HAS_FEATURE_DYNARRAYS}
  411. tkDynArray:
  412. fpc_dynarray_assign(PPointer(Dest)^,PPointer(Src)^,typeinfo);
  413. {$endif FPC_HAS_FEATURE_DYNARRAYS}
  414. tkInterface:
  415. fpc_intf_assign(PPointer(Dest)^,PPointer(Src)^);
  416. {$ifdef FPC_HAS_FEATURE_VARIANTS}
  417. tkVariant:
  418. begin
  419. VarCopyProc(pvardata(dest)^,pvardata(src)^);
  420. result:=sizeof(tvardata);
  421. end;
  422. {$endif FPC_HAS_FEATURE_VARIANTS}
  423. end;
  424. end;
  425. { For internal use by the compiler, because otherwise $x- can cause trouble. }
  426. { Generally disabling extended syntax checking for all compilerprocs may }
  427. { have unintended side-effects }
  428. procedure fpc_Copy_proc (Src, Dest, TypeInfo : Pointer);compilerproc; inline;
  429. begin
  430. fpc_copy_internal(src,dest,typeinfo);
  431. end;
  432. procedure fpc_initialize_array(data,typeinfo : pointer;count : SizeInt); [public,alias:'FPC_INITIALIZE_ARRAY']; compilerproc;
  433. var
  434. i, size : SizeInt;
  435. {$ifndef VER3_0}
  436. hasManagementOp: boolean;
  437. begin
  438. size:=RTTISizeAndOp(typeinfo, rotInitialize, hasManagementOp);
  439. if (size>0) or hasManagementOp then
  440. {$else VER3_0}
  441. begin
  442. size:=RTTISize(typeInfo);
  443. if size>0 then
  444. {$endif VER3_0}
  445. for i:=0 to count-1 do
  446. int_initialize(data+size*i,typeinfo);
  447. end;
  448. procedure fpc_finalize_array(data,typeinfo : pointer;count : SizeInt); [Public,Alias:'FPC_FINALIZE_ARRAY']; compilerproc;
  449. var
  450. i, size: SizeInt;
  451. {$ifndef VER3_0}
  452. hasManagementOp: boolean;
  453. begin
  454. size:=RTTISizeAndOp(typeinfo, rotFinalize, hasManagementOp);
  455. if (size>0) or hasManagementOp then
  456. {$else VER3_0}
  457. begin
  458. size:=RTTISize(typeInfo);
  459. if size>0 then
  460. {$endif VER3_0}
  461. for i:=0 to count-1 do
  462. int_finalize(data+size*i,typeinfo);
  463. end;
  464. procedure fpc_addref_array(data,typeinfo: pointer; count: SizeInt); [public,alias:'FPC_ADDREF_ARRAY']; compilerproc;
  465. var
  466. i, size: SizeInt;
  467. {$ifndef VER3_0}
  468. hasManagementOp: boolean;
  469. begin
  470. size:=RTTISizeAndOp(typeinfo, rotAddRef, hasManagementOp);
  471. if (size>0) or hasManagementOp then
  472. {$else VER3_0}
  473. begin
  474. size:=RTTISize(typeInfo);
  475. if size>0 then
  476. {$endif VER3_0}
  477. for i:=0 to count-1 do
  478. int_addref(data+size*i,typeinfo);
  479. end;
  480. { The following two procedures are now obsolete, needed only for bootstrapping }
  481. procedure fpc_decref (Data, TypeInfo : Pointer);[Public,alias : 'FPC_DECREF']; compilerproc;
  482. begin
  483. int_finalize(Data,TypeInfo);
  484. end;
  485. procedure fpc_decref_array(data,typeinfo: pointer; count: SizeInt); [public,alias:'FPC_DECREF_ARRAY']; compilerproc;
  486. begin
  487. int_finalizeArray(data,typeinfo,count);
  488. end;
  489. procedure InitializeArray(p, typeInfo: Pointer; count: SizeInt);
  490. external name 'FPC_INITIALIZE_ARRAY';
  491. procedure FinalizeArray(p, typeInfo: Pointer; count: SizeInt);
  492. external name 'FPC_FINALIZE_ARRAY';
  493. procedure CopyArray(dest, source, typeInfo: Pointer; count: SizeInt);
  494. var
  495. i, size: SizeInt;
  496. {$ifndef VER3_0}
  497. hasManagementOp: boolean;
  498. begin
  499. size:=RTTISizeAndOp(typeinfo, rotCopy, hasManagementOp);
  500. if (size>0) or hasManagementOp then
  501. {$else VER3_0}
  502. begin
  503. size:=RTTISize(typeInfo);
  504. if size>0 then
  505. {$endif VER3_0}
  506. for i:=0 to count-1 do
  507. fpc_Copy_internal(source+size*i, dest+size*i, typeInfo);
  508. end;