Skip to content

Commit

Permalink
Fix CoreGlue crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Feb 2, 2025
1 parent 4c4be4f commit c8176cf
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 10 deletions.
20 changes: 20 additions & 0 deletions Sources/OpenSwiftUI/CoreGlue/OpenSwiftUIGlue.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// OpenSwiftUIGlue.swift
// OpenSwiftUI
//
// Audited for iOS 18.0
// Status: Empty

@_spi(ForOpenSwiftUIOnly)
import OpenSwiftUICore

@_cdecl("OpenSwiftUIGlueClass")
func OpenSwiftUIGlueClass() -> CoreGlue.Type {
OpenSwiftUIGlue.self
}

final class OpenSwiftUIGlue: CoreGlue {
override func makeDefaultLayoutComputer() -> MakeDefaultLayoutComputerResult {
MakeDefaultLayoutComputerResult(value: ViewGraph.current.$defaultLayoutComputer)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

public import Foundation
package import OpenGraphShims
import OpenSwiftUI_SPI

@_spi(ForOpenSwiftUIOnly)
@objc(OpenSwiftUICoreGlue)
open class CoreGlue: NSObject {
package static var shared: CoreGlue = CoreGlue() // FIXME

package static var shared: CoreGlue = _initializeCoreGlue() as! CoreGlue

open func makeDefaultLayoutComputer() -> MakeDefaultLayoutComputerResult {
preconditionFailure("TODO")
preconditionFailure("")
}
}

Expand Down
7 changes: 3 additions & 4 deletions Sources/OpenSwiftUICore/Graph/GraphInputs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,8 @@ extension _GraphInputs {

@inline(__always)
package func detechedEnvironmentInputs() -> Self {
// var newInputs = self
// newInputs.cachedEnvironment = MutableBox(cachedEnvironment.wrappedValue)
// return newInputs
preconditionFailure("TO BE REMOVED")
var newInputs = self
newInputs.cachedEnvironment = MutableBox(cachedEnvironment.wrappedValue)
return newInputs
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ package struct _SafeAreaInsetsModifier: /* MultiViewModifier, */ PrimitiveViewMo
}

nonisolated package static func _makeView(modifier: _GraphValue<_SafeAreaInsetsModifier>, inputs: _ViewInputs, body: @escaping (_Graph, _ViewInputs) -> _ViewOutputs) -> _ViewOutputs {
preconditionFailure("TODO")
// preconditionFailure("TODO")
return body(_Graph(), inputs)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ package struct HitTestBindingModifier: ViewModifier, /*MultiViewModifier,*/ Prim
body: @escaping (_Graph, _ViewInputs) -> _ViewOutputs
) -> _ViewOutputs {
// preconditionFailure("TODO")
makeDebuggableView(modifier: modifier, inputs: inputs, body: body)
return body(_Graph(), inputs)
}

package typealias Body = Never
Expand Down
15 changes: 15 additions & 0 deletions Sources/OpenSwiftUI_SPI/Util/CoreGlue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// CoreGlue.h
// OpenSwiftUI_SPI
//
// Audited for iOS 15.5
// Status: Complete

#ifndef CoreGlue_h
#define CoreGlue_h

#include "OpenSwiftUIBase.h"

id _initializeCoreGlue();

#endif /* CoreGlue_h */
42 changes: 42 additions & 0 deletions Sources/OpenSwiftUI_SPI/Util/CoreGlue.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// CoreGlue.m
// OpenSwiftUI_SPI
//
// Audited for iOS 18.0
// Status: Complete

#include "CoreGlue.h"
#include <dlfcn.h>

void abort_report_np(const char*, ...);

void* OpenSwiftUILibrary();
void * getSwiftUIGlueClassSymbolLoc();

id _initializeCoreGlue() {
void *location = getSwiftUIGlueClassSymbolLoc();
Class (*classFunc)(void) = (Class (*)(void))location;
Class glueClass = classFunc();
return [[glueClass alloc] init];
}

void* OpenSwiftUILibrary() {
// Since we are staticlly linking OpenSwiftUI and OpenSwiftUICore into the final binary,
// we can just use dlopen(NULL, RTLD_LAZY) to get the current macho binary handle
return dlopen(NULL, RTLD_LAZY);
}

void *getSwiftUIGlueClassSymbolLoc() {
static void *ptr;
if (ptr == NULL) {
@try {
ptr = dlsym(OpenSwiftUILibrary(), "OpenSwiftUIGlueClass");
} @finally {
}
}
if (ptr == NULL) {
const char *error = dlerror();
abort_report_np("%s", error);
}
return ptr;
}
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI_SPI/Util/LockedPointer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// LockedPointer.h
// OpenSwiftUI
// OpenSwiftUI_SPI
//
// Audited for iOS 15.5
// Status: Complete
Expand Down

0 comments on commit c8176cf

Please sign in to comment.