[C++-sig] shared_ptr<> to Boost.Python wrapped object going out ofscope early?

Christopher Wicklein chrisw at wicklein.org
Mon Jun 16 19:27:21 CEST 2008


The code in my original post was missing the return type void.  The  
actual argument to onModify is something like a shared_ptr to a record  
owned by the library, but I meant to leave that vague since the  
onModify method is not and can not ever be called by the library  
because the library's weak_ptr to the observer has become invalid.

Something I neglected to mention before is that when I add printf  
statements to the destructors of Observer and ObserverWrap and even to  
the __del__ method of Watcher, I never see those messages displayed.   
The precise lifetime of the shared_ptr to my Observer wrapped through  
the instance watcher is not clear.

struct ObserverWrap : Observer, wrapper<Observer> {
     void onModify(Record record) { ... }
}

On Jun 16, 2008, at 10:57 AM, English, Mark wrote:

>> -----Original Message-----
>> From: c++-sig-bounces at python.org
>> [mailto:c++-sig-bounces at python.org] On Behalf Of Christopher Wicklein
>> Sent: 16 June 2008 16:43
>>
>> Python code above.  To fill things out a bit, here is the
>> Boost.Python statement used to wrap the Observer:
>>
>> class_<ObserverWrap, boost::noncopyable>("Observer")
>>    .def("onModify", pure_virtual(&Observer::onModify))
>> ;
>>
>> Here is the wrapper class:
>>
>> struct ObserverWrap : Observer, wrapper<Observer> {
>>    onModify(Record record) {
>> this->get_override("onModify")(record); } }
>>
>
> What is the function signature of "onModify()" ?
>
> Should the function signature be based around shared_ptr (I've also
> included a void return type) ?
> E.g.
> struct ObserverWrap : Observer, wrapper<Observer> {
> void onModify(shared_ptr<Record> record) {
> this->get_override("onModify")(record); } }
> _______________________________________________________________________
>

----
Christopher Wicklein <chrisw at wicklein.org>






More information about the Cplusplus-sig mailing list