Repository navigation
Conversation
…ling Fixes Signal 6 (SIGABRT via _objc_terminate) and non-ASCII path corruption when opening layout files from macOS Finder / LaunchServices without LANG: - src/tl/tl/tlString.cc: Preserve UTF-8 in to_local() and to_string_from_local() under #if defined(__APPLE__) because Darwin VFS (APFS/HFS+/FileProvider) POSIX paths are unconditionally UTF-8 even under the "C"/US-ASCII locale. - src/tl/tl/tlInternational.cc: Replace obsolete Qt4 macro Q_WS_MAC with defined(__APPLE__) || defined(Q_OS_MAC) and call setlocale(LC_CTYPE, "UTF-8") in initialize_codecs(). - src/lay/lay/layApplication.cc: Wrap QEvent::FileOpen layout loading in BEGIN_PROTECTED ... END_PROTECTED (matching MainWindow::dropEvent) and return true so tl::Exception displays KLayout's error dialog instead of unwinding across Objective-C into _objc_terminate. - macbuild/Resources/Info.plist.template: Set LSEnvironment (LANG and LC_CTYPE) to UTF-8 for macOS app bundle launches. - src/tl/unit_tests/tlStringTests.cc: Add macOS regression test in TEST(15) verifying UTF-8 CJK/accented paths survive to_local()/to_string_from_local() under setlocale(LC_ALL, "C"). Refs: KLayout#1213, KLayout#2442
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a macOS crash (
SIGABRT/ Signal 6 via_objc_terminate) and silent non-ASCII path corruption when opening layout files with non-ASCII (e.g. CJK, accented) characters in their path from macOS Finder / LaunchServices (including CloudStorage / FileProvider mounts such as Synology Drive, iCloud Drive, OneDrive).Related issues: #1213, #2442.
Root Causes
Q_WS_MACinsrc/tl/tl/tlInternational.cc:tl::initialize_codecs()checked#elif defined(Q_WS_MAC), which was removed in Qt 5. On Qt 5/Qt 6 macOS builds, execution fell through to#else(setlocale(LC_ALL, "")+nl_langinfo(CODESET)). Because macOS Finder launches.appbundles withoutLANG/LC_CTYPE, the C locale stays"C"(US-ASCII), leavingms_system_codecand C multibyte routines unable to represent UTF-8 paths.tl::to_local()/tl::to_string_from_local()under"C"locale insrc/tl/tl/tlString.cc:Under
"C"/US-ASCIILC_CTYPE,wctomb()returns-1for every non-ASCII code point (silently stripping non-ASCII characters from file paths, causingENOENT), andmbrtowc()aborts at the first byte>= 0x80(truncating paths). On macOS, Darwin VFS (APFS/HFS+/FileProvider) POSIX paths are unconditionally UTF-8 regardless ofLC_CTYPE.FileOpenboundary insrc/lay/lay/layApplication.cc:Unlike
MainWindow::dropEvent(),GuiApplication::event()did not wrap itsQEvent::FileOpenhandler (mp_mw->load_layout(...)) inBEGIN_PROTECTED ... END_PROTECTEDand did not returntrue. Anytl::Exceptionthrown while loading a file from Finder unwound into Cocoa (-[NSApplication _openURLs:...]), triggering_objc_terminateand aborting withSIGABRT(Signal 6) instead of showing KLayout's error dialog.Changes
src/tl/tl/tlString.cc: Under#if defined(__APPLE__), return UTF-8 directly intl::to_local()andtl::to_string_from_local()(preserving Darwin VFS UTF-8 paths even whenLC_CTYPEis"C", in both Qt and headlessHAVE_QT=0builds).src/tl/tl/tlInternational.cc: Replace dead#elif defined(Q_WS_MAC)with#elif defined(__APPLE__) || defined(Q_OS_MAC)and callsetlocale (LC_CTYPE, "UTF-8")soms_system_codecand C-libraryLC_CTYPEare UTF-8 while keepingLC_NUMERICat"C".src/lay/lay/layApplication.cc: Guard theQEvent::FileOpenhandler inGuiApplication::event()withBEGIN_PROTECTED ... END_PROTECTED(matchingMainWindow::dropEvent()) andreturn true;after handling.macbuild/Resources/Info.plist.template: AddLSEnvironment(LANG=en_US.UTF-8,LC_CTYPE=UTF-8) so macOS LaunchServices launches the.appbundle with a UTF-8 environment for embedded Python/Ruby and C libraries.src/tl/unit_tests/tlStringTests.cc: Add an#if defined(__APPLE__)regression test inTEST(15)verifyingtl::to_local()andtl::to_string_from_local()preserve CJK/accented UTF-8 paths undersetlocale(LC_ALL, "C").Verification
Info.plist.templatewithplutil -lintandxmllint --noout.src/tl/tl/tlString.ccandsrc/tl/tl/tlInternational.cccompile cleanly in headless (!HAVE_QT) mode withc++ -std=c++17 -Wall -Wextra -fsyntax-only.to_local/to_string_from_localUTF-8 round-trip undersetlocale(LC_ALL, "C")andsetlocale(LC_CTYPE, "UTF-8")(preservingLC_NUMERIC="C") via standalone C++17-Wall -Wextra -Werrortest on macOS arm64.env -i ... open -a klayout.app <CJK path>.gds) withLSEnvironmentUTF-8 loads cleanly with zero crash.