[Core] Standardise number types to int32_t for array indices, lengths and capacities (#152)
Some checks failed
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Failing after 1m44s
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Failing after 13s
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled

This commit is contained in:
Nic Barker 2025-01-03 11:24:32 +13:00 committed by GitHub
parent a44423a133
commit cf12cd6af8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 227 additions and 226 deletions

View File

@ -18,7 +18,7 @@ when ODIN_OS == .Windows {
}
String :: struct {
length: c.int,
length: c.int32_t,
chars: [^]c.char,
}
@ -258,8 +258,8 @@ LayoutConfig :: struct {
}
ClayArray :: struct($type: typeid) {
capacity: u32,
length: u32,
capacity: i32,
length: i32,
internalArray: [^]type,
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

420
clay.h

File diff suppressed because it is too large Load Diff

View File

@ -178,6 +178,7 @@
}
case 'float': return 4;
case 'uint32_t': return 4;
case 'int32_t': return 4;
case 'uint16_t': return 2;
case 'uint8_t': return 1;
case 'bool': return 1;
@ -206,6 +207,7 @@
}
case 'float': return { value: memoryDataView.getFloat32(address, true), __size: 4 };
case 'uint32_t': return { value: memoryDataView.getUint32(address, true), __size: 4 };
case 'int32_t': return { value: memoryDataView.getUint32(address, true), __size: 4 };
case 'uint16_t': return { value: memoryDataView.getUint16(address, true), __size: 2 };
case 'uint8_t': return { value: memoryDataView.getUint8(address, true), __size: 1 };
case 'bool': return { value: memoryDataView.getUint8(address, true), __size: 1 };
@ -312,7 +314,6 @@
const importObject = {
clay: {
measureTextFunction: (addressOfDimensions, textToMeasure, addressOfConfig) => {
let stringLength = memoryDataView.getUint32(textToMeasure, true);
let pointerToString = memoryDataView.getUint32(textToMeasure + 4, true);
@ -358,8 +359,8 @@
}
function renderLoopHTML() {
let capacity = memoryDataView.getUint32(scratchSpaceAddress, true);
let length = memoryDataView.getUint32(scratchSpaceAddress + 4, true);
let capacity = memoryDataView.getInt32(scratchSpaceAddress, true);
let length = memoryDataView.getInt32(scratchSpaceAddress + 4, true);
let arrayOffset = memoryDataView.getUint32(scratchSpaceAddress + 8, true);
let scissorStack = [{ nextAllocation: { x: 0, y: 0 }, element: htmlRoot, nextElementIndex: 0 }];
let previousId = 0;

View File

@ -1,3 +1,3 @@
$NAME$ $NAME$_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) {
$NAME$ $NAME$_Allocate_Arena(int32_t capacity, Clay_Arena *arena) {
return CLAY__INIT($NAME$){.capacity = capacity, .length = 0, .internalArray = ($TYPE$ *)Clay__Array_Allocate_Arena(capacity, sizeof($TYPE$), CLAY__ALIGNMENT($TYPE$), arena)};
}

View File

@ -1,3 +1,3 @@
$NAME$ $NAME$_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) {
$NAME$ $NAME$_Allocate_Arena(int32_t capacity, Clay_Arena *arena) {
return CLAY__INIT($NAME$){.capacity = capacity, .length = 0, .internalArray = ($TYPE$ *)Clay__Array_Allocate_Arena(capacity, sizeof($TYPE$), CLAY__POINTER_ALIGNMENT, arena)};
}

View File

@ -1,6 +1,6 @@
CLAY__TYPEDEF($NAME$, struct
{
uint32_t capacity;
uint32_t length;
int32_t capacity;
int32_t length;
$TYPE$ *internalArray;
});

View File

@ -1,5 +1,5 @@
CLAY__TYPEDEF($NAME$Slice, struct
{
uint32_t length;
int32_t length;
$TYPE$ *internalArray;
});

View File

@ -1,3 +1,3 @@
$TYPE$ *$NAME$_Get($NAME$ *array, int index) {
$TYPE$ *$NAME$_Get($NAME$ *array, int32_t index) {
return Clay__Array_RangeCheck(index, array->length) ? &array->internalArray[index] : $DEFAULT_VALUE$;
}

View File

@ -1,3 +1,3 @@
$TYPE$ *$NAME$Slice_Get($NAME$Slice *slice, int index) {
$TYPE$ *$NAME$Slice_Get($NAME$Slice *slice, int32_t index) {
return Clay__Array_RangeCheck(index, slice->length) ? &slice->internalArray[index] : $DEFAULT_VALUE$;
}

View File

@ -1,3 +1,3 @@
$TYPE$ $NAME$_Get($NAME$ *array, int index) {
$TYPE$ $NAME$_Get($NAME$ *array, int32_t index) {
return Clay__Array_RangeCheck(index, array->length) ? array->internalArray[index] : $DEFAULT_VALUE$;
}

View File

@ -1,4 +1,4 @@
$TYPE$ $NAME$_RemoveSwapback($NAME$ *array, int index) {
$TYPE$ $NAME$_RemoveSwapback($NAME$ *array, int32_t index) {
if (Clay__Array_RangeCheck(index, array->length)) {
array->length--;
$TYPE$ removed = array->internalArray[index];

View File

@ -1,4 +1,4 @@
void $NAME$_Set($NAME$ *array, int index, $TYPE$ value) {
void $NAME$_Set($NAME$ *array, int32_t index, $TYPE$ value) {
if (Clay__Array_RangeCheck(index, array->capacity)) {
array->internalArray[index] = value;
array->length = index < array->length ? array->length : index + 1;