ObjCRuntime.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. {
  2. * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
  3. *
  4. * @APPLE_LICENSE_HEADER_START@
  5. *
  6. * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
  7. *
  8. * This file contains Original Code and/or Modifications of Original Code
  9. * as defined in and that are subject to the Apple Public Source License
  10. * Version 2.0 (the 'License'). You may not use this file except in
  11. * compliance with the License. Please obtain a copy of the License at
  12. * http://www.opensource.apple.com/apsl/ and read it before using this
  13. * file.
  14. *
  15. * The Original Code and all software distributed under the License are
  16. * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  17. * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  18. * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  20. * Please see the License for the specific language governing rights and
  21. * limitations under the License.
  22. *
  23. * @APPLE_LICENSE_HEADER_END@
  24. }
  25. {
  26. Pascal translation by Adriaan van Os <[email protected]>, April 2008
  27. * objc-class.h
  28. * Copyright 1988-1996, NeXT Software, Inc.
  29. * objc.h
  30. * Copyright 1988-1996, NeXT Software, Inc.
  31. * objc-auto.h
  32. * Copyright 2004 Apple Computer, Inc.
  33. * objc_exception.h
  34. Support for Objective-C language Exceptions
  35. Created by Blaine Garst on Fri Nov 01 2002.
  36. * Copyright (c) 2002-3 Apple Computer, Inc. All rights reserved.
  37. * objc_sync.h
  38. * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
  39. * objc-runtime.h
  40. * Copyright 1988-1996, NeXT Software, Inc.
  41. }
  42. {
  43. Modified for use with Free Pascal
  44. Version 308
  45. Please report any bugs to <[email protected]>
  46. }
  47. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  48. {$mode macpas}
  49. {$packenum 1}
  50. {$macro on}
  51. {$inline on}
  52. {$calling mwpascal}
  53. unit ObjCRuntime;
  54. interface
  55. {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
  56. {$setc GAP_INTERFACES_VERSION := $0308}
  57. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  58. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  59. {$endc}
  60. {$ifc defined CPUPOWERPC and defined CPUI386}
  61. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  62. {$endc}
  63. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  64. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  65. {$endc}
  66. {$ifc not defined __ppc__ and defined CPUPOWERPC32}
  67. {$setc __ppc__ := 1}
  68. {$elsec}
  69. {$setc __ppc__ := 0}
  70. {$endc}
  71. {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
  72. {$setc __ppc64__ := 1}
  73. {$elsec}
  74. {$setc __ppc64__ := 0}
  75. {$endc}
  76. {$ifc not defined __i386__ and defined CPUI386}
  77. {$setc __i386__ := 1}
  78. {$elsec}
  79. {$setc __i386__ := 0}
  80. {$endc}
  81. {$ifc not defined __x86_64__ and defined CPUX86_64}
  82. {$setc __x86_64__ := 1}
  83. {$elsec}
  84. {$setc __x86_64__ := 0}
  85. {$endc}
  86. {$ifc not defined __arm__ and defined CPUARM}
  87. {$setc __arm__ := 1}
  88. {$elsec}
  89. {$setc __arm__ := 0}
  90. {$endc}
  91. {$ifc defined cpu64}
  92. {$setc __LP64__ := 1}
  93. {$elsec}
  94. {$setc __LP64__ := 0}
  95. {$endc}
  96. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  97. {$error Conflicting definitions for __ppc__ and __i386__}
  98. {$endc}
  99. {$ifc defined __ppc__ and __ppc__}
  100. {$setc TARGET_CPU_PPC := TRUE}
  101. {$setc TARGET_CPU_PPC64 := FALSE}
  102. {$setc TARGET_CPU_X86 := FALSE}
  103. {$setc TARGET_CPU_X86_64 := FALSE}
  104. {$setc TARGET_CPU_ARM := FALSE}
  105. {$setc TARGET_OS_MAC := TRUE}
  106. {$setc TARGET_OS_IPHONE := FALSE}
  107. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  108. {$elifc defined __ppc64__ and __ppc64__}
  109. {$setc TARGET_CPU_PPC := FALSE}
  110. {$setc TARGET_CPU_PPC64 := TRUE}
  111. {$setc TARGET_CPU_X86 := FALSE}
  112. {$setc TARGET_CPU_X86_64 := FALSE}
  113. {$setc TARGET_CPU_ARM := FALSE}
  114. {$setc TARGET_OS_MAC := TRUE}
  115. {$setc TARGET_OS_IPHONE := FALSE}
  116. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  117. {$elifc defined __i386__ and __i386__}
  118. {$setc TARGET_CPU_PPC := FALSE}
  119. {$setc TARGET_CPU_PPC64 := FALSE}
  120. {$setc TARGET_CPU_X86 := TRUE}
  121. {$setc TARGET_CPU_X86_64 := FALSE}
  122. {$setc TARGET_CPU_ARM := FALSE}
  123. {$ifc defined(iphonesim)}
  124. {$setc TARGET_OS_MAC := FALSE}
  125. {$setc TARGET_OS_IPHONE := TRUE}
  126. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  127. {$elsec}
  128. {$setc TARGET_OS_MAC := TRUE}
  129. {$setc TARGET_OS_IPHONE := FALSE}
  130. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  131. {$endc}
  132. {$elifc defined __x86_64__ and __x86_64__}
  133. {$setc TARGET_CPU_PPC := FALSE}
  134. {$setc TARGET_CPU_PPC64 := FALSE}
  135. {$setc TARGET_CPU_X86 := FALSE}
  136. {$setc TARGET_CPU_X86_64 := TRUE}
  137. {$setc TARGET_CPU_ARM := FALSE}
  138. {$setc TARGET_OS_MAC := TRUE}
  139. {$setc TARGET_OS_IPHONE := FALSE}
  140. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  141. {$elifc defined __arm__ and __arm__}
  142. {$setc TARGET_CPU_PPC := FALSE}
  143. {$setc TARGET_CPU_PPC64 := FALSE}
  144. {$setc TARGET_CPU_X86 := FALSE}
  145. {$setc TARGET_CPU_X86_64 := FALSE}
  146. {$setc TARGET_CPU_ARM := TRUE}
  147. { will require compiler define when/if other Apple devices with ARM cpus ship }
  148. {$setc TARGET_OS_MAC := FALSE}
  149. {$setc TARGET_OS_IPHONE := TRUE}
  150. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  151. {$elsec}
  152. {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ is defined.}
  153. {$endc}
  154. {$ifc defined __LP64__ and __LP64__ }
  155. {$setc TARGET_CPU_64 := TRUE}
  156. {$elsec}
  157. {$setc TARGET_CPU_64 := FALSE}
  158. {$endc}
  159. {$ifc defined FPC_BIG_ENDIAN}
  160. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  161. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  162. {$elifc defined FPC_LITTLE_ENDIAN}
  163. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  164. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  165. {$elsec}
  166. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  167. {$endc}
  168. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  169. {$setc CALL_NOT_IN_CARBON := FALSE}
  170. {$setc OLDROUTINENAMES := FALSE}
  171. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  172. {$setc OPAQUE_UPP_TYPES := TRUE}
  173. {$setc OTCARBONAPPLICATION := TRUE}
  174. {$setc OTKERNEL := FALSE}
  175. {$setc PM_USE_SESSION_APIS := TRUE}
  176. {$setc TARGET_API_MAC_CARBON := TRUE}
  177. {$setc TARGET_API_MAC_OS8 := FALSE}
  178. {$setc TARGET_API_MAC_OSX := TRUE}
  179. {$setc TARGET_CARBON := TRUE}
  180. {$setc TARGET_CPU_68K := FALSE}
  181. {$setc TARGET_CPU_MIPS := FALSE}
  182. {$setc TARGET_CPU_SPARC := FALSE}
  183. {$setc TARGET_OS_UNIX := FALSE}
  184. {$setc TARGET_OS_WIN32 := FALSE}
  185. {$setc TARGET_RT_MAC_68881 := FALSE}
  186. {$setc TARGET_RT_MAC_CFM := FALSE}
  187. {$setc TARGET_RT_MAC_MACHO := TRUE}
  188. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  189. {$setc TYPE_BOOL := FALSE}
  190. {$setc TYPE_EXTENDED := FALSE}
  191. {$setc TYPE_LONGLONG := TRUE}
  192. uses MacTypes;
  193. {$endc} {not MACOSALLINCLUDE}
  194. {$ifc not TARGET_CPU_64 and TARGET_OS_MAC}
  195. {$ALIGN POWER}
  196. {$ifc TARGET_CPU_64 }
  197. {$errorc 64-bit not supported}
  198. {$endc}
  199. type
  200. objc_ivar_list_Ptr = ^objc_ivar_list;
  201. objc_method_list_PtrPtr = ^objc_method_list_Ptr;
  202. objc_method_list_Ptr = ^objc_method_list;
  203. objc_cache_Ptr = ^objc_cache;
  204. objc_protocol_list_Ptr = ^objc_protocol_list;
  205. {
  206. * Class Template
  207. }
  208. objc_class_Ptr = ^objc_class;
  209. objc_class = record
  210. isa: objc_class_Ptr;
  211. super_class: objc_class_Ptr;
  212. name: CStringPtr;
  213. version: SInt32;
  214. info: SInt32;
  215. instance_size: SInt32;
  216. ivars: objc_ivar_list_Ptr;
  217. methodLists: objc_method_list_PtrPtr;
  218. cache: objc_cache_Ptr;
  219. protocols: objc_protocol_list_Ptr
  220. end;
  221. {
  222. * Category Template
  223. }
  224. objc_category_Ptr = ^objc_category;
  225. objc_category = record
  226. category_name: CStringPtr;
  227. class_name: CStringPtr;
  228. instance_methods: objc_method_list_Ptr;
  229. class_methods: objc_method_list_Ptr;
  230. protocols: objc_protocol_list_Ptr
  231. end;
  232. Category = objc_category_Ptr;
  233. {
  234. * Instance Variable Template
  235. }
  236. objc_ivar_Ptr = ^objc_ivar;
  237. objc_ivar = record
  238. ivar_name: CStringPtr;
  239. ivar_type: CStringPtr;
  240. ivar_offset: SInt32;
  241. {$ifc not undefined __alpha__ }
  242. space: SInt32;
  243. {$endc}
  244. end;
  245. Ivar = objc_ivar_Ptr;
  246. objc_ivar_list = record
  247. ivar_count: SInt32;
  248. {$ifc not undefined __alpha__ }
  249. space: SInt32;
  250. {$endc}
  251. ivar_list: array[ 0..0] of objc_ivar { variable length structure }
  252. end;
  253. { use _ObjC suffix to avoid Object Pascal class an self conflicts }
  254. Class_ObjC_Ptr = ^Class_ObjC;
  255. Class_ObjC = objc_class_Ptr;
  256. objc_object_Ptr = ^objc_object;
  257. objc_object = record
  258. isa: Class_ObjC
  259. end;
  260. objc_id_Ptr = ^objc_id;
  261. objc_id = objc_object_Ptr;
  262. id = objc_id;
  263. id_Ptr = objc_id_Ptr;
  264. objc_selector_Ptr = UnivPtr;
  265. SELPtr = ^SEL;
  266. SEL = objc_selector_Ptr;
  267. IMP = function( self_ObjC: objc_id; param2: SEL; ... ): objc_id;
  268. {
  269. * Method Template
  270. }
  271. objc_method_Ptr = ^objc_method;
  272. objc_method = record
  273. method_name: SEL;
  274. method_types: CStringPtr;
  275. method_imp: IMP
  276. end;
  277. Method = objc_method_Ptr;
  278. objc_method_list = record
  279. obsolete: objc_method_list_Ptr;
  280. method_count: SInt32;
  281. {$ifc not undefined __alpha__ }
  282. space: SInt32;
  283. {$endc}
  284. method_list: array[0..0] of objc_method { variable length structure }
  285. end;
  286. { Protocol support }
  287. Protocol = objc_object;
  288. objc_protocol_list = record
  289. next: objc_protocol_list_Ptr;
  290. count: SInt32;
  291. list: array[0..0] of Protocol
  292. end;
  293. Cache = objc_cache_Ptr;
  294. objc_cache = record
  295. mask: UInt32; { total = mask + 1 }
  296. occupied: UInt32;
  297. buckets: array[0..0] of Method
  298. end;
  299. type
  300. BOOL = boolean; {SInt8}
  301. {
  302. BOOL is explicitly signed so @encode(BOOL) == "c" rather than "C"
  303. even if -funsigned-char is used.
  304. }
  305. const
  306. YES = True; {BOOL(1)}
  307. NO = False; {BOOL(0)}
  308. {
  309. # define __strong
  310. }
  311. {$ifc not defined(STRICT_OPENSTEP) }
  312. {
  313. type
  314. STR = CStringPtr;
  315. }
  316. function sel_isMapped(_sel: SEL): boolean; external name '_sel_isMapped';
  317. function sel_getName(_sel: SEL): CStringPtr; external name '_sel_getName';
  318. function sel_getUid( str: CStringPtr): SEL; external name '_sel_getUid';
  319. function sel_registerName(str: CStringPtr): SEL; external name '_sel_registerName';
  320. function object_getClassName(obj: objc_id): CStringPtr; external name '_object_getClassName';
  321. function object_getIndexedIvars(obj: objc_id): UnivPtr; external name '_object_getIndexedIvars';
  322. {$ifc defined(__osf__) and defined(__alpha__) }
  323. type
  324. arith_t = SInt32;
  325. uarith_t = UInt32;
  326. const ARITH_SHIFT = 32;
  327. {$elsec}
  328. type
  329. arith_t = SInt32;
  330. uarith_t = UInt32;
  331. const ARITH_SHIFT = 16;
  332. {$endc}
  333. {$endc} { not defined(STRICT_OPENSTEP) }
  334. const
  335. CLS_CLASS = $01;
  336. CLS_META = $02;
  337. CLS_INITIALIZED = $04;
  338. CLS_POSING = $08;
  339. CLS_MAPPED = $010;
  340. CLS_FLUSH_CACHE = $020;
  341. CLS_GROW_CACHE = $040;
  342. CLS_NEED_BIND = $080;
  343. CLS_METHOD_ARRAY = $0100;
  344. { the JavaBridge constructs classes with these markers }
  345. CLS_JAVA_HYBRID = $0200;
  346. CLS_JAVA_CLASS = $0400;
  347. { thread-safe +initialize }
  348. CLS_INITIALIZING = $0800;
  349. { bundle unloading }
  350. CLS_FROM_BUNDLE = $01000;
  351. { C++ ivar support }
  352. CLS_HAS_CXX_STRUCTORS = $02000;
  353. { Lazy method list arrays }
  354. CLS_NO_METHOD_ARRAY = $04000;
  355. { +load implementation }
  356. CLS_HAS_LOAD_METHOD = $08000;
  357. function object_setInstanceVariable(param1: objc_id; name: CStringPtr; param3: UnivPtr): Ivar; external name '_object_setInstanceVariable';
  358. function object_getInstanceVariable(param1: objc_id; name: CStringPtr; var param3: UnivPtr): Ivar; external name '_object_getInstanceVariable';
  359. { Definitions of filer types }
  360. Const
  361. _C_ID = '@';
  362. _C_CLASS = '#';
  363. _C_SEL = ':';
  364. _C_CHR = 'c';
  365. _C_UCHR = 'C';
  366. _C_SHT = 's';
  367. _C_USHT = 'S';
  368. _C_INT = 'i';
  369. _C_UINT = 'I';
  370. _C_LNG = 'l';
  371. _C_ULNG = 'L';
  372. _C_FLT = 'f';
  373. _C_DBL = 'd';
  374. _C_BFLD = 'b';
  375. _C_VOID = 'v';
  376. _C_UNDEF = '?';
  377. _C_PTR = '^';
  378. _C_CHARPTR = '*';
  379. _C_ARY_B = '[';
  380. _C_ARY_E = ']';
  381. _C_UNION_B = '(';
  382. _C_UNION_E = ')';
  383. _C_STRUCT_B = '{';
  384. _C_STRUCT_E = '}';
  385. { Structure for method cache - allocated/sized at runtime }
  386. {todo}
  387. {
  388. #define CACHE_BUCKET_NAME(B) ((B)->method_name)
  389. #define CACHE_BUCKET_IMP(B) ((B)->method_imp)
  390. #define CACHE_BUCKET_VALID(B) (B)
  391. #define CACHE_HASH(sel, mask) (((uarith_t)(sel)>>2) & (mask))
  392. }
  393. { operations }
  394. function class_createInstance( param1: Class_ObjC; idxIvars: UInt32 ): objc_id; external name '_class_createInstance';
  395. function class_createInstanceFromZone( param1: Class_ObjC; idxIvars: UInt32; z: UnivPtr): objc_id; external name '_class_createInstanceFromZone';
  396. procedure class_setVersion( param1: Class_ObjC; param2: SInt32); external name '_class_setVersion';
  397. function class_getVersion( param1: Class_ObjC): SInt32; external name '_class_getVersion';
  398. function class_getInstanceVariable( param1: Class_ObjC; param2: CStringPtr): Ivar; external name '_class_getInstanceVariable';
  399. function class_getInstanceMethod( param1: Class_ObjC; param2: SEL): Method; external name '_class_getInstanceMethod';
  400. function class_getClassMethod( param1: Class_ObjC; param2: SEL): Method; external name '_class_getClassMethod';
  401. procedure class_addMethods( param1: Class_ObjC; param2: objc_method_list_Ptr); external name '_class_addMethods';
  402. procedure class_removeMethods( param1: Class_ObjC; param2: objc_method_list_Ptr); external name '_class_removeMethods';
  403. function class_poseAs( imposter: Class_ObjC; original: Class_ObjC): Class_ObjC; external name '_class_poseAs';
  404. function method_getNumberOfArguments( param1: Method): UInt32; external name '_method_getNumberOfArguments';
  405. function method_getSizeOfArguments( param1: Method): UInt32; external name '_method_getSizeOfArguments';
  406. function method_getArgumentInfo( m: Method; arg: SInt32; var argtype: CStringPtr; var offset: SInt32): UInt32; external name '_method_getArgumentInfo';
  407. {
  408. usage for nextMethodList
  409. void *iterator = 0;
  410. struct objc_method_list *mlist;
  411. while ( mlist = class_nextMethodList( cls, &iterator ) )
  412. }
  413. const
  414. OBJC_NEXT_METHOD_LIST = 1;
  415. function class_nextMethodList( param1: Class_ObjC; var param2: UnivPtr): objc_method_list_Ptr; external name '_class_nextMethodList';
  416. type
  417. marg_list = UnivPtr;
  418. {$ifc TARGET_CPU_PPC}
  419. const
  420. marg_prearg_size = 128;
  421. {$elsec}
  422. const
  423. marg_prearg_size = 0;
  424. {$endc}
  425. {todo}
  426. {
  427. #define marg_malloc(margs, method) \
  428. do ( \
  429. margs = (marg_list *)malloc (marg_prearg_size + ((7 + method_getSizeOfArguments(method)) & ~7)); \
  430. ) while (0)
  431. #define marg_free(margs) \
  432. do ( \
  433. free(margs); \
  434. ) while (0)
  435. #define marg_adjustedOffset(method, offset) \
  436. (marg_prearg_size + offset)
  437. #define marg_getRef(margs, offset, type) \
  438. ( (type *)((char *)margs + marg_adjustedOffset(method,offset) ) )
  439. #define marg_getValue(margs, offset, type) \
  440. ( *marg_getRef(margs, offset, type) )
  441. #define marg_setValue(margs, offset, type, value) \
  442. ( marg_getValue(margs, offset, type) = (value) )
  443. }
  444. { Collection utilities }
  445. const
  446. OBJC_GENERATIONAL = 1 shl 0;
  447. procedure objc_collect_if_needed( options: UInt32); external name '_objc_collect_if_needed';
  448. function objc_numberAllocated: UInt32; external name '_objc_numberAllocated';
  449. function objc_collecting_enabled: boolean; external name '_objc_collecting_enabled';
  450. { Memory management }
  451. function objc_allocate_object(cls: Class_ObjC; extra: SInt32): objc_id; external name '_objc_allocate_object';
  452. { Write barriers }
  453. function objc_assign_strongCast( val: objc_id; dest: objc_id_Ptr): objc_id; external name '_objc_assign_strongCast';
  454. function objc_assign_global( val: objc_id; dest: objc_id_Ptr): objc_id; external name '_objc_assign_global';
  455. function objc_assign_ivar( value: objc_id; dest: objc_id_ptr; offset: UInt32): objc_id; external name '_objc_assign_ivar';
  456. function objc_memmove_collectable( dst: UnivPtr; src: UnivPtr; size: size_t): UnivPtr; external name '_objc_memmove_collectable';
  457. { Testing tools }
  458. function objc_is_finalized( ptr: UnivPtr): boolean; external name '_objc_is_finalized';
  459. { compiler reserves a setjmp buffer + 4 words as localExceptionData}
  460. procedure objc_exception_throw( exception: objc_id); external name '_objc_exception_throw';
  461. procedure objc_exception_try_enter( localExceptionData: UnivPtr); external name '_objc_exception_try_enter';
  462. procedure objc_exception_try_exit( localExceptionData: UnivPtr); external name '_objc_exception_try_exit';
  463. function objc_exception_extract( localExceptionData: UnivPtr): objc_id; external name '_objc_exception_extract';
  464. function objc_exception_match( exceptionClass: Class_ObjC; exception: objc_id): SInt32; external name '_objc_exception_match';
  465. type
  466. throw_exc_t = procedure( param1: objc_id);
  467. try_enter_t = procedure( param1: UnivPtr);
  468. try_exit_t = procedure( param1: UnivPtr);
  469. extract_t = function( param1: UnivPtr): objc_id;
  470. match_t = function( param1: Class_ObjC; param2: objc_id): SInt32;
  471. objc_exception_functions_t_Ptr = ^objc_exception_functions_t;
  472. objc_exception_functions_t = record
  473. version: SInt32;
  474. throw_exc: throw_exc_t; { version 0 }
  475. try_enter: try_enter_t; { version 0 }
  476. try_exit: try_exit_t; { version 0 }
  477. extract: extract_t; { version 0 }
  478. match: match_t; { version 0 }
  479. end;
  480. { get table; version tells how many }
  481. procedure objc_exception_get_functions( table: objc_exception_functions_t_Ptr); external name '_objc_exception_get_functions';
  482. { set table }
  483. procedure objc_exception_set_functions( table: objc_exception_functions_t_Ptr); external name '_objc_exception_set_functions';
  484. {
  485. Begin synchronizing on 'obj'.
  486. Allocates recursive pthread_mutex associated with 'obj' if needed.
  487. Returns OBJC_SYNC_SUCCESS once lock is acquired.
  488. }
  489. function objc_sync_enter( obj: objc_id): SInt32; external name '_objc_sync_enter';
  490. {
  491. End synchronizing on 'obj'.
  492. Returns OBJC_SYNC_SUCCESS or OBJC_SYNC_NOT_OWNING_THREAD_ERROR
  493. }
  494. function objc_sync_exit( obj: objc_id): SInt32; external name '_objc_sync_exit';
  495. {
  496. Temporarily release lock on 'obj' and wait for another thread to notify on 'obj'
  497. Return OBJC_SYNC_SUCCESS, OBJC_SYNC_NOT_OWNING_THREAD_ERROR, OBJC_SYNC_TIMED_OUT
  498. }
  499. function objc_sync_wait( obj: objc_id; milliSecondsMaxWait: SInt64): SInt32; external name '_objc_sync_wait';
  500. {
  501. Wake up another thread waiting on 'obj'
  502. Return OBJC_SYNC_SUCCESS, OBJC_SYNC_NOT_OWNING_THREAD_ERROR
  503. }
  504. function objc_sync_notify( obj: objc_id): SInt32; external name '_objc_sync_notify';
  505. {
  506. Wake up all threads waiting on 'obj'
  507. Return OBJC_SYNC_SUCCESS, OBJC_SYNC_NOT_OWNING_THREAD_ERROR
  508. }
  509. function objc_sync_notifyAll( obj: objc_id): SInt32; external name '_objc_sync_notifyAll';
  510. const
  511. OBJC_SYNC_SUCCESS = 0;
  512. OBJC_SYNC_NOT_OWNING_THREAD_ERROR = -1;
  513. OBJC_SYNC_TIMED_OUT = -2;
  514. OBJC_SYNC_NOT_INITIALIZED = -3;
  515. type
  516. objc_symtab_Ptr = ^objc_symtab;
  517. objc_symtab = record
  518. sel_ref_cnt: UInt32;
  519. refs: SELPtr;
  520. cls_def_cnt: UInt16;
  521. cat_def_cnt: UInt16;
  522. defs: array[ 0..0] of UnivPtr
  523. end;
  524. Symtab = objc_symtab_Ptr;
  525. type
  526. objc_module_Ptr = ^objc_module;
  527. objc_module = record
  528. version: UInt32;
  529. size: UInt32;
  530. name: CStringPtr;
  531. _symtab: Symtab
  532. end;
  533. Module = objc_module_Ptr;
  534. type
  535. objc_super_Ptr = ^objc_super;
  536. objc_super = record
  537. receiver: objc_id;
  538. super_class: Class_ObjC
  539. end;
  540. {
  541. * Messaging Primitives (prototypes)
  542. }
  543. function objc_getClass( name: cStringPtr): objc_id; external name '_objc_getClass';
  544. function objc_getMetaClass( name: CStringPtr): objc_id; external name '_objc_getMetaClass';
  545. function objc_msgSend( self_ObjC: objc_id; op: SEL; ...): objc_id; external name '_objc_msgSend'; (* attribute ignoreable *)
  546. function objc_msgSendSuper( super: objc_super_Ptr; op: SEL; ...): objc_id; external name '_objc_msgSendSuper'; (* attribute ignoreable *)
  547. { Floating-point-returning Messaging Primitives (prototypes)
  548. *
  549. * On some platforms, the ABI for functions returning a floating-point
  550. * value is incompatible with that for functions returning an integral type.
  551. * objc_msgSend_fpret must be used for these.
  552. *
  553. * ppc: objc_msgSend_fpret not used
  554. * ppc64: objc_msgSend_fpret not used
  555. * i386: objc_msgSend_fpret REQUIRED
  556. *
  557. * For `float` or `long double` return types, cast the function
  558. * to an appropriate function pointer type first.
  559. }
  560. {$ifc TARGET_CPU_X86}
  561. function objc_msgSend_fpret(self_ObjC: objc_id; op: SEL; ...): double; external name '_objc_msgSend_fpret';
  562. {$endc}
  563. { Struct-returning Messaging Primitives (prototypes)
  564. *
  565. * For historical reasons, the prototypes for the struct-returning
  566. * messengers are unusual. The portable, correct way to call these functions
  567. * is to cast them to your desired return type first.
  568. *
  569. * For example, `NSRect result = [myNSView frame]` could be written as:
  570. * NSRect (*msgSend_stret_fn)(id, SEL, ...) = (NSRect(*)(id, SEL, ...))objc_msgSend_stret;
  571. * NSRect result = (*msgSend_stret_fn)(myNSView, @selector(frame));
  572. * or, without the function pointer:
  573. * NSRect result = (*(NSRect(*)(id, SEL, ...))objc_msgSend_stret)(myNSView, @selector(frame));
  574. *
  575. * BE WARNED that these prototypes have changed in the past and will change
  576. * in the future. Code that uses a cast like the example above will be
  577. * unaffected.
  578. }
  579. procedure objc_msgSend_stret( stretAddr: UnivPtr; self_ObjC: objc_id; op: SEL; ...); external name '_objc_msgSend_stret';
  580. procedure objc_msgSendSuper_stret( stretAddr: UnivPtr; super: objc_super_Ptr; op: SEL; ...); external name '_objc_msgSendSuper_stret';
  581. { Forwarding }
  582. { Note that objc_msgSendv_stret() does not return a structure type,
  583. * and should not be cast to do so. This is unlike objc_msgSend_stret()
  584. * and objc_msgSendSuper_stret().
  585. }
  586. function objc_msgSendv( self_ObjC: objc_id; op: SEL; arg_size: UInt32; arg_frame: marg_list): objc_id; external name '_objc_msgSendv';
  587. procedure objc_msgSendv_stret( stretAddr: UnivPtr; self_ObjC: objc_id; op: SEL; arg_size: UInt32; arg_frame: marg_list); external name '_objc_msgSendv_stret';
  588. {$ifc TARGET_CPU_X86}
  589. function objc_msgSendv_fpret( seflid: objc_id; op: SEL; arg_size: UInt32; arg_frame: marg_list ): double; external name '_objc_msgSendv_fpret';
  590. {$endc}
  591. {
  592. getting all the classes in the application...
  593. int objc_getClassList(buffer, bufferLen)
  594. classes is an array of Class values (which are pointers)
  595. which will be filled by the function; if this
  596. argument is NULL, no copying is done, only the
  597. return value is returned
  598. bufferLen is the number of Class values the given buffer
  599. can hold; if the buffer is not large enough to
  600. hold all the classes, the buffer is filled to
  601. the indicated capacity with some arbitrary subset
  602. of the known classes, which could be different
  603. from call to call
  604. returns the number of classes, which is the number put
  605. in the buffer if the buffer was large enough,
  606. or the length the buffer should have been
  607. int numClasses = 0, newNumClasses = objc_getClassList(NULL, 0);
  608. Class *classes = NULL;
  609. while (numClasses < newNumClasses) (
  610. numClasses = newNumClasses;
  611. classes = realloc(classes, sizeof(Class) * numClasses);
  612. newNumClasses = objc_getClassList(classes, numClasses);
  613. )
  614. // now, can use the classes list; if NULL, there are no classes
  615. free(classes);
  616. }
  617. function objc_getClassList( buffer: Class_ObjC_Ptr; bufferLen: SInt32): SInt32; external name '_objc_getClassList';
  618. {$setc OBSOLETE_OBJC_GETCLASSES := 1}
  619. {$ifc OBSOLETE_OBJC_GETCLASSES}
  620. function objc_getClasses: UnivPtr; external name '_objc_getClasses';
  621. {$endc}
  622. function objc_lookUpClass( name: CStringPtr): objc_id; external name '_objc_lookUpClass';
  623. function objc_getRequiredClass( name: CStringPtr): objc_id; external name '_objc_getRequiredClass';
  624. procedure objc_addClass( myClass: Class_ObjC ); external name '_objc_addClass';
  625. { customizing the error handling for objc_getClass/objc_getMetaClass }
  626. type
  627. ClassHandlerCallback = function( param1: CStringPtr): SInt32;
  628. procedure objc_setClassHandler( handler: ClassHandlerCallback); external name '_objc_setClassHandler';
  629. { Making the Objective-C runtime thread safe. }
  630. procedure objc_setMultithreaded ( flag: boolean); external name '_objc_setMultithreaded';
  631. { overriding the default object allocation and error handling routines }
  632. {todo}
  633. {
  634. OBJC_EXPORT id (_alloc)(Class, unsigned int);
  635. OBJC_EXPORT id (_copy)(id, unsigned int);
  636. OBJC_EXPORT id (_realloc)(id, unsigned int);
  637. OBJC_EXPORT id (_dealloc)(id);
  638. OBJC_EXPORT id (_zoneAlloc)(Class, unsigned int, void *);
  639. OBJC_EXPORT id (_zoneRealloc)(id, unsigned int, void *);
  640. OBJC_EXPORT id (_zoneCopy)(id, unsigned int, void *);
  641. OBJC_EXPORT void (_error)(id, const char *, va_list);
  642. }
  643. {$endc} {not TARGET_CPU_64 and TARGET_OS_MAC}
  644. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  645. end.
  646. {$endc} {not MACOSALLINCLUDE}