ディレクトリを反復するためにboost/filesystemを使用しており、それらをMacOSX + XCode3のZipファイルに追加しています。
私の元のロジックは次のようになります
path targetDir( "Volumes/data/some_directory" );
directory_iterator it( targetDir ), eod;
std::string filename;
std::string strPath;
// I tried both of two types of making loop
for( ; it != eod ; ++it )
{
path const& p = *it;
filename = p.filename();
if( is_directory(p) )
{
strPath = strDirectory + filename + string("/");
// Initially I wanted this logic to be recursive(these code block is a part of PackDirectory)
PackDirectory( archive, strPath, lpszPackFile );
}
else if( is_regular_file(p) )
{
strPath = strDirectory + filename;
// add this file to specified Zip file here
}
}
then function returns here.
この関数を返した後、特に directory_iterator のデストラクタが呼び出されたときに問題が発生すると思います。無効なポインタを削除し、SIGABRT を受け取っているようです。以下のようにプログラムがクラッシュすることもあれば、ステップ オーバーを押すとフリーズすることもあります。そして要点は、ループ内で何もしなくても問題が残るということです。つまり、変数が単純に作成され、関数が返される場合です。
詳細については、プログラムがクラッシュしたときのコール スタックは次のようになります。
#0 0x93f86c5a in __kill
#1 0x93f86c4c in kill$UNIX2003
#2 0x940195a5 in raise
#3 0x9402f6e4 in abort
#4 0x93f2c575 in free
#5 0x00134aea in dir_itr_close [inlined] at v2_operations.cpp:1300
#6 0x00134aea in ~dir_itr_imp [inlined] at operations.hpp:877
#7 0x00134aea in checked_delete<boost::filesystem2::detail::dir_itr_imp<boost::filesystem2::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem2::path_traits> > > [inlined] at checked_delete.hpp:34
#8 0x00134aea in boost::detail::sp_counted_impl_p<boost::filesystem2::detail::dir_itr_imp<boost::filesystem2::basic_path<std::string, boost::filesystem2::path_traits> > >::dispose at v2_operations.cpp:78
#9 0x00136583 in boost::detail::sp_counted_base::weak_release at sp_counted_base_pt.hpp:97
~dir_itr_imp に入るので、型チェックをパスして正しいデストラクタにたどり着くようです。
directory_iterator で何か問題がありましたか? 誰かがこの問題を経験した場合は、私に知らせてください。