Skip to content

Commit

Permalink
Finalise static asserts for typedef size checks.
Browse files Browse the repository at this point in the history
Signed-off-by: Rule Timothy (VM/EMT3) <[email protected]>
  • Loading branch information
timrulebosch committed Sep 11, 2024
1 parent ece1e0c commit a580b21
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 44 deletions.
2 changes: 1 addition & 1 deletion dse/modelc/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ typedef struct ModelDesc {
ModelVTable vtable;

/* Reserved. */
uint64_t __reserved__[2];
uint64_t __reserved__[4];
} ModelDesc;


Expand Down
9 changes: 2 additions & 7 deletions dse/modelc/model/gateway.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@

__attribute__((unused)) static void __compile_time_checks(void)
{
/* Compile-time type size check. Get actual size with:
* char (*___)[sizeof(ModelGatewayDesc)] = 1;
*/
#if __SIZEOF_POINTER__ == 8
// Compile-time type size check. Get actual size with:
// char(*___)[sizeof(ModelGatewayDesc)] = 1;
_Static_assert(sizeof(ModelGatewayDesc) == 80, "Compatibility FAIL!");
#else
_Static_assert(sizeof(ModelGatewayDesc) == 64, "Compatibility FAIL!");
#endif
}


Expand Down
27 changes: 11 additions & 16 deletions dse/modelc/model/mcl.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,11 @@

__attribute__((unused)) static void __compile_time_checks(void)
{
/* Compile-time type size check. Get actual size with:
* char (*___)[sizeof(MclDesc)] = 1;
* char (*___)[sizeof(MarshalSignalMap)] = 1;
*/
#if __SIZEOF_POINTER__ == 8
_Static_assert(sizeof(MclDesc) == 256, "Compatibility FAIL!");
// Compile-time type size check. Get actual size with:
// char(*___)[sizeof(MclDesc)] = 1;
// char(*___)[sizeof(MarshalSignalMap)] = 1;
_Static_assert(sizeof(MclDesc) == 272, "Compatibility FAIL!");
_Static_assert(sizeof(MarshalSignalMap) == 56, "Compatibility FAIL!");
#else
_Static_assert(sizeof(MclDesc) == 160, "Compatibility FAIL!");
_Static_assert(sizeof(MarshalSignalMap) == 28, "Compatibility FAIL!");
#endif
}


Expand Down Expand Up @@ -133,7 +127,8 @@ int32_t mcl_load(MclDesc* model)
size_t count = hashlist_length(&msm_list);
model->msm = calloc(count + 1, sizeof(MarshalSignalMap));
for (uint32_t i = 0; i < count; i++) {
memcpy(&model->msm[i], hashlist_at(&msm_list, i), sizeof(MarshalSignalMap));
memcpy(&model->msm[i], hashlist_at(&msm_list, i),
sizeof(MarshalSignalMap));
free(hashlist_at(&msm_list, i));
}
hashlist_destroy(&msm_list);
Expand Down Expand Up @@ -204,7 +199,7 @@ int32_t mcl_step(MclDesc* model, double end_time)
double model_stop_time;
double model_current_time;
double mcl_epsilon = 0.0;
int rc;
int rc;

if (model && model->vtable.step) {
/* Calculate epsilon value (if necessary). */
Expand Down Expand Up @@ -233,11 +228,11 @@ int32_t mcl_step(MclDesc* model, double end_time)
/* Model stop time past Simulation stop time. */
if (model_stop_time > end_time + mcl_epsilon) return 0;

log_trace("Step the FMU Model: %f %f (%f) %f",
model_current_time, model_stop_time,
(model_stop_time + mcl_epsilon), end_time);
log_trace("Step the FMU Model: %f %f (%f) %f", model_current_time,
model_stop_time, (model_stop_time + mcl_epsilon), end_time);

rc = model->vtable.step(model, &model_current_time, model_stop_time);
rc =
model->vtable.step(model, &model_current_time, model_stop_time);
model->model_time = model_current_time;
} while (model_stop_time + mcl_epsilon < end_time);

Expand Down
22 changes: 11 additions & 11 deletions dse/modelc/model/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@

__attribute__((unused)) static void __compile_time_checks(void)
{
/* Compile-time type size check. Get actual size with:
* char (*___)[sizeof(ModelInstanceSpec)] = 1;
* char (*___)[sizeof(ModelDesc)] = 1;
*/
#if __SIZEOF_POINTER__ == 8
_Static_assert(sizeof(ModelInstanceSpec) == 128, "Compatibility FAIL!");
_Static_assert(sizeof(ModelDesc) == 96, "Compatibility FAIL!");
#else
_Static_assert(sizeof(ModelInstanceSpec) == 80, "Compatibility FAIL!");
_Static_assert(sizeof(ModelDesc) == 56, "Compatibility FAIL!");
#endif
// Compile-time type size check. Get actual size with:
// char(*___)[sizeof(SimulationSpec)] = 1;
// char(*___)[sizeof(ModelInstanceSpec)] = 1;
// char(*___)[sizeof(ModelDesc)] = 1;
// char(*___)[sizeof(ModelCArguments)] = 1;
// char(*___)[sizeof(RuntimeModelDesc)] = 1;
_Static_assert(sizeof(SimulationSpec) == 104, "Compatibility FAIL!");
_Static_assert(sizeof(ModelInstanceSpec) == 160, "Compatibility FAIL!");
_Static_assert(sizeof(ModelDesc) == 112, "Compatibility FAIL!");
_Static_assert(sizeof(ModelCArguments) == 160, "Compatibility FAIL!");
_Static_assert(sizeof(RuntimeModelDesc) == 272, "Compatibility FAIL!");
}


Expand Down
9 changes: 2 additions & 7 deletions dse/modelc/model/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@ extern void ncodec_trace_destroy(NCodecInstance* nc);

__attribute__((unused)) static void __compile_time_checks(void)
{
/* Compile-time type size check. Get actual size with:
* char (*___)[sizeof(SignalVector)] = 1;
*/
#if __SIZEOF_POINTER__ == 8
// Compile-time type size check. Get actual size with:
// char (*___)[sizeof(SignalVector)] = 1;
_Static_assert(sizeof(SignalVector) == 256, "Compatibility FAIL!");
#else
_Static_assert(sizeof(SignalVector) == 168, "Compatibility FAIL!");
#endif
}


Expand Down
13 changes: 11 additions & 2 deletions dse/modelc/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ typedef struct ModelInstanceSpec {
void* private;

/* Reserved. */
uint64_t __reserved__[4];
uint64_t __reserved__[8];
} ModelInstanceSpec;


Expand All @@ -70,6 +70,9 @@ typedef struct SimulationSpec {
const char* sim_path;
/* Operational properties needed for loopback operation. */
bool mode_loopback;

/* Reserved. */
uint64_t __reserved__[4];
} SimulationSpec;


Expand All @@ -96,6 +99,9 @@ typedef struct ModelCArguments {
uint32_t steps;
/* The simulation is in a different location (i.e. not the CWD). */
const char* sim_path;

/* Reserved. */
uint64_t __reserved__[4];
} ModelCArguments;


Expand Down Expand Up @@ -145,7 +151,7 @@ DLL_PRIVATE int model_configure_channel(ModelInstanceSpec* model_instance,
#define MODEL_RUNTIME_STEP_FUNC_NAME "model_runtime_step"
#define MODEL_RUNTIME_DESTROY_FUNC_NAME "model_runtime_destroy"

typedef struct {
typedef struct RuntimeModelDesc {
ModelDesc model;

/* Runtime properties. */
Expand All @@ -168,6 +174,9 @@ typedef struct {
double step_time_correction;
bool binary_signals_reset;
} runtime;

/* Reserved. */
uint64_t __reserved__[8];
} RuntimeModelDesc;

DLL_PUBLIC RuntimeModelDesc* model_runtime_create(RuntimeModelDesc* model);
Expand Down

0 comments on commit a580b21

Please sign in to comment.