digitalmars.D - Semantics of casting **to** shared?
- dsimcha (12/12) Sep 04 2010 I noticed that the following code compiles even in SafeD. Is this a bug...
- Jason House (2/16) Sep 04 2010
- dsimcha (6/7) Sep 04 2010 sort of partitions data and there is no provably safe way to create or u...
- Denis Koroskin (6/21) Sep 04 2010 I loved the recent clone() idea. I think it might be better to disable
- dsimcha (10/15) Sep 04 2010 Holy %)(*$%, casting **to** immutable works in SafeD, too? Of course ca...
I noticed that the following code compiles even in SafeD. Is this a bug? If not, what are the semantics of casting unshared to shared? TDPL doesn't seem to mention this. Isn't it dangerous to have shared and unshared references to the same memory? safe: class Foo { uint num; } void main() { auto foo = new Foo; auto bar = cast(shared) foo; }
Sep 04 2010
safeD doesn't mean your code is safe... only "memory safe". Similarly, "shared" sort of partitions data and there is no provably safe way to create or use it. I have no idea if your example is truly legit safeD or not... dsimcha Wrote:I noticed that the following code compiles even in SafeD. Is this a bug? If not, what are the semantics of casting unshared to shared? TDPL doesn't seem to mention this. Isn't it dangerous to have shared and unshared references to the same memory? safe: class Foo { uint num; } void main() { auto foo = new Foo; auto bar = cast(shared) foo; }
Sep 04 2010
== Quote from Jason House (jason.james.house gmail.com)'s articlesafeD doesn't mean your code is safe... only "memory safe". Similarly, "shared"sort of partitions data and there is no provably safe way to create or use it. I have no idea if your example is truly legit safeD or not... 1. Using __gshared and casting **away** shared are illegal in SafeD. 2. Low level data races can cause memory corruption if pointers get overwritten with invalid data.
Sep 04 2010
On Sat, 04 Sep 2010 22:05:05 +0400, dsimcha <dsimcha yahoo.com> wrote:I noticed that the following code compiles even in SafeD. Is this a bug? If not, what are the semantics of casting unshared to shared? TDPL doesn't seem to mention this. Isn't it dangerous to have shared and unshared references to the same memory? safe: class Foo { uint num; } void main() { auto foo = new Foo; auto bar = cast(shared) foo; }I loved the recent clone() idea. I think it might be better to disable casting to (and from) shared (and immutable) and make a (deep?) copy of an object instead. This will make sure that the isn't any dangling reference left. I strongly believe dangling references could become a major source of bugs which might be hard to find and fix.
Sep 04 2010
== Quote from Denis Koroskin (2korden gmail.com)'s articleI loved the recent clone() idea. I think it might be better to disable casting to (and from) shared (and immutable) and make a (deep?) copy of an object instead. This will make sure that the isn't any dangling reference left. I strongly believe dangling references could become a major source of bugs which might be hard to find and fix.Holy %)(*$%, casting **to** immutable works in SafeD, too? Of course casting from/to shared/immutable should be allowed in non- safe code, but I don't think either should be allowed in safe code. The only way to get aliasing between mutable and immutable data in safe code should be by using broken trusted code. Otherwise the safe-ty of SafeD is really questionable. Also, as far as cloning, The fact that it's really a special case of serialization was brought up by a few people, so I'm taking a wait-and-see attitude and seeing what people who wrote serialization libraries come up w/ for cloning, rather than working on cloning now.
Sep 04 2010