@@ -285,7 +285,7 @@ class segment_manager_base
285
285
void *ptr_struct = this ->allocate_aligned (block_info.total_size (), table.alignment , nothrow<>::get ());
286
286
if (!ptr_struct){
287
287
return ipcdetail::null_or_bad_alloc<void >(dothrow);
288
- }
288
+ }
289
289
290
290
// Build scoped ptr to avoid leaks with constructor exception
291
291
ipcdetail::mem_algo_deallocator<MemoryAlgorithm> mem (ptr_struct, *this );
@@ -298,7 +298,7 @@ class segment_manager_base
298
298
// Now call constructors
299
299
table.construct_n (ptr, num);
300
300
301
- // All constructors successful, we don't want erase memory
301
+ // All constructors successful, disable rollback
302
302
mem.release ();
303
303
return ptr;
304
304
}
@@ -315,7 +315,7 @@ class segment_manager_base
315
315
// scoped_lock<rmutex> guard(m_header);
316
316
// -------------------------------
317
317
318
- // This is not an anonymous object, the pointer is wrong!
318
+ // This is not an anonymous object, the pointer is wrong!
319
319
BOOST_ASSERT (ctrl_data->alloc_type () == anonymous_type);
320
320
321
321
// Call destructors and free memory
@@ -1061,7 +1061,7 @@ class segment_manager
1061
1061
IndexType<ipcdetail::index_config<CharT, MemoryAlgorithm> > &index, ipcdetail::true_ is_intrusive)
1062
1062
{
1063
1063
(void )is_intrusive;
1064
- std::size_t namelen = std::char_traits<CharT>::length (name);
1064
+ std::size_t namelen = std::char_traits<CharT>::length (name);
1065
1065
1066
1066
block_header_t block_info ( size_type (table.size *num)
1067
1067
, size_type (table.alignment )
@@ -1112,34 +1112,21 @@ class segment_manager
1112
1112
if (try2find){
1113
1113
return it->get_block_header ()->value ();
1114
1114
}
1115
- if (dothrow){
1116
- throw interprocess_exception (already_exists_error);
1117
- }
1118
- else {
1119
- return 0 ;
1120
- }
1115
+ return ipcdetail::null_or_already_exists<void >(dothrow);
1121
1116
}
1122
1117
1123
1118
// Allocates buffer for name + data, this can throw (it hurts)
1124
- void *buffer_ptr;
1119
+ void *buffer_ptr = this ->allocate
1120
+ (block_info.template total_size_with_header <intrusive_value_type>(), nothrow<>::get ());
1125
1121
1126
1122
// Check if there is enough memory
1127
- if (dothrow){
1128
- buffer_ptr = this ->allocate
1129
- (block_info.template total_size_with_header <intrusive_value_type>());
1130
- }
1131
- else {
1132
- buffer_ptr = this ->allocate
1133
- (block_info.template total_size_with_header <intrusive_value_type>(), nothrow<>::get ());
1134
- if (!buffer_ptr)
1135
- return 0 ;
1136
- }
1123
+ if (!buffer_ptr)
1124
+ return ipcdetail::null_or_bad_alloc<void >(dothrow);
1137
1125
1138
1126
// Now construct the intrusive hook plus the header
1139
1127
intrusive_value_type * intrusive_hdr = ::new (buffer_ptr, boost_container_new_t ()) intrusive_value_type ();
1140
- block_header_t * hdr = ::new (intrusive_hdr->get_block_header (), boost_container_new_t ())block_header_t (block_info);
1141
- void *ptr = 0 ; // avoid gcc warning
1142
- ptr = hdr->value ();
1128
+ block_header_t * hdr = ::new (intrusive_hdr->get_block_header (), boost_container_new_t ()) block_header_t (block_info);
1129
+ void *ptr = hdr->value ();
1143
1130
1144
1131
// Copy name to memory segment and insert data
1145
1132
CharT *name_ptr = static_cast <CharT *>(hdr->template name <CharT>());
@@ -1229,15 +1216,13 @@ class segment_manager
1229
1216
1230
1217
index_it it = insert_ret.first ;
1231
1218
1232
- // If found and this is find or construct, return data
1233
- // else return null
1219
+ // If found and this is find or construct, return data, error otherwise
1234
1220
if (!insert_ret.second ){
1235
1221
if (try2find){
1236
- block_header_t *hdr = static_cast <block_header_t *>
1237
- (ipcdetail::to_raw_pointer (it->second .m_ptr ));
1222
+ block_header_t *hdr = static_cast <block_header_t *>(ipcdetail::to_raw_pointer (it->second .m_ptr ));
1238
1223
return hdr->value ();
1239
1224
}
1240
- return 0 ;
1225
+ return ipcdetail::null_or_already_exists< void >(dothrow) ;
1241
1226
}
1242
1227
// Initialize the node value_eraser to erase inserted node
1243
1228
// if something goes wrong
@@ -1248,34 +1233,24 @@ class segment_manager
1248
1233
block_header_t * hdr;
1249
1234
1250
1235
// Allocate and construct the headers
1251
- if (is_node_index_t ::value){
1236
+ BOOST_IF_CONSTEXPR (is_node_index_t ::value){
1252
1237
size_type total_size = block_info.template total_size_with_header <index_it>();
1253
- if (dothrow){
1254
- buffer_ptr = this ->allocate (total_size);
1255
- }
1256
- else {
1257
- buffer_ptr = this ->allocate (total_size, nothrow<>::get ());
1258
- if (!buffer_ptr)
1259
- return 0 ;
1260
- }
1238
+ buffer_ptr = this ->allocate (total_size, nothrow<>::get ());
1239
+ if (!buffer_ptr)
1240
+ return ipcdetail::null_or_bad_alloc<void >(dothrow);
1261
1241
index_it *idr = ::new (buffer_ptr, boost_container_new_t ()) index_it (it);
1262
1242
hdr = block_header_t ::template from_first_header<index_it>(idr);
1263
1243
}
1264
1244
else {
1265
- if (dothrow){
1266
- buffer_ptr = this ->allocate (block_info.total_size ());
1267
- }
1268
- else {
1269
- buffer_ptr = this ->allocate (block_info.total_size (), nothrow<>::get ());
1270
- if (!buffer_ptr)
1271
- return 0 ;
1272
- }
1245
+ buffer_ptr = this ->allocate (block_info.total_size (), nothrow<>::get ());
1246
+ // Check if there is enough memory
1247
+ if (!buffer_ptr)
1248
+ return ipcdetail::null_or_bad_alloc<void >(dothrow);
1273
1249
hdr = static_cast <block_header_t *>(buffer_ptr);
1274
1250
}
1275
1251
1276
- hdr = ::new (hdr, boost_container_new_t ())block_header_t (block_info);
1277
- void *ptr = 0 ; // avoid gcc warning
1278
- ptr = hdr->value ();
1252
+ hdr = ::new (hdr, boost_container_new_t ()) block_header_t (block_info);
1253
+ void *ptr = hdr->value ();
1279
1254
1280
1255
// Copy name to memory segment and insert data
1281
1256
CharT *name_ptr = static_cast <CharT *>(hdr->template name <CharT>());
0 commit comments