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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this file uses ICU - is this change required / relevant?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it was needed to resolve some of the aliases.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the functions that would break without this? While I can believe this change is needed for us to build, I'm surprised that it's because of the ICU change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S:/SourceCache/swift-project/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift:390:37: error: property 'd_type' is not available due to missing import of defining module '_FoundationCShims' [#MemberImportVisibility]
118 | @preconcurrency import Android
119 | import posix_filesystem.dirent
120 | // internal import _FoundationCShims
    | `- note: add import of module '_FoundationCShims'
121 | #elseif canImport(Glibc)
122 | @preconcurrency import Glibc
    :
388 |                 if appendSlash {
389 |                     var isDirectory = false
390 |                     if dent.pointee.d_type == DT_DIR {
    |                                     `- error: property 'd_type' is not available due to missing import of defining module '_FoundationCShims' [#MemberImportVisibility]
391 |                         isDirectory = true
392 |                     } else if dent.pointee.d_type == DT_UNKNOWN {

#elseif canImport(Glibc)
@preconcurrency import Glibc
internal import _FoundationCShims
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 @@ -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 @@ -423,8 +431,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
Loading