Skip to content

[SE-0101] Migration #571

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion Tests/POSIXTests/ReaddirTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ReaddirTests: XCTestCase {

do {
var s = dirent()
let n = sizeof(s.d_name.dynamicType)
let n = MemoryLayout.of(s.d_name).size
Copy link
Member Author

@rintaro rintaro Jul 29, 2016

Choose a reason for hiding this comment

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

@gribozavr the type of s is platform dependent and something like (Int8, Int8, Int8, ...)
Is there any way without using ._ofInstance(_:) here?

#if os(Linux)
let n = MemoryLayout<(Int8, Int8, Int8, Int8... * 245)>.size
#elif of(macOS)
let n = MemoryLayout<(Int8, Int8, Int8, Int8, Int8... * 1024)>.size
...
#end

is not reasonable to me :(

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the least damaging thing we can do here is copying our _ofInstance implementation into this file (maybe under a non-underscored name):

extension MemoryLayout {
  fileprivate static func ofInstance(_: @autoclosure () -> T) -> MemoryLayout<T>.Type {
    return MemoryLayout<T>.self
  }
}

withUnsafeMutablePointer(to: &s.d_name) { ptr in
let ptr = unsafeBitCast(ptr, to: UnsafeMutablePointer<UInt8>.self)
for i in 0 ..< n {
Expand Down