[PyKDE] could not pass std::list<...>&

elho eh1 at delair.de
Mon Oct 17 15:14:22 BST 2005


I got problems by passing an std::list by Value (and even if it was 
passed by Reference) to a c++-method. When I'm returning the list 
directly it works. (See the code below). What is going on there?

See the source below - the first is how to execute it:
________________________________________________________________________
##  ___  file: test.py  ___ ##
from crash import *

c = crash()
### c.ReturnIntList()
### ..with the line below it works! With out I got 'Segmentation fault'
c.GetIntList()
________________________________________________________________________
//  ___  file: crash.hh  ___ //
#include <list>
using namespace std;

class crash
{
public:
	static void GetIntList(list<int>& lInt);
	static list<int> ReturnIntList();
};
________________________________________________________________________
//  ___  file: crash.cc  ___ //
#include "crash.hh"

void crash::GetIntList(list<int>& lInt)
{
     lInt.push_back (1);
     lInt.push_back (2);
}

list<int> crash::ReturnIntList()
{
     list<int> lInt;
     lInt.push_back (1);
     lInt.push_back (2);
     return lInt;
}
________________________________________________________________________
//  ___  file: crash.sip  ___ //
%Module crash 1

class crash
{
%TypeHeaderCode
#include "crash.hh"
#include <iostream>
%End

public:
     void GetIntList ();
%MethodCode
         list<int>    listInt;
	crash::GetIntList(listInt);
	cout<<"__ crash::GetIntList  before__"<<endl;
	listInt.clear();
	cout<<"__ crash::GetIntList  afterwards__"<<endl;
%End

     void ReturnIntList();
%MethodCode
         list<int>    listInt;
	listInt = crash::ReturnIntList();
	cout<<"__ crash::ReturnIntList  before__"<<endl;
	listInt.clear();
	cout<<"__ crash::ReturnIntList  afterwards__"<<endl;
%End
};
________________________________________________________________________
##  ___  file: configure.py  ___ ##
import os
import sipconfig

# == Konstanten =======================================================
sipFileLocation     ="./sip"
build_file          ="crash.sbf"

# == configuration information ========================================
config = sipconfig.Configuration()
config.sip_inc_dir=os.environ["HOME"] + '/crash/'


# === Run SIP to generate the code ====================================
os.system(" ".join([config.sip_bin,
                 "-c", sipFileLocation,
                 "-b", sipFileLocation+"/"+build_file,
                 "crash.sip"]))


# == Makefile =========================================================
makefile = sipconfig.SIPModuleMakefile(
     configuration   =config,
     build_file      =build_file,
     dir             =sipFileLocation
)

makefile.extra_libs = [ "crash" ]
makefile.extra_lib_dirs=[ os.environ["HOME"] + "/crash" ]
makefile.extra_include_dirs=[ os.environ["HOME"] + "/crash" ]

# Generate the Makefile itself.
makefile.generate()




More information about the PyQt mailing list