[C++-sig] I want to solve the Py_Finalize problem.
Podpruzhnikov Yuri
ypodpruzhnikov at mcode.ru
Mon Apr 9 17:37:51 CEST 2007
If I correctly understood the Py_Finalize problem
there was the way of solving the problem which already had been
implemented and more or less tested.
But I don't know some static and global variables in Boost.Python which
should be corrected.
That's why I have a request: Please, anyone, who knows Boost very much
tell me what I should change.
The decision is quite simple:
I've created class-wrapper TStaticSmartPtr
Actually, it implements two methods GetPtr and SetPtr
TStaticSmartPtr makes possible following features:
1) it wraps absolutely any objects
2) on finalization of Python interpreter all wrapped objects will be
automatically deleted (calling destructor)
3) it allows every Interpretter to have it own value of wrapped object,
it's something like the Interpreter Local Storage (ILS)
Note: there won't be any changes in the Python library!!!
//------------------------------------------------------------
// Using Example(wrap static object with type SomeType):
//------------------------------------------------------------
SomeType* GetSomeType()
{
static TStaticSmartPtr<SomeType> StaticPtr; // My class
SomeType* LocalPtr; // local pointer to object
if(!StaticPtr.GetPtr(&LocalPtr)) // Get pointer from ILS
{
// If pointer is not set - Create new Object
LocalPtr = new SomeType();
LocalPtr->SomeInitialize();
StaticPtr.SetPtr(LocalPtr);
}
// Work with object
LocalPtr->SomeAction();
return LocalPtr;
}
//------------------------------------------------------------
place for intialize data:
if(!StaticPtr.GetPtr(&LocalPtr)) // Get pointer from ILS
{
...
}
place for finalize data:
destructor of SomeType
PS:
If I don't understand the exact reason of the Py_Finalize problem, so
tell me what it is, please!!!
PPS:
Sorry for my English
More information about the Cplusplus-sig
mailing list