ObjFW  Diff

Differences From Artifact [cde4d41e21]:

To Artifact [d471bf4a2f]:


26
27
28
29
30
31
32



33
34
35
36
37
38
39
#import "runtime-private.h"

static struct objc_hashtable *classes = NULL;
static Class *load_queue = NULL;
static size_t load_queue_cnt = 0;
static struct objc_sparsearray *empty_dtable = NULL;




static void
register_class(struct objc_abi_class *cls)
{
	if (classes == NULL)
		classes = objc_hashtable_new(2);

	objc_hashtable_set(classes, cls->name, cls);







>
>
>







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#import "runtime-private.h"

static struct objc_hashtable *classes = NULL;
static Class *load_queue = NULL;
static size_t load_queue_cnt = 0;
static struct objc_sparsearray *empty_dtable = NULL;

static SEL cxx_construct = NULL;
static SEL cxx_destruct = NULL;

static void
register_class(struct objc_abi_class *cls)
{
	if (classes == NULL)
		classes = objc_hashtable_new(2);

	objc_hashtable_set(classes, cls->name, cls);
289
290
291
292
293
294
295





296
297
298
299
300
301
302
}

void
objc_register_all_classes(struct objc_abi_symtab *symtab)
{
	uint_fast32_t i;






	for (i = 0; i < symtab->cls_def_cnt; i++) {
		struct objc_abi_class *cls =
		    (struct objc_abi_class*)symtab->defs[i];

		register_class(cls);
		register_selectors(cls);
		register_selectors(cls->metaclass);







>
>
>
>
>







292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
}

void
objc_register_all_classes(struct objc_abi_symtab *symtab)
{
	uint_fast32_t i;

	if (cxx_construct == NULL)
		cxx_construct = sel_registerName(".cxx_construct");
	if (cxx_destruct == NULL)
		cxx_destruct = sel_registerName(".cxx_destruct");

	for (i = 0; i < symtab->cls_def_cnt; i++) {
		struct objc_abi_class *cls =
		    (struct objc_abi_class*)symtab->defs[i];

		register_class(cls);
		register_selectors(cls);
		register_selectors(cls->metaclass);
529
530
531
532
533
534
535






















































536
537
538
539
540
541
542

	objc_update_dtable(cls);

	objc_global_mutex_unlock();

	return (IMP)nil;
}























































static void
free_class(Class rcls)
{
	struct objc_abi_class *cls = (struct objc_abi_class*)rcls;

	if (rcls->subclass_list != NULL) {







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
564
565
566
567
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
599
600
601
602
603
604

	objc_update_dtable(cls);

	objc_global_mutex_unlock();

	return (IMP)nil;
}

id
objc_constructInstance(Class cls, void *bytes)
{
	id obj = (id)bytes;
	BOOL (*last)(id, SEL) = NULL;

	if (cls == Nil || bytes == NULL)
		return nil;

	object_setClass(obj, cls);

	/* FIXME: Constructors of superclasses should be called first */
	for (; cls != Nil; cls = class_getSuperclass(cls)) {
		BOOL (*ctor)(id, SEL);

		if (class_respondsToSelector(cls, cxx_construct)) {
			if ((ctor = (BOOL(*)(id, SEL))
			    class_getMethodImplementation(cls,
			    cxx_construct)) != last)
				if (!ctor(obj, cxx_construct))
					return nil;

			last = ctor;
		} else
			break;
	}

	return obj;
}

void*
objc_destructInstance(id obj)
{
	Class cls;
	void (*last)(id, SEL) = NULL;

	for (cls = object_getClass(obj); cls != Nil;
	    cls = class_getSuperclass(cls)) {
		void (*dtor)(id, SEL);

		if (class_respondsToSelector(cls, cxx_destruct)) {
			if ((dtor = (void(*)(id, SEL))
			    class_getMethodImplementation(cls,
			    cxx_destruct)) != last)
				dtor(obj, cxx_destruct);

			last = dtor;
		} else
			break;
	}

	return obj;
}

static void
free_class(Class rcls)
{
	struct objc_abi_class *cls = (struct objc_abi_class*)rcls;

	if (rcls->subclass_list != NULL) {