mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-11 20:16:02 +00:00
AK: Support storing blocks in AK::Function
This has two slightly different implementations for ARC and non-ARC compiler modes. The main idea is to store a block pointer as our closure and use either ARC magic or BlockRuntime methods to manage the memory for the block. Things are complicated by the fact that we don't yet force-enable swift, so we can't count on the swift.org llvm fork being our compiler toolchain. The patch adds some CMake checks and ifdefs to still support environments without support for blocks or ARC.
This commit is contained in:
parent
72acb1111f
commit
01ac48b36f
Notes:
github-actions[bot]
2025-03-18 23:16:13 +00:00
Author: https://github.com/ADKaster
Commit: 01ac48b36f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3963
Reviewed-by: https://github.com/alimpfard
Reviewed-by: https://github.com/bugaevc
5 changed files with 287 additions and 11 deletions
|
@ -45,3 +45,22 @@ serenity_option(ENABLE_STD_STACKTRACE OFF CACHE BOOL "Force use of std::stacktra
|
|||
if (ENABLE_SWIFT)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/Swift/swift-settings.cmake)
|
||||
endif()
|
||||
|
||||
include(CheckCXXSourceCompiles)
|
||||
set(BLOCKS_REQUIRED_LIBRARIES "")
|
||||
if (NOT APPLE)
|
||||
find_package(BlocksRuntime)
|
||||
if (BlocksRuntime_FOUND)
|
||||
set(BLOCKS_REQUIRED_LIBRARIES BlocksRuntime::BlocksRuntime)
|
||||
set(CMAKE_REQUIRED_LIBRARIES BlocksRuntime::BlocksRuntime)
|
||||
endif()
|
||||
endif()
|
||||
check_cxx_source_compiles([=[
|
||||
int main() { __block int x = 0; auto b = ^{++x;}; b(); }
|
||||
]=] CXX_COMPILER_SUPPORTS_BLOCKS)
|
||||
|
||||
set(CMAKE_REQUIRED_FLAGS "-fobjc-arc")
|
||||
check_cxx_source_compiles([=[
|
||||
int main() { auto b = ^{}; auto __weak w = b; w(); }
|
||||
]=] CXX_COMPILER_SUPPORTS_OBJC_ARC)
|
||||
unset(CMAKE_REQUIRED_FLAGS)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue