Skip to content

Conversation

@spevans
Copy link
Contributor

@spevans spevans commented Feb 17, 2018

  • Reparse the environment variables each time
    ProcessInfo.processinfo.enviroment is read.

- Reparse the environment variables each time
  ProcessInfo.processinfo.enviroment is read.
let equalSign = Int32(UInt8(ascii: "="))
var env: [String : String] = [:]
var idx = 0
let envp = environ
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this use _CFEnviron() instead of environ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I think you are correct, it should also work correctly on Windows then as well. I will update it in a bit.

@spevans
Copy link
Contributor Author

spevans commented Feb 19, 2018

@swift-ci please test

guard keyLen > 0 else {
continue
}
if let key = NSString(bytes: entry, length: keyLen, encoding: String.Encoding.utf8.rawValue) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it guaranteed that all platforms use a UTF8 encoding?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@parkera Probably not, I had looked at __CFGetEnvironment() and saw the decoding of UTF-8 but not the fallback to CFStringGetSystemEncoding(). Does the following look more portable?

open var environment: [String : String] {
        let equalSign = Character("=")
        var env: [String : String] = [:]
        var idx = 0
        let envp = _CFEnviron()
        let strEncoding = String.Encoding(rawValue: CFStringConvertEncodingToNSStringEncoding(CFStringGetSystemEncoding()))

        while let entry = envp.advanced(by: idx).pointee {
            if let entry = String(cString: entry, encoding: strEncoding), let i = entry.index(of: equalSign) {
                let key = String(entry.prefix(upTo: i))
                let value = String(entry.suffix(from: i).dropFirst())
                env[key] = value
            }
            idx += 1
        }
        return env
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

That looks fine too.

Copy link
Contributor

Choose a reason for hiding this comment

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

-let strEncoding = String.Encoding(rawValue: CFStringConvertEncodingToNSStringEncoding(CFStringGetSystemEncoding()))
+let strEncoding = String.defaultCStringEncoding

Copy link
Contributor

@parkera parkera left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@spevans
Copy link
Contributor Author

spevans commented Feb 20, 2018

@swift-ci please test

2 similar comments
@alblue
Copy link
Contributor

alblue commented Feb 20, 2018

@swift-ci please test

@spevans
Copy link
Contributor Author

spevans commented Feb 20, 2018

@swift-ci please test

@millenomi
Copy link
Contributor

The test failure seems unrelated.

@millenomi
Copy link
Contributor

@swift-ci please test

@alblue
Copy link
Contributor

alblue commented Feb 20, 2018

@swift-ci please clean test

@millenomi
Copy link
Contributor

This is failing in upstream tests:

******************** TEST 'Swift(linux-x86_64) :: compiler_crashers_fixed/01691-clang-astcontext-getrecordtype.swift' FAILED ********************

@ianpartridge
Copy link
Contributor

Once we land this, I'd like to propose we backport it to the swift-4.1-branch as well. We have been unable to use ProcessInfo.processInfo.environment because of this problem.

@spevans
Copy link
Contributor Author

spevans commented Feb 21, 2018

No problem, I have a few bug fixes I want to back port once CI is working again

@spevans
Copy link
Contributor Author

spevans commented Feb 21, 2018

@swift-ci please test

@alblue
Copy link
Contributor

alblue commented Feb 22, 2018

@swift-ci please test and merge

1 similar comment
@spevans
Copy link
Contributor Author

spevans commented Feb 22, 2018

@swift-ci please test and merge

@alblue
Copy link
Contributor

alblue commented Feb 22, 2018

@shahmishal do you know why we're seeing these errors in the test build?

:0: error: compilation involves pch was disabled in PCH file but is currently enabled
:0: error: PCH was compiled with module cache path '/tmp/swift-testsuite-clang-module-cachetoZRBb/1CROV3ELEU92S', but the path is currently '/tmp/swift-testsuite-clang-module-cachetoZRBb/1KM07I68PTKB3'
:0: error: clang importer creation failed

@millenomi
Copy link
Contributor

@swift-ci please clean test

@spevans
Copy link
Contributor Author

spevans commented Feb 22, 2018

@swift-ci please test and merge

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.

7 participants