This repository was archived by the owner on Mar 22, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +41
-5
lines changed
Expand file tree Collapse file tree 3 files changed +41
-5
lines changed Original file line number Diff line number Diff line change 11/*
2- * Copyright 2016-2018 , Intel Corporation
2+ * Copyright 2016-2021 , Intel Corporation
33 *
44 * Redistribution and use in source and binary forms, with or without
55 * modification, are permitted provided that the following conditions
@@ -372,7 +372,10 @@ class persistent_ptr_base {
372372 inline ptrdiff_t
373373 calculate_offset () const
374374 {
375- static const ptrdiff_t ptr_offset_magic = 0xDEADBEEF ;
375+ static const ptrdiff_t ptr_offset_magic = 0xF00000000000000 ;
376+
377+ static_assert (ptr_offset_magic % alignof (U) == 0 , " " );
378+ static_assert (ptr_offset_magic % alignof (T) == 0 , " " );
376379
377380 U *tmp{reinterpret_cast <U *>(ptr_offset_magic)};
378381 T *diff = static_cast <T *>(tmp);
Original file line number Diff line number Diff line change 11/*
2- * Copyright 2018-2020 , Intel Corporation
2+ * Copyright 2018-2021 , Intel Corporation
33 *
44 * Redistribution and use in source and binary forms, with or without
55 * modification, are permitted provided that the following conditions
@@ -245,7 +245,7 @@ struct range_snapshotting_iterator
245245 {
246246 assert (data <= ptr);
247247
248- if (snapshot_size > 0 )
248+ if (snapshot_size && ptr )
249249 snapshot_range (ptr);
250250 }
251251
Original file line number Diff line number Diff line change 11/*
2- * Copyright 2015-2019 , Intel Corporation
2+ * Copyright 2015-2021 , Intel Corporation
33 *
44 * Redistribution and use in source and binary forms, with or without
55 * modification, are permitted provided that the following conditions
@@ -344,6 +344,38 @@ test_offset(nvobj::pool<root> &pop)
344344 UT_ASSERT (0 );
345345 }
346346}
347+
348+ /*
349+ * test_offset_with_alignment -- test offset calculation within a hierarchy of
350+ * objects with different alignments
351+ */
352+ void
353+ test_offset_alignment (nvobj::pool<root> &pop)
354+ {
355+ struct A {
356+ char a;
357+ };
358+
359+ struct B {
360+ uint64_t b;
361+ };
362+
363+ struct C : public A , public B {
364+ uint64_t c;
365+ };
366+
367+ try {
368+ nvobj::transaction::run (pop, [] {
369+ auto cptr = nvobj::make_persistent<C>();
370+ nvobj::persistent_ptr<B> bptr = cptr;
371+ UT_ASSERT ((bptr.raw ().off - cptr.raw ().off ) ==
372+ alignof (B));
373+ nvobj::delete_persistent<C>(cptr);
374+ });
375+ } catch (...) {
376+ UT_ASSERT (0 );
377+ }
378+ }
347379}
348380
349381int
@@ -370,6 +402,7 @@ main(int argc, char *argv[])
370402 test_ptr_transactional (pop);
371403 test_ptr_array (pop);
372404 test_offset (pop);
405+ test_offset_alignment (pop);
373406
374407 pop.close ();
375408
You can’t perform that action at this time.
0 commit comments