NICE-ESG-Libs Digest Tue, 25 Apr 95 Volume 1 : Issue 213
Today's Topics:
clone causing aliasing problems in copy (Re: NICE-ESG-Libs Digest V1 #211)
Erratum
NICE Eiffel Standards Group -- Library Committee Mailing List
To post to list:
NICE-ESG-Libs@atlanta.twr.com
To send mail to the Chairman of the committee:
NICE-ESG-Libs-chair@atlanta.twr.com
Administrative matters (sign up, unsubscribe, mail problems, etc):
NICE-ESG-Libs-request@atlanta.twr.com
Date: Mon, 24 Apr 95 15:39:45 MDT
From: "Jacob Gore"
Subject: clone causing aliasing problems in copy (Re: NICE-ESG-Libs Digest V1 #211)
To: "C. Frederick Hart"
On Apr. 20 95, 11:39 MDT, "C. Frederick Hart" wrote:
> | However, if `other' has features that reference other objects, same
> | features in `Current' will end up referencing the same objects. If
> No features of Current are affected by anything in clone. In
> particular, the line below:
> Result :=3D C_function_to_malloc_and_bcopy(other);
> has no effect whatsoever on Current nor does it use Current in any
> way.
Sorry -- I was referring to `Current' as `copy' sees it, which is `Result'
in `clone'.
> | `copy(other)' is immediately called, this aliasing can destroy the
> | internals of `other' -- and that is exactly what happens in many of
the
> | object structure examples in my book.
> The call:
> Result.copy(other)
> cannot affect `other' in any way.
Sure it can. Let me give you an example. Suppose class LINKED_LIST is
done like this:
feature
off_left: NODE;
off_right: NODE;
wipe_out is
do
off_left.set_right(off_right);
off_right.set_left(off_left);
end;
make is
do
!!off_left;
=09 !!off_right;
wipe_out;
end
So a list with three items in it looks like this:
off_left off_right
| |
V V
/------\ /------\ /------\ /------\ /------\
| |<->| item |<->| item |<->| item |<->| |
\------/ \------/ \------/ \------/ \------/
Now suppose `copy' is done this way:
copy(other) is
local
other_node: NODE;
do=09
from
wipe_out;
=09 other_node :=3D other.off_left.right;
until
other_node =3D other.off_right
loop
append(other_node.item);
other_node :=3D other_node.right;
end;
end;
Looks reasonable, doesn't it? But if `clone' calls it after doing a
bitwise copy of `other', then (as seen from inside `copy')
`Current.off_left' =3D `other.off_left' and `Current.off_right' =3D
`other.off_right', so `wipe_out' makes `other' empty.
Jacob
---
Jacob Gore, Eastern NM U. Jacob@BlackBox.ENMU.Edu | Jacob@ToolCASE.Com
Date: Mon, 24 Apr 95 21:43:52 PDT
From: bertrand@vienna.eiffel.com (Bertrand Meyer)
Subject: Erratum
To: NICE-Board@atlanta.twr.com
For the motion on PELKS I meant version 7, of course, not version 6.
Sorry for the typo.
-- BM
