We were leaving the isa pointer pointing to the deleted class and were
then following its super_class pointer, both of which are potentially
serious. This didn't show up on FreeBSD, because the relevant memory
was always returned to a thread-local pool and the accesses were
immediately afterwards, so it always worked. It broke with malloc
implementations that were more aggressive about checking for
use-after-free.
Coverage checking of the test suite showed that objc_disposeClassPair
wasn't tested at all, which then led to discovering that it didn't
unregister the class.
Add a flag to indicate that instance variables have an extended type
encoding.
Remove the alignment field and replace it with 6 bits from the flags
field. We only support power of two alignments, so we may as well store
them in log form, which means we can save a field. Note that this
doesn't actually save us any space except on 32-bit platforms, because
alignment means that we end up with extra padding at the end of the
struct.
Every class is either a class or a metaclass, it doesn't make sense to
use two flags to store one bit of data.
Also remove the newabi flag from classes in the v2 ABI, where it's
redundant.
Several of the structures now end with an array of structures that may
have other fields added to them that the runtime doesn't know about yet
by a compiler. Rather than indexing into them directly, we must call an
accessor to find the correct address.
A few of the places where accesses were replaced were in functions where
it is safe because they only deal with versions of the structures that
are dynamically allocated (and will therefore have the correct size).
This was done to simplify future auditing: these fields should be
accessed directly only from the accessor functions in the header and
from the upgraders (currently in legacy.c).
Also fix a few bugs where the sizes weren't being filled in.
This change set incorporates a number of changes that all needed to
happen together:
* The imp is now the first field of the `objc_method` structure. This
makes it possible to extend the structure without breaking anything
that relies on being able to access the IMP.
* There is no owner in the slot, so we must use other mechanisms for
determining the owner of a method (e.g. whether the same method appears
in the superclass)
* Again, because there is no owner in the slot, we can't use this as a
fast path for finding the C++ construct / destruct methods. These are
now cached in the class structure when they are found.
* The version field is gone from the slot and now we provide a global
version. This is based on the observation that method replacements
are relatively infrequent and the overhead of invalidating all method
caches is cheaper than adding extra state for every (class, method)
pair.
* A number of the runtime functions are simplified because replacing
the IMP in a `Method` now implicitly updates the dtable.
In the legact ABI, superclass pointers are initially set to strings
containing the superclass name and the runtime fixes them up. In the
new ABI, the compiler sets up the linkage directly.
We're now using a new class and category structure and auto-upgrading the old ones. Other changes:
- The Ivar structure now points to the ivar offset variable, so we can more easily find it.
- Categories can now add properties.
at the start of the structure, making it easier to change the layout in
the future.
Also clean up the growth of various fields and consolidate some of the
metadata into a pointer to the `struct objc_method`.
The new structure has extra fields for alignment and flags (e.g.
ownership).
Old structures are auto-upgraded at load time, so the rest of the code
can assume the presence of the new structure type.
- Don't call C++ constructors if they don't exist.
- Don't check the owner of retain / release methods if they are not implemented.
- Add arc.m as a file to ignore when checking for GC compatibility.
Weak references are still not supported, but code that doesn't use them (i.e. any code that wants to be compatible with OS X 10.6) will work fine.
The current implementation is VERY inefficient and has a large number of missed optimisation opportunities: this is the 'make it right' phase, and should be almost equivalent to explicit retain / release code.
- __strong pointers, preventing objects from being freed
_ __weak pointers are automatically freed when the last remaining __strong pointer goes away
- objc_gc_{retain,release}_np() functions, which can be used to implement CFRetain() and CFRelease() (adds an reference count - the object will not be collected until after its last retain is gone.