Differences From Artifact [7f71e00414]:
- File src/OFObject.m — part of check-in [df914ca51d] at 2011-07-31 20:03:26 on branch trunk — Correctly update the dtable for the old GNU runtime. (user: js, size: 26946) [annotate] [blame] [check-ins using]
To Artifact [b74fa282bf]:
- File
src/OFObject.m
— part of check-in
[7b5b0c8174]
at
2011-08-01 19:01:21
on branch trunk
— Don't use any other classes for +[inheritMethodsFromClass:].
Using other classes there would make it impossible to use
+[inheritMethodsFromClass:] in the classes being used, which would be
unfortunate as the classes that were used are potential candidates for
collection classes. (user: js, size: 28590) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
23 24 25 26 27 28 29 | #include <string.h> #include <unistd.h> #include <assert.h> #import "OFObject.h" | < < < | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #include <string.h> #include <unistd.h> #include <assert.h> #import "OFObject.h" #import "OFAutoreleasePool.h" #import "OFAllocFailedException.h" #import "OFEnumerationMutationException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFMemoryNotPartOfObjectException.h" |
︙ | ︙ | |||
583 584 585 586 587 588 589 | @throw [OFNotImplementedException newWithClass: self selector: _cmd]; #endif } + (void)inheritMethodsFromClass: (Class)class { | < | < < < < | < < | < | < < < < | < < | < < < < < < < < | | | > > > | > | < | | | | | > > | | | | | > | < | > > > | | | > > > > | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | | > > | | | | | > | > > > | 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 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 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 | @throw [OFNotImplementedException newWithClass: self selector: _cmd]; #endif } + (void)inheritMethodsFromClass: (Class)class { Class superclass = [self superclass]; if ([self isSubclassOfClass: class]) return; #if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME) Method *methodList; unsigned i, count; methodList = class_copyMethodList(((OFObject*)class)->isa, &count); @try { for (i = 0; i < count; i++) { SEL selector = method_getName(methodList[i]); IMP implementation; /* * Don't replace methods implemented in receiving class. */ if ([self methodForSelector: selector] != [superclass methodForSelector: selector]) continue; implementation = [class methodForSelector: selector]; if ([self respondsToSelector: selector]) [self setImplementation: implementation forClassMethod: selector]; else { const char *typeEncoding = method_getTypeEncoding(methodList[i]); [self addClassMethod: selector withTypeEncoding: typeEncoding implementation: implementation]; } } } @finally { free(methodList); } methodList = class_copyMethodList(class, &count); @try { for (i = 0; i < count; i++) { SEL selector = method_getName(methodList[i]); IMP implementation; /* * Don't replace methods implemented in receiving class. */ if ([self instanceMethodForSelector: selector] != [superclass instanceMethodForSelector: selector]) continue; implementation = [class instanceMethodForSelector: selector]; if ([self instancesRespondToSelector: selector]) [self setImplementation: implementation forInstanceMethod: selector]; else { const char *typeEncoding = method_getTypeEncoding(methodList[i]); [self addInstanceMethod: selector withTypeEncoding: typeEncoding implementation: implementation]; } } } @finally { free(methodList); } #elif defined(OF_OLD_GNU_RUNTIME) MethodList_t methodList; for (methodList = class->class_pointer->methods; methodList != NULL; methodList = methodList->method_next) { int i; for (i = 0; i < methodList->method_count; i++) { SEL selector = methodList->method_list[i].method_name; IMP implementation; /* * Don't replace methods implemented in receiving class. */ if ([self instanceMethodForSelector: selector] != [superclass instanceMethodForSelector: selector]) continue; implementation = [class instanceMethodForSelector: selector]; if ([self instancesRespondToSelector: selector]) [self setImplementation: implementation forClassMethod: selector]; else { const char *typeEncoding = methodList->method_list[i].method_types; [self addClassMethod: selector withTypeEncoding: typeEncoding implementation: implementation]; } } } for (methodList = class->methods; methodList != NULL; methodList = methodList->method_next) { int i; for (i = 0; i < methodList->method_count; i++) { SEL selector = methodList->method_list[i].method_name; IMP implementation; /* * Don't replace methods implemented in receiving class. */ if ([self instanceMethodForSelector: selector] != [superclass instanceMethodForSelector: selector]) continue; implementation = [class instanceMethodForSelector: selector]; if ([self instancesRespondToSelector: selector]) [self setImplementation: implementation forInstanceMethod: selector]; else { const char *typeEncoding = methodList->method_list[i].method_types; [self addInstanceMethod: selector withTypeEncoding: typeEncoding implementation: implementation]; } } } #else @throw [OFNotImplementedException newWithClass: self selector: _cmd]; #endif [self inheritMethodsFromClass: [class superclass]]; } - init { return self; |
︙ | ︙ |