star-cad

Geometric operators for computer-aided design
git clone git://git.meso-star.fr/star-cad.git
Log | Files | Refs | README | LICENSE

commit acebcf026722e9bc475003ec1fcdc08bca5ef962
parent 56c6585df2eb2c628f7870e5c6e7b007c04d9d1e
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Fri,  1 Aug 2025 14:09:37 +0200

Fix geometries not released before calling finalize in tests

These geometries are then automatically released, generating logs.

Diffstat:
Msrc/test_export.c | 8++++++++
Msrc/test_export2.c | 3+++
Msrc/test_lifetime.c | 2+-
Msrc/test_partition.c | 11+++++++++--
Msrc/test_periodic.c | 4++++
5 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/test_export.c b/src/test_export.c @@ -35,11 +35,14 @@ main(int argc, char* argv[]) struct scad_geometry* fused = NULL; struct scad_geometry* geoms[2]; struct mem_allocator allocator; + struct scad_options options = SCAD_DEFAULT_OPTIONS; (void)argc; (void)argv; OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); OK(scad_initialize(NULL, &allocator, 3)); + options.Misc.LogRefCounting = SCAD_LOG_DIMTAGS_ALL | SCAD_LOG_GEOMETRY; + OK(scad_set_options(&options)); OK(scad_add_rectangle(p1, d1, &rectangle)); OK(scad_geometry_set_name(rectangle, "rectangle")); @@ -72,6 +75,11 @@ main(int argc, char* argv[]) OK(scad_stl_export(cube, "cube_quasi", SCAD_FORCE_NORMALS_OUTWARD, 0)); OK(scad_stl_export(fused, "fused_quasi", SCAD_FORCE_NORMALS_OUTWARD, 0)); + OK(scad_geometry_ref_put(rectangle)); + OK(scad_geometry_ref_put(cube)); + OK(scad_geometry_ref_put(geoms[1])); + OK(scad_geometry_ref_put(fused)); + OK(scad_finalize()); check_memory_allocator(&allocator); diff --git a/src/test_export2.c b/src/test_export2.c @@ -55,12 +55,15 @@ main(int argc, char* argv[]) struct scad_geometry* cube2 = NULL; struct scad_geometry* cube3 = NULL; struct mem_allocator allocator; + struct scad_options options = SCAD_DEFAULT_OPTIONS; (void)argc; (void)argv; OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); darray_double_init(&allocator, &array); OK(scad_initialize(NULL, &allocator, 3)); + options.Misc.LogRefCounting = SCAD_LOG_DIMTAGS_ALL | SCAD_LOG_GEOMETRY; + OK(scad_set_options(&options)); OK(scad_add_box(p1, d1, &cube1)); OK(scad_geometry_set_name(cube1, "cube1")); diff --git a/src/test_lifetime.c b/src/test_lifetime.c @@ -108,8 +108,8 @@ main(int argc, char* argv[]) ASSERT(center_n == 1); OK(scad_geometry_get_centerofmass(list[i], center)); OK(scad_geometry_get_normal(list[i], center, N, &geom)); + OK(scad_geometry_ref_put(geom)); } - OK(scad_geometry_ref_put(geom)); for(i = 0; i < list_n; i++) { OK(scad_geometry_ref_put(list[i])); } diff --git a/src/test_partition.c b/src/test_partition.c @@ -46,12 +46,15 @@ two_geoms double d1[3] = {1, 1, 1}; double p2[3]; double d2[3] = {0.5, 0.5, 0.5}; - struct scad_geometry* geoms[2]; - struct scad_geometry* out_geoms[2]; + struct scad_geometry* geoms[2] = {NULL, NULL}; + struct scad_geometry* out_geoms[2] = {NULL, NULL}; char name[64]; + struct scad_options options = SCAD_DEFAULT_OPTIONS; res_T res; OK(scad_initialize(NULL, allocator, 3)); + options.Misc.LogRefCounting = SCAD_LOG_DIMTAGS_ALL | SCAD_LOG_GEOMETRY; + OK(scad_set_options(&options)); /* set position for cube #2 */ d3(p2, x, 0.25, 0.25); @@ -95,6 +98,10 @@ two_geoms } end: + if(geoms[0]) OK(scad_geometry_ref_put(geoms[0])); + if(geoms[1]) OK(scad_geometry_ref_put(geoms[1])); + if(out_geoms[0]) OK(scad_geometry_ref_put(out_geoms[0])); + if(out_geoms[1]) OK(scad_geometry_ref_put(out_geoms[1])); OK(scad_finalize()); return res; } diff --git a/src/test_periodic.c b/src/test_periodic.c @@ -36,12 +36,16 @@ main(int argc, char* argv[]) double r1 = 1, r2 = r1 * XR, len; double cyl_affine[16] = { 1, 0, 0, 0, 0, XR, 0, 0, 0, 0, XR, 0, 0, 0, 0, 1 }; size_t i, facesn; + struct scad_options options = SCAD_DEFAULT_OPTIONS; (void)argc; (void)argv; OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); OK(scad_initialize(NULL, &allocator, 2)); + options.Misc.LogRefCounting = SCAD_LOG_DIMTAGS_ALL | SCAD_LOG_GEOMETRY; + OK(scad_set_options(&options)); + r2 = r1 * XR; OK(scad_add_cylinder(p1, d2, r1, 2*PI, &cyl1)); OK(scad_add_cylinder(p1, d2, r2, 2*PI, &cyl2));