Grabbing Mac Computer Name through C++ Interop hangs

I'm defining a simple call in swift to grab the name of the local Mac:

public func getMacName() -> String {
  return Host.current().localizedName ?? "Unknown"
}

Then I call this from C++ as follows:

  std::string val = TestApp::getMacName();

I'm finding that If my Mac is named "Eric’s MacBook Pro" then the C++ call to getMacName() hangs. If I take out the fancy apostrophe character then it returns.
Here's what it's up to when hung:

Hard coding the Swift function to return the exact value "Eric’s MacBook Pro" does not hang. And printing the name in Swift before returning it shows the correct name was fetched; it just gets stuck on its way out to C++ land.

This is using Xcode 15.0.1 and I've repro'd the hanging behavior on Sonoma 14.1.1 Arm and on Monterey 12.7.1 Intel.

I wanted to post this here first in case its another manifestation of the other string/container issues I recently ran into recently. If this looks to be a separate and valid issue then I'm happy to put together a full repro case on GitHub or whatnot.

1 Like

Thanks for the report, could you file a GitHub issue? I'll see if I can reproduce in the meantime. It sounds like it hangs whilst traversing utf8 codepoints while casting the Swift string to a C++ string.

1 Like

Sure thing; I'll get that going right now :+1:

1 Like

Ok, GitHub issue is up:

1 Like