Skip to content

Conversation

compnerd
Copy link
Owner

Remove the Foundation dependency as we used it for a single purpose: to convert to a UTF16 string representation for use on Windows. Introduce a withUTF16CString helper that avoids Foundation for the single use.

@compnerd compnerd requested a review from Copilot August 29, 2025 21:57
Copilot

This comment was marked as outdated.

Remove the Foundation dependency as we used it for a single purpose: to
convert to a UTF16 string representation for use on Windows. Introduce a
`withUTF16CString` helper that avoids Foundation for the single use.
@compnerd compnerd force-pushed the compnerd/foundational branch from 3dc18f4 to 7b9bfea Compare August 29, 2025 22:02
@compnerd compnerd requested a review from Copilot August 29, 2025 22:02
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes the Foundation dependency from WindowsCore by implementing a custom UTF-16 string conversion helper. The main purpose is to eliminate the heavy Foundation dependency that was only used for converting strings to UTF16 encoding for Windows APIs.

  • Implements a custom withUTF16CString extension method on String
  • Replaces Foundation import with FoundationEssentials
  • Updates the single usage site to use the new helper method

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
Sources/WindowsCore/String+Extensions.swift Adds new String extension with withUTF16CString method for UTF-16 conversion
Sources/WindowsCore/NTAPI.swift Updates import and replaces Foundation's withCString call with custom helper

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

pBuffer.baseAddress?.initialize(from: pSource, count: count)
}
}) == nil {
_ = pBuffer.initialize(from: self.utf16)
Copy link
Preview

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

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

The initialize(from:) method on UnsafeMutableBufferPointer expects a sequence, but self.utf16 returns a String.UTF16View which may not provide the expected initialization behavior. Consider using pBuffer.baseAddress?.initialize(from: self.utf16, count: count) or explicitly iterate through the UTF16 view to ensure proper initialization.

Suggested change
_ = pBuffer.initialize(from: self.utf16)
pBuffer.baseAddress?.initialize(from: self.utf16, count: count)

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant