Skip to content

Commit 140859a

Browse files
linesightclaude
andcommitted
Fix macOS ARM64 compilation errors in macOS message loop and CMake
main_message_loop_external_pump_mac.mm: update from old Chromium idioms to modern C++/CEF 146 API: - Replace OVERRIDE macro with C++11 override keyword - Replace int64 with int64_t to match base class signatures (prevents vtable mismatch / override not recognized by compiler) - Replace scoped_ptr<>/new with std::unique_ptr/std::make_unique in Create() (scoped_ptr is no longer defined in CEF 146) - Fix NSNumber truncation: numberWithInt(int64_t) -> numberWithLongLong and integerValue -> longLongValue to preserve full 64-bit range - Add #if !__has_feature(objc_arc) guards around retain/release calls for ARC compatibility; nil out pointers in destructor CMakeLists.txt / src/subprocess/CMakeLists.txt: use -mmacosx-version-min=11.0 on arm64 (Apple Silicon requires macOS 11+; using 10.9 with -arch arm64 is rejected by the Apple linker) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 372af5f commit 140859a

3 files changed

Lines changed: 52 additions & 29 deletions

File tree

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,13 @@ elseif(APPLE)
218218
BROWSER_PROCESS
219219
CEFPYTHON_API_H_FILE="cefpython_api_fixed.h"
220220
)
221+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
222+
set(_macos_ver_min 11.0)
223+
else()
224+
set(_macos_ver_min 10.9)
225+
endif()
221226
target_link_options(${MODULE_NAME} PRIVATE
222-
-mmacosx-version-min=10.9
227+
-mmacosx-version-min=${_macos_ver_min}
223228
-Wl,-search_paths_first -Wl,-dead_strip
224229
"-F${CEF_ROOT}/bin" "-framework" "Chromium Embedded Framework"
225230
"-Wl,-rpath,@loader_path/"

src/subprocess/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,16 @@ if(WIN32)
135135
/MANIFEST:NO /LARGEADDRESSAWARE /SUBSYSTEM:WINDOWS
136136
)
137137
elseif(APPLE)
138+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
139+
set(_macos_ver_min 11.0)
140+
else()
141+
set(_macos_ver_min 10.9)
142+
endif()
138143
target_compile_options(cefpython_subprocess PRIVATE -DNDEBUG -O3)
139144
target_compile_definitions(cefpython_subprocess PRIVATE
140145
CEFPYTHON_API_H_FILE="cefpython_api_fixed.h")
141146
target_link_options(cefpython_subprocess PRIVATE
142-
-mmacosx-version-min=10.9
147+
-mmacosx-version-min=${_macos_ver_min}
143148
"-F${CEFPYTHON_CEF_ROOT}/bin"
144149
"-framework" "Chromium Embedded Framework"
145150
)

src/subprocess/main_message_loop/main_message_loop_external_pump_mac.mm

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
#include "main_message_loop_external_pump.h"
66

7-
#import <Foundation/Foundation.h>
87
#import <AppKit/AppKit.h>
8+
#import <Foundation/Foundation.h>
9+
10+
#include <memory>
911

1012
#include "include/cef_app.h"
1113

@@ -17,22 +19,22 @@
1719
~MainMessageLoopExternalPumpMac();
1820

1921
// MainMessageLoopStd methods:
20-
void Quit() OVERRIDE;
21-
int Run() OVERRIDE;
22+
void Quit() override;
23+
int Run() override;
2224

2325
// MainMessageLoopExternalPump methods:
24-
void OnScheduleMessagePumpWork(int64 delay_ms) OVERRIDE;
26+
void OnScheduleMessagePumpWork(int64_t delay_ms) override;
2527

2628
// Internal methods used for processing the event callbacks. They are public
2729
// for simplicity but should not be used directly.
28-
void HandleScheduleWork(int64 delay_ms);
30+
void HandleScheduleWork(int64_t delay_ms);
2931
void HandleTimerTimeout();
3032

3133
protected:
3234
// MainMessageLoopExternalPump methods:
33-
void SetTimer(int64 delay_ms) OVERRIDE;
34-
void KillTimer() OVERRIDE;
35-
bool IsTimerPending() OVERRIDE { return timer_ != nil; }
35+
void SetTimer(int64_t delay_ms) override;
36+
void KillTimer() override;
37+
bool IsTimerPending() override { return timer_ != nil; }
3638

3739
private:
3840
// Owner thread that will run events.
@@ -66,7 +68,7 @@ - (id)initWithPump:(MainMessageLoopExternalPumpMac*)pump {
6668
}
6769

6870
- (void)scheduleWork:(NSNumber*)delay_ms {
69-
pump_->HandleScheduleWork([delay_ms integerValue]);
71+
pump_->HandleScheduleWork([delay_ms longLongValue]);
7072
}
7173

7274
- (void)timerTimeout:(id)obj {
@@ -76,15 +78,21 @@ - (void)timerTimeout:(id)obj {
7678
@end
7779

7880
MainMessageLoopExternalPumpMac::MainMessageLoopExternalPumpMac()
79-
: owner_thread_([[NSThread currentThread] retain]),
80-
timer_(nil) {
81-
event_handler_ = [[[EventHandler alloc] initWithPump:this] retain];
81+
: owner_thread_([NSThread currentThread]), timer_(nil) {
82+
#if !__has_feature(objc_arc)
83+
[owner_thread_ retain];
84+
#endif
85+
event_handler_ = [[EventHandler alloc] initWithPump:this];
8286
}
8387

8488
MainMessageLoopExternalPumpMac::~MainMessageLoopExternalPumpMac() {
8589
KillTimer();
90+
#if !__has_feature(objc_arc)
8691
[owner_thread_ release];
8792
[event_handler_ release];
93+
#endif
94+
owner_thread_ = nil;
95+
event_handler_ = nil;
8896
}
8997

9098
void MainMessageLoopExternalPumpMac::Quit() {
@@ -106,59 +114,64 @@ - (void)timerTimeout:(id)obj {
106114

107115
// Do some work.
108116
CefDoMessageLoopWork();
109-
117+
110118
// Sleep to allow the CEF proc to do work.
111119
[NSThread sleepForTimeInterval: 0.05];
112120
}
113121

114122
return 0;
115123
}
116124

117-
void MainMessageLoopExternalPumpMac::OnScheduleMessagePumpWork(int64 delay_ms) {
125+
void MainMessageLoopExternalPumpMac::OnScheduleMessagePumpWork(
126+
int64_t delay_ms) {
118127
// This method may be called on any thread.
119-
NSNumber* number = [NSNumber numberWithInt:static_cast<int>(delay_ms)];
128+
NSNumber* number = [NSNumber numberWithLongLong:delay_ms];
120129
[event_handler_ performSelector:@selector(scheduleWork:)
121130
onThread:owner_thread_
122131
withObject:number
123132
waitUntilDone:NO];
124133
}
125134

126-
void MainMessageLoopExternalPumpMac::HandleScheduleWork(int64 delay_ms) {
135+
void MainMessageLoopExternalPumpMac::HandleScheduleWork(int64_t delay_ms) {
127136
OnScheduleWork(delay_ms);
128137
}
129138

130139
void MainMessageLoopExternalPumpMac::HandleTimerTimeout() {
131140
OnTimerTimeout();
132141
}
133142

134-
void MainMessageLoopExternalPumpMac::SetTimer(int64 delay_ms) {
143+
void MainMessageLoopExternalPumpMac::SetTimer(int64_t delay_ms) {
135144
DCHECK_GT(delay_ms, 0);
136145
DCHECK(!timer_);
137146

138147
const double delay_s = static_cast<double>(delay_ms) / 1000.0;
139-
timer_ = [[NSTimer timerWithTimeInterval: delay_s
140-
target: event_handler_
141-
selector: @selector(timerTimeout:)
142-
userInfo: nil
143-
repeats: NO] retain];
148+
timer_ = [NSTimer timerWithTimeInterval:delay_s
149+
target:event_handler_
150+
selector:@selector(timerTimeout:)
151+
userInfo:nil
152+
repeats:NO];
153+
#if !__has_feature(objc_arc)
154+
[timer_ retain];
155+
#endif
144156

145157
// Add the timer to default and tracking runloop modes.
146158
NSRunLoop* owner_runloop = [NSRunLoop currentRunLoop];
147-
[owner_runloop addTimer: timer_ forMode: NSRunLoopCommonModes];
148-
[owner_runloop addTimer: timer_ forMode: NSEventTrackingRunLoopMode];
159+
[owner_runloop addTimer:timer_ forMode:NSRunLoopCommonModes];
160+
[owner_runloop addTimer:timer_ forMode:NSEventTrackingRunLoopMode];
149161
}
150162

151163
void MainMessageLoopExternalPumpMac::KillTimer() {
152164
if (timer_ != nil) {
153165
[timer_ invalidate];
166+
#if !__has_feature(objc_arc)
154167
[timer_ release];
168+
#endif
155169
timer_ = nil;
156170
}
157171
}
158172

159173
// static
160-
scoped_ptr<MainMessageLoopExternalPump>
174+
std::unique_ptr<MainMessageLoopExternalPump>
161175
MainMessageLoopExternalPump::Create() {
162-
return scoped_ptr<MainMessageLoopExternalPump>(
163-
new MainMessageLoopExternalPumpMac());
176+
return std::make_unique<MainMessageLoopExternalPumpMac>();
164177
}

0 commit comments

Comments
 (0)