ObjFW  Diff

Differences From Artifact [8659e5eda9]:

  • File src/runtime/class.m — part of check-in [fe2cbe0021] at 2018-04-22 16:13:04 on branch trunk — runtime: Define BOOL to be the same as bool

    As we define the ABI, we can just replace BOOL with bool everywhere,
    including in ObjFW itself. For the Apple platforms where BOOL and bool
    are different, this is not a problem as BOOL and bool are passed and
    returned the same way in the ABI.

    This still defines BOOL to bool for compatibility, except on AmigaOS and
    Wii, which both have its own BOOL type. (user: js, size: 19487) [annotate] [blame] [check-ins using]

To Artifact [8d78186ef9]:


415
416
417
418
419
420
421
422



423
424
425
426
427
428
429
415
416
417
418
419
420
421

422
423
424
425
426
427
428
429
430
431







-
+
+
+







			cls->info |= OBJC_CLASS_INFO_LOADED;
	}

	process_load_queue();
}

Class
objc_allocateClassPair(Class superclass, const char *name, size_t extra_bytes)
objc_allocateClassPair(Class superclass OBJC_M68K_REG("a0"),
    const char *name OBJC_M68K_REG("a1"),
    size_t extra_bytes OBJC_M68K_REG("d0"))
{
	struct objc_class *cls, *metaclass;
	Class iter, rootclass = Nil;

	if (extra_bytes > LONG_MAX)
		OBJC_ERROR("extra_bytes out of range!")

449
450
451
452
453
454
455
456

457
458
459
460
461
462
463
451
452
453
454
455
456
457

458
459
460
461
462
463
464
465







-
+







	metaclass->instance_size = (superclass != Nil ?
	    superclass->isa->instance_size : 0) + (long)extra_bytes;

	return cls;
}

void
objc_registerClassPair(Class cls)
objc_registerClassPair(Class cls OBJC_M68K_REG("a0"))
{
	objc_global_mutex_lock();

	register_class((struct objc_abi_class *)cls);

	if (cls->superclass != Nil) {
		add_subclass(cls);
526
527
528
529
530
531
532
533


534
535
536
537
538
539
540
528
529
530
531
532
533
534

535
536
537
538
539
540
541
542
543







-
+
+







Class
objc_get_class(const char *name)
{
	return objc_getRequiredClass(name);
}

unsigned int
objc_getClassList(Class *buf, unsigned int count)
objc_getClassList(Class *buf OBJC_M68K_REG("a0"),
    unsigned int count OBJC_M68K_REG("d0"))
{
	unsigned int j;
	objc_global_mutex_lock();

	if (buf == NULL)
		return classes_cnt;

566
567
568
569
570
571
572
573

574
575
576
577
578
579
580
569
570
571
572
573
574
575

576
577
578
579
580
581
582
583







-
+








	objc_global_mutex_unlock();

	return j;
}

Class *
objc_copyClassList(unsigned int *len)
objc_copyClassList(unsigned int *len OBJC_M68K_REG("a0"))
{
	Class *ret;
	unsigned int count;

	objc_global_mutex_lock();

	if ((ret = malloc((classes_cnt + 1) * sizeof(Class))) == NULL)
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
618
619
620
621
622
623
624

625
626
627
628
629
630
631
632
633


634
635
636
637
638
639
640
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

618
619
620
621
622
623
624
625
626

627
628
629
630
631
632
633
634
635

636
637
638
639
640
641
642
643
644







-
+








-
+








-
+








-
+








-
+
+








	objc_global_mutex_unlock();

	return ret;
}

bool
class_isMetaClass(Class cls)
class_isMetaClass(Class cls OBJC_M68K_REG("a0"))
{
	if (cls == Nil)
		return false;

	return (cls->info & OBJC_CLASS_INFO_METACLASS);
}

const char *
class_getName(Class cls)
class_getName(Class cls OBJC_M68K_REG("a0"))
{
	if (cls == Nil)
		return "";

	return cls->name;
}

Class
class_getSuperclass(Class cls)
class_getSuperclass(Class cls OBJC_M68K_REG("a0"))
{
	if (cls == Nil)
		return Nil;

	return cls->superclass;
}

unsigned long
class_getInstanceSize(Class cls)
class_getInstanceSize(Class cls OBJC_M68K_REG("a0"))
{
	if (cls == Nil)
		return 0;

	return cls->instance_size;
}

IMP
class_getMethodImplementation(Class cls, SEL sel)
class_getMethodImplementation(Class cls OBJC_M68K_REG("a0"),
    SEL sel OBJC_M68K_REG("a1"))
{
	/*
	 * We use a dummy object here so that the normal lookup is used, even
	 * though we don't have an object. Doing so is safe, as objc_msg_lookup
	 * does not access the object, but only its class.
	 *
	 * Just looking it up in the dispatch table could result in returning
650
651
652
653
654
655
656
657


658
659
660
661
662
663
664
654
655
656
657
658
659
660

661
662
663
664
665
666
667
668
669







-
+
+







		return NULL;

	dummy.isa = cls;
	return objc_msg_lookup((id)&dummy, sel);
}

IMP
class_getMethodImplementation_stret(Class cls, SEL sel)
class_getMethodImplementation_stret(Class cls OBJC_M68K_REG("a0"),
    SEL sel OBJC_M68K_REG("a1"))
{
	/*
	 * Same as above, but use objc_msg_lookup_stret instead, so that the
	 * correct forwarding handler is returned.
	 */
	struct {
		Class isa;
717
718
719
720
721
722
723
724


725
726
727
728
729
730
731
722
723
724
725
726
727
728

729
730
731
732
733
734
735
736
737







-
+
+








	cls->methodlist = ml;

	objc_update_dtable(cls);
}

const char *
class_getMethodTypeEncoding(Class cls, SEL sel)
class_getMethodTypeEncoding(Class cls OBJC_M68K_REG("a0"),
    SEL sel OBJC_M68K_REG("a1"))
{
	struct objc_method *method;

	if (cls == Nil)
		return NULL;

	objc_global_mutex_lock();
741
742
743
744
745
746
747
748


749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766


767
768
769
770
771
772
773
747
748
749
750
751
752
753

754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772

773
774
775
776
777
778
779
780
781







-
+
+

















-
+
+







	if (cls->superclass != Nil)
		return class_getMethodTypeEncoding(cls->superclass, sel);

	return NULL;
}

bool
class_addMethod(Class cls, SEL sel, IMP imp, const char *types)
class_addMethod(Class cls OBJC_M68K_REG("a0"), SEL sel OBJC_M68K_REG("a1"),
    IMP imp OBJC_M68K_REG("a2"), const char *types OBJC_M68K_REG("a3"))
{
	bool ret;

	objc_global_mutex_lock();

	if (get_method(cls, sel) == NULL) {
		add_method(cls, sel, imp, types);
		ret = true;
	} else
		ret = false;

	objc_global_mutex_unlock();

	return ret;
}

IMP
class_replaceMethod(Class cls, SEL sel, IMP newimp, const char *types)
class_replaceMethod(Class cls OBJC_M68K_REG("a0"), SEL sel OBJC_M68K_REG("a1"),
    IMP newimp OBJC_M68K_REG("a2"), const char *types OBJC_M68K_REG("a3"))
{
	struct objc_method *method;
	IMP oldimp;

	objc_global_mutex_lock();

	if ((method = get_method(cls, sel)) != NULL) {
781
782
783
784
785
786
787
788

789
790
791
792
793
794
795
796
797
798
799
800
801

802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818

819
820
821
822
823
824
825
789
790
791
792
793
794
795

796
797
798
799
800
801
802
803
804
805
806
807
808

809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825

826
827
828
829
830
831
832
833







-
+












-
+
















-
+








	objc_global_mutex_unlock();

	return oldimp;
}

Class
object_getClass(id obj_)
object_getClass(id obj_ OBJC_M68K_REG("a0"))
{
	struct objc_object *obj;

	if (obj_ == nil)
		return Nil;

	obj = (struct objc_object *)obj_;

	return obj->isa;
}

Class
object_setClass(id obj_, Class cls)
object_setClass(id obj_ OBJC_M68K_REG("a0"), Class cls OBJC_M68K_REG("a1"))
{
	struct objc_object *obj;
	Class old;

	if (obj_ == nil)
		return Nil;

	obj = (struct objc_object *)obj_;

	old = obj->isa;
	obj->isa = cls;

	return old;
}

const char *
object_getClassName(id obj)
object_getClassName(id obj OBJC_M68K_REG("a0"))
{
	return class_getName(object_getClass(obj));
}

static void
unregister_class(Class rcls)
{