Skip to content
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

Fix Issue 6644 - std.stdio write/writef(ln) are not @trusted #2230

Closed
wants to merge 1 commit into from

Conversation

rbanderton
Copy link
Contributor

https://issues.dlang.org/show_bug.cgi?id=6644
More discussion here: http://stackoverflow.com/questions/19101305/how-can-i-do-i-o-in-safe-functions-in-d

Changes I have made to get write and family callable from @safe code:

  • Made LockingTextWriter and factory function @trusted - I didn't see anything inherently unsafe about the way it manages the lock. I'm certainly open to correction, though.
  • Moved File.write, File.writeln, File.writef and File.writefln to non-member functions (UFCS). This is because member functions, even templated ones, cannot infer safety. If you do not infer safety then you can call toString on @system types (that may actually be unsafe) from @safe code.
  • Wrapped the stdout global variable's usage in a private @trusted property that is used by write and friends. If this is not done they always infer to @system due to accessing a global variable. I'm not 100% sure this is safe to to, but with the property being private all external use of the global will still be @system.

Squashed commit:

[0699330] Added unit tests

[9a43947] Made File.writeln (and family) into UFCS templated functions so they can infer @safe/@trusted/etc. Also wrapped stdout in @trusted private function so writeln (and family) free functions don't always infer @System. Lots of unit tests are still needed.
@jmdavis
Copy link
Member

jmdavis commented Jun 6, 2014

Moved File.write, File.writeln, File.writef and File.writefln to non-member functions (UFCS). This is because member functions, even templated ones, cannot infer safety.

If they can't infer safety, that that's a bug, and I really don't like the idea of moving to free functions just to get around that. It opens the door for symbol conflicts and the like. It would be far better IMHO to fix the compiler bug.

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