ios: XCode 16 workaround to prevent stack overflow (#5771)

* ios: Workaround for stackoverflow with Xcode 16

- Increased stack size to 4MiB
- Fix: https://github.com/simplex-chat/simplex-chat/issues/4837

* Remove Main Thread Stack Size Linker Setting

Removed the linker setting for the main thread stack size as the main thread is no longer used.

* Set Thread Stack Size to 2MiB

Set the thread stack size to 2MiB. In my environment, 992KiB worked fine, so increasing the size to more than double should provide sufficient margin.

* ios: moving content up when setting emoji on the first message (#5766)

* simplify

---------

Co-authored-by: ISHIHARA Kazuto <acevif@kubkul.in>
Co-authored-by: Avently <7953703+avently@users.noreply.github.com>
This commit is contained in:
Evgeny 2025-03-21 11:49:59 +00:00 committed by GitHub
parent 6020c6010d
commit 15742aee30
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -183,7 +183,9 @@ public func chatResponse(_ s: String) -> ChatResponse {
// let p = UnsafeMutableRawPointer.init(mutating: UnsafeRawPointer(cjson))
// let d = Data.init(bytesNoCopy: p, count: strlen(cjson), deallocator: .free)
do {
let r = try jsonDecoder.decode(APIResponse.self, from: d)
let r = try callWithLargeStack {
try jsonDecoder.decode(APIResponse.self, from: d)
}
return r.resp
} catch {
logger.error("chatResponse jsonDecoder.decode error: \(error.localizedDescription)")
@ -231,6 +233,32 @@ public func chatResponse(_ s: String) -> ChatResponse {
return ChatResponse.response(type: type ?? "invalid", json: json ?? s)
}
private let largeStackSize: Int = 2 * 1024 * 1024
private func callWithLargeStack<T>(_ f: @escaping () throws -> T) throws -> T {
let semaphore = DispatchSemaphore(value: 0)
var result: Result<T, Error>?
let thread = Thread {
do {
result = .success(try f())
} catch {
result = .failure(error)
}
semaphore.signal()
}
thread.stackSize = largeStackSize
thread.qualityOfService = Thread.current.qualityOfService
thread.start()
semaphore.wait()
switch result! {
case let .success(r): return r
case let .failure(e): throw e
}
}
private func decodeUser_(_ jDict: NSDictionary) -> UserRef? {
if let user_ = jDict["user_"] {
try? decodeObject(user_ as Any)