Re: Bug on references under OS>8
Re: Bug on references under OS>8
- Subject: Re: Bug on references under OS>8
- From: Axel Luttgens <email@hidden>
- Date: Thu, 13 Sep 2001 09:32:13 +0200
- Organization: ---
Emmanuel wrote :
>
I know that much has been posted on this topic, that I did not thoroughly
>
read, so I present my apologies in advance for stating the obvious - yet,
>
thanks in advance for pointing me to some information on the subject.
My apologies too, should I not have correctly understood your query.
The latest posts to this list I remember of are dated june 2001; if I'm
correct, they all have the string "reference to" in their subject.
In summary, they tend to let appear that references may be made only to
entities that have a global scope in the script (global variables, scripts
properties, top-level script objects properties).
With one (the only one?) exception to that rule:
on f(P)
script S
property Prp : P
end script
return a reference to S's Prp
end f
on g()
set X to f("abc")
set Y to f("abc")
log contents of X = contents of Y
log X = Y
end g
g()
--> true
--> false
Hmm... either a script object is always a global entity (even an implicit,
un-named one), with its permanent and correctly handled memory allocation,
or...
(would be happy to have a correct explanation of what's internally happening)
>
-----------------------
>
on TestRef(theRef)
>
item 1 of (get contents of theRef)
>
end TestRef
>
>
set theVar to {"it works"}
>
set theRef to a reference to theVar
>
TestRef(theRef)
>
>
-- "it works"
>
-----------------------
So, this works because 'theVar' is a global variable...
>
-----------------------
>
on TestRef(theRef)
>
item 1 of (get contents of theRef)
>
end TestRef
>
>
on Testit()
>
set theVar to {"it works"}
>
set theRef to a reference to theVar
>
TestRef(theRef)
>
end Testit
>
>
Testit()
>
>
-- error -1700 in SE "could not make the data into the expected type"
>
-- error -1700 as applet
>
-- error -1728 in Smile "could not get theVar"
>
-----------------------
... and this won't because 'theVar' is a local variable.
>
(error messages may differ: the above are translations from French)
>
>
This is bug, since the programmer expects "theRef" to contain a reference
>
to the very variable "theVar of the Testit() handler". Instead, it contains
>
a very virtual and very dangerous reference to "theVar of whatever is
>
around as a context".
Huho... so, such references would be usable?
Moreover, in a potentially dangerous way?
Could you show examples?
>
I insist that the transmission of references worked flawlessly before AS
>
1.4.3. Some handler ("ExtractScriptFromLine") in one of the important
>
scripts of Smile, used to change the contents of a list that was passed as
>
the argument. It got broken (and re-written, now returning the changed
>
list) since 1.4.3.
Do you mean that references to a handler's local variables used in another
handler worked before AS 1.4.3? As in your second example script?
I really didn't remember of that (instead, I thought remember of just
unsuccessful trials in that direction... but time has passed, and workstations
and AS versions with it...).
If relevant and not too long, could you post the "not re-written" version of
the 'ExtractScriptFromLine' handler? I'm really curious.
TIA