From 4456467c50fcdfea3ff09f1edae2d202c447d6e5 Mon Sep 17 00:00:00 2001 From: yuanyuanxiang <962914132@qq.com> Date: Sat, 14 Nov 2026 12:19:44 +0100 Subject: [PATCH] Fix(client): build on macOS after the pthread_t cast MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The macOS client failed to compile at client/IOCPClient.cpp:788: static_cast from 'pthread_t' (aka '_opaque_pthread_t *') to 'uintptr_t' is not allowed. Darwin defines pthread_t as a pointer, while Linux and Android define it as an integer, so routing it through uintptr_t refused to build there. On POSIX the stored value is only a non-null "a worker thread exists" marker: CloseHandle and SAFE_CLOSE_HANDLE are no-ops, and nothing ever dereferences it. reinterpret_cast accepts both shapes — integer to pointer on Linux/Android, pointer to pointer on macOS — so the same line now compiles everywhere. IOCPUDPClient.cpp had the identical cast and got the same one-line change; it is not in any current build list, but it would hit the same error if it were. Verified with a green Linux client rebuild (integral pthread_t). Not yet built on a real Mac. Co-Authored-By: deepseek-flash --- client/IOCPClient.cpp | 6 +++++- client/IOCPUDPClient.cpp | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/client/IOCPClient.cpp b/client/IOCPClient.cpp index 7ed5fae..24e3e68 100644 --- a/client/IOCPClient.cpp +++ b/client/IOCPClient.cpp @@ -785,7 +785,11 @@ BOOL IOCPClient::ConnectServer(const char* szServerIP, unsigned short uPort) // the TCP stream and prevent any complete command from being delivered. // SAFE_CLOSE_HANDLE and CloseHandle are no-ops on Android, so the value // is never dereferenced as a kernel handle. - m_hWorkThread = reinterpret_cast(static_cast(id)); + // POSIX 下这个值只当「线程已存在」的非空标志用,从不反向解引用。 + // 不能用 static_cast(id):macOS 的 pthread_t 是 + // _opaque_pthread_t*(Linux/Android 是整型),指针经整型中转是非法的。 + // reinterpret_cast 对两种形态都成立(整型→指针 / 指针→指针)。 + m_hWorkThread = reinterpret_cast(id); } else { // pthread_create 直接返回错误码(不经 errno):EAGAIN(35)/EPERM(1) 基本就是 // 进程/用户的线程数到顶。这条路径原本完全静默——连接看起来「成功」了, diff --git a/client/IOCPUDPClient.cpp b/client/IOCPUDPClient.cpp index 6c65806..9d35115 100644 --- a/client/IOCPUDPClient.cpp +++ b/client/IOCPUDPClient.cpp @@ -49,7 +49,9 @@ BOOL IOCPUDPClient::ConnectServer(const char* szServerIP, unsigned short uPort) if (ret == 0) { m_bWorkThread = S_RUN; m_bIsRunning = TRUE; - m_hWorkThread = reinterpret_cast(static_cast(id)); + // 同 IOCPClient:macOS 的 pthread_t 是 _opaque_pthread_t*,不能经 + // static_cast 中转,reinterpret_cast 对整型/指针两种实现都成立。 + m_hWorkThread = reinterpret_cast(id); } #endif }