Skip to content
Snippets Groups Projects
Commit 86446598 authored by Kostyantyn Vorobyov's avatar Kostyantyn Vorobyov
Browse files

Renamed a struct member tracking the number of initialized bytes in a

block to init_bytes
parent 2e70ad64
No related branches found
No related tags found
No related merge requests found
...@@ -401,7 +401,7 @@ static void bt_clean_block_init (bt_block * ptr) { ...@@ -401,7 +401,7 @@ static void bt_clean_block_init (bt_block * ptr) {
native_free(ptr->init_ptr); native_free(ptr->init_ptr);
ptr->init_ptr = NULL; ptr->init_ptr = NULL;
} }
ptr->init_cpt = 0; ptr->init_bytes = 0;
} }
/* erase all information about a block */ /* erase all information about a block */
...@@ -442,7 +442,7 @@ static void bt_print_block(bt_block * ptr) { ...@@ -442,7 +442,7 @@ static void bt_print_block(bt_block * ptr) {
if (ptr != NULL) { if (ptr != NULL) {
DLOG("%a; %lu Bytes; %slitteral; [init] : %d ", DLOG("%a; %lu Bytes; %slitteral; [init] : %d ",
(char*)ptr->ptr, ptr->size, (char*)ptr->ptr, ptr->size,
ptr->is_readonly ? "" : "not ", ptr->init_cpt); ptr->is_readonly ? "" : "not ", ptr->init_bytes);
if(ptr->init_ptr != NULL) { if(ptr->init_ptr != NULL) {
unsigned i; unsigned i;
for(i = 0; i < ptr->size/8; i++) for(i = 0; i < ptr->size/8; i++)
......
...@@ -36,7 +36,7 @@ struct bt_block { ...@@ -36,7 +36,7 @@ struct bt_block {
size_t ptr; //!< Base address size_t ptr; //!< Base address
size_t size; //!< Block length (in bytes) size_t size; //!< Block length (in bytes)
unsigned char * init_ptr; //!< Per-bit initialization unsigned char * init_ptr; //!< Per-bit initialization
size_t init_cpt; //!< Number of initialized bytes within a block size_t init_bytes; //!< Number of initialized bytes within a block
_Bool is_readonly; //!< True if a block is marked read-only _Bool is_readonly; //!< True if a block is marked read-only
_Bool freeable; //!< True if a block can be de-allocated using `free` _Bool freeable; //!< True if a block can be de-allocated using `free`
}; };
......
...@@ -73,7 +73,7 @@ void* __store_block(void* ptr, size_t size) { ...@@ -73,7 +73,7 @@ void* __store_block(void* ptr, size_t size) {
tmp->ptr = (size_t)ptr; tmp->ptr = (size_t)ptr;
tmp->size = size; tmp->size = size;
tmp->init_ptr = NULL; tmp->init_ptr = NULL;
tmp->init_cpt = 0; tmp->init_bytes = 0;
tmp->is_readonly = false; tmp->is_readonly = false;
tmp->freeable = false; tmp->freeable = false;
bt_insert(tmp); bt_insert(tmp);
...@@ -158,13 +158,13 @@ void* __realloc(void* ptr, size_t size) { ...@@ -158,13 +158,13 @@ void* __realloc(void* ptr, size_t size) {
bt_insert(tmp); bt_insert(tmp);
} }
/* uninitialized, do nothing */ /* uninitialized, do nothing */
if(tmp->init_cpt == 0) ; if(tmp->init_bytes == 0) ;
/* already fully initialized block */ /* already fully initialized block */
else if (tmp->init_cpt == tmp->size) { else if (tmp->init_bytes == tmp->size) {
/* realloc smaller block */ /* realloc smaller block */
if(size <= tmp->size) if(size <= tmp->size)
/* adjust new size, allocation not necessary */ /* adjust new size, allocation not necessary */
tmp->init_cpt = size; tmp->init_bytes = size;
/* realloc bigger larger block */ /* realloc bigger larger block */
else { else {
/* size of tmp->init_ptr in the new block */ /* size of tmp->init_ptr in the new block */
...@@ -185,10 +185,10 @@ void* __realloc(void* ptr, size_t size) { ...@@ -185,10 +185,10 @@ void* __realloc(void* ptr, size_t size) {
tmp->init_ptr = native_realloc(tmp->init_ptr, nb); tmp->init_ptr = native_realloc(tmp->init_ptr, nb);
for(i = nb_old; i < nb; i++) for(i = nb_old; i < nb; i++)
tmp->init_ptr[i] = 0; tmp->init_ptr[i] = 0;
tmp->init_cpt = 0; tmp->init_bytes = 0;
for(i = 0; i < nb; i++) for(i = 0; i < nb; i++)
tmp->init_cpt += nbr_bits_to_1[tmp->init_ptr[i]]; tmp->init_bytes += nbr_bits_to_1[tmp->init_ptr[i]];
if(tmp->init_cpt == size || tmp->init_cpt == 0) { if(tmp->init_bytes == size || tmp->init_bytes == 0) {
native_free(tmp->init_ptr); native_free(tmp->init_ptr);
tmp->init_ptr = NULL; tmp->init_ptr = NULL;
} }
...@@ -216,7 +216,7 @@ void* __calloc(size_t nbr_block, size_t size_block) { ...@@ -216,7 +216,7 @@ void* __calloc(size_t nbr_block, size_t size_block) {
DASSERT(new_block != NULL && (void*)new_block->ptr != NULL); DASSERT(new_block != NULL && (void*)new_block->ptr != NULL);
/* Mark allocated block as freeable and initialized */ /* Mark allocated block as freeable and initialized */
new_block->freeable = true; new_block->freeable = true;
new_block->init_cpt = size; new_block->init_bytes = size;
return (void*)new_block->ptr; return (void*)new_block->ptr;
} }
...@@ -235,11 +235,11 @@ void __initialize (void * ptr, size_t size) { ...@@ -235,11 +235,11 @@ void __initialize (void * ptr, size_t size) {
return; return;
/* already fully initialized, do nothing */ /* already fully initialized, do nothing */
if(tmp->init_cpt == tmp->size) if(tmp->init_bytes == tmp->size)
return; return;
/* fully uninitialized */ /* fully uninitialized */
if(tmp->init_cpt == 0) { if(tmp->init_bytes == 0) {
int nb = needed_bytes(tmp->size); int nb = needed_bytes(tmp->size);
tmp->init_ptr = native_malloc(nb); tmp->init_ptr = native_malloc(nb);
memset(tmp->init_ptr, 0, nb); memset(tmp->init_ptr, 0, nb);
...@@ -263,12 +263,12 @@ void __initialize (void * ptr, size_t size) { ...@@ -263,12 +263,12 @@ void __initialize (void * ptr, size_t size) {
if (!checkbit(bit, tmp->init_ptr[byte])) { /* if bit is unset ... */ if (!checkbit(bit, tmp->init_ptr[byte])) { /* if bit is unset ... */
setbit(bit, tmp->init_ptr[byte]); /* ... set the bit ... */ setbit(bit, tmp->init_ptr[byte]); /* ... set the bit ... */
tmp->init_cpt++; /* ... and increment initialized bytes count */ tmp->init_bytes++; /* ... and increment initialized bytes count */
} }
} }
/* now fully initialized */ /* now fully initialized */
if(tmp->init_cpt == tmp->size) { if(tmp->init_bytes == tmp->size) {
native_free(tmp->init_ptr); native_free(tmp->init_ptr);
tmp->init_ptr = NULL; tmp->init_ptr = NULL;
} }
...@@ -288,8 +288,7 @@ void __full_init (void * ptr) { ...@@ -288,8 +288,7 @@ void __full_init (void * ptr) {
native_free(tmp->init_ptr); native_free(tmp->init_ptr);
tmp->init_ptr = NULL; tmp->init_ptr = NULL;
} }
tmp->init_bytes = tmp->size;
tmp->init_cpt = tmp->size;
} }
/* mark a block as read-only */ /* mark a block as read-only */
...@@ -315,10 +314,10 @@ int __initialized (void * ptr, size_t size) { ...@@ -315,10 +314,10 @@ int __initialized (void * ptr, size_t size) {
return false; return false;
/* fully uninitialized */ /* fully uninitialized */
if(tmp->init_cpt == 0) if(tmp->init_bytes == 0)
return false; return false;
/* fully initialized */ /* fully initialized */
if(tmp->init_cpt == tmp->size) if(tmp->init_bytes == tmp->size)
return true; return true;
/* see implementation of function __initialize for details */ /* see implementation of function __initialize for details */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment