Skip to content

Commit

Permalink
aspl: fix some more issues with the new internal capacity field of lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Wertzui123 committed Aug 4, 2024
1 parent 66747cb commit ff2215f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions stdlib/aspl/compiler/backend/stringcode/c/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ ASPL_OBJECT_TYPE aspl_object_clone_shallow(ASPL_OBJECT_TYPE obj)
ASPL_ACCESS(clone).value.list->typeLen = ASPL_ACCESS(obj).value.list->typeLen;
ASPL_ACCESS(clone).value.list->length = ASPL_ACCESS(obj).value.list->length;
ASPL_ACCESS(clone).value.list->capacity = ASPL_ACCESS(obj).value.list->capacity;
ASPL_ACCESS(clone).value.list->value = ASPL_MALLOC(ASPL_ACCESS(clone).value.list->capacity);
ASPL_ACCESS(clone).value.list->value = ASPL_MALLOC(sizeof(ASPL_OBJECT_TYPE) * ASPL_ACCESS(clone).value.list->capacity);
memcpy(ASPL_ACCESS(clone).value.list->value, ASPL_ACCESS(obj).value.list->value, sizeof(ASPL_OBJECT_TYPE) * ASPL_ACCESS(obj).value.list->length);
break;
case ASPL_OBJECT_KIND_MAP:
Expand Down Expand Up @@ -518,7 +518,7 @@ ASPL_OBJECT_TYPE aspl_object_clone_deep(ASPL_OBJECT_TYPE obj)
ASPL_ACCESS(clone).value.list->typeLen = ASPL_ACCESS(obj).value.list->typeLen;
ASPL_ACCESS(clone).value.list->length = ASPL_ACCESS(obj).value.list->length;
ASPL_ACCESS(clone).value.list->capacity = ASPL_ACCESS(obj).value.list->capacity;
ASPL_ACCESS(clone).value.list->value = ASPL_MALLOC(ASPL_ACCESS(clone).value.list->capacity);
ASPL_ACCESS(clone).value.list->value = ASPL_MALLOC(sizeof(ASPL_OBJECT_TYPE) * ASPL_ACCESS(clone).value.list->capacity);
for (int i = 0; i < ASPL_ACCESS(obj).value.list->length; i++)
{
ASPL_ACCESS(clone).value.list->value[i] = aspl_object_clone_deep(ASPL_ACCESS(obj).value.list->value[i]);
Expand Down Expand Up @@ -4021,7 +4021,7 @@ ASPL_OBJECT_TYPE aspl_method_list_insertElements(ASPL_OBJECT_TYPE* obj, ASPL_OBJ
if (ASPL_ACCESS(objB).value.integer32 >= 0 && ASPL_ACCESS(objB).value.integer32 <= l->length)
{
l->length += ASPL_ACCESS(objC).value.list->length;
if (l->length >= l->capacity) {
while (l->length >= l->capacity) {
l->capacity *= 2;
l->value = ASPL_REALLOC(l->value, sizeof(ASPL_OBJECT_TYPE) * l->capacity);
}
Expand Down Expand Up @@ -4058,8 +4058,8 @@ ASPL_OBJECT_TYPE aspl_method_list_remove(ASPL_OBJECT_TYPE* obj, ASPL_OBJECT_TYPE
l->length--;
if (l->length < l->capacity / 2) {
l->capacity /= 2;
l->value = ASPL_REALLOC(l->value, sizeof(ASPL_OBJECT_TYPE) * l->capacity);
}
l->value = ASPL_REALLOC(l->value, sizeof(ASPL_OBJECT_TYPE) * l->capacity);
return ASPL_TRUE();
}
}
Expand All @@ -4085,8 +4085,8 @@ ASPL_OBJECT_TYPE aspl_method_list_removeAt(ASPL_OBJECT_TYPE* obj, ASPL_OBJECT_TY
l->length--;
if (l->length < l->capacity / 2) {
l->capacity /= 2;
l->value = ASPL_REALLOC(l->value, sizeof(ASPL_OBJECT_TYPE) * l->capacity);
}
l->value = ASPL_REALLOC(l->value, sizeof(ASPL_OBJECT_TYPE) * l->capacity);
}
return objA;
}
Expand Down

0 comments on commit ff2215f

Please sign in to comment.