2013-03-27 2 views
1

J'essaie de compiler un code Boost Interprocess vers un environnement qui n'a pas d'implémentations pour les fonctions wchar telles que wcslen et wmemset.Comment empêcher Boost.Interprocess d'utiliser wchar?

Voici mon code:

#define BOOST_NO_CWCHAR 
#define BOOST_NO_CWCTYPE 
#define BOOST_NO_CTYPE_FUNCTIONS 
#define BOOST_NO_INTRINSIC_WCHAR_T 
#define BOOST_NO_STD_WSTREAMBUF 
#define BOOST_NO_STD_WSTRING 
#define BOOST_NO_CHAR32_T 
#define BOOST_NO_CHAR16_T 
#define BOOST_NO_CXX11_CHAR16_T 
#define BOOST_NO_CXX11_CHAR32_T 
#define BOOST_NO_UNICODE_LITERALS 

#define BOOST_DATE_TIME_NO_LIB 
#define BOOST_ALL_NO_LIB 
//#define BOOST_INTERPROCESS_POSIX_PROCESS_SHARED 
//#define BOOST_INTERPROCESS_POSIX_TIMEOUTS 
//#define BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK 
#define BOOST_HAS_GETTIMEOFDAY 
#define CGAL_HAS_NO_THREADS -U__GNUG__ 
#define BOOST_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY 
#define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS 



#include <boost/interprocess/managed_external_buffer.hpp> 
#include <boost/interprocess/allocators/allocator.hpp> 
#include <boost/interprocess/containers/list.hpp> 
#include <cstring> 
#include <boost/aligned_storage.hpp> 

using namespace boost::interprocess; 

//Alias an integer node allocator type 
//This allocator will allocate memory inside the static buffer 
typedef allocator<int, wmanaged_external_buffer::segment_manager> 
    allocator_t; 

//Alias a STL compatible list to be constructed in the static buffer 
typedef list<int, allocator_t> MyBufferList; 


void processWork(char *data, int size) 
{ 
    const int localSize = 65536; 
    static boost::aligned_storage<localSize>::type static_buffer2; 
    std::memcpy(&static_buffer2, data, localSize); 

    wmanaged_external_buffer objects_in_static_memory2 
     (open_only, &static_buffer2, localSize); 

    //Check that "MyList" has been duplicated in the second buffer 
    MyBufferList *list = objects_in_static_memory2.find<MyBufferList>(L"MyList").first; 
    std::cout << list->front(); 

    **objects_in_static_memory2.destroy<MyBufferList>(L"MyList");** 

} 

int main() 
{ 
    std::cout << "Starting"; 

    //Create the static memory who will store all objects 
    const int memsize = 65536; 

    static boost::aligned_storage<memsize>::type static_buffer; 

    //This managed memory will construct objects associated with 
    //a wide string in the static buffer 
    wmanaged_external_buffer objects_in_static_memory 
     (create_only, &static_buffer, memsize); 

    //We optimize resources to create 100 named objects in the static buffer 
    objects_in_static_memory.reserve_named_objects(100); 



    //The list must be initialized with the allocator 
    //All objects created with objects_in_static_memory will 
    //be stored in the static_buffer! 
    MyBufferList *list = objects_in_static_memory.construct<MyBufferList>(L"MyList") 
          (objects_in_static_memory.get_segment_manager()); 


    list->push_back(624); 
    processWork((char*)static_buffer.address(), memsize); 
    objects_in_static_memory.destroy<MyBufferList>(L"MyList"); 

    return 0; 
} 

Les appels avec L "MyList" dans les précipiter un appel coup de pouce à /interprocess/segment_manager.cpp:

index_it it = index.find(key_type (name, std::char_traits<CharT>::length(name))); 

Et qui essaie d'appeler wcslen dans libcxx/string, c'est ce que j'essaie d'éviter.

J'ai essayé d'enlever le 'L' du nom de tampon, mais alors il se plaint que l'argument n'est pas wchar. Tout conseil sur la façon de supprimer cette dépendance wchar plus apprécié - les macros que j'ai définies ne semblent malheureusement pas faire l'affaire.

J'utilise

Marcos

+0

Ahhh. C'était ça. Être un dufuss et en utilisant wmanaged_external_buffer au lieu de managed_external_buffer –

Répondre

4

wmanaged_external_buffer est un typedef pour basic_managed_external_buffer<wchar_t>, tout comme std::wstring est un typedef pour std::basic_string<wchar_t> les tous derniers Boost (pas ceux sur mon système). Vous devez utiliser managed_external_buffer (ou basic_managed_external_buffer<char> directement).

+0

+1 vient de courir dans la même conclusion. – WhozCraig

+0

C'est de ma faute si j'ai simplement copié et collé l'exemple ici: http://www.boost.org/doc/libs/1_53_0/doc/html/interprocess/managed_memory_segments.html#interprocess.managed_memory_segments.managed_heap_memory_external_buffer.managed_external_buffer –

Questions connexes