[Trilinos-Users] Teuchos::RCP behavior

Villa Andrea (RSE) Andrea.Villa at rse-web.it
Fri May 10 08:12:19 MDT 2013


At page 68 of "Teuchos C++ Memory Management Classes, Idioms , and Related Topics" I think that the same problem is treated.
As I have understood the built-in debug mode should identify this dangling reference...

AV


-----Original Message-----
From: Holger Brandsmeier [mailto:holger.brandsmeier at sam.math.ethz.ch]
Sent: Fri 5/10/2013 3:36 PM
To: Villa Andrea (RSE)
Cc: trilinos-users at software.sandia.gov
Subject: Re: [Trilinos-Users] Teuchos::RCP behavior
 
Enabling:
>> -D Teuchos_ENABLE_DEBUG:BOOL=ON
>> -D Teuchos_ENABLE_DEBUG_RCP_NODE_TRACING:BOOL=ON
Does not give you an "internal" Debugger. You should use `valgrind`
for that. If you use an RCP and some other class outside of RCP is
deleting the underlying object, then trilinos has no way to warn you
about it. You likely will get an segfault.

`rcpFromRef` is a dangerous function. You should really be sure that
the reference you generate stays alive longer than the RCP. If not you
are in trouble and there is nothing that Trilinos can do about it.

I am not an expert on those debug settings, they mostly help you to
see if an RCP is deleted not at all (still alive when trilinos exits)
and for some protections using weak RCPs. Plus I need to go for Tennis
now ;-)

-Holger

On Fri, May 10, 2013 at 3:26 PM, Villa Andrea (RSE)
<Andrea.Villa at rse-web.it> wrote:
> In fact I was triggering a serious trouble to see whether the internal
> debugger can recognize it.
> How to activate the run-time debugging mode?
> Only making Trilinos with
>
>
>> -D Teuchos_ENABLE_DEBUG:BOOL=ON
>> -D Teuchos_ENABLE_DEBUG_RCP_NODE_TRACING:BOOL=ON
>
> ?
>
> Thanks.
> Andrea.
>
>
>
>
> -----Original Message-----
> From: Holger Brandsmeier [mailto:holger.brandsmeier at sam.math.ethz.ch]
> Sent: Fri 5/10/2013 3:24 PM
> To: Villa Andrea (RSE)
> Cc: trilinos-users at software.sandia.gov
> Subject: Re: [Trilinos-Users] Teuchos::RCP behavior
>
> Andrea,
>
> indeed you are running in serious trouble here ...
>
>> void assign(Teuchos::RCP<UInt> & P)
>> {
>>   UInt i = 4;
>>   P = Teuchos::rcpFromRef(i);
>>   cout << *P << endl;
>> }
> So you generate a class i of type "UInt" and P is a pointer on that
> piece of memory. Once `assign` exists `i` is deleted and `P` referes
> to invalid memory. This is bad.
>
> Why don't you do:
> void assign(Teuchos::RCP<UInt> & P)
> {
>    UInt* i = new UInt();
>    *i = 4;
>    P = Teuchos::rcp(i);
>    cout << *P << endl;
>  }
>
> Or at least tell us what you try to achieve.
>
> -Holger
>
>
> On Fri, May 10, 2013 at 3:15 PM, Villa Andrea (RSE)
> <Andrea.Villa at rse-web.it> wrote:
>>
>> I've implemented a very simple test code:
>>
>> void assign(Teuchos::RCP<UInt> & P)
>> {
>>   UInt i = 4;
>>   P = Teuchos::rcpFromRef(i);
>>   cout << *P << endl;
>> }
>>
>> int main(int argc, char *argv[])
>> {
>>   Teuchos::RCP<UInt> P;
>>   assign(P);
>>
>>   cout << *P << endl;
>>   cout << "count: " << P.total_count() << endl;
>> }
>>
>> I think that this is a non-correct usage of the RCP class, since a
>> temporary
>> reference is passed to P. In fact I get the following output:
>>
>> 4
>> 0
>> count: 1
>>
>> However even I have built Trilinos using
>> -D Teuchos_ENABLE_DEBUG:BOOL=ON \
>> -D Teuchos_ENABLE_DEBUG_RCP_NODE_TRACING:BOOL=ON \
>> no exception is thrown. Am I missing something?
>>
>> Thank you very much.
>> Andrea Villa.
>>
>>
>> RSE SpA ha adottato il Modello Organizzativo ai sensi del D.Lgs.231/2001,
>> in
>> forza del quale l'assunzione di obbligazioni da parte della Società
>> avviene
>> con firma di un procuratore, munito di idonei poteri. RSE adopts a
>> Compliance Programme under the Italian Law (D.Lgs.231/2001). According to
>> this RSE Compliance Programme, any commitment of RSE is taken by the
>> signature of one Representative granted by a proper Power of Attorney.
>>
>> Le informazioni contenute in questo messaggio di posta elettronica sono
>> riservate e confidenziali e ne e' vietata la diffusione in qualsiasi modo
>> o
>> forma. Qualora Lei non fosse la persona destinataria del presente
>> messaggio,
>> La invitiamo a non diffonderlo e ad eliminarlo, dandone gentilmente
>> comunicazione al mittente. The information included in this e-mail and any
>> attachments are confidential and may also be privileged. If you are not
>> the
>> correct recipient, you are kindly requested to notify the sender
>> immediately, to cancel it and not to disclose the contents to any other
>> person.
>>
>> _______________________________________________
>> Trilinos-Users mailing list
>> Trilinos-Users at software.sandia.gov
>> http://software.sandia.gov/mailman/listinfo/trilinos-users
>>
>
>
>
> --
> Holger Brandsmeier, SAM, ETH Zürich
> http://www.sam.math.ethz.ch/people/bholger
>
>
> RSE SpA ha adottato il Modello Organizzativo ai sensi del D.Lgs.231/2001, in
> forza del quale l'assunzione di obbligazioni da parte della Società avviene
> con firma di un procuratore, munito di idonei poteri. RSE adopts a
> Compliance Programme under the Italian Law (D.Lgs.231/2001). According to
> this RSE Compliance Programme, any commitment of RSE is taken by the
> signature of one Representative granted by a proper Power of Attorney.
>
> Le informazioni contenute in questo messaggio di posta elettronica sono
> riservate e confidenziali e ne e' vietata la diffusione in qualsiasi modo o
> forma. Qualora Lei non fosse la persona destinataria del presente messaggio,
> La invitiamo a non diffonderlo e ad eliminarlo, dandone gentilmente
> comunicazione al mittente. The information included in this e-mail and any
> attachments are confidential and may also be privileged. If you are not the
> correct recipient, you are kindly requested to notify the sender
> immediately, to cancel it and not to disclose the contents to any other
> person.



-- 
Holger Brandsmeier, SAM, ETH Zürich
http://www.sam.math.ethz.ch/people/bholger


RSE SpA ha adottato il Modello Organizzativo ai sensi del D.Lgs.231/2001, in forza del quale l'assunzione di obbligazioni da parte della Società avviene con firma di un procuratore, munito di idonei poteri.
RSE adopts a Compliance Programme under the Italian Law (D.Lgs.231/2001). According to this RSE Compliance Programme, any commitment of RSE is taken by the signature of one Representative granted by a proper Power of Attorney. Le informazioni contenute in questo messaggio di posta elettronica sono riservate e confidenziali e ne e' vietata la diffusione in qualsiasi modo o forma. Qualora Lei non fosse la persona destinataria del presente messaggio, La invitiamo a non diffonderlo e ad eliminarlo, dandone gentilmente comunicazione al mittente. The information included in this e-mail and any attachments are confidential and may also be privileged. If you are not the correct recipient, you are kindly requested to notify the sender immediately, to cancel it and not to disclose the contents to any other person.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://software.sandia.gov/pipermail/trilinos-users/attachments/20130510/353f30e7/attachment.html 


More information about the Trilinos-Users mailing list