Skip to content

FoundationEssentials,FoundationInternationalization: adjust for aliasing #1340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ let availabilityMacros: [SwiftSetting] = versionNumbers.flatMap { version in

let featureSettings: [SwiftSetting] = [
.enableExperimentalFeature("StrictConcurrency"),
.enableExperimentalFeature("ImportMacroAliases"),
.enableUpcomingFeature("InferSendableFromCaptures"),
.enableUpcomingFeature("MemberImportVisibility")
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ import Darwin
#elseif canImport(Android)
@preconcurrency import Android
import posix_filesystem.dirent
internal import _FoundationCShims
#elseif canImport(Glibc)
@preconcurrency import Glibc
internal import _FoundationCShims
Expand Down
1 change: 1 addition & 0 deletions Sources/FoundationInternationalization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ add_subdirectory(TimeZone)

target_compile_options(FoundationInternationalization PRIVATE
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend AccessLevelOnImport>"
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend ImportMacroAliases>"
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend StrictConcurrency>"
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-upcoming-feature -Xfrontend InferSendableFromCaptures>"
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-upcoming-feature -Xfrontend MemberImportVisibility>")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ internal class ICUNumberFormatterBase : @unchecked Sendable {
// MARK: -

class FormatResult {
var result: OpaquePointer
var result: OpaquePointer?

init(formatter: OpaquePointer, value: Int64) throws {
var status = U_ZERO_ERROR
Expand Down Expand Up @@ -188,7 +188,9 @@ internal class ICUNumberFormatterBase : @unchecked Sendable {
var str = value.description
#endif // FOUNDATION_FRAMEWORK
str.withUTF8 {
unumf_formatDecimal(formatter, $0.baseAddress, Int32($0.count), result, &status)
$0.withMemoryRebound(to: CChar.self) {
unumf_formatDecimal(formatter, $0.baseAddress, Int32($0.count), result, &status)
}
}
try status.checkSuccess()
}
Expand All @@ -200,7 +202,9 @@ internal class ICUNumberFormatterBase : @unchecked Sendable {

var value = value
value.withUTF8 {
unumf_formatDecimal(formatter, $0.baseAddress, Int32($0.count), result, &status)
$0.withMemoryRebound(to: CChar.self) {
unumf_formatDecimal(formatter, $0.baseAddress, Int32($0.count), result, &status)
}
}

try status.checkSuccess()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import FoundationEssentials

extension ICU {
final class CaseMap : @unchecked Sendable {
let casemap: OpaquePointer
let casemap: OpaquePointer?

let lock: LockedState<Void>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal import _FoundationICU

extension ICU {
final class FieldPositer {
let positer: OpaquePointer
let positer: OpaquePointer?

internal init() throws {
var status = U_ZERO_ERROR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ internal struct ICUError: Error, CustomDebugStringConvertible {
}

var debugDescription: String {
String(validatingUTF8: u_errorName(code)) ?? "Unknown ICU error \(code.rawValue)"
guard let error = u_errorName(code) else {
return "Unknown ICU error \(code.rawValue)"
}
return String(cString: error)
}

#if canImport(os)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ extension ICU.StringConverter {
converter,
dest,
capacity,
src.baseAddress,
src.baseAddress?.assumingMemoryBound(to: CChar.self),
srcLength,
&status
)
Expand All @@ -85,7 +85,7 @@ extension ICU.StringConverter {
}

func encode(string: String, allowLossyConversion lossy: Bool) -> Data? {
return _converter.withLock { (converter) -> Data? in
return self._converter.withLock { (converter) -> Data? in
defer {
ucnv_resetFromUnicode(converter)
}
Expand Down Expand Up @@ -117,7 +117,7 @@ extension ICU.StringConverter {

ucnv_setFromUCallBack(
converter,
UCNV_FROM_U_CALLBACK_SUBSTITUTE,
{ UCNV_FROM_U_CALLBACK_SUBSTITUTE($0, $1, $2, $3, $4, $5, $6) },
nil, // newContext
nil, // oldAction
nil, // oldContext
Expand All @@ -127,7 +127,7 @@ extension ICU.StringConverter {
} else {
ucnv_setFromUCallBack(
converter,
UCNV_FROM_U_CALLBACK_STOP,
{ UCNV_FROM_U_CALLBACK_STOP($0, $1, $2, $3, $4, $5, $6) },
nil, // newContext
nil, // oldAction
nil, // oldContext
Expand All @@ -138,7 +138,7 @@ extension ICU.StringConverter {

let actualLength = ucnv_fromUChars(
converter,
dest,
dest.assumingMemoryBound(to: CChar.self),
CInt(capacity),
uchars.baseAddress,
CInt(srcLength),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ extension Locale.Region {
return nil
}

guard let code = String(validatingUTF8: uregion_getRegionCode(containingRegion)) else {
guard let region = uregion_getRegionCode(containingRegion) else {
return nil
}

guard let code = String(validatingUTF8: region) else {
return nil
}

Expand All @@ -236,7 +240,11 @@ extension Locale.Region {
return nil
}

guard let code = String(validatingUTF8: uregion_getRegionCode(containingContinent)) else {
guard let region = uregion_getRegionCode(containingContinent) else {
return nil
}

guard let code = String(validatingUTF8: region) else {
return nil
}

Expand Down Expand Up @@ -445,7 +453,11 @@ extension Locale.Region {
return nil
}

guard let code = String(validatingCString: uregion_getRegionCode(containing)) else {
guard let region = uregion_getRegionCode(containing) else {
return nil
}

guard let code = String(validatingCString: region) else {
return nil
}

Expand Down Expand Up @@ -599,8 +611,8 @@ extension Locale.NumberingSystem {
var status = U_ZERO_ERROR
let numberingSystem = unumsys_open(localeIdentifier, &status)
defer { unumsys_close(numberingSystem) }
if let numberingSystem, status.isSuccess {
self.init(String(cString: unumsys_getName(numberingSystem)))
if let numberingSystem, status.isSuccess, let name = unumsys_getName(numberingSystem) {
self.init(String(cString: name))
} else {
self = .latn
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,8 @@ extension Locale {
var working = Set<String>()
let localeCount = uloc_countAvailable()
for locale in 0..<localeCount {
let localeID = String(cString: uloc_getAvailable(locale))
guard let name = uloc_getAvailable(locale) else { continue }
let localeID = String(cString: name)
working.insert(localeID)
}
return Array(working)
Expand Down