Skip to content
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

Simplify C string to String conversion in IOError.reasonForError #544

Merged
merged 3 commits into from
Aug 1, 2018
Merged

Simplify C string to String conversion in IOError.reasonForError #544

merged 3 commits into from
Aug 1, 2018

Conversation

ole
Copy link
Contributor

@ole ole commented Aug 1, 2018

Motivation:

The standard library already has a String initializer that takes a
null-terminated UTF-8 C string. There's no need to construct an
UnsafeBufferPointer to use the Collection-based init(decoding:as:).

Modifications:

  • Replaced a manual pointer conversion with the appropriate stdlib API.

  • I also removed a stray space from the end of the string interpolation literal
    that's used to construct the error message. The stray space looked like an oversight.

Result:

The string API change doesn't change the result of the method. Both versions return the same String. The new version is is arguably more correct because it saves the memory-rebinding step. I haven't added new tests because the modified code is covered by SystemTest.testErrorsWorkCorrectly.

Removing the space at the end of the error message string changes the exact value (but not the meaning) of the error message string. Clients that match against the exact error message might break, but that's arguably bad practice.

ole added 2 commits August 1, 2018 16:30
Motivation:

The stray space looks like an oversight.

Modifications:

Removed a stray space from the end of a string interpolation literal
that's used to construct an error message.

Result:

The exact value (but not the meaning) of the error message string
changes. Clients that match against the exact error message might break,
but that's arguably bad practice.
Motivation:

The standard library already has a String initializer that takes a
null-terminated UTF-8 C string. There's no need to construct an
UnsafeBufferPointer to use the Collection-based init(decoding:as:).

Modifications:

Replaced a manual pointer conversion with the appropriate stdlib API.

Result:

No change. Both version return the same String. The new version is
is arguably more correct because it saves the memory-rebinding step.

I haven't added new tests because the modified code is covered by
SystemTest.testErrorsWorkCorrectly.
@swift-nio-bot
Copy link

Can one of the admins verify this patch?

1 similar comment
@swift-nio-bot
Copy link

Can one of the admins verify this patch?

Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

This looks reasonable to me! We're about to cut a release so I'm afraid this will slip into 1.10 (or 1.9.1, if we ship it), so I'll hold off merging for a little while.

@Lukasa Lukasa added the 🔨 semver/patch No public API change. label Aug 1, 2018
@Lukasa Lukasa added this to the 1.10.0 milestone Aug 1, 2018
@ole
Copy link
Contributor Author

ole commented Aug 1, 2018

@Lukasa Sure, no problem. 👍

@Lukasa
Copy link
Contributor

Lukasa commented Aug 1, 2018

@swift-nio-bot test this please

@Lukasa Lukasa merged commit cf55bee into apple:master Aug 1, 2018
@weissi weissi modified the milestones: 1.10.0, 1.9.3 Aug 28, 2018
weissi pushed a commit that referenced this pull request Aug 29, 2018
* Simplify C string to String conversion in IOError.reasonForError

Motivation:

The standard library already has a String initializer that takes a
null-terminated UTF-8 C string. There's no need to construct an
UnsafeBufferPointer to use the Collection-based init(decoding:as:).

Modifications:

Replaced a manual pointer conversion with the appropriate stdlib API.

Result:

No change. Both version return the same String. The new version is
is arguably more correct because it saves the memory-rebinding step.

I haven't added new tests because the modified code is covered by
SystemTest.testErrorsWorkCorrectly.

Motivation:

Explain here the context, and why you're making that change.
What is the problem you're trying to solve.

Modifications:

Describe the modifications you've done.

Result:

After your change, what will change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants