Skip to content

Commit

Permalink
free schema!
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklan committed May 2, 2024
1 parent 4fbb2e6 commit 00f6309
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions ffi/examples/read-table/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,26 @@ void visit_timestamp_ntz(void *data, uintptr_t sibling_list_id, struct KernelStr
visit_simple_type(data, sibling_list_id, name, "timestamp_ntz");
}

// free all the data in the builder (but not the builder itself, since that might be stack allocated)
void free_builder(SchemaBuilder builder) {
for (int i = 0; i < builder.list_count; i++) {
SchemaItemList *list = (builder.lists)+i;
for (int j = 0; j < list->len; j++) {
SchemaItem *item = list->list+j;
free(item->name);
// don't free item->type, those are static strings
if (!strncmp(item->type, "decimal", 7)) {
// except decimal types, we malloc'd those :)
free(item->type);
}
// don't free item->children, it's just a list in the builder so will be freed by the outer
// loop.
}
free(list->list); // free all the items in this list (we alloc'd them together)
}
free(builder.lists);
}

// Print the schema of the snapshot
void print_schema(const SnapshotHandle *snapshot) {
SchemaBuilder builder = {
Expand Down Expand Up @@ -234,4 +254,5 @@ void print_schema(const SnapshotHandle *snapshot) {
printf("Schema:\n");
print_list(builder.lists+schema_list_id, 0, false);
printf("\n");
free_builder(builder);
}
2 changes: 1 addition & 1 deletion ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ pub unsafe extern "C" fn visit_schema(

fn visit_array_item(visitor: &EngineSchemaVisitor, at: &ArrayType) -> usize {
let child_list_id = (visitor.make_field_list)(visitor.data, 1);
visit_schema_item(&at.element_type, "list_data_type", visitor, child_list_id);
visit_schema_item(&at.element_type, "array_data_type", visitor, child_list_id);
child_list_id
}

Expand Down

0 comments on commit 00f6309

Please sign in to comment.