boost::serialization и STLport совместимы?
От: _Winnie Россия C++.freerun
Дата: 29.06.04 00:20
Оценка:
при совместном использовании boost::serialization и STLport непонятная ошибка

При компиляции возникает ошибка (в коде я отметил, где именно)
c:\data\boost\include\boost-1_31\boost\archive\add_facet.hpp(44): //заметьте, строка 44, а не 17. 
error C3861: '_Addfac': identifier not found, even with argument-dependent lookup


Если же закоментировать вот это

// does STLport uses native STL for locales?
#if (defined _STLPORT_VERSION) && !(defined _STLP_USE_NO_IOSTREAMS)
// and this native STL lib is old Dinkumware (has not defined _CPPLIB_VER)
#  if (defined _YVALS) && !(defined __IBMCPP__)
#    define BOOST_ARCHIVE_OLD_DINKUMWARE_BENEATH_STLPORT
#  endif
#endif


или сделать #undef
#undef BOOST_DINKUMWARE_STDLIB
#undef BOOST_ARCHIVE_OLD_DINKUMWARE_BENEATH_STLPORT


то программа крашится в _fstream.c стл-порта
Unhandled exception at 0xeef9cc87 in test.exe: 0xC0000005: Access violation reading location 0xeef9cc87.


файл _fstream.c из STLport


  // Put __c at the end of the internal buffer.
  if (!traits_type::eq_int_type(__c, traits_type::eof()))
    *__iend++ = __c;

  // For variable-width encodings, output may take more than one pass.
  while (__ibegin != __iend) {
    const _CharT* __inext = __ibegin;
    char* __enext         = _M_ext_buf;
    typename _Codecvt::result __status
      = _M_codecvt->out(_M_state, __ibegin, __iend, __inext,
                                  _M_ext_buf, _M_ext_buf_EOS, __enext);
    if (__status == _Codecvt::noconv)  <----------------------------------------вот здесь чтение из какого-то ненулевого мусорного указателя
      return _Noconv_output<_Traits>::_M_doit(this, __ibegin, __iend)
        ? traits_type::not_eof(__c)
        : _M_output_error();




мой код


#include <fstream>

#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>

void main() 
{
  std::string x1, x2;

  x1= "w";

  {
    std::ofstream ofs("filename", std::ios::binary);
    boost::archive::binary_oarchive(ofs)&x1;
  } <----------------------------------------------------- вот на этой скобке программа падает. в предыдущем куске кода показано 
где именно.

  {
    std::ifstream ifs("filename", std::ios::binary);
    boost::archive::binary_iarchive(ifs)&x2;
  }

  assert(x1 == x2);
}


кнопочку clean/rebuild уже нажимал. для компиляции jam не использовал, просто добавил все .cpp из библиотеки к себе в проект.
При использовании STL из vc71 никаких проблем нет ни при компиляции, ни при выполнении.


Это c:\data\boost\include\boost-1_31\boost\archive\add_facet.hpp целиком.

#ifndef BOOST_ARCHIVE_ADD_FACET_HPP
#define BOOST_ARCHIVE_ADD_FACET_HPP


/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// add_facet.hpp

// (C) Copyright 2003 Robert Ramey - http://www.rrsd.com . 
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

//  See http://www.boost.org for updates, documentation, and revision history.

#include <locale>
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>

// does STLport uses native STL for locales?
#if (defined _STLPORT_VERSION) && !(defined _STLP_USE_NO_IOSTREAMS)
// and this native STL lib is old Dinkumware (has not defined _CPPLIB_VER)
#  if (defined _YVALS) && !(defined __IBMCPP__)
#    define BOOST_ARCHIVE_OLD_DINKUMWARE_BENEATH_STLPORT
#  endif
#endif 

namespace boost { 
namespace archive {

template<class Facet>
inline std::locale * 
add_facet(const std::locale &l, Facet * f){
    return
        #if defined BOOST_ARCHIVE_OLD_DINKUMWARE_BENEATH_STLPORT 
            #if (defined _STLP_USE_OWN_NAMESPACE) && !(defined _STLP_NO_IMPORT_LOCALE)
                // namespace was relocated
                #ifndef _STLP_NEW_IO_NAMESPACE
                #  error Unhandled STLport configuration - please change code and report problem
                #endif


// Вот здесь ошибка компиляции!!!
//c:\data\boost\include\boost-1_31\boost\archive\add_facet.hpp(44): 
//error C3861: '_Addfac': identifier not found, even with argument-dependent lookup


                new std::locale(_STLP_NEW_IO_NAMESPACE::_Addfac(l, f)); 
            #else
                // std namespace used for native locale
                new std::locale(std::_Addfac(l, f));
            #endif 
        #elif BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) // old Dinkumware
            new std::locale(std::_Addfac(l, f));
        #else
            // standard compatible
            new std::locale(l, f);
        #endif
}

} // namespace archive
} // namespace boost

#undef BOOST_ARCHIVE_OLD_DINKUMWARE_BENEATH_STLPORT

#endif // BOOST_ARCHIVE_ADD_FACET_HPP




А вот так вообще не компилируется:


#include <fstream>

#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>

void main() 
{
  std::string x1, x2;

  x1= "w";

  {
    std::ofstream ofs("filename");
    boost::archive::text_oarchive(ofs)&x1;
  } //<- вот на этой скобке программа падает.

  {
    std::ifstream ifs("filename");
    boost::archive::text_iarchive(ifs)&x2;
  }

  assert(x1 == x2);
}

unresolved external symbol "protected: virtual int __thiscall _STL::codecvt::do_length(int const
unresolved external symbol "protected: virtual bool __thiscall _STL::codecvt::do_always_noconv(v
unresolved external symbol "protected: virtual enum _STL::codecvt_base::result __thiscall _STL::
unresolved external symbol "protected: virtual int __thiscall _STL::codecvt::do_max_length(void)
unresolved external symbol "protected: virtual int __thiscall _STL::codecvt::do_encoding(void)co
unresolved external symbol "protected: virtual enum _STL::codecvt_base::result __thiscall _STL::
unresolved external symbol "protected: virtual enum _STL::codecvt_base::result __thiscall _STL::
unresolved external symbol "protected: virtual __thiscall _STL::codecvt::~codecvt(void)" (??1?$c
unresolved external symbol "public: static class _STL::locale::id _STL::numpunct::id" (?id@?$num
unresolved external symbol "public: static class _STL::locale::id _STL::ctype::id" (?id@?$ctype@
unresolved external symbol "public: static class _STL::locale::id _STL::codecvt::id" (?id@?$code



ох уж эти потоковый ввод-вывод, такой сложный... и столько проблем создает. Неужели что бы написать std::cout <<"hello, world" по-японски нужна такая нечитабельная гора кода. ведь то, что сложно, то ненадежно Запихнули интернационализацию, форматирование текста, и буфферизиванный ввод-вывод в одну кучу, теперь сидим и кушаем.
И нафиг все мне эти фасеты и локали, если мне нужно просто бинарник записать... тоже мне блин null-overhead принцип ((

Приму бубен в хорошие руки. Можно с мемориликами.
Правильно работающая программа — просто частный случай Undefined Behavior
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.