Skip to content

Fixup SourceKit module on Windows #100

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

Merged
merged 1 commit into from
Apr 18, 2019
Merged
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
7 changes: 6 additions & 1 deletion Sources/SourceKit/SourceKitServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,13 @@ public final class SourceKitServer: LanguageServer {
return nil
}

#if os(Windows)
let pid: Int = unsafeBitCast(GetCurrentProcess(), to: Int.self)
#else
let pid: Int = Int(getpid())
#endif
Copy link

Choose a reason for hiding this comment

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

Why we are reimplementing things already in Foundation?

This could simply be:

let pid = Int(ProcessInfo.processInfo.processIdentifier)

Which is already cross-platform.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah fair point, I didn't realize that existed. Plus GetCurrentProcess gives a handle instead of a pid which now that I think about it, is probably the wrong thing to identify a process with. I'll swap it.

let resp = try service.sendSync(InitializeRequest(
processId: Int(getpid()),
processId: pid,
rootPath: nil,
rootURL: (workspace?.rootPath).map { URL(fileURLWithPath: $0.pathString) },
initializationOptions: InitializationOptions(),
Expand Down
6 changes: 5 additions & 1 deletion Sources/SourceKit/sourcekitd/SwiftSourceKitFramework.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ final class SwiftSourceKitFramework {

init(dylib path: AbsolutePath) throws {
self.path = path
#if os(Windows)
self.dylib = try dlopen(path.pathString, mode: [])
#else
self.dylib = try dlopen(path.pathString, mode: [.lazy, .local, .first, .deepBind])
#endif

func dlsym_required<T>(_ handle: DLHandle, symbol: String) throws -> T {
guard let sym: T = dlsym(handle, symbol: symbol) else {
Expand All @@ -54,7 +58,7 @@ final class SwiftSourceKitFramework {
// Workaround rdar://problem/43656704 by not constructing the value directly.
// self.api = sourcekitd_functions_t(
let ptr = UnsafeMutablePointer<sourcekitd_functions_t>.allocate(capacity: 1)
bzero(UnsafeMutableRawPointer(ptr), MemoryLayout<sourcekitd_functions_t>.stride)
memset(UnsafeMutableRawPointer(ptr), 0, MemoryLayout<sourcekitd_functions_t>.stride)
var api = ptr.pointee
ptr.deallocate()

Expand Down