[pygccxml-development] Re : Call policy for a function returning a map
Brought to you by:
mbaas,
roman_yakovenko
From: Vincent F. <vin...@gm...> - 2008-07-30 15:00:28
|
Ok, thanks for your answear. With further investigations, I thing the cause of my problem comes from the non-call to the constructor when instanciating my class. Some variables are not initialized and then the program encounters problems to store datas in unreserved memory. (-> segmentations faults) I have the following constructor (I simpllify it a little) : dataBase::dataBase(void) : generic::dataBase() { try { // Just for debugging purpose cout << "Here we are in constructor!" << endl; properties.clear(); } catchAll("dataBase::dataBase(void)",""); } I didn't seem to go through it, the first log sentence was never printed. I've gone in the associated wrapper class and found this declaration for the constructor : struct dataBase_wrapper : postLib::nastran::dataBase, bp::wrapper< postLib::nastran::dataBase > { dataBase_wrapper( ) : postLib::nastran::dataBase( ) , bp::wrapper< postLib::nastran::dataBase >(){ // null constructor } It seems weird to me... According to me, the instanciation of the corresponding class in Python should instanciate the underneath class with its defined constructor... Is there a bug or am I missing something? Thanks again! 2008/7/30, Roman Yakovenko <rom...@gm...>: > On Wed, Jul 30, 2008 at 11:17 AM, Vincent Ferries > <vin...@gm...> wrote: >> I'm getting segmentation fault errors trying to replace data in a map. >> >> I've have the following attribute in my class : >> std::map<int,property> properties ; >> >> I get this map from a getter function with the following signature: >> map<int,property> & dataBase::getProperties(void) { >> return properties; >> } >> >> Then the method is called from another class in the C++ code : >> map<int,property> &target=DB.getProperties(); >> >> And I try to change data in it : >> target[tmpProperty.id]=tmpProperty; >> >> I get the segmentation fault at this line. >> The compiled C++ code is completely working alone, I allready tested it. >> I can load a file using one of my functions from C++ directly without >> any problem, but when I try to use this same function from Python, I >> get this segfault. >> >> I think the problem comes from a bad call policy fro this >> getProperties() function, but I'm not really sure. >> I'm currently using the following one : >> function.call_policies = >> call_policies.return_value_policy(call_policies.reference_existing_object) > > http://www.boost.org/doc/libs/1_35_0/libs/python/doc/v2/return_internal_reference.html > > In this case return_internal_reference should be used > > > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > |