fix leaks
This commit is contained in:
@@ -5,28 +5,24 @@ import "core:strings"
|
||||
|
||||
// DynamoDB AttributeValue - the core data type
|
||||
Attribute_Value :: union {
|
||||
String, // S
|
||||
Number, // N = stored as string, I'm keeping this so we can still do the parsing/serialization
|
||||
DDB_Number, // N Dynamo uses whole numbers and not floats or strings so we'll make that its own type
|
||||
Binary, // B (base64)
|
||||
Bool, // BOOL
|
||||
Null, // NULL
|
||||
String_Set, // SS
|
||||
Number_Set, // NS
|
||||
Binary_Set, // BS
|
||||
DDB_Number_Set,// BS
|
||||
List, // L
|
||||
Map, // M
|
||||
String, // S
|
||||
DDB_Number, // N — decimal-preserving numeric type
|
||||
Binary, // B (base64)
|
||||
Bool, // BOOL
|
||||
Null, // NULL
|
||||
String_Set, // SS
|
||||
DDB_Number_Set, // NS
|
||||
Binary_Set, // BS
|
||||
List, // L
|
||||
Map, // M
|
||||
}
|
||||
|
||||
String :: distinct string
|
||||
Number :: distinct string
|
||||
Binary :: distinct string
|
||||
Bool :: distinct bool
|
||||
Null :: distinct bool
|
||||
|
||||
String_Set :: distinct []string
|
||||
Number_Set :: distinct []string
|
||||
DDB_Number_Set :: distinct []DDB_Number
|
||||
Binary_Set :: distinct []string
|
||||
List :: distinct []Attribute_Value
|
||||
@@ -63,7 +59,7 @@ key_from_item :: proc(item: Item, key_schema: []Key_Schema_Element) -> (Key, boo
|
||||
|
||||
// Validate that key is a scalar type (S, N, or B)
|
||||
#partial switch _ in attr {
|
||||
case String, Number, Binary:
|
||||
case String, DDB_Number, Binary:
|
||||
// Valid key type
|
||||
case:
|
||||
return {}, false
|
||||
@@ -119,12 +115,11 @@ key_get_values :: proc(key: ^Key) -> (Key_Values, bool) {
|
||||
#partial switch v in key.pk {
|
||||
case String:
|
||||
pk_bytes = transmute([]byte)string(v)
|
||||
case Number:
|
||||
pk_bytes = transmute([]byte)string(v)
|
||||
case DDB_Number:
|
||||
pk_bytes = encode_ddb_number_for_sort(v)
|
||||
case Binary:
|
||||
pk_bytes = transmute([]byte)string(v)
|
||||
case:
|
||||
// Keys should only be scalar types (S, N, or B)
|
||||
return {}, false
|
||||
}
|
||||
|
||||
@@ -133,12 +128,11 @@ key_get_values :: proc(key: ^Key) -> (Key_Values, bool) {
|
||||
#partial switch v in sk {
|
||||
case String:
|
||||
sk_bytes = transmute([]byte)string(v)
|
||||
case Number:
|
||||
sk_bytes = transmute([]byte)string(v)
|
||||
case DDB_Number:
|
||||
sk_bytes = encode_ddb_number_for_sort(v)
|
||||
case Binary:
|
||||
sk_bytes = transmute([]byte)string(v)
|
||||
case:
|
||||
// Keys should only be scalar types
|
||||
return {}, false
|
||||
}
|
||||
}
|
||||
@@ -369,13 +363,27 @@ error_to_response :: proc(err_type: DynamoDB_Error_Type, message: string) -> str
|
||||
|
||||
// Build an Attribute_Value with the correct scalar type from raw bytes
|
||||
build_attribute_value_with_type :: proc(raw_bytes: []byte, attr_type: Scalar_Attribute_Type) -> Attribute_Value {
|
||||
owned := strings.clone(string(raw_bytes))
|
||||
switch attr_type {
|
||||
case .S: return String(owned)
|
||||
case .N: return Number(owned)
|
||||
case .B: return Binary(owned)
|
||||
case .S:
|
||||
return String(strings.clone(string(raw_bytes)))
|
||||
case .N:
|
||||
// Key bytes are canonical-encoded via encode_ddb_number_for_sort.
|
||||
// Decode them back to a DDB_Number.
|
||||
ddb_num, ok := decode_ddb_number_from_sort(raw_bytes)
|
||||
if ok {
|
||||
return clone_ddb_number(ddb_num)
|
||||
}
|
||||
// Fallback: try interpreting as a plain numeric string
|
||||
fallback_num, fb_ok := parse_ddb_number(string(raw_bytes))
|
||||
if fb_ok {
|
||||
return fallback_num
|
||||
}
|
||||
// Last resort — return as string (shouldn't happen)
|
||||
return String(strings.clone(string(raw_bytes)))
|
||||
case .B:
|
||||
return Binary(strings.clone(string(raw_bytes)))
|
||||
}
|
||||
return String(owned)
|
||||
return String(strings.clone(string(raw_bytes)))
|
||||
}
|
||||
|
||||
// Deep copy an attribute value
|
||||
@@ -383,8 +391,6 @@ attr_value_deep_copy :: proc(attr: Attribute_Value) -> Attribute_Value {
|
||||
switch v in attr {
|
||||
case String:
|
||||
return String(strings.clone(string(v)))
|
||||
case Number:
|
||||
return Number(strings.clone(string(v)))
|
||||
case DDB_Number:
|
||||
return clone_ddb_number(v)
|
||||
case Binary:
|
||||
@@ -399,12 +405,6 @@ attr_value_deep_copy :: proc(attr: Attribute_Value) -> Attribute_Value {
|
||||
ss[i] = strings.clone(s)
|
||||
}
|
||||
return String_Set(ss)
|
||||
case Number_Set:
|
||||
ns := make([]string, len(v))
|
||||
for n, i in v {
|
||||
ns[i] = strings.clone(n)
|
||||
}
|
||||
return Number_Set(ns)
|
||||
case DDB_Number_Set:
|
||||
ddb_ns := make([]DDB_Number, len(v))
|
||||
for num, i in v {
|
||||
@@ -441,8 +441,6 @@ attr_value_destroy :: proc(attr: ^Attribute_Value) {
|
||||
case DDB_Number:
|
||||
delete(v.integer_part)
|
||||
delete(v.fractional_part)
|
||||
case Number:
|
||||
delete(string(v))
|
||||
case Binary:
|
||||
delete(string(v))
|
||||
case String_Set:
|
||||
@@ -451,12 +449,6 @@ attr_value_destroy :: proc(attr: ^Attribute_Value) {
|
||||
}
|
||||
slice := v
|
||||
delete(slice)
|
||||
case Number_Set:
|
||||
for n in v {
|
||||
delete(n)
|
||||
}
|
||||
slice := v
|
||||
delete(slice)
|
||||
case DDB_Number_Set:
|
||||
for num in v {
|
||||
delete(num.integer_part)
|
||||
@@ -497,4 +489,4 @@ item_destroy :: proc(item: ^Item) {
|
||||
attr_value_destroy(&val_copy)
|
||||
}
|
||||
delete(item^)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user