Replace BOOST_TRY/CATCH family macros with BOOST_INTERPROCESS_TRY/CATCH

This commit is contained in:
Ion Gaztañaga
2024-08-03 22:37:11 +02:00
parent 1e28228d9c
commit 865573a821
11 changed files with 44 additions and 43 deletions

View File

@@ -37,7 +37,7 @@ int main ()
,"MySharedMemory" //name
,read_write //read-write mode
);
BOOST_TRY{
BOOST_INTERPROCESS_TRY{
//Set size
shm.truncate(sizeof(trace_queue));
@@ -72,10 +72,11 @@ int main ()
data->message_in = true;
}
}
BOOST_CATCH(interprocess_exception &ex){
BOOST_INTERPROCESS_CATCH(interprocess_exception &ex){
std::cout << ex.what() << std::endl;
return 1;
} BOOST_CATCH_END
}
BOOST_INTERPROCESS_CATCH_END
return 0;
}

View File

@@ -27,7 +27,7 @@ int main ()
,read_write //read-write mode
);
BOOST_TRY{
BOOST_INTERPROCESS_TRY{
//Map the whole shared memory in this process
mapped_region region
(shm //What to map
@@ -60,10 +60,10 @@ int main ()
}
while(!end_loop);
}
BOOST_CATCH(interprocess_exception &ex){
BOOST_INTERPROCESS_CATCH(interprocess_exception &ex){
std::cout << ex.what() << std::endl;
return 1;
} BOOST_CATCH_END
} BOOST_INTERPROCESS_CATCH_END
return 0;
}

View File

@@ -20,7 +20,7 @@ using namespace boost::interprocess;
int main ()
{
BOOST_TRY{
BOOST_INTERPROCESS_TRY{
//Remove shared memory on construction and destruction
struct shm_remove
{
@@ -71,10 +71,10 @@ int main ()
break;
}
}
BOOST_CATCH(interprocess_exception &ex){
BOOST_INTERPROCESS_CATCH(interprocess_exception &ex){
std::cout << ex.what() << std::endl;
return 1;
} BOOST_CATCH_END
} BOOST_INTERPROCESS_CATCH_END
return 0;
}
//]

View File

@@ -17,7 +17,7 @@ using namespace boost::interprocess;
int main ()
{
BOOST_TRY{
BOOST_INTERPROCESS_TRY{
//Erase previous message queue
message_queue::remove("message_queue");
@@ -34,10 +34,10 @@ int main ()
mq.send(&i, sizeof(i), 0);
}
}
BOOST_CATCH(interprocess_exception &ex){
BOOST_INTERPROCESS_CATCH(interprocess_exception &ex){
std::cout << ex.what() << std::endl;
return 1;
} BOOST_CATCH_END
} BOOST_INTERPROCESS_CATCH_END
return 0;
}

View File

@@ -17,7 +17,7 @@ using namespace boost::interprocess;
int main ()
{
BOOST_TRY{
BOOST_INTERPROCESS_TRY{
//Open a message queue.
message_queue mq
(open_only //only open
@@ -35,11 +35,11 @@ int main ()
return 1;
}
}
BOOST_CATCH(interprocess_exception &ex){
BOOST_INTERPROCESS_CATCH(interprocess_exception &ex){
message_queue::remove("message_queue");
std::cout << ex.what() << std::endl;
return 1;
} BOOST_CATCH_END
} BOOST_INTERPROCESS_CATCH_END
message_queue::remove("message_queue");
return 0;
}

View File

@@ -17,7 +17,7 @@
int main ()
{
using namespace boost::interprocess;
BOOST_TRY{
BOOST_INTERPROCESS_TRY{
//Create an anonymous shared memory segment with size 1000
mapped_region region(anonymous_shared_memory(1000));
@@ -26,10 +26,10 @@ int main ()
//The segment is unmapped when "region" goes out of scope
}
BOOST_CATCH(interprocess_exception &ex){
BOOST_INTERPROCESS_CATCH(interprocess_exception &ex){
std::cout << ex.what() << std::endl;
return 1;
} BOOST_CATCH_END
} BOOST_INTERPROCESS_CATCH_END
return 0;
}
//]

View File

@@ -31,14 +31,14 @@ int main ()
managed_heap_memory::handle_t list_handle = heap_memory.get_handle_from_address(mylist);
//Fill list until there is no more memory in the buffer
BOOST_TRY{
BOOST_INTERPROCESS_TRY{
while(1) {
mylist->insert(mylist->begin(), 0);
}
}
BOOST_CATCH(const bad_alloc &){
BOOST_INTERPROCESS_CATCH(const bad_alloc &){
//memory is full
} BOOST_CATCH_END
} BOOST_INTERPROCESS_CATCH_END
//Let's obtain the size of the list
MyList::size_type old_size = mylist->size();
//<-
@@ -55,14 +55,14 @@ int main ()
(heap_memory.get_address_from_handle(list_handle));
//Fill list until there is no more memory in the buffer
BOOST_TRY{
BOOST_INTERPROCESS_TRY{
while(1) {
mylist->insert(mylist->begin(), 0);
}
}
BOOST_CATCH(const bad_alloc &){
BOOST_INTERPROCESS_CATCH(const bad_alloc &){
//memory is full
} BOOST_CATCH_END
} BOOST_INTERPROCESS_CATCH_END
//Let's obtain the new size of the list
MyList::size_type new_size = mylist->size();

View File

@@ -43,7 +43,7 @@ int main ()
const std::size_t FileSize = 1000;
file_mapping::remove(FileName);
BOOST_TRY{
BOOST_INTERPROCESS_TRY{
MyList::size_type old_size = 0;
managed_mapped_file::handle_t list_handle;
{
@@ -55,14 +55,14 @@ int main ()
list_handle = mfile_memory.get_handle_from_address(mylist);
//Fill list until there is no more room in the file
BOOST_TRY{
BOOST_INTERPROCESS_TRY{
while(1) {
mylist->insert(mylist->begin(), 0);
}
}
BOOST_CATCH(const bad_alloc &){
BOOST_INTERPROCESS_CATCH(const bad_alloc &){
//mapped file is full
} BOOST_CATCH_END
} BOOST_INTERPROCESS_CATCH_END
//Let's obtain the size of the list
old_size = mylist->size();
}
@@ -80,14 +80,14 @@ int main ()
(mfile_memory.get_address_from_handle(list_handle));
//Fill list until there is no more room in the file
BOOST_TRY{
BOOST_INTERPROCESS_TRY{
while(1) {
mylist->insert(mylist->begin(), 0);
}
}
BOOST_CATCH(const bad_alloc &){
BOOST_INTERPROCESS_CATCH(const bad_alloc &){
//mapped file is full
} BOOST_CATCH_END
} BOOST_INTERPROCESS_CATCH_END
//Let's obtain the new size of the list
MyList::size_type new_size = mylist->size();
@@ -98,10 +98,10 @@ int main ()
return (new_size > old_size) ? 0 : 1;
}
}
BOOST_CATCH(...){
BOOST_INTERPROCESS_CATCH(...){
file_mapping::remove(FileName);
BOOST_RETHROW
} BOOST_CATCH_END
BOOST_INTERPROCESS_RETHROW
} BOOST_INTERPROCESS_CATCH_END
file_mapping::remove(FileName);
return 0;
}

View File

@@ -22,7 +22,7 @@
int main ()
{
using namespace boost::interprocess;
BOOST_TRY{
BOOST_INTERPROCESS_TRY{
struct file_remove
{
//<-
@@ -87,10 +87,10 @@ int main ()
file << std::endl;
}
}
BOOST_CATCH(interprocess_exception &ex){
BOOST_INTERPROCESS_CATCH(interprocess_exception &ex){
std::cout << ex.what() << std::endl;
return 1;
} BOOST_CATCH_END
} BOOST_INTERPROCESS_CATCH_END
return 0;
}
//]

View File

@@ -92,7 +92,7 @@ int main ()
//we destroy the object automatically
my_deleter<my_class> d(shmem.get_segment_manager());
BOOST_TRY{
BOOST_INTERPROCESS_TRY{
scoped_ptr<my_class, my_deleter<my_class> > s_ptr(my_object, d);
//Let's emulate a exception capable operation
//In the second try, throw an exception
@@ -104,7 +104,7 @@ int main ()
//to avoid destruction
s_ptr.release();
}
BOOST_CATCH(const my_exception &){} BOOST_CATCH_END
BOOST_INTERPROCESS_CATCH(const my_exception &){} BOOST_INTERPROCESS_CATCH_END
//Here, scoped_ptr is destroyed
//so it we haven't thrown an exception
//the object should be there, otherwise, destroyed

View File

@@ -23,14 +23,14 @@ using namespace boost::interprocess;
void remove_old_shared_memory(const xsi_key &key)
{
BOOST_TRY{
BOOST_INTERPROCESS_TRY{
xsi_shared_memory xsi(open_only, key);
xsi_shared_memory::remove(xsi.get_shmid());
}
BOOST_CATCH(interprocess_exception &e){
BOOST_INTERPROCESS_CATCH(interprocess_exception &e){
if(e.get_error_code() != not_found_error)
BOOST_RETHROW
} BOOST_CATCH_END
BOOST_INTERPROCESS_RETHROW
} BOOST_INTERPROCESS_CATCH_END
}
int main(int argc, char *argv[])