Skip to content

Commit

Permalink
feat: exposes allocation functions via C bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
NickUfer committed Sep 30, 2024
1 parent 3c8d486 commit 3b4b2a9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
12 changes: 12 additions & 0 deletions bindings/c/include/manifold/manifoldc.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,18 @@ size_t manifold_box_size();
size_t manifold_rect_size();
size_t manifold_curvature_size();

// allocation

ManifoldManifold *manifold_alloc_manifold();
ManifoldManifoldVec *manifold_alloc_manifold_vec();
ManifoldCrossSection *manifold_alloc_cross_section();
ManifoldCrossSectionVec *manifold_alloc_cross_section_vec();
ManifoldSimplePolygon *manifold_alloc_simple_polygon();
ManifoldPolygons *manifold_alloc_polygons();
ManifoldMeshGL *manifold_alloc_meshgl();
ManifoldBox *manifold_alloc_box();
ManifoldRect *manifold_alloc_rect();

// destruction

void manifold_destruct_manifold(ManifoldManifold *m);
Expand Down
34 changes: 34 additions & 0 deletions bindings/c/manifoldc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,40 @@ size_t manifold_meshgl_size() { return sizeof(MeshGL); }
size_t manifold_box_size() { return sizeof(Box); }
size_t manifold_rect_size() { return sizeof(Rect); }

// allocation
ManifoldManifold *manifold_alloc_manifold() {
return to_c(static_cast<Manifold *>(malloc(manifold_manifold_size())));

Check warning on line 604 in bindings/c/manifoldc.cpp

View check run for this annotation

Codecov / codecov/patch

bindings/c/manifoldc.cpp#L603-L604

Added lines #L603 - L604 were not covered by tests
}
ManifoldManifoldVec *manifold_alloc_manifold_vec() {
return to_c(static_cast<std::vector<Manifold> *>(
malloc(manifold_manifold_vec_size())));

Check warning on line 608 in bindings/c/manifoldc.cpp

View check run for this annotation

Codecov / codecov/patch

bindings/c/manifoldc.cpp#L606-L608

Added lines #L606 - L608 were not covered by tests
}
ManifoldCrossSection *manifold_alloc_cross_section() {
return to_c(
static_cast<CrossSection *>(malloc(manifold_cross_section_size())));

Check warning on line 612 in bindings/c/manifoldc.cpp

View check run for this annotation

Codecov / codecov/patch

bindings/c/manifoldc.cpp#L610-L612

Added lines #L610 - L612 were not covered by tests
}
ManifoldCrossSectionVec *manifold_alloc_cross_section_vec() {
return to_c(static_cast<std::vector<CrossSection> *>(
malloc(manifold_cross_section_vec_size())));

Check warning on line 616 in bindings/c/manifoldc.cpp

View check run for this annotation

Codecov / codecov/patch

bindings/c/manifoldc.cpp#L614-L616

Added lines #L614 - L616 were not covered by tests
}
ManifoldSimplePolygon *manifold_alloc_simple_polygon() {
return to_c(
static_cast<SimplePolygon *>(malloc(manifold_simple_polygon_size())));

Check warning on line 620 in bindings/c/manifoldc.cpp

View check run for this annotation

Codecov / codecov/patch

bindings/c/manifoldc.cpp#L618-L620

Added lines #L618 - L620 were not covered by tests
}
ManifoldPolygons *manifold_alloc_polygons() {
return to_c(static_cast<std::vector<SimplePolygon> *>(
malloc(manifold_polygons_size())));

Check warning on line 624 in bindings/c/manifoldc.cpp

View check run for this annotation

Codecov / codecov/patch

bindings/c/manifoldc.cpp#L622-L624

Added lines #L622 - L624 were not covered by tests
}
ManifoldMeshGL *manifold_alloc_meshgl() {
return to_c(static_cast<MeshGL *>(malloc(manifold_meshgl_size())));

Check warning on line 627 in bindings/c/manifoldc.cpp

View check run for this annotation

Codecov / codecov/patch

bindings/c/manifoldc.cpp#L626-L627

Added lines #L626 - L627 were not covered by tests
}
ManifoldBox *manifold_alloc_box() {
return to_c(static_cast<Box *>(malloc(manifold_box_size())));

Check warning on line 630 in bindings/c/manifoldc.cpp

View check run for this annotation

Codecov / codecov/patch

bindings/c/manifoldc.cpp#L629-L630

Added lines #L629 - L630 were not covered by tests
}
ManifoldRect *manifold_alloc_rect() {
return to_c(static_cast<Rect *>(malloc(manifold_rect_size())));

Check warning on line 633 in bindings/c/manifoldc.cpp

View check run for this annotation

Codecov / codecov/patch

bindings/c/manifoldc.cpp#L632-L633

Added lines #L632 - L633 were not covered by tests
}

// pointer free + destruction
void manifold_delete_cross_section(ManifoldCrossSection *c) {
delete from_c(c);
Expand Down

0 comments on commit 3b4b2a9

Please sign in to comment.