fix_progress

This commit is contained in:
masterexplorer 2024-10-07 18:13:18 +02:00
parent bd781f335c
commit 5eb99e742d
2 changed files with 10 additions and 6 deletions

View File

@ -7,8 +7,8 @@ void test_basics(amap mapdo, void *map) {
assert(NULL == mapdo(map, AMAP_GET, "asdf", NULL)); assert(NULL == mapdo(map, AMAP_GET, "asdf", NULL));
int i = 42; int i = 42;
int *iptr; int *iptr;
assert(NULL != mapdo(map, AMAP_SET, "meanging", &i)); assert(NULL != mapdo(map, AMAP_SET, "meaning", &i));
assert(NULL != (iptr = (int *)mapdo(map, AMAP_GET, "asdf", NULL))); assert(NULL != (iptr = (int *)mapdo(map, AMAP_GET, "meaning", NULL)));
assert(*iptr == 42); assert(*iptr == 42);
assert(iptr == &i); assert(iptr == &i);
} }

12
simap.h
View File

@ -132,8 +132,12 @@ static inline simap_ptr64 *simap_search_internal(simap_instance *map, const char
/** Gets padding bytes for a size to be padded to divisible alignment */ /** Gets padding bytes for a size to be padded to divisible alignment */
static inline unsigned int get_size_padding(unsigned int size, unsigned int alignment) { static inline unsigned int get_size_padding(unsigned int size, unsigned int alignment) {
// return (alignment - (size % alignment)) % alignment; /* Would ensure returned value divisible by alignment */
return (size + alignment - 1) / alignment * alignment; /* return (size + alignment - 1) / alignment * alignment; */
/* same: return (alignment - (size % alignment)) % alignment; */
/* Substracting size leads to padding */
return ((size + alignment - 1) / alignment) * alignment - size;
} }
/** Returns the size of the storage needed for the given key */ /** Returns the size of the storage needed for the given key */
@ -151,8 +155,8 @@ static inline uint32_t simap_elem_storage_size(const char *key) {
/** Force-add the (key,value) to the end of the map */ /** Force-add the (key,value) to the end of the map */
static inline void *simap_force_add_internal(simap_instance *map, const char *key, void *ptr) { static inline void *simap_force_add_internal(simap_instance *map, const char *key, void *ptr) {
uint32_t storage_needed = simap_elem_storage_size(key); uint32_t storage_needed = simap_elem_storage_size(key);
assert((storage_needed & 8) == 0); assert((storage_needed % 8) == 0);
if(map->end - map->usage_end > storage_needed) { if(map->end - map->usage_end < storage_needed) {
/* Need storage */ /* Need storage */
aralloc(&(map->a), aralloc(&(map->a),
sizeof(uint8_t)/*esize*/, sizeof(uint8_t)/*esize*/,