Minor fix to prevent creation of schemas with invalid types.

This commit is contained in:
yukirij 2023-08-26 12:13:11 -07:00
parent b3b3f14758
commit 4cd0f03b0a
2 changed files with 12 additions and 8 deletions

View File

@ -5,12 +5,6 @@ fn main() {
const MAGAZINE :usize = 0x100;
const MAGAZINE_ROW :usize = 0x101;
// define schema "Magazine Row"
szun::Schema::with(vec![
("Content", szun::natural()),
("Quantity", szun::natural()),
]).bind(MAGAZINE_ROW);
// define schema "Magazine"
let magazine = szun::Schema::with(vec![
("Capacity", szun::natural()),
@ -19,6 +13,12 @@ fn main() {
]);
magazine.bind(MAGAZINE);
// define schema "Magazine Row"
szun::Schema::with(vec![
("Content", szun::natural()),
("Quantity", szun::natural()),
]).bind(MAGAZINE_ROW);
// create record "Magazine"
let _data = szun::Record::with(MAGAZINE, vec![
("Capacity", *szun::Natural::with(30)),

View File

@ -1250,6 +1250,10 @@ extern "C" size_t schema_bind(Reference addr, size_t id)
size_t type_id = *reinterpret_cast<size_t*>(rawlist_cell(object.data, sizeof(size_t), i));
size_t size = type_size(type_id);
// fail if size is not valid
if(size == 0) { return 0; }
size_t alignment = type_alignment(type_id);
binding.alignment = std::max(alignment, binding.alignment);
size_t position = ((binding.size + (alignment - 1)) & ~(alignment - 1));
@ -1290,9 +1294,9 @@ extern "C" size_t schema_bind(Reference addr, size_t id)
// add binding to pool
DB_SCHEMA.set(id, binding);
return id;
}
return id;
return 0;
}
extern "C" bool schema_has(size_t id)