-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't rely on load order for built-in classes.
Generate these classes using the structures that the runtime expects internally, rather than relying on the Objective-C compiler. This change means that they can always be the latest version, even if the runtime is compiled with an older compiler, and ensures that the `Protocol` class is always available, independent of global constructor ordering between libraries. Fixes #283
- Loading branch information
1 parent
feaf007
commit a9d0313
Showing
13 changed files
with
212 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#include "protocol.h" | ||
#include "class.h" | ||
#include "method.h" | ||
#include "loader.h" | ||
|
||
OBJC_PUBLIC struct objc_class _OBJC_CLASS_Object; | ||
|
||
static struct objc_class _OBJC_METACLASS_Object = { | ||
.isa = NULL, | ||
.name = "Object", | ||
.info = objc_class_flag_meta, | ||
}; | ||
OBJC_PUBLIC struct objc_class _OBJC_CLASS_Object = { | ||
.isa = &_OBJC_METACLASS_Object, | ||
.super_class = NULL, | ||
.name = "Object", | ||
}; | ||
|
||
static struct objc_class _OBJC_METACLASS_Protocol = { | ||
.isa = &_OBJC_METACLASS_Object, | ||
.super_class = &_OBJC_METACLASS_Object, | ||
.name = "Protocol", | ||
.info = objc_class_flag_meta, | ||
}; | ||
static struct objc_class _OBJC_METACLASS_ProtocolGCC = { | ||
.isa = &_OBJC_METACLASS_Object, | ||
.super_class = &_OBJC_METACLASS_Object, | ||
.name = "ProtocolGCC", | ||
.info = objc_class_flag_meta, | ||
}; | ||
static struct objc_class _OBJC_METACLASS_ProtocolGSv1 = { | ||
.isa = &_OBJC_METACLASS_Object, | ||
.super_class = &_OBJC_METACLASS_Object, | ||
.name = "ProtocolGSv2", | ||
.info = objc_class_flag_meta, | ||
}; | ||
static struct objc_class _OBJC_METACLASS___IncompleteProtocol = { | ||
.isa = &_OBJC_METACLASS_Object, | ||
.super_class = &_OBJC_METACLASS_Object, | ||
.name = "ProtocolGCC", | ||
.info = objc_class_flag_meta, | ||
}; | ||
|
||
OBJC_PUBLIC struct objc_class _OBJC_CLASS_Protocol = { | ||
.isa = &_OBJC_METACLASS_Protocol, | ||
.super_class = &_OBJC_CLASS_Object, | ||
.name = "Protocol", | ||
.info = objc_class_flag_permanent_instances, | ||
}; | ||
|
||
OBJC_PUBLIC struct objc_class _OBJC_CLASS_ProtocolGCC = { | ||
.isa = &_OBJC_METACLASS_ProtocolGCC, | ||
.super_class = &_OBJC_CLASS_Protocol, | ||
.name = "ProtocolGCC", | ||
.info = objc_class_flag_permanent_instances, | ||
}; | ||
|
||
OBJC_PUBLIC struct objc_class _OBJC_CLASS___IncompleteProtocol = { | ||
.isa = &_OBJC_METACLASS_Protocol, | ||
.super_class = &_OBJC_CLASS_Protocol, | ||
.name = "__IncompleteProtocol", | ||
.info = objc_class_flag_permanent_instances, | ||
}; | ||
|
||
OBJC_PUBLIC struct objc_class _OBJC_CLASS_ProtocolGSv1 = { | ||
.isa = &_OBJC_METACLASS_Protocol, | ||
.super_class = &_OBJC_CLASS_Protocol, | ||
.name = "ProtocolGSv1", | ||
.info = objc_class_flag_permanent_instances, | ||
}; | ||
|
||
#ifdef OLDABI_COMPAT | ||
static struct objc_class _OBJC_METACLASS___ObjC_Protocol_Holder_Ugly_Hack = { | ||
.isa = NULL, | ||
.name = "__ObjC_Protocol_Holder_Ugly_Hack", | ||
.info = objc_class_flag_meta, | ||
}; | ||
OBJC_PUBLIC struct objc_class _OBJC_CLASS__ObjC_Protocol_Holder_Ugly_Hack = { | ||
.isa = &_OBJC_METACLASS___ObjC_Protocol_Holder_Ugly_Hack, | ||
.super_class = NULL, | ||
.name = "__ObjC_Protocol_Holder_Ugly_Hack", | ||
}; | ||
#endif | ||
|
||
PRIVATE void init_builtin_classes(void) | ||
{ | ||
// Load the classes that are compiled into the runtime. | ||
objc_load_class(&_OBJC_CLASS_Object); | ||
objc_load_class(&_OBJC_CLASS_Protocol); | ||
objc_load_class(&_OBJC_CLASS_ProtocolGCC); | ||
objc_load_class(&_OBJC_CLASS_ProtocolGSv1); | ||
objc_load_class(&_OBJC_CLASS___IncompleteProtocol); | ||
objc_resolve_class(&_OBJC_CLASS_Object); | ||
objc_resolve_class(&_OBJC_CLASS_Protocol); | ||
objc_resolve_class(&_OBJC_CLASS_ProtocolGCC); | ||
objc_resolve_class(&_OBJC_CLASS_ProtocolGSv1); | ||
objc_resolve_class(&_OBJC_CLASS___IncompleteProtocol); | ||
// Fix up the sizes of the various protocol classes that we will use. | ||
_OBJC_CLASS_Object.instance_size = sizeof(void*); | ||
_OBJC_CLASS_Protocol.instance_size = sizeof(struct objc_protocol); | ||
_OBJC_CLASS___IncompleteProtocol.instance_size = sizeof(struct objc_protocol); | ||
#ifdef OLDABI_COMPAT | ||
objc_load_class(&_OBJC_CLASS__ObjC_Protocol_Holder_Ugly_Hack); | ||
objc_resolve_class(&_OBJC_CLASS__ObjC_Protocol_Holder_Ugly_Hack); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#pragma once | ||
#include <assert.h> | ||
|
||
/** | ||
|
Oops, something went wrong.