DConf 2013 Day 1 Talk 2: Copy and Move Semantics in D by Ali Cehreli
Dicebot
m.strashun at gmail.com
Wed May 15 00:42:06 PDT 2013
On Friday, 10 May 2013 at 12:08:10 UTC, Andrei Alexandrescu wrote:
> ...
After some more thinking on topic I get the feeling that this is
yet another case when having defined and working "scope" for
function parameters would have been extremely useful.
Lets imagine some string processing function I want to use:
int foo(string);
That is like Phobos string processing functions are defined, they
take immutable(char)[], not const(char)[]. That is good in a
sense that guarantees that function thread safety, but becomes an
issue when you want to use that function with a mutable char
buffer (some typical network packet manipulation, for example).
Presentation recommends to use assumeUnique in such cases as you
can be sure that mutable entity only exists in calling scope and
is practically immutable for the duration of function call.
However, this is potentially dangerous, because foo may save
reference of some kind to its immutable argument in global state
and then your program is in undefined behavior. It is OK with
Phobos string processing functions because common sense and open
sources guarantee that no such stuff happens, but in general this
sounds like a type system hole.
scope may have solved it.
More information about the Digitalmars-d-announce
mailing list