-
-
Notifications
You must be signed in to change notification settings - Fork 706
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into dirEntries-pred
- Loading branch information
Showing
56 changed files
with
1,872 additions
and
4,941 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
Added `SafeRefCounted`, that can be used in `@safe` with `-preview=dip1000`. | ||
|
||
`RefCounted` is only available for `@system` code, because of the possibility of | ||
escaping a reference to its payload past the end of its lifetime. a modified | ||
copy of it, `std.typecons.SafeRefCounted` has been added. Also added is a | ||
`borrow` function, that lets one safely access and modify the payload. | ||
`-preview=dip1000` prevents escaping a reference to it in `@safe` code. | ||
|
||
------- | ||
@safe pure nothrow void fun() | ||
{ | ||
import std.typecons; | ||
|
||
auto rcInt = safeRefCounted(5); | ||
assert(rcInt.borrow!(theInt => theInt) == 5); | ||
auto sameInt = rcInt; | ||
assert(sameInt.borrow!"a" == 5); | ||
|
||
// using `ref` in the function | ||
auto arr = [0, 1, 2, 3, 4, 5, 6]; | ||
sameInt.borrow!(ref (x) => arr[x]) = 10; | ||
assert(arr == [0, 1, 2, 3, 4, 10, 6]); | ||
|
||
// modifying the payload via an alias | ||
sameInt.borrow!"a*=2"; | ||
assert(rcInt.borrow!"a" == 10); | ||
} | ||
------- | ||
|
||
Direct access to the payload unfortunately has to be `@system`, though. While | ||
`-dip1000` could prevent escaping the reference, it is possible to destroy the | ||
last reference before the end of it's scope: | ||
|
||
------- | ||
int destroyFirstAndUseLater() | ||
{ | ||
import std.typecons; | ||
|
||
auto rc = SafeRefCounted!int(123); | ||
int* ptr = &rc.refCountedPayload(); | ||
destroy(rc); | ||
return *ptr; // Reads from freed memory. Don't do this. | ||
} | ||
------- | ||
|
||
As a side effect, this enabled us to make $(REF dirEntries, std, file) `@safe` | ||
with `-preview=dip1000`. | ||
|
||
Some member functions of `RefCounted` that are `@safe` are not so in | ||
`SafeRefCounted`. The `RefCounted` type and `refCounted` function are still | ||
available for the old behaviour. However, their main purpose is backwards | ||
compatibility. They are not recommended for new code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
std.experimental.typecons has been removed | ||
|
||
This was an attempt to update `std.typecons.wrap` with an implementation that could work with struct, but it did not go anywhere. | ||
See [this post on the forum](https://forum.dlang.org/post/[email protected]). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
std.digest.digest has been removed | ||
|
||
This module was initially deprecated in 2.076.1, and has been empty since | ||
2.092.0 when all deprecated symbols were removed in favour of importing | ||
`std.digest` or its submodules instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
std.xml has been removed | ||
|
||
This module is considered out-dated and not up to Phobos' current standards. | ||
If you still need it, go to $(LINK https://github.com/DigitalMars/undeaD) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.