[aspectc-user] reset tjp->that()?
Michael Gong
mwgong at cs.utoronto.ca
Sun Dec 10 04:28:12 CET 2006
"pass-by-value" is fine, because you might pass the value of a pointer,
and deference it inside the advice body.
Just for you information, AspectC ( not AspectC++) has a mechansim to
expose the address of a function parameter to the advice body, like:
before(int * p): args(*p) && call(void foo(int)) {
<-- p will have the address of the parameter
passed to foo
*p = 3; <-- this will actually change the value of the
parameter passed to foo
}
before(int p): args(p) && call(void foo(int)) {
<-- p will have the value of the parameter
passed to foo
p = 3; <-- this will NOT change the value of the parameter
passed to foo
}
I am not sure whether AspectC++ could do that or not.
Anyway, it is an interesting problem.
Regards,
Mike
----- Original Message -----
From: "Yan Mao" <maoyan at gmx.net>
To: "Michael Gong" <mwgong at cs.toronto.edu>
Cc: <aspectc-user at aspectc.org>
Sent: Saturday, December 09, 2006 4:40 PM
Subject: Re: Re: Re: [aspectc-user] reset tjp->that()?
> Hello Mike,
>
> just as Daniel said, AC++ use pass-by-value in advice body, then it is
> hard to change the object pointer. Maybe it's a inveterate problem?
> Although I would like to use AC++ to do something with those pointers.
>
> Regards,
>
> Yan
>
>
> -------- Original-Nachricht --------
> Datum: Sat, 9 Dec 2006 13:24:08 -0500
> Von: "Michael Gong" <mwgong at cs.utoronto.ca>
> An: "Yan Mao" <maoyan at gmx.net>, "Daniel Lohmann"
> <daniel.lohmann at informatik.uni-erlangen.de>
> Betreff: Re: Re: [aspectc-user] reset tjp->that()?
>
>> Hi, Daniel & Yan,
>>
>> It brings an interesting question.
>>
>> The template works fine for this case.
>>
>> > I am afraid what you are trying to achieve is not possible.
>> > // Template, works for any class that offers a Release() method
>> > template< class T > void Release( T*& _this ) {
>> > _this->Release(); // destroy
>> > _this = 0; // invalidate
>> > }
>> >
>>
>> But how about I want to do the "invalidation" for method "Release2" ,
>> "Release3", or etc ? Using template, you might have :
>>
>> template< class T > void Release2( T*& _this ) {
>> _this->Release2(); // destroy
>> _this = 0; // invalidate
>> }
>>
>> template< class T > void Release3( T*& _this ) {
>> _this->Release3(); // destroy
>> _this = 0; // invalidate
>> }
>>
>> ...
>>
>>
>> Looks familiar ? :-)
>>
>> It is typical crosscutting concern, I think.
>>
>> Since AOP is targeted to modularize crosscutting concern, can it be
>> used
>> for this case ? More specifically, can AspectC++ capture it ?
>>
>> Regards,
>>
>> Mike
>>
>>
>>
>> ----- Original Message -----
>> From: "Yan Mao" <maoyan at gmx.net>
>> To: "Daniel Lohmann" <daniel.lohmann at informatik.uni-erlangen.de>
>> Cc: <aspectc-user at aspectc.org>
>> Sent: Saturday, December 09, 2006 11:18 AM
>> Subject: Re: Re: [aspectc-user] reset tjp->that()?
>>
>>
>> Hello Daniel,
>>
>> thank for the explation, it's very helpful.
>>
>> regards,
>>
>> Yan Mao
>>
>>
>>
>> -------- Original-Nachricht --------
>> Datum: Fri, 08 Dec 2006 17:06:02 +0100
>> Von: Daniel Lohmann <daniel.lohmann at informatik.uni-erlangen.de>
>> An: aspectc-user at aspectc.org
>> Betreff: Re: [aspectc-user] reset tjp->that()?
>>
>> > Hi Yan,
>> >
>> > I am afraid what you are trying to achieve is not possible.
>> >
>> > > //the C++ code
>> > > ClassA *p = new ClassA();
>> > > p->DoSomething();
>> > > p->Release();
>> > > //now i want to set p=NULL with AOP
>> >
>> > In C++ the object instance pointer (this) is always passed
>> > by-value.
>> > Technically, it is passed as a "hidden" first parameter:
>> >
>> > class A {
>> > void Release();
>> > };
>> >
>> > becomes (technically) something such as
>> >
>> > void ClassA::Release( ClassA* this ) {
>> > // this is by-value parameter
>> > }
>> >
>> > The object reference inside some method (this) is a copy of the
>> > original
>> > parameter. The same holds for the value returned by tjp->that()
>> > in
>> > advice code, it is another value copy of the originally passed
>> > instance
>> > pointer. It is not possible to affect the "original" from advice
>> > code.
>> >
>> > Side node:
>> > The common C++ idiom to invalidate the reference when destroying an
>> > instance is to use a non-member function:
>> >
>> > // Template, works for any class that offers a Release() method
>> > template< class T > void Release( T*& _this ) {
>> > _this->Release(); // destroy
>> > _this = 0; // invalidate
>> > }
>> >
>> > //the C++ code
>> > ClassA *p = new ClassA();
>> > p->DoSomething();
>> > Release(p);
>> > // now p == 0
>> >
>> >
>> > Daniel
>>
>> --
>> "Ein Herz für Kinder" - Ihre Spende hilft! Aktion:
>> www.deutschlandsegelt.de
>> Unser Dankeschön: Ihr Name auf dem Segel der 1. deutschen America's
>> Cup-Yacht!
>> _______________________________________________
>> aspectc-user mailing list
>> aspectc-user at aspectc.org
>> http://www.aspectc.org/mailman/listinfo/aspectc-user
>
> --
> "Ein Herz für Kinder" - Ihre Spende hilft! Aktion:
> www.deutschlandsegelt.de
> Unser Dankeschön: Ihr Name auf dem Segel der 1. deutschen America's
> Cup-Yacht!
>
More information about the aspectc-user
mailing list