test-spark: rename number_of_bits -> object_size

In the original version, I used 'number_of_bits' because Ada's 'Size
returns the size in bits, not bytes. But the values (for objects) are
always a multiple of 8. On the C++ side, performing size checks at the
granularity of bits is just awkward. The term 'object size' is more
natural.
This commit is contained in:
Norman Feske 2019-04-05 12:27:52 +02:00 committed by Christian Helmuth
parent 5937492e93
commit 6d11591d83
3 changed files with 11 additions and 11 deletions

View File

@ -2,10 +2,10 @@ pragma Ada_2012;
package body Machinery is package body Machinery is
function Number_Of_Bits (Machinery : Machinery_Type) return Number_Of_Bits_Type is function Object_Size (Machinery : Machinery_Type) return Object_Size_Type is
begin begin
return Machinery'Size; return Machinery'Size / 8;
end Number_Of_Bits; end Object_Size;
procedure Initialize (Machinery : out Machinery_Type) is procedure Initialize (Machinery : out Machinery_Type) is
begin begin

View File

@ -2,16 +2,16 @@ package Machinery is
pragma Pure; pragma Pure;
type Number_Of_Bits_Type is mod 2**32 with Size => 32; type Object_Size_Type is mod 2**32 with Size => 32;
type Temperature_Type is mod 2**32 with Size => 32; type Temperature_Type is mod 2**32 with Size => 32;
type Machinery_Type is private; type Machinery_Type is private;
function Number_of_bits (Machinery : Machinery_Type) return Number_Of_Bits_Type function Object_Size (Machinery : Machinery_Type) return Object_Size_Type
with Export, with Export,
Convention => C, Convention => C,
External_Name => "_ZN5Spark14number_of_bitsERKNS_9MachineryE"; External_Name => "_ZN5Spark11object_sizeERKNS_9MachineryE";
procedure Initialize (Machinery : out Machinery_Type) procedure Initialize (Machinery : out Machinery_Type)
with Export, with Export,
@ -32,6 +32,6 @@ private
type Machinery_Type is record type Machinery_Type is record
Temperature : Temperature_Type; Temperature : Temperature_Type;
end record with Size => 32; end record;
end Machinery; end Machinery;

View File

@ -17,7 +17,7 @@ namespace Spark {
* *
* \param BYTES size of the SPARK record in bytes * \param BYTES size of the SPARK record in bytes
*/ */
template <Genode::size_t BYTES> template <Genode::uint32_t BYTES>
struct Object struct Object
{ {
/** /**
@ -25,7 +25,7 @@ namespace Spark {
*/ */
struct Object_size_mismatch { }; struct Object_size_mismatch { };
static constexpr Genode::size_t bytes() { return BYTES; } static constexpr Genode::uint32_t bytes() { return BYTES; }
long _space[(BYTES + sizeof(long) - 1)/sizeof(long)] { }; long _space[(BYTES + sizeof(long) - 1)/sizeof(long)] { };
}; };
@ -39,12 +39,12 @@ namespace Spark {
Genode::uint32_t temperature() const; Genode::uint32_t temperature() const;
}; };
Genode::size_t number_of_bits(Machinery const &); Genode::uint32_t object_size(Machinery const &);
template <typename T> template <typename T>
static inline void assert_valid_object_size() static inline void assert_valid_object_size()
{ {
if (number_of_bits(*(T *)nullptr) > T::bytes()*8) if (object_size(*(T *)nullptr) > T::bytes())
throw typename T::Object_size_mismatch(); throw typename T::Object_size_mismatch();
} }
} }