2
0

rtti.inc 16 KB

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