111 Commits

Author SHA1 Message Date
Jake Petroules
90953dfb68
Transparently add the \\?\ prefix to Win32 calls for extended length path handling (#1257)
On Windows, there is a built-in maximum path limitation of 260 characters under most conditions. This can be extended to 32767 characters under either of the following two conditions:

- Adding the longPathAware attribute to the executable's manifest AND enabling the LongPathsEnabled system-wide registry key or group policy.
- Ensuring fully qualified paths passed to Win32 APIs are prefixed with \?\

Unfortunately, the former is not realistic for the Swift ecosystem, since it requires developers to have awareness of this specific Windows limitation, AND set longPathAware in their apps' manifest AND expect end users of those apps to change their system configuration.

Instead, this patch transparently prefixes all eligible paths in calls to Win32 APIs with the \?\ prefix to allow them to work with paths longer than 260 characters without requiring the caller of Foundation to manually prefix the paths.

See https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation for more info.
2025-04-23 14:51:43 -07:00
Jonathan Flat
914b9f7bbd
Support NS/CFURL re-core in Swift (#1238)
* (146349351) Support NS/CFURL re-core in Swift

* Fix .fileSystemPath() calls in Windows test

* Use encoded strings for .absoluteURL, fix NSURL bridging and CFURL lastPathComponent edge cases

* Add workaround for crash on Linux

* Fix typo
2025-04-11 22:37:51 -06:00
David Smith
b0b89ccac1
Allocationless constant String -> NSString bridging via a new tagged pointer type (#1232)
* Revert "Revert "rdar://142693100 (Allocationless constant String -> NSString bridging via a new tagged pointer type) (#2798)" (#2843)"

This reverts commit c378439322f5b960ecb972b27ab1419a622ad6b2.

* Adopt the new entry point for bridging the new tagged pointers

* All remaining callsites passed null-terminated strings, so just eliminate the isTerminated bit and simplify further. Also gets us up to 13 bits of length

* Address review comments
2025-03-28 10:19:09 -07:00
Kenta Kubo
68dd6d85a6
[wasm] Make FileManager.createFile() work on WASI (#992)
* [wasm] Make `FileManager.createFile()` work on WASI

fixes swiftwasm/swift#5593

`FileManager.createFile()` currently doesn't work on WASI because it
requires `.atomic`, it requires creating a temporary file, and it isn't
suppported on WASI.

So I have fixed that by removing the `.atomic` requirement only on WASI.

* [wasm] Make `Data.WritingOptions.atomic` unavailable on WASI

`writeToFileAux`, `createTemporaryFile`, and `createProtectedTemporaryFile` also become unavailable on WASI.
2025-03-25 09:42:15 -07:00
Tony Parker
ee467a19cb
Add an upcall point to swift-corelibs-foundation for String encoding conversion (#1217)
* Add an upcall point to swift-corelibs-foundation for String encoding conversion

* Add upcall for conversion from bytes to String in non-swift-foundation encodings
2025-03-24 09:28:00 -07:00
Jeremy Schonfeld
9ba455dcfa
Fix ISO Latin 1 Encoding/Decoding issues (#1219) 2025-03-19 14:24:02 -07:00
Christopher Thielen
fa43c96f5f
Move temporarily relocated FileManager extensions back to their original locations (#1213) 2025-03-18 11:29:53 -07:00
Jeremy Schonfeld
93e3bac3d9
(144909030) FSR writes bytes to end of buffer even on success cases (#1199) 2025-03-04 21:54:29 -08:00
Johannes Weiss
601e847faa
always @preconcurrency import Glibc (#1175)
Co-authored-by: Johannes Weiss <johannes@jweiss.io>
2025-03-04 09:25:51 -08:00
Jeremy Schonfeld
7aacaff577
Drop UTF-8 BOM when present while decoding UTF-8 bytes into String (#1165) 2025-02-13 15:52:30 -08:00
Jeremy Schonfeld
c3397fc452
Temporarily remove special tagged pointer string bridging behavior (#1144)
Co-authored-by: David (Swift) Smith <david_smith@apple.com>
2025-01-28 09:53:53 -08:00
Christopher Thielen
8d56fb70f0
Include String+Bridging.swift in CMakeLists.txt (#1136) 2025-01-22 17:11:50 -08:00
Christopher Thielen
215f1ce06b
Publish NSString bridging (#1133)
* Publish NSString->String bridging

* Relocate Swift extensions of some Objective-C NS_TYPED_ENUM types to work around swiftlang/swift #78731
2025-01-22 13:29:41 -08:00
Jeremy Schonfeld
f337a2c04f
Prevent potential buffer over-reads of file system representations (#1124)
* (133687793) Prevent buffer over-reads with string file system representations that fail

Signed-off-by: Jeremy Schonfeld <jschonfeld@apple.com>

* Account for empty buffers

Signed-off-by: Jeremy Schonfeld <jschonfeld@apple.com>

* Move empty buffer check earlier

Signed-off-by: Jeremy Schonfeld <jschonfeld@apple.com>

---------

Signed-off-by: Jeremy Schonfeld <jschonfeld@apple.com>
2025-01-21 10:37:09 -08:00
Jonathan Flat
8a95c62e3e
(141294361) URL.appendingPathExtension("") appends a trailing dot (#1082) 2024-12-11 14:20:31 -08:00
Jeremy Schonfeld
2eeb1b0772
(140882573) Home directory for non-existent user should not fall back to /var/empty or %ALLUSERSPROFILE% (#1072) 2024-12-06 15:51:08 -08:00
Jeremy Schonfeld
b0313440a4
(140789630) Correct buffer size logic when calling confstr (#1064) 2024-12-02 15:11:44 -08:00
Charles Hu
7bb410015a
OpenStep plist decoding via PropertyListDecoder is not available on Windows and Linux (#1002)
resolves: rdar://136243566

Co-authored-by: Kevin Perry <kperry@apple.com>
2024-10-23 14:24:27 -07:00
Jeremy Schonfeld
71eefee7fc
Fetching user/group info causes race conditions (#994)
* Avoid racy stdlib functions for fetching user/group info

* Refactor naming

* Fix build failure
2024-10-23 09:18:15 -07:00
Alex Hoppen
3f9171072d
Conditionalize stripping of \\?\ on it actually being present (#974)
As far as I know `\\?\` is always returned by `GetFinalPathNameByHandleW` but it’s better to be safe and actually check instead of unconditionally trimming the first 4 characters from the returned path.

See https://github.com/swiftlang/swift-tools-support-core/pull/485#discussion_r1795781075
2024-10-11 11:38:06 -07:00
Jonathan Flat
09bdd0d0b5
(137287143) URL path extension APIs should strip trailing slashes (#965) 2024-10-07 11:49:51 -06:00
Jeremy Schonfeld
cfcf10a2e1
Support initializing string with nonLossyASCII encoding (#932) 2024-09-20 14:32:23 -07:00
Jonathan Flat
706ef7f9ea
(128094957) String+Path parsing performance improvements (#927) 2024-09-19 15:58:19 -07:00
rjmansfield
9d9a53722d
Fix deleteLastPathComponent() for absolute paths with trailing / (#897)
Paths like /home/ would return "" instead of /

Co-authored-by: Ryan Mansfield <ryan_mansfield@apple.com>
2024-09-05 15:35:11 -07:00
LamTrinh.Dev
aca65acbc5
Correct available version macOS 10.10 for String+Essentials.swift (#886) 2024-08-28 13:44:03 -07:00
Tony Parker
446af5c0c5
Formatting performance improvements (#884) 2024-08-23 14:13:17 -07:00
Jeremy Schonfeld
ecf5445939
Fix Windows home directory for specific user (#861)
* Fix Windows home directory for specific user

* Fix test failure
2024-08-16 13:32:04 -07:00
Jonathan Flat
83073e236e
(133878310) URL.fileSystemPath should drop all trailing slashes (#852) 2024-08-16 09:32:42 -07:00
Jeremy Schonfeld
ebb00b8077
Use fallback home directory on Windows (#854)
* Use %SystemDrive\Users\Public as fallback home directory on Windows

* Update to ALLUSERSPROFILE

* Fix test failure

* Fix iOS test failure
2024-08-15 17:27:56 -07:00
finagolfin
c15a5e1f5c
[Android] Use the Bionic module in more places (#842)
Also, use `canImport()` wherever importing APIs, reserving `os(Android)` for
platform differences.
2024-08-15 14:34:15 -07:00
Evan Wilde
aecc1b158c
[main] Get Swift-Foundation building against MUSL for Swift Static SDK (#848)
* Get FoundationEssentials building

Adding the missing musl imports to get FoundationEssentials building for
the Swift static SDKs again.

Also providing an option to disable building the macros. The macros
aren't necessary for building the library and will not be run as part of
the static SDK. No need to bloat the SDK or build times further. For
Swift 6, the macros should be provided by the toolchain since the
toolchain and SDK are current revlocked due to swiftmodules.

* Get FoundationInternationalization building

Adding the missing Musl imports to get FoundationInternationalization
building for the static SDK.
2024-08-14 13:34:15 -07:00
Alex Lorenz
ad6ca71b4e
[android] fix the LP32 armv7/i686 android build (#846)
* [android] fix the LP32 armv7/i686 android build

* Update Sources/FoundationEssentials/Android+Extensions.swift

Co-authored-by: Jeremy Schonfeld <1004103+jmschonfeld@users.noreply.github.com>

* drop the android Lp32 specific operator &

---------

Co-authored-by: Jeremy Schonfeld <1004103+jmschonfeld@users.noreply.github.com>
2024-08-14 10:56:25 -07:00
Tony Parker
07f38c4ca2
Add compatibility path for invalid UTF8 data (#815) 2024-08-02 10:21:32 -07:00
Yuta Saito
c82d1673eb
Add WASI platform conditions for libc imports and word size (#776)
* Add `import WASILibc` statements to libc import chains

* Declare wasm32 arch as 32-bit environment

* Switch to _pointerBitWidth for architecture checks

This change switches the architecture checks in Data.swift to use the
_pointerBitWidth instead of the arch() checks for consistency with newer
platforms.
2024-08-02 09:55:56 -07:00
Jonathan Flat
628fe671f9
Prevent null character in Windows home directory (#808) 2024-08-01 21:03:00 -07:00
Yuta Saito
0b3974d351
Guard out user/group related code on WASI (#783)
* Guard out user/group related code on WASI

This change guards out the user/group related code on WASI, as WASI does
not have the concept of users or groups.

* Throw explicit unsupported error if trying to set user or group on WASI

Instead of implicitly ignoring user-given values, we should throw
exception to make it clear that those values cannot be set on WASI.
2024-08-01 09:23:13 -07:00
Jeremy Schonfeld
acae3d26b6
Implement isoLatin1 and macOSRoman encoding (#743)
* Implement isoLatin1 and macOSRoman encoding

* Limit new behavior to non-framework build
2024-07-25 08:52:30 -07:00
Jonathan Flat
523ffcb1a4
Port UIDNAHook to FoundationInternationalization (#746) 2024-07-22 12:30:22 -07:00
Tony Parker
90109a4cf6
Revert formatting performance improvements (#744)
There appears to be some kind of race or memory smash in ICU after these, and we need more time to investigate the full root cause.
2024-07-18 17:43:34 -07:00
Jeremy Schonfeld
75a3f5a047
[Windows] Standardize slashes before path processing (#731)
* Standardize backslashes before string path processing on Windows

* Call _standardizingSlashes() from normalizedPath(with:)

* Return self when possible on non-Windows
2024-07-15 09:51:58 -07:00
Jeremy Schonfeld
c3fc214351
(130296407) Gracefully handle confstr failures (#728) 2024-07-11 16:28:47 -07:00
Tony Parker
6ee772ba7f
Improve performance of FormatStyle formatting when used in multithreaded context (#719)
* Improve performance of FormatStyle formatting when used in multithreaded context

* Change canImport statement to support newer SDK on older macOS
2024-07-09 10:06:47 -07:00
Saleem Abdulrasool
a7692238a8
FoundationEssentials: initial pass to add Android support (#704)
This adds the necessary guards and includes for the Android modules.
While the module does not compile currently due to nullability
differences (and in some cases missing declarations), this at least
brings the module to a point where we can start working on the errors
and differences to create a maintainable codebase for Android.
2024-06-26 16:00:37 -07:00
Charles Hu
60506f3af4
Renamed _CShims to _FoundationCShims (#656)
Rationale: _CShims will effectivly become semi-public in the toolchain. We add the Foundation prefix to make it less generic.
2024-06-21 16:18:38 -07:00
Tony Parker
9218bda96a
Only use the underscored utf16 function when we are a contiguous UTF8 string. (#685)
Co-authored-by: Jeremy Schonfeld <jschonfeld@apple.com>
2024-06-17 15:23:13 -07:00
Charles Hu
8976fc4fd6
Introduce Cmake support for SwiftFoundation (#573) 2024-06-16 22:21:28 -07:00
Jeremy Schonfeld
b1acbafbca
Fix calloc build failure on macOS (#680) 2024-06-14 09:47:54 -07:00
Tony Parker
e53bc1ccd4
Unify UTF16 conversion path for String (#670) 2024-06-13 10:00:04 -07:00
Saleem Abdulrasool
654fa54be7
FoundationEssentials: canonicalise the arc separator more aggressively (#669)
When trying to get the file system representation of a string, we may
have previously used `appendingPathComponent(_:)` which will have used
the incorrect separator. Ensure that all the separators are properly
converted prior to returning the path.
2024-06-07 17:16:39 -07:00
Tony Parker
7997b425ed
String(bytes:encoding:) should not skip BOM on UTF16 to UTF8 conversion (#663) 2024-06-07 09:25:49 -07:00