-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[BUG]: Creating a String from a DynamicVector drops the last character in the vector #1753
Comments
I'm not sure if this is a doc bug or an API design issue--maybe a bit of both. The first constructor for The constructors that take pointers also assume that the data is already null-terminated and that the provided There's a private TL;DR: It seems kind of backwards to me that the default paths in/out of String assume that the buffer coming in is null-terminated. But if that's the case we should just make sure the API docs for any method that takes a |
So workaround is--use |
Wow, this looks like we should require a keyword argument here, so |
Thanks @arthurevans my question is answered, the behavior does at a minimum seem unexpected, feel free to close this if needed. RE |
@arthurevans What I get from your response is that the internal representation of |
@sstadick private methods (with a leading underscore) don't appear in the docs but do appear in code completion hints. In this case, I don't see it there, either, so it must be new. Sorry for the confusion. At any event, adding the null yourself is probably the better path for now. I've opened a PR to clarify the API docs as a short-term fix until the API can be updated. @soraros yes, the internal buffer requires null termination. I believe this is not really for Mojo's sake, since Mojo tracks the length of the string. But it simplifies communicating with lower-level facilities that take C-style strings. (For example, if you open a file on Linux, at some point the Mojo std library will call into libc's |
@arthurevans Thanks for the reply. That explanation is both foreseeable and unfortunate. However, why didn't Mojo go with a separate |
Bug description
Converting a
DynamicVector
to aString
using theString
constructor results in a string that is missing the last element of theDynamicVecotor
used to create it.Steps to reproduce
The following code reproduces the issue:
System information
On an M1 Mac.
The text was updated successfully, but these errors were encountered: