ObjFW  Check-in [688eef7561]

Overview
Comment:runtime: Make ivars opaque and provide an API
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 688eef7561e339c0469720c023ec7e36c51b43fef13b2abaf6e7548877a4f0ce
User & Date: js on 2019-11-24 15:22:55
Other Links: manifest | tags
Context
2019-11-24
15:25
.travis.yml: Re-enable Amiga and Wii builds check-in: 7a52095b63 user: js tags: trunk
15:22
runtime: Make ivars opaque and provide an API check-in: 688eef7561 user: js tags: trunk
2019-11-17
21:17
Fix incorrect indentation check-in: abc9d84958 user: js tags: trunk
Changes

Modified src/OFIntrospection.m from [58e26172d8] to [87a3a4c527].

384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
@synthesize name = _name, offset = _offset, typeEncoding = _typeEncoding;

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

#if defined(OF_OBJFW_RUNTIME)
- (instancetype)of_initWithIVar: (struct objc_ivar *)iVar
{
	self = [super init];

	@try {
		if (iVar->name != NULL)
			_name = [[OFString alloc]
			    initWithUTF8String: iVar->name];

		_typeEncoding = iVar->typeEncoding;
		_offset = iVar->offset;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
#elif defined(OF_APPLE_RUNTIME)
- (instancetype)of_initWithIVar: (Ivar)iVar
{
	self = [super init];

	@try {
		const char *name = ivar_getName(iVar);

		if (name != NULL)
			_name = [[OFString alloc] initWithUTF8String: name];

		_typeEncoding = ivar_getTypeEncoding(iVar);
		_offset = ivar_getOffset(iVar);
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
#else
# error Invalid ObjC runtime!
#endif

- (void)dealloc
{
	[_name release];

	[super dealloc];
}







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<



















<
<
<







384
385
386
387
388
389
390




















391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409



410
411
412
413
414
415
416
@synthesize name = _name, offset = _offset, typeEncoding = _typeEncoding;

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}





















- (instancetype)of_initWithIVar: (Ivar)iVar
{
	self = [super init];

	@try {
		const char *name = ivar_getName(iVar);

		if (name != NULL)
			_name = [[OFString alloc] initWithUTF8String: name];

		_typeEncoding = ivar_getTypeEncoding(iVar);
		_offset = ivar_getOffset(iVar);
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}




- (void)dealloc
{
	[_name release];

	[super dealloc];
}
467
468
469
470
471
472
473

474
475
476
477
478
479
480
481
482
483
	@try {
#if defined(OF_OBJFW_RUNTIME)
		struct objc_method_list *methodList;
		struct objc_property_list *propertyList;
#elif defined(OF_APPLE_RUNTIME)
		Method *methodList;
		objc_property_t *propertyList;

		Ivar *iVarList;
		unsigned count;
#endif
		void *pool;

		_classMethods = [[OFMutableArray alloc] init];
		_instanceMethods = [[OFMutableArray alloc] init];
		_properties = [[OFMutableArray alloc] init];
		_instanceVariables = [[OFMutableArray alloc] init];








>


<







444
445
446
447
448
449
450
451
452
453

454
455
456
457
458
459
460
	@try {
#if defined(OF_OBJFW_RUNTIME)
		struct objc_method_list *methodList;
		struct objc_property_list *propertyList;
#elif defined(OF_APPLE_RUNTIME)
		Method *methodList;
		objc_property_t *propertyList;
#endif
		Ivar *iVarList;
		unsigned count;

		void *pool;

		_classMethods = [[OFMutableArray alloc] init];
		_instanceMethods = [[OFMutableArray alloc] init];
		_properties = [[OFMutableArray alloc] init];
		_instanceVariables = [[OFMutableArray alloc] init];

511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
			pool = objc_autoreleasePoolPush();

			for (unsigned int i = 0; i < propertyList->count; i++)
				[_properties addObject: [[[OFProperty alloc]
				    of_initWithProperty:
				    &propertyList->properties[i]] autorelease]];

			objc_autoreleasePoolPop(pool);
		}

		if (class->iVars != NULL) {
			pool = objc_autoreleasePoolPush();

			for (unsigned int i = 0; i < class->iVars->count; i++)
				[_instanceVariables addObject:
				    [[[OFInstanceVariable alloc]
				    of_initWithIVar:
				    &class->iVars->iVars[i]] autorelease]];

			objc_autoreleasePoolPop(pool);
		}
#elif defined(OF_APPLE_RUNTIME)
		methodList = class_copyMethodList(object_getClass(class),
		    &count);
		@try {
			pool = objc_autoreleasePoolPush();







<
<
<
<
<
<
<
<
<
<
<
<







488
489
490
491
492
493
494












495
496
497
498
499
500
501
			pool = objc_autoreleasePoolPush();

			for (unsigned int i = 0; i < propertyList->count; i++)
				[_properties addObject: [[[OFProperty alloc]
				    of_initWithProperty:
				    &propertyList->properties[i]] autorelease]];













			objc_autoreleasePoolPop(pool);
		}
#elif defined(OF_APPLE_RUNTIME)
		methodList = class_copyMethodList(object_getClass(class),
		    &count);
		@try {
			pool = objc_autoreleasePoolPush();
568
569
570
571
572
573
574



575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
				    of_initWithProperty: propertyList[i]]
				    autorelease]];

			objc_autoreleasePoolPop(pool);
		} @finally {
			free(propertyList);
		}




		iVarList = class_copyIvarList(class, &count);
		@try {
			pool = objc_autoreleasePoolPush();

			for (unsigned int i = 0; i < count; i++)
				[_instanceVariables addObject:
				    [[[OFInstanceVariable alloc]
				    of_initWithIVar: iVarList[i]] autorelease]];

			objc_autoreleasePoolPop(pool);
		} @finally {
			free(iVarList);
		}
#else
# error Invalid ObjC runtime!
#endif

		[_classMethods makeImmutable];
		[_instanceMethods makeImmutable];
		[_properties makeImmutable];
		[_instanceVariables makeImmutable];
	} @catch (id e) {
		[self release];







>
>
>














<
<
<







533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556



557
558
559
560
561
562
563
				    of_initWithProperty: propertyList[i]]
				    autorelease]];

			objc_autoreleasePoolPop(pool);
		} @finally {
			free(propertyList);
		}
#else
# error Invalid ObjC runtime!
#endif

		iVarList = class_copyIvarList(class, &count);
		@try {
			pool = objc_autoreleasePoolPush();

			for (unsigned int i = 0; i < count; i++)
				[_instanceVariables addObject:
				    [[[OFInstanceVariable alloc]
				    of_initWithIVar: iVarList[i]] autorelease]];

			objc_autoreleasePoolPop(pool);
		} @finally {
			free(iVarList);
		}




		[_classMethods makeImmutable];
		[_instanceMethods makeImmutable];
		[_properties makeImmutable];
		[_instanceVariables makeImmutable];
	} @catch (id e) {
		[self release];

Modified src/runtime/Makefile from [a2eae9738b] to [4f7f906070].

14
15
16
17
18
19
20

21
22
23
24
25
26
27
SRCS = arc.m			\
       category.m		\
       class.m			\
       dtable.m			\
       exception.m		\
       hashtable.m		\
       init.m			\

       lookup.m			\
       misc.m			\
       property.m		\
       protocol.m		\
       selector.m		\
       sparsearray.m		\
       static-instances.m	\







>







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
SRCS = arc.m			\
       category.m		\
       class.m			\
       dtable.m			\
       exception.m		\
       hashtable.m		\
       init.m			\
       ivar.m			\
       lookup.m			\
       misc.m			\
       property.m		\
       protocol.m		\
       selector.m		\
       sparsearray.m		\
       static-instances.m	\

Modified src/runtime/ObjFWRT.h from [0d652d980c] to [7fa4aef07e].

57
58
59
60
61
62
63

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#define nil (id _Null_unspecified)0
#define YES true
#define NO  false

typedef struct objc_class *Class;
typedef struct objc_object *id;
typedef const struct objc_selector *SEL;

#if !defined(__wii__) && !defined(__amigaos__)
typedef bool BOOL;
#endif
typedef id _Nullable (*IMP)(id _Nonnull, SEL _Nonnull, ...);
typedef void (*objc_uncaught_exception_handler_t)(id _Nullable);
typedef void (*objc_enumeration_mutation_handler_t)(id _Nonnull);

struct objc_class {
	Class _Nonnull isa;
	Class _Nullable superclass;
	const char *_Nonnull name;
	unsigned long version;
	unsigned long info;
	long instanceSize;
	struct objc_ivar_list *_Nullable iVars;
	struct objc_method_list *_Nullable methodList;
	struct objc_dtable *_Nonnull DTable;
	Class _Nullable *_Nullable subclassList;
	void *_Nullable siblingClass;
	struct objc_protocol_list *_Nullable protocols;
	void *_Nullable GCObjectType;
	unsigned long ABIVersion;
	int32_t *_Nonnull *_Nullable iVarOffsets;
	struct objc_property_list *_Nullable properties;
};

enum objc_class_info {
	OBJC_CLASS_INFO_CLASS	    = 0x001,
	OBJC_CLASS_INFO_METACLASS   = 0x002,
	OBJC_CLASS_INFO_NEW_ABI	    = 0x010,







>














|







|







57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#define nil (id _Null_unspecified)0
#define YES true
#define NO  false

typedef struct objc_class *Class;
typedef struct objc_object *id;
typedef const struct objc_selector *SEL;
typedef struct objc_ivar *Ivar;
#if !defined(__wii__) && !defined(__amigaos__)
typedef bool BOOL;
#endif
typedef id _Nullable (*IMP)(id _Nonnull, SEL _Nonnull, ...);
typedef void (*objc_uncaught_exception_handler_t)(id _Nullable);
typedef void (*objc_enumeration_mutation_handler_t)(id _Nonnull);

struct objc_class {
	Class _Nonnull isa;
	Class _Nullable superclass;
	const char *_Nonnull name;
	unsigned long version;
	unsigned long info;
	long instanceSize;
	struct objc_ivar_list *_Nullable ivars;
	struct objc_method_list *_Nullable methodList;
	struct objc_dtable *_Nonnull DTable;
	Class _Nullable *_Nullable subclassList;
	void *_Nullable siblingClass;
	struct objc_protocol_list *_Nullable protocols;
	void *_Nullable GCObjectType;
	unsigned long ABIVersion;
	int32_t *_Nonnull *_Nullable ivarOffsets;
	struct objc_property_list *_Nullable properties;
};

enum objc_class_info {
	OBJC_CLASS_INFO_CLASS	    = 0x001,
	OBJC_CLASS_INFO_METACLASS   = 0x002,
	OBJC_CLASS_INFO_NEW_ABI	    = 0x010,
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
	const char *_Nonnull categoryName;
	const char *_Nonnull className;
	struct objc_method_list *_Nullable instanceMethods;
	struct objc_method_list *_Nullable classMethods;
	struct objc_protocol_list *_Nullable protocols;
};

struct objc_ivar {
	const char *_Nonnull name;
	const char *_Nonnull typeEncoding;
	unsigned int offset;
};

struct objc_ivar_list {
	unsigned int count;
	struct objc_ivar iVars[1];
};

enum objc_property_attributes {
	OBJC_PROPERTY_READONLY	= 0x01,
	OBJC_PROPERTY_GETTER	= 0x02,
	OBJC_PROPERTY_ASSIGN	= 0x04,
	OBJC_PROPERTY_READWRITE	= 0x08,
	OBJC_PROPERTY_RETAIN	= 0x10,
	OBJC_PROPERTY_COPY	= 0x20,







<
<
<
<
<
<
<
<
<
<
<







131
132
133
134
135
136
137











138
139
140
141
142
143
144
	const char *_Nonnull categoryName;
	const char *_Nonnull className;
	struct objc_method_list *_Nullable instanceMethods;
	struct objc_method_list *_Nullable classMethods;
	struct objc_protocol_list *_Nullable protocols;
};












enum objc_property_attributes {
	OBJC_PROPERTY_READONLY	= 0x01,
	OBJC_PROPERTY_GETTER	= 0x02,
	OBJC_PROPERTY_ASSIGN	= 0x04,
	OBJC_PROPERTY_READWRITE	= 0x08,
	OBJC_PROPERTY_RETAIN	= 0x10,
	OBJC_PROPERTY_COPY	= 0x20,
256
257
258
259
260
261
262





263
264
265
266
267
268
269
    Class _Nonnull class_);
extern const char *_Nullable object_getClassName(id _Nullable object);
extern const char *_Nonnull protocol_getName(Protocol *_Nonnull protocol);
extern bool protocol_isEqual(Protocol *_Nonnull protocol1,
    Protocol *_Nonnull protocol2);
extern bool protocol_conformsToProtocol(Protocol *_Nonnull protocol1,
    Protocol *_Nonnull protocol2);





extern void objc_exit(void);
extern _Nullable objc_uncaught_exception_handler_t
    objc_setUncaughtExceptionHandler(
    objc_uncaught_exception_handler_t _Nullable handler);
extern void objc_setForwardHandler(IMP _Nullable forward,
    IMP _Nullable stretForward);
extern void objc_setEnumerationMutationHandler(







>
>
>
>
>







246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
    Class _Nonnull class_);
extern const char *_Nullable object_getClassName(id _Nullable object);
extern const char *_Nonnull protocol_getName(Protocol *_Nonnull protocol);
extern bool protocol_isEqual(Protocol *_Nonnull protocol1,
    Protocol *_Nonnull protocol2);
extern bool protocol_conformsToProtocol(Protocol *_Nonnull protocol1,
    Protocol *_Nonnull protocol2);
extern Ivar _Nullable *_Nullable class_copyIvarList(Class _Nullable class_,
    unsigned int *_Nullable outCount);
extern const char *_Nonnull ivar_getName(Ivar _Nonnull ivar);
extern const char *_Nonnull ivar_getTypeEncoding(Ivar _Nonnull ivar);
extern ptrdiff_t ivar_getOffset(Ivar _Nonnull ivar);
extern void objc_exit(void);
extern _Nullable objc_uncaught_exception_handler_t
    objc_setUncaughtExceptionHandler(
    objc_uncaught_exception_handler_t _Nullable handler);
extern void objc_setForwardHandler(IMP _Nullable forward,
    IMP _Nullable stretForward);
extern void objc_setEnumerationMutationHandler(

Modified src/runtime/amiga-glue.m from [f152603cb3] to [91f4bad4cf].

629
630
631
632
633
634
635

































}

void __saveds
glue_objc_exit(void)
{
	objc_exit();
}








































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
}

void __saveds
glue_objc_exit(void)
{
	objc_exit();
}

Ivar *__saveds
glue_class_copyIvarList PPC_PARAMS(Class class, unsigned int *outCount)
{
	M68K_ARG(Class, class, a0)
	M68K_ARG(unsigned int *, outCount, a1)

	return class_copyIvarList(class, outCount);
}

const char *__saveds
glue_ivar_getName PPC_PARAMS(Ivar ivar)
{
	M68K_ARG(Ivar, ivar, a0)

	return ivar_getName(ivar);
}

const char *__saveds
glue_ivar_getTypeEncoding PPC_PARAMS(Ivar ivar)
{
	M68K_ARG(Ivar, ivar, a0)

	return ivar_getTypeEncoding(ivar);
}

ptrdiff_t __saveds
glue_ivar_getOffset PPC_PARAMS(Ivar ivar)
{
	M68K_ARG(Ivar, ivar, a0)

	return ivar_getOffset(ivar);
}

Modified src/runtime/amiga-library.m from [f3f4183dca] to [f11cc5f9b0].

124
125
126
127
128
129
130




131
132
133
134
135
136
137
extern bool glue_protocol_conformsToProtocol(void);
extern _Nullable objc_uncaught_exception_handler_t
    glue_objc_setUncaughtExceptionHandler(void);
extern void glue_objc_setForwardHandler(void);
extern void glue_objc_setEnumerationMutationHandler(void);
extern void glue_objc_zero_weak_references(void);
extern void glue_objc_exit(void);





#ifdef OF_MORPHOS
const ULONG __abox__ = 1;
#endif
struct ExecBase *SysBase;
struct objc_libc libc;
FILE *stdout;







>
>
>
>







124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
extern bool glue_protocol_conformsToProtocol(void);
extern _Nullable objc_uncaught_exception_handler_t
    glue_objc_setUncaughtExceptionHandler(void);
extern void glue_objc_setForwardHandler(void);
extern void glue_objc_setEnumerationMutationHandler(void);
extern void glue_objc_zero_weak_references(void);
extern void glue_objc_exit(void);
extern Ivar *glue_class_copyIvarList(void);
extern const char *glue_ivar_getName(void);
extern const char *glue_ivar_getTypeEncoding(void);
extern ptrdiff_t glue_ivar_getOffset(void);

#ifdef OF_MORPHOS
const ULONG __abox__ = 1;
#endif
struct ExecBase *SysBase;
struct objc_libc libc;
FILE *stdout;
631
632
633
634
635
636
637




638
639
640
641
642
643
644
	(CONST_APTR)glue_protocol_isEqual,
	(CONST_APTR)glue_protocol_conformsToProtocol,
	(CONST_APTR)glue_objc_setUncaughtExceptionHandler,
	(CONST_APTR)glue_objc_setForwardHandler,
	(CONST_APTR)glue_objc_setEnumerationMutationHandler,
	(CONST_APTR)glue_objc_zero_weak_references,
	(CONST_APTR)glue_objc_exit,




	(CONST_APTR)-1,
#ifdef OF_MORPHOS
	(CONST_APTR)FUNCARRAY_END
#endif
};
#pragma GCC diagnostic pop








>
>
>
>







635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
	(CONST_APTR)glue_protocol_isEqual,
	(CONST_APTR)glue_protocol_conformsToProtocol,
	(CONST_APTR)glue_objc_setUncaughtExceptionHandler,
	(CONST_APTR)glue_objc_setForwardHandler,
	(CONST_APTR)glue_objc_setEnumerationMutationHandler,
	(CONST_APTR)glue_objc_zero_weak_references,
	(CONST_APTR)glue_objc_exit,
	(CONST_APTR)glue_class_copyIvarList,
	(CONST_APTR)glue_ivar_getName,
	(CONST_APTR)glue_ivar_getTypeEncoding,
	(CONST_APTR)glue_ivar_getOffset,
	(CONST_APTR)-1,
#ifdef OF_MORPHOS
	(CONST_APTR)FUNCARRAY_END
#endif
};
#pragma GCC diagnostic pop

Modified src/runtime/amigaos3.sfd from [de4ad75da8] to [af633e4379].

67
68
69
70
71
72
73




74
bool glue_protocol_isEqual(Protocol *_Nonnull protocol1, Protocol *_Nonnull protocol2)(a0,a1)
bool glue_protocol_conformsToProtocol(Protocol *_Nonnull protocol1, Protocol *_Nonnull protocol2)(a0,a1)
_Nullable objc_uncaught_exception_handler_t glue_objc_setUncaughtExceptionHandler(objc_uncaught_exception_handler_t _Nullable handler)(a0)
void glue_objc_setForwardHandler(IMP _Nullable forward, IMP _Nullable stretForward)(a0,a1)
void glue_objc_setEnumerationMutationHandler(objc_enumeration_mutation_handler_t _Nullable handler)(a0)
void glue_objc_zero_weak_references(id _Nonnull value)(a0)
void glue_objc_exit(void)()




==end







>
>
>
>

67
68
69
70
71
72
73
74
75
76
77
78
bool glue_protocol_isEqual(Protocol *_Nonnull protocol1, Protocol *_Nonnull protocol2)(a0,a1)
bool glue_protocol_conformsToProtocol(Protocol *_Nonnull protocol1, Protocol *_Nonnull protocol2)(a0,a1)
_Nullable objc_uncaught_exception_handler_t glue_objc_setUncaughtExceptionHandler(objc_uncaught_exception_handler_t _Nullable handler)(a0)
void glue_objc_setForwardHandler(IMP _Nullable forward, IMP _Nullable stretForward)(a0,a1)
void glue_objc_setEnumerationMutationHandler(objc_enumeration_mutation_handler_t _Nullable handler)(a0)
void glue_objc_zero_weak_references(id _Nonnull value)(a0)
void glue_objc_exit(void)()
Ivar _Nullable *_Nullable glue_class_copyIvarList(Class _Nullable class_, unsigned int *_Nullable outCount)(a0,a1)
const char *_Nonnull glue_ivar_getName(Ivar _Nonnull ivar)(a0)
const char *_Nonnull glue_ivar_getTypeEncoding(Ivar _Nonnull ivar)(a0)
ptrdiff_t glue_ivar_getOffset(Ivar _Nonnull ivar)(a0)
==end

Modified src/runtime/class.m from [132bb904b5] to [d1f09c48dd].

253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
		OBJC_ERROR("Not enough memory for subclass list of class %s\n",
		    class->superclass->name);

	class->superclass->subclassList[i] = class;
	class->superclass->subclassList[i + 1] = Nil;
}


static void
updateIVarOffsets(Class class)
{
	if (!(class->info & OBJC_CLASS_INFO_NEW_ABI))
		return;

	if (class->instanceSize > 0)
		return;

	class->instanceSize = -class->instanceSize;

	if (class->superclass != Nil) {
		class->instanceSize += class->superclass->instanceSize;

		if (class->iVars != NULL) {
			for (unsigned int i = 0; i < class->iVars->count; i++) {
				class->iVars->iVars[i].offset +=
				    class->superclass->instanceSize;
				*class->iVarOffsets[i] =
				    class->iVars->iVars[i].offset;
			}
		}
	} else
		for (unsigned int i = 0; i < class->iVars->count; i++)
			*class->iVarOffsets[i] = class->iVars->iVars[i].offset;
}

static void
setupClass(Class class)
{
	const char *superclassName;








<

|












|
|
|

|
|



|
|







253
254
255
256
257
258
259

260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
		OBJC_ERROR("Not enough memory for subclass list of class %s\n",
		    class->superclass->name);

	class->superclass->subclassList[i] = class;
	class->superclass->subclassList[i + 1] = Nil;
}


static void
updateIvarOffsets(Class class)
{
	if (!(class->info & OBJC_CLASS_INFO_NEW_ABI))
		return;

	if (class->instanceSize > 0)
		return;

	class->instanceSize = -class->instanceSize;

	if (class->superclass != Nil) {
		class->instanceSize += class->superclass->instanceSize;

		if (class->ivars != NULL) {
			for (unsigned int i = 0; i < class->ivars->count; i++) {
				class->ivars->ivars[i].offset +=
				    class->superclass->instanceSize;
				*class->ivarOffsets[i] =
				    class->ivars->ivars[i].offset;
			}
		}
	} else
		for (unsigned int i = 0; i < class->ivars->count; i++)
			*class->ivarOffsets[i] = class->ivars->ivars[i].offset;
}

static void
setupClass(Class class)
{
	const char *superclassName;

309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
		class->isa->superclass = super->isa;

		addSubclass(class);
		addSubclass(class->isa);
	} else
		class->isa->superclass = class;

	updateIVarOffsets(class);

	class->info |= OBJC_CLASS_INFO_SETUP;
	class->isa->info |= OBJC_CLASS_INFO_SETUP;
}

static void
initializeClass(Class class)







|







308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
		class->isa->superclass = super->isa;

		addSubclass(class);
		addSubclass(class->isa);
	} else
		class->isa->superclass = class;

	updateIvarOffsets(class);

	class->info |= OBJC_CLASS_INFO_SETUP;
	class->isa->info |= OBJC_CLASS_INFO_SETUP;
}

static void
initializeClass(Class class)

Added src/runtime/ivar.m version [d2a643d575].































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019
 *   Jonathan Schleifer <js@heap.zone>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "ObjFWRT.h"
#import "private.h"

Ivar *
class_copyIvarList(Class class, unsigned int *outCount)
{
	unsigned int count;
	Ivar *ivars;

	if (class == Nil)
		return NULL;

	objc_global_mutex_lock();

	if (class->ivars == NULL) {
		objc_global_mutex_unlock();
		return NULL;
	}

	count = class->ivars->count;

	if (count == 0) {
		objc_global_mutex_unlock();
		return NULL;
	}

	if ((ivars = malloc((count + 1) * sizeof(Ivar))) == NULL) {
		objc_global_mutex_unlock();
		return NULL;
	}

	for (unsigned int i = 0; i < count; i++)
		ivars[i] = &class->ivars->ivars[i];
	ivars[count] = NULL;

	if (outCount != NULL)
		*outCount = count;

	objc_global_mutex_unlock();

	return ivars;
}

const char *
ivar_getName(Ivar ivar)
{
	return ivar->name;
}

const char *
ivar_getTypeEncoding(Ivar ivar)
{
	return ivar->typeEncoding;
}

ptrdiff_t
ivar_getOffset(Ivar ivar)
{
	return ivar->offset;
}

Modified src/runtime/linklib/linklib.m from [9569bc8b44] to [97d16c1155].

587
588
589
590
591
592
593
























}

void
objc_exit(void)
{
	glue_objc_exit();
}































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
}

void
objc_exit(void)
{
	glue_objc_exit();
}

Ivar *
class_copyIvarList(Class class, unsigned int *outCount)
{
	return glue_class_copyIvarList(class, outCount);
}

const char *
ivar_getName(Ivar ivar)
{
	return glue_ivar_getName(ivar);
}

const char *
ivar_getTypeEncoding(Ivar ivar)
{
	return glue_ivar_getTypeEncoding(ivar);
}

ptrdiff_t
ivar_getOffset(Ivar ivar)
{
	return glue_ivar_getOffset(ivar);
}

Modified src/runtime/morphos-clib.h from [4a0280b314] to [d7678b7243].

61
62
63
64
65
66
67




bool glue_protocol_isEqual(Protocol *, Protocol *);
bool glue_protocol_conformsToProtocol(Protocol *, Protocol *);
objc_uncaught_exception_handler_t glue_objc_setUncaughtExceptionHandler(objc_uncaught_exception_handler_t);
void glue_objc_setForwardHandler(IMP, IMP);
void glue_objc_setEnumerationMutationHandler(objc_enumeration_mutation_handler_t);
void glue_objc_zero_weak_references(id);
void glue_objc_exit(void);











>
>
>
>
61
62
63
64
65
66
67
68
69
70
71
bool glue_protocol_isEqual(Protocol *, Protocol *);
bool glue_protocol_conformsToProtocol(Protocol *, Protocol *);
objc_uncaught_exception_handler_t glue_objc_setUncaughtExceptionHandler(objc_uncaught_exception_handler_t);
void glue_objc_setForwardHandler(IMP, IMP);
void glue_objc_setEnumerationMutationHandler(objc_enumeration_mutation_handler_t);
void glue_objc_zero_weak_references(id);
void glue_objc_exit(void);
Ivar *glue_class_copyIvarList(Class class_, unsigned int *outCount);
const char *glue_ivar_getName(Ivar ivar);
const char *glue_ivar_getTypeEncoding(Ivar ivar);
ptrdiff_t glue_ivar_getOffset(Ivar ivar);

Modified src/runtime/morphos.fd from [28b3a4e6a7] to [308b16b2df].

63
64
65
66
67
68
69




70
glue_protocol_isEqual(protocol1,protocol2)(sysv,r12base)
glue_protocol_conformsToProtocol(protocol1,protocol2)(sysv,r12base)
glue_objc_setUncaughtExceptionHandler(handler)(sysv,r12base)
glue_objc_setForwardHandler(forward,stretForward)(sysv,r12base)
glue_objc_setEnumerationMutationHandler(handler)(sysv,r12base)
glue_objc_zero_weak_references(value)(sysv,r12base)
glue_objc_exit()(sysv,r12base)




##end







>
>
>
>

63
64
65
66
67
68
69
70
71
72
73
74
glue_protocol_isEqual(protocol1,protocol2)(sysv,r12base)
glue_protocol_conformsToProtocol(protocol1,protocol2)(sysv,r12base)
glue_objc_setUncaughtExceptionHandler(handler)(sysv,r12base)
glue_objc_setForwardHandler(forward,stretForward)(sysv,r12base)
glue_objc_setEnumerationMutationHandler(handler)(sysv,r12base)
glue_objc_zero_weak_references(value)(sysv,r12base)
glue_objc_exit()(sysv,r12base)
glue_class_copyIvarList(class_,outCount)(sysv,r12base)
glue_ivar_getName(ivar)(sysv,r12base)
glue_ivar_getTypeEncoding(ivar)(sysv,r12base)
glue_ivar_getOffset(ivar)(sysv,r12base)
##end

Modified src/runtime/private.h from [62b52db4cc] to [182926c01c].

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65











66
67
68
69
70
71
72
struct objc_abi_class {
	struct objc_abi_class *_Nonnull metaclass;
	const char *_Nullable superclass;
	const char *_Nonnull name;
	unsigned long version;
	unsigned long info;
	long instanceSize;
	void *_Nullable iVars;
	struct objc_abi_method_list *_Nullable methodList;
	void *_Nullable DTable;
	void *_Nullable subclassList;
	void *_Nullable siblingClass;
	void *_Nullable protocols;
	void *_Nullable GCObjectType;
	long ABIVersion;
	int32_t *_Nonnull *_Nullable iVarOffsets;
	void *_Nullable properties;
};

struct objc_abi_selector {
	const char *_Nonnull name;
	const char *_Nullable typeEncoding;
};

struct objc_abi_method {
	struct objc_abi_selector selector;
	IMP _Nonnull implementation;
};

struct objc_abi_method_list {
	struct objc_abi_method_list *_Nullable next;
	unsigned int count;
	struct objc_abi_method methods[1];
};












struct objc_abi_category {
	const char *_Nonnull categoryName;
	const char *_Nonnull className;
	struct objc_abi_method_list *_Nullable instanceMethods;
	struct objc_abi_method_list *_Nullable classMethods;
	struct objc_protocol_list *_Nullable protocols;







|







|


















>
>
>
>
>
>
>
>
>
>
>







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
struct objc_abi_class {
	struct objc_abi_class *_Nonnull metaclass;
	const char *_Nullable superclass;
	const char *_Nonnull name;
	unsigned long version;
	unsigned long info;
	long instanceSize;
	void *_Nullable ivars;
	struct objc_abi_method_list *_Nullable methodList;
	void *_Nullable DTable;
	void *_Nullable subclassList;
	void *_Nullable siblingClass;
	void *_Nullable protocols;
	void *_Nullable GCObjectType;
	long ABIVersion;
	int32_t *_Nonnull *_Nullable ivarOffsets;
	void *_Nullable properties;
};

struct objc_abi_selector {
	const char *_Nonnull name;
	const char *_Nullable typeEncoding;
};

struct objc_abi_method {
	struct objc_abi_selector selector;
	IMP _Nonnull implementation;
};

struct objc_abi_method_list {
	struct objc_abi_method_list *_Nullable next;
	unsigned int count;
	struct objc_abi_method methods[1];
};

struct objc_ivar {
	const char *_Nonnull name;
	const char *_Nonnull typeEncoding;
	unsigned int offset;
};

struct objc_ivar_list {
	unsigned int count;
	struct objc_ivar ivars[1];
};

struct objc_abi_category {
	const char *_Nonnull categoryName;
	const char *_Nonnull className;
	struct objc_abi_method_list *_Nullable instanceMethods;
	struct objc_abi_method_list *_Nullable classMethods;
	struct objc_protocol_list *_Nullable protocols;