Add generic function to convert D string to C string#9482
Add generic function to convert D string to C string#9482jacob-carlborg wants to merge 1 commit intodlang:masterfrom
Conversation
Adds a new function `toStringzThen` which will convert the given D string to a null terminated C string. It passes the C string to the given callable. The C string is only valid during the call to the callable and will be freed after it returns.
|
Thanks for your pull request and interest in making D better, @jacob-carlborg! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + dmd#9482" |
|
We already have this in |
| import dmd.root.rmem : pureMalloc, pureFree; | ||
|
|
||
| if (str.length == 0) | ||
| return func(&""[0]); |
There was a problem hiding this comment.
Shouldn't we check here if the string is already null-terminated?
|
Yep we have |
There's no need to move it yet. The use case is this PR #9480 and it could be used in the Objective-C integration as well. |
|
New PR with a minor tweak to the existing function: #9483. |
Adds a new function
toStringzThenwhich will convert the given D string to a null terminated C string. It passes the C string to the given callable. The C string is only valid during the call to the callable and will be freed after it returns.