(FEA) More macros for Status
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
Status Memory_Create(Memory *inst, size_t size)
|
||||
{
|
||||
fails(inst, UnavailableInstance);
|
||||
fails(inst, apply(UnavailableInstance));
|
||||
|
||||
*inst = (Memory) {
|
||||
.addr = NULL,
|
||||
@@ -11,57 +11,58 @@ Status Memory_Create(Memory *inst, size_t size)
|
||||
.alive = false
|
||||
};
|
||||
|
||||
return NormalStatus;
|
||||
return apply(NormalStatus);
|
||||
}
|
||||
|
||||
Status Memory_Allocate(Memory *inst)
|
||||
{
|
||||
fails(inst, UnavailableInstance);
|
||||
state(inst->alive, InstanceStillAlive);
|
||||
fails(inst, apply(UnavailableInstance));
|
||||
state(inst->alive, apply(InstanceStillAlive));
|
||||
|
||||
/* When failed on allocating. */
|
||||
state(!(inst->addr = malloc(inst->size)), InsufficientMemory);
|
||||
state(!(inst->addr = malloc(inst->size)), apply(InsufficientMemory));
|
||||
inst->alive = true;
|
||||
|
||||
return NormalStatus;
|
||||
return apply(NormalStatus);
|
||||
}
|
||||
|
||||
Status Memory_Reallocate(Memory *inst, size_t size)
|
||||
{
|
||||
fails(inst, UnavailableBuffer);
|
||||
state(!inst->alive, InstanceNotAlive);
|
||||
fails(inst, apply(UnavailableBuffer));
|
||||
state(!inst->alive, apply(InstanceNotAlive));
|
||||
|
||||
/* When failed on reallocating. */
|
||||
state(!(inst->addr = realloc(inst->addr, size)),
|
||||
error(InsufficientMemory, "Unsuccessful reallocation was received."))
|
||||
apply(error(InsufficientMemory, "Unsuccessful reallocation was received.")));
|
||||
|
||||
return NormalStatus;
|
||||
return apply(NormalStatus);
|
||||
}
|
||||
|
||||
Status Memory_Release(Memory *inst)
|
||||
{
|
||||
fails(inst, UnavailableInstance);
|
||||
state(!inst->alive, error(InstanceNotAlive, "Cannot release a non-alive "
|
||||
"instance."));
|
||||
fails(inst, apply(UnavailableInstance));
|
||||
state(!inst->alive,
|
||||
apply(error(InstanceNotAlive, "Cannot release a non-alive instance.")));
|
||||
|
||||
free(inst->addr);
|
||||
inst->alive = false;
|
||||
|
||||
return NormalStatus;
|
||||
return apply(NormalStatus);
|
||||
}
|
||||
|
||||
Status Memory_Delete(Memory *inst)
|
||||
{
|
||||
fails(inst, UnavailableInstance);
|
||||
state(inst->alive, error(InstanceStillAlive, "Cannot deinitialise a instance "
|
||||
"still alive."));
|
||||
fails(inst, apply(UnavailableInstance));
|
||||
state(inst->alive,
|
||||
apply(
|
||||
error(InstanceStillAlive, "Cannot deinitialise a instance still alive.")));
|
||||
|
||||
inst->addr = NULL;
|
||||
inst->priority = 0;
|
||||
inst->size = 0;
|
||||
inst = NULL;
|
||||
|
||||
return NormalStatus;
|
||||
return apply(NormalStatus);
|
||||
}
|
||||
|
||||
bool Memory_Equals(Memory *inst, Memory *other)
|
||||
|
Reference in New Issue
Block a user