cperera@localhost ~/go/src/pkg/json $ hg log -l 1 .
changeset: 4519:73da0cb12dc6
user: Rob Pike <r...@golang.org>
date: Tue Jan 05 11:33:06 2010 +1100
summary: Check for errors when writing fields of a struct.
Nice. If I would now also receive an answer to my main question I
would be more than happy ;)
Deserializing pointers is an excellent way to corrupt memory and cause
segfaults. Maybe even the best. Without deserialization,
serialization is not very useful.
(why do you need to serialize something? so you can send it to
another process. what will the pointer point to in that process? god
only knows.)
-jake
Sorry for not being clear enough, but I didn't meant to serialize the
pointer itself, but what it points to. If you look into the patch I
have attached to my original posting, you will find, that it writes
either "null" for nil pointers or it dereferences the pointer and
writes the resulting value.
Cheers,
C.P.
type A struct {
b *B
}
type B struct {
a *A
}
Now create an instance of A, 'obj', that points to a B, which points
back to the original A -- circular references. How is json supposed
to know that obj.b.a simply points to obj? The result is an infinite
recursive loop.
Now this could be avoided if the implementation also gave each object
a unique id, but I lack sufficient knowledge of the json spec and the
potential security issues to comment further along that thought.
-Ostsol
On Jan 6, 5:39 am, Carlisle Perera <carlisle.per...@googlemail.com>
wrote:
Json can't know, because it only describes trees. One could
introduce a map to keep track of all the written pointers and
return an error when the same node is encountered multiple times
during the process, but I think that's overkill.
> The result is an infinite recursive loop.
Same problem:
func f() { f() }
Same solution: don't do that. ;-)
Russ