Issue 7942 - Appending different string types corrupts memory #915
Conversation
Must be merged before dmd pull: dlang/dmd#3831 |
@@ -1939,6 +1939,70 @@ extern (C) void[] _d_arrayappendwd(ref byte[] x, dchar c) | |||
|
|||
|
|||
/** | |||
* Append wchar[] to char[] | |||
*/ | |||
extern (C) void _d_arrayappendcwa(ref byte[] chars, wchar[] wchars) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why byte[]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, copy-paste error from the existing code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
A unittest for the new functions in |
I have unittests in the dmd pull. Are they really necessary here? |
I'd really appreciate it. Keeping tests co-located to the source helps during development. char[] chars = "chars";
wchar[] wchars = "wchars"w;
_d_arrayappendcwa(chars, wchars);
assert(chars == "charswchars"); |
I really don't see the point, and I'd rather not. I always find unittests in druntime cumbersome to work with. Updated to add redundant unittests. |
It takes about 10 minutes to run dmd tests and they are part of a different repo.
Why? I'm not too happy with the Makefile tests, but I don't see what is wrong with D unittests. |
Auto-merge toggled on |
Issue 7942 - Appending different string types corrupts memory
Maybe it's just that I'm not used to working on druntime. These tests have to be in the dmd test suite, and dmd is the only caller of these functions. I'm much more comfortable running the dmd tests, and the way I have it set up it takes much less than 10 minutes. And thanks. |
Thanks for fixing the bug :). |
Not fixed until the dmd pull is merged too! |
Original issue is an accepts-invalid bug. Why specially allow transcoding on appending? I'm afraid that implicit transcoding will be hidden cost addition to the gc operation and elements copying. If the appended string is very long, the cost will be bigger. |
The cost will still be O(N), as expected for array concatenation. |
As I said in the bug report, it seems like a straightforward extension of the single char case. Isn't this a useful thing to do with unicode strings? |
I never needed or used it, that's why I think it won't introduce a performance issue. |
No, but it's not as high priority because it isn't wrong-code. |
This adds the runtime functions necessary to append any string type to any other string type.
The performance is probably not ideal but is also not a priority as the current situation causes memory corruption.
https://issues.dlang.org/show_bug.cgi?id=7942