Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Issue 7942 - Appending different string types corrupts memory #915

Merged
merged 1 commit into from Jul 30, 2014

Conversation

yebblies
Copy link
Member

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

@yebblies
Copy link
Member Author

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)
Copy link
Member

Choose a reason for hiding this comment

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

Why byte[]?

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@MartinNowak
Copy link
Member

A unittest for the new functions in rt.lifetime would be nice :).

@yebblies
Copy link
Member Author

I have unittests in the dmd pull. Are they really necessary here?

@MartinNowak
Copy link
Member

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.
Something simple like this would suffice.

char[] chars = "chars";
wchar[] wchars = "wchars"w;
_d_arrayappendcwa(chars, wchars);
assert(chars == "charswchars");

@yebblies
Copy link
Member Author

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.

@MartinNowak
Copy link
Member

I really don't see the point, and I'd rather not.

It takes about 10 minutes to run dmd tests and they are part of a different repo.
This makes it unnecessarily harder to test changes in druntime.

I always find unittests in druntime cumbersome to work with.

Why? I'm not too happy with the Makefile tests, but I don't see what is wrong with D unittests.
The splitting is also pretty clear, druntime tests should check that functions implementations are correctly, dmd tests should check that the compiler<->rt interface works.

@MartinNowak
Copy link
Member

Auto-merge toggled on

MartinNowak added a commit that referenced this pull request Jul 30, 2014
Issue 7942 - Appending different string types corrupts memory
@MartinNowak MartinNowak merged commit d0e3b25 into dlang:master Jul 30, 2014
@yebblies
Copy link
Member Author

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.

@yebblies yebblies deleted the issue7942 branch July 30, 2014 13:20
@MartinNowak
Copy link
Member

Thanks for fixing the bug :).

@yebblies
Copy link
Member Author

Not fixed until the dmd pull is merged too!

@9rnsr
Copy link
Contributor

9rnsr commented Jul 30, 2014

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.

@yebblies
Copy link
Member Author

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.

@yebblies
Copy link
Member Author

Original issue is an accepts-invalid bug. Why specially allow transcoding on appending?

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?

@MartinNowak
Copy link
Member

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.
Also note that it's more efficient to do concat a different string type than it is to first convert and then concat.
@yebblies will your code also allow to concat string literals of different type, because currently "foo"c ~ "bar"d is not allowed.

@yebblies
Copy link
Member Author

@yebblies will your code also allow to concat string literals of different type, because currently "foo"c ~ "bar"d is not allowed.

No, but it's not as high priority because it isn't wrong-code.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants