Skip to content

Commit

Permalink
Merge pull request cezheng#1 from MelDev1/xcode16Fix
Browse files Browse the repository at this point in the history
Fix for Xcode16: safe way to create UnsafeBufferPointer
  • Loading branch information
MelDev1 authored Nov 6, 2024
2 parents e853de3 + 6915afb commit 46f628e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Sources/Document.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,15 @@ open class XMLDocument {
- returns: An `XMLDocument` with the contents of the specified XML string.
*/
public convenience init(cChars: [CChar]) throws {
let buffer = cChars.withUnsafeBufferPointer { buffer in
UnsafeBufferPointer(rebasing: buffer[0..<buffer.count])
}
try self.init(buffer: buffer)
let mutablebuffer = UnsafeMutableBufferPointer<CChar>.allocate(capacity: cChars.count)
_ = mutablebuffer.initialize(from: cChars)

defer {
mutablebuffer.deallocate()
}

let buffer = UnsafeBufferPointer(mutablebuffer)
try self.init(buffer: buffer)
}

/**
Expand Down

0 comments on commit 46f628e

Please sign in to comment.