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

Use 'cpointer' instead of 'cstring' where applicable #1320

Merged
merged 1 commit into from
Oct 19, 2016

Conversation

malthe
Copy link
Contributor

@malthe malthe commented Oct 13, 2016

This closes #1309.

data.cpointer(),
data.space(),
addressof again
)
Copy link
Member

Choose a reason for hiding this comment

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

This is probably the style I would use on my personal code, but I think it doesn't match the Pony standard library style of only using line breaks where strictly necessary in argument and parameter lists.

@@ -101,14 +100,36 @@ actor Main
_set(0, 0)
else
_size = len
_alloc = alloc.max(_size + 1)
Copy link
Member

Choose a reason for hiding this comment

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

At first glance I think this does the wrong thing in the overflow case (_size == USize.max_value()).

only with C-FFI functions that return pony_alloc'd character
arrays. The pointer is scanned for the first null byte, which will
be interpreted as the null terminator. If a null pointer is given
then an empty string is returned.
Copy link
Member

Choose a reason for hiding this comment

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

I think the docstring should warn about the dangers of passing in a pointer that has no null byte within its bounds. Specifically, it seems that doing so would violate memory safety. Obviously this can only be done via FFI, but it should still be documented. The previous implementation of from_cstring also gave a warning about memory safety if the len argument was not given, and there was no null byte in the scan.

@jemc
Copy link
Member

jemc commented Oct 13, 2016

Thank you again for spearheading this RFC - I'm much happier with this solution than with the null_terminated().cstring() crap I did 😉!

Copy link
Member

@jemc jemc 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 now, but any idea why the crypto package tests are failing?

@malthe
Copy link
Contributor Author

malthe commented Oct 14, 2016

The crypto tests are failing because of #1319 (closed now).

@SeanTAllen
Copy link
Member

@malthe can you rebase your branch off of master so this can be restested with issue-1309 in place? While you are doing that, can you squash the 4 commits to 1?

@jemc
Copy link
Member

jemc commented Oct 14, 2016

Looks like rebasing didn't stop the crypto tests from failing...

@SeanTAllen
Copy link
Member

This also needs a CHANGELOG entry

@SeanTAllen
Copy link
Member

@malthe 0.5.1 was released last night. The CHANGELOG needs to be updated to reflect that, you currently have your change in the section that is already 0.5.1 on master. You'll need to rebase against it.

@malthe malthe force-pushed the issue-1309 branch 5 times, most recently from b2a563b to f75f6ad Compare October 18, 2016 22:53
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.

RFC: C-string vs bytes
3 participants