Skip to content

Commit b745f6a

Browse files
linesightclaude
andcommitted
build(cython): drop platform_cimports.pxi workaround; keep IF/DEF usage consistent
Revert the fork-only partial IF/DEF conversions the CEF 147 modernization introduced, per reviewer request (r3512025176): keep the codebase uniform on IF; a complete IF/DEF migration is out of scope for this PR. - Delete the fork-only src/platform_cimports.pxi and src/extern/cef/platform_cimports.pxi (both absent from upstream cefpython147). Restore upstream's inline per-file `IF UNAME_SYSNAME` platform cimports in cefpython.pyx and cef_app/cef_browser/cef_browser_static/cef_platform.pxd, plus the CEF 147 `cimport sandbox_linux`. - utils.pyx: revert GetSystemError() to its original `IF UNAME_SYSNAME` form, dropping the inline `cdef extern from *` C block. - browser.pyx: restore `IF UNAME_SYSNAME == "Linux": cimport x11`. - window_utils_win.pyx: restore the IsWindowHandle IF/ELSE guard. Verified on Windows: clean build + 85/85 unit tests. Cython front-end also transpiles clean for Linux and Darwin (forced via -E UNAME_SYSNAME); C++ compile/link on those platforms is left to CI. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent f37d7f7 commit b745f6a

10 files changed

Lines changed: 54 additions & 38 deletions

src/browser.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ cimport cef_types
88
from libc.stdint cimport uint32_t, int64_t
99
from libcpp cimport nullptr
1010
from cef_types cimport cef_state_t
11+
IF UNAME_SYSNAME == "Linux":
12+
cimport x11
1113

1214
# cef_mouse_button_type_t, SendMouseClickEvent().
1315
MOUSEBUTTON_LEFT = cef_types.MBT_LEFT

src/cefpython.pyx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,21 @@ ctypedef uintptr_t WindowHandle
212212
# noinspection PyUnresolvedReferences
213213
cimport ctime
214214

215-
include "platform_cimports.pxi"
215+
IF UNAME_SYSNAME == "Windows":
216+
from windows cimport *
217+
from dpi_aware_win cimport *
218+
ELIF UNAME_SYSNAME == "Linux":
219+
from linux cimport *
220+
ELIF UNAME_SYSNAME == "Darwin":
221+
from mac cimport *
216222

217223
from cpp_utils cimport *
218224
from task cimport *
219225

226+
IF UNAME_SYSNAME == "Linux":
227+
cimport x11
228+
cimport sandbox_linux
229+
220230
from cef_string cimport *
221231
cdef extern from *:
222232
# noinspection PyUnresolvedReferences

src/extern/cef/cef_app.pxd

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@
55
# Circular imports are allowed in form "cimport ...",
66
# but won't work if you do "from ... cimport *".
77

8-
include "platform_cimports.pxi"
8+
include "compile_time_constants.pxi"
99

1010
from cef_types cimport CefSettings
1111
from cef_ptr cimport CefRefPtr
1212
from libcpp cimport bool as cpp_bool
1313

14+
IF UNAME_SYSNAME == "Windows":
15+
from cef_win cimport CefMainArgs
16+
ELIF UNAME_SYSNAME == "Linux":
17+
from cef_linux cimport CefMainArgs
18+
ELIF UNAME_SYSNAME == "Darwin":
19+
from cef_mac cimport CefMainArgs
20+
1421
cdef extern from "include/cef_app.h":
1522

1623
cdef cppclass CefApp:

src/extern/cef/cef_browser.pxd

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
# All rights reserved. Licensed under BSD 3-clause license.
33
# Project website: https://github.com/cztomczak/cefpython
44

5-
include "platform_cimports.pxi"
5+
include "compile_time_constants.pxi"
6+
7+
IF UNAME_SYSNAME == "Windows":
8+
from cef_win cimport CefWindowHandle, CefWindowInfo
9+
ELIF UNAME_SYSNAME == "Linux":
10+
from cef_linux cimport CefWindowHandle, CefWindowInfo
11+
ELIF UNAME_SYSNAME == "Darwin":
12+
from cef_mac cimport CefWindowHandle, CefWindowInfo
613

714
from cef_ptr cimport CefRefPtr
815
from cef_string cimport CefString

src/extern/cef/cef_browser_static.pxd

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
# All rights reserved. Licensed under BSD 3-clause license.
33
# Project website: https://github.com/cztomczak/cefpython
44

5-
include "platform_cimports.pxi"
5+
include "compile_time_constants.pxi"
6+
7+
IF UNAME_SYSNAME == "Windows":
8+
from cef_win cimport CefWindowInfo
9+
ELIF UNAME_SYSNAME == "Linux":
10+
from cef_linux cimport CefWindowInfo
11+
ELIF UNAME_SYSNAME == "Darwin":
12+
from cef_mac cimport CefWindowInfo
613

714
from libcpp cimport bool as cpp_bool
815
from cef_ptr cimport CefRefPtr

src/extern/cef/cef_platform.pxd

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,11 @@
22
# All rights reserved. Licensed under BSD 3-clause license.
33
# Project website: https://github.com/cztomczak/cefpython
44

5-
include "platform_cimports.pxi"
5+
include "compile_time_constants.pxi"
6+
7+
IF UNAME_SYSNAME == "Windows":
8+
from cef_win cimport *
9+
ELIF UNAME_SYSNAME == "Darwin":
10+
from cef_mac cimport *
11+
ELIF UNAME_SYSNAME == "Linux":
12+
from cef_linux cimport *

src/extern/cef/platform_cimports.pxi

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/platform_cimports.pxi

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/utils.pyx

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,12 @@ cdef void NonCriticalError(object msg) except *:
6363
msg = "[Browser process] " + msg
6464
cef_log_error(PyStringToChar(msg))
6565

66-
cdef extern from *:
67-
"""
68-
#ifdef _WIN32
69-
#include <windows.h>
70-
static int _cefpy_get_win32_last_error(void) { return (int)GetLastError(); }
71-
static int _cefpy_is_windows(void) { return 1; }
72-
#else
73-
static int _cefpy_get_win32_last_error(void) { return 0; }
74-
static int _cefpy_is_windows(void) { return 0; }
75-
#endif
76-
"""
77-
cdef int _cefpy_get_win32_last_error() noexcept nogil
78-
cdef int _cefpy_is_windows() noexcept nogil
79-
8066
cpdef str GetSystemError():
81-
if _cefpy_is_windows():
82-
return "Error Code = %d" % _cefpy_get_win32_last_error()
83-
return ""
67+
IF UNAME_SYSNAME == "Windows":
68+
cdef DWORD errorCode = GetLastError()
69+
return "Error Code = %d" % errorCode
70+
ELSE:
71+
return ""
8472

8573
cpdef py_bool IsFunctionOrMethod(object valueType):
8674
if (valueType == types.FunctionType

src/window_utils_win.pyx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ class WindowUtils(object):
143143

144144
@classmethod
145145
def IsWindowHandle(cls, WindowHandle windowHandle):
146-
return bool(IsWindow(<HWND>windowHandle))
146+
IF UNAME_SYSNAME == "Windows":
147+
return bool(IsWindow(<HWND>windowHandle))
148+
ELSE:
149+
return False
147150

148151
@classmethod
149152
def InstallX11ErrorHandlers(cls):

0 commit comments

Comments
 (0)