Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions arc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <stdlib.h>
#include <assert.h>
#include <atomic>
#include <type_traits>
#include <vector>
#include <tsl/robin_map.h>
#import "lock.h"
Expand Down Expand Up @@ -250,9 +251,11 @@ static TLS_CALLBACK(cleanupPools)(struct arc_tls* tls)


static Class AutoreleasePool;
static IMP NewAutoreleasePool;
static IMP DeleteAutoreleasePool;
static IMP AutoreleaseAdd;
template<typename Return, typename... Arguments>
using Selector = Return (*)(id, SEL, Arguments...);
static Selector<id> NewAutoreleasePool;
static Selector<void> DeleteAutoreleasePool;
static Selector<void, id> AutoreleaseAdd;

static BOOL useARCAutoreleasePool;

Expand Down Expand Up @@ -566,12 +569,14 @@ static inline void initAutorelease(void)
if (!useARCAutoreleasePool)
{
[AutoreleasePool class];
NewAutoreleasePool = class_getMethodImplementation(object_getClass(AutoreleasePool),
SELECTOR(new));
DeleteAutoreleasePool = class_getMethodImplementation(AutoreleasePool,
SELECTOR(release));
AutoreleaseAdd = class_getMethodImplementation(object_getClass(AutoreleasePool),
SELECTOR(addObject:));
auto storeSelector = [](auto &target, Class cls, SEL selector)
{
target = reinterpret_cast<std::remove_reference_t<decltype(target)>>(
class_getMethodImplementation(cls, selector));
};
storeSelector(NewAutoreleasePool, object_getClass(AutoreleasePool), SELECTOR(new));
storeSelector(DeleteAutoreleasePool, AutoreleasePool, SELECTOR(release));
storeSelector(AutoreleaseAdd, object_getClass(AutoreleasePool), SELECTOR(addObject:));
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions class.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include "sarray2.h"
#include <stdint.h>

typedef id (*CXXConstructIMP)(id, SEL);
typedef void (*CXXDestructIMP)(id, SEL);

#ifdef __cplusplus
extern "C"
{
Expand Down Expand Up @@ -107,12 +110,12 @@ struct objc_class
* Pointer to the .cxx_construct method if one exists. This method needs
* to be called outside of the normal dispatch mechanism.
*/
IMP cxx_construct;
CXXConstructIMP cxx_construct;
/**
* Pointer to the .cxx_destruct method if one exists. This method needs to
* be called outside of the normal dispatch mechanism.
*/
IMP cxx_destruct;
CXXDestructIMP cxx_destruct;
/**
* A pointer to the next sibling class to this. You may find all
* subclasses of a given class by following the subclass_list pointer and
Expand Down
9 changes: 5 additions & 4 deletions dtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,11 @@ static BOOL installMethodInDtable(Class class,
}
if (selEqualUnTyped(method->selector, cxx_construct))
{
class->cxx_construct = method->imp;
class->cxx_construct = (CXXConstructIMP)method->imp;
}
else if (selEqualUnTyped(method->selector, cxx_destruct))
{
class->cxx_destruct = method->imp;
class->cxx_destruct = (CXXDestructIMP)method->imp;
}

for (struct objc_class *subclass=class->subclass_list ;
Expand Down Expand Up @@ -673,6 +673,7 @@ LEGACY void update_dispatch_table_for_class(Class cls)
}

BOOL objc_resolve_class(Class);
typedef void (*InitializeIMP)(id, SEL);

__attribute__((unused)) static void objc_release_object_lock(id *x)
{
Expand Down Expand Up @@ -851,6 +852,6 @@ OBJC_PUBLIC void objc_send_initialize(id object)
// Store the buffer in the temporary dtables list. Note that it is safe to
// insert it into a global list, even though it's a temporary variable,
// because we will clean it up after this function.
initializeSlot->imp((id)class, initializeSel);
InitializeIMP initialize = (InitializeIMP)initializeSlot->imp;
initialize((id)class, initializeSel);
}

1 change: 0 additions & 1 deletion runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,4 +846,3 @@ void objc_registerClassPair(Class cls)
class_table_insert(cls);
objc_resolve_class(cls);
}