feat: add vector

This commit is contained in:
2025-09-07 23:24:17 +02:00
parent 16ee246956
commit ad54d35f2b
7 changed files with 231 additions and 2 deletions

View File

@@ -142,12 +142,24 @@ int mcl_string_extend(mcl_string_s *destination, mcl_string_s *source) {
return -1;
}
if (mtx_lock(&destination->lock) != thrd_success) {
return -1;
}
if (mtx_lock(&source->lock) != thrd_success) {
mtx_unlock(&destination->lock);
return -1;
}
size_t need = destination->size + source->size;
if (need > destination->capacity) {
/* Reallocate destination data buffer */
destination->capacity = next_power_two(need);
char *tmp = realloc(destination->data, destination->capacity);
if (tmp == NULL) {
mtx_unlock(&destination->lock);
mtx_unlock(&source->lock);
return -1;
}
destination->data = tmp;
@@ -158,6 +170,9 @@ int mcl_string_extend(mcl_string_s *destination, mcl_string_s *source) {
destination->size = need;
destination->data[destination->size] = '\0';
mtx_unlock(&destination->lock);
mtx_unlock(&source->lock);
return 0;
}