[m-rev.] for review: Attribute memory allocations in mercury_cairo.

Peter Wang novalazy at gmail.com
Fri May 20 14:36:31 AEST 2022


extras/graphics/mercury_cairo/*.m:
    As above.

diff --git a/extras/graphics/mercury_cairo/cairo.font_options.m b/extras/graphics/mercury_cairo/cairo.font_options.m
index 951b2d7bb..a3d3ba7e0 100644
--- a/extras/graphics/mercury_cairo/cairo.font_options.m
+++ b/extras/graphics/mercury_cairo/cairo.font_options.m
@@ -140,7 +140,7 @@
     cairo_font_options_t    *raw_font_options;
 
     raw_font_options = cairo_font_options_create();
-    FntOpts = MR_GC_NEW(MCAIRO_font_options);
+    FntOpts = MR_GC_NEW_ATTRIB(MCAIRO_font_options, MR_ALLOC_ID);
     FntOpts->mcairo_raw_font_options = raw_font_options;
     MR_GC_register_finalizer(FntOpts, MCAIRO_finalize_font_options, 0);
 ").
@@ -152,7 +152,7 @@
     cairo_font_options_t    *raw_copy;
 
     raw_copy = cairo_font_options_copy(Orig->mcairo_raw_font_options);
-    Copy = MR_GC_NEW(MCAIRO_font_options);
+    Copy = MR_GC_NEW_ATTRIB(MCAIRO_font_options, MR_ALLOC_ID);
     Copy->mcairo_raw_font_options = raw_copy;
     MR_GC_register_finalizer(Copy, MCAIRO_finalize_font_options, 0);
 ").
diff --git a/extras/graphics/mercury_cairo/cairo.image.m b/extras/graphics/mercury_cairo/cairo.image.m
index 60f871faf..6d5fa290f 100644
--- a/extras/graphics/mercury_cairo/cairo.image.m
+++ b/extras/graphics/mercury_cairo/cairo.image.m
@@ -91,7 +91,7 @@ create_surface(Format, Width, Height, Surface, !IO) :-
     Status = cairo_surface_status(raw_surface);
 
     if (Status == CAIRO_STATUS_SUCCESS) {
-        Surface = MR_GC_NEW(MCAIRO_surface);
+        Surface = MR_GC_NEW_ATTRIB(MCAIRO_surface, MR_ALLOC_ID);
         Surface->mcairo_raw_surface = raw_surface;
         MR_GC_register_finalizer(Surface, MCAIRO_finalize_surface, 0);
     } else {
diff --git a/extras/graphics/mercury_cairo/cairo.m b/extras/graphics/mercury_cairo/cairo.m
index b2728cf5a..a5118ab55 100644
--- a/extras/graphics/mercury_cairo/cairo.m
+++ b/extras/graphics/mercury_cairo/cairo.m
@@ -876,7 +876,7 @@ create_context(Surface, Context, !IO) :-
 
     raw_context = cairo_create(
         ((MCAIRO_surface *)Surface)->mcairo_raw_surface);
-    Context = MR_GC_NEW(MCAIRO_context);
+    Context = MR_GC_NEW_ATTRIB(MCAIRO_context, MR_ALLOC_ID);
     Context->mcairo_raw_context = raw_context;
     /*
     ** We fill the cached font face in later.
@@ -915,7 +915,7 @@ create_context(Surface, Context, !IO) :-
     ** its reference count.
     */
     raw_surface = cairo_surface_reference(raw_surface);
-    wrapped_surface = MR_GC_NEW(MCAIRO_surface);
+    wrapped_surface = MR_GC_NEW_ATTRIB(MCAIRO_surface, MR_ALLOC_ID);
     wrapped_surface->mcairo_raw_surface = raw_surface;
     MR_GC_register_finalizer(wrapped_surface, MCAIRO_finalize_surface, 0);
     Target = (MR_Word) wrapped_surface;
@@ -942,7 +942,7 @@ create_context(Surface, Context, !IO) :-
     cairo_pattern_t *new_pattern;
 
     new_pattern = cairo_pop_group(Ctxt->mcairo_raw_context);
-    Pattern = MR_GC_NEW(MCAIRO_pattern);
+    Pattern = MR_GC_NEW_ATTRIB(MCAIRO_pattern, MR_ALLOC_ID);
     Pattern->mcairo_raw_pattern = new_pattern;
     MR_GC_register_finalizer(Pattern, MCAIRO_finalize_pattern, 0);
 ").
@@ -968,7 +968,7 @@ create_context(Surface, Context, !IO) :-
     ** its reference count.
     */
     raw_surface = cairo_surface_reference(raw_surface);
-    wrapped_surface = MR_GC_NEW(MCAIRO_surface);
+    wrapped_surface = MR_GC_NEW_ATTRIB(MCAIRO_surface, MR_ALLOC_ID);
     wrapped_surface->mcairo_raw_surface = raw_surface;
     MR_GC_register_finalizer(wrapped_surface, MCAIRO_finalize_surface, 0);
     Target = (MR_Word) wrapped_surface;
@@ -1021,7 +1021,7 @@ create_context(Surface, Context, !IO) :-
     ** it we need to increment the reference count here.
     */
     raw_pattern = cairo_pattern_reference(raw_pattern);
-    Pattern = MR_GC_NEW(MCAIRO_pattern);
+    Pattern = MR_GC_NEW_ATTRIB(MCAIRO_pattern, MR_ALLOC_ID);
     Pattern->mcairo_raw_pattern = raw_pattern;
     MR_GC_register_finalizer(Pattern, MCAIRO_finalize_pattern, 0);
 ").
@@ -1100,11 +1100,14 @@ set_dash(Context, Dashes, OffSet, !IO) :-
         IsValid::out, _IO0::di, _IO::uo),
     [promise_pure, will_not_call_mercury],
 "
+    MR_Word ptr;
     double  *dashes;
     double  dash;
     size_t  i = 0;
 
-    dashes = MR_GC_malloc(sizeof(double) * NumDashes);
+    MR_incr_hp_atomic_msg(ptr, MR_bytes_to_words(sizeof(double) * NumDashes),
+        MR_ALLOC_ID, ""dash_array"");
+    dashes = (double *) ptr;
 
     while (!MR_list_is_empty(Dashes)) {
         dash = MR_word_to_float(MR_list_head(Dashes));
diff --git a/extras/graphics/mercury_cairo/cairo.matrix.m b/extras/graphics/mercury_cairo/cairo.matrix.m
index 2564f7432..b94dd0318 100644
--- a/extras/graphics/mercury_cairo/cairo.matrix.m
+++ b/extras/graphics/mercury_cairo/cairo.matrix.m
@@ -119,7 +119,7 @@
 "
     cairo_matrix_t  *new_matrix;
 
-    new_matrix = MR_GC_NEW(cairo_matrix_t);
+    new_matrix = MR_GC_NEW_ATTRIB(cairo_matrix_t, MR_ALLOC_ID);
     cairo_matrix_init(new_matrix, Xx, Yx, Xy, Yy, X0, Y0);
     Matrix = new_matrix;
 ").
@@ -130,7 +130,7 @@
 "
     cairo_matrix_t  *new_matrix;
 
-    new_matrix = MR_GC_NEW(cairo_matrix_t);
+    new_matrix = MR_GC_NEW_ATTRIB(cairo_matrix_t, MR_ALLOC_ID);
     cairo_matrix_init_identity(new_matrix);
     Matrix = new_matrix;
 ").
@@ -141,7 +141,7 @@
 "
     cairo_matrix_t  *new_matrix;
 
-    new_matrix = MR_GC_NEW(cairo_matrix_t);
+    new_matrix = MR_GC_NEW_ATTRIB(cairo_matrix_t, MR_ALLOC_ID);
     cairo_matrix_init_translate(new_matrix, Tx, Ty);
     Matrix = new_matrix;
 ").
@@ -152,7 +152,7 @@
 "
     cairo_matrix_t  *new_matrix;
 
-    new_matrix = MR_GC_NEW(cairo_matrix_t);
+    new_matrix = MR_GC_NEW_ATTRIB(cairo_matrix_t, MR_ALLOC_ID);
     cairo_matrix_init_scale(new_matrix, Sx, Sy);
     Matrix = new_matrix;
 ").
@@ -163,7 +163,7 @@
 "
     cairo_matrix_t  *new_matrix;
 
-    new_matrix = MR_GC_NEW(cairo_matrix_t);
+    new_matrix = MR_GC_NEW_ATTRIB(cairo_matrix_t, MR_ALLOC_ID);
     cairo_matrix_init_rotate(new_matrix, Radians);
     Matrix = new_matrix;
 ").
diff --git a/extras/graphics/mercury_cairo/cairo.path.m b/extras/graphics/mercury_cairo/cairo.path.m
index 514614f8c..9c79bf7d5 100644
--- a/extras/graphics/mercury_cairo/cairo.path.m
+++ b/extras/graphics/mercury_cairo/cairo.path.m
@@ -178,7 +178,7 @@
     cairo_path_t    *raw_path;
 
     raw_path = cairo_copy_path(Ctxt->mcairo_raw_context);
-    Path = MR_GC_NEW(MCAIRO_path);
+    Path = MR_GC_NEW_ATTRIB(MCAIRO_path, MR_ALLOC_ID);
     Path->mcairo_raw_path = raw_path;
     MR_GC_register_finalizer(Path, MCAIRO_finalize_path, 0);
 ").
@@ -190,7 +190,7 @@
     cairo_path_t    *raw_path;
 
     raw_path = cairo_copy_path_flat(Ctxt->mcairo_raw_context);
-    Path = MR_GC_NEW(MCAIRO_path);
+    Path = MR_GC_NEW_ATTRIB(MCAIRO_path, MR_ALLOC_ID);
     Path->mcairo_raw_path = raw_path;
     MR_GC_register_finalizer(Path, MCAIRO_finalize_path, 0);
 ").
diff --git a/extras/graphics/mercury_cairo/cairo.pattern.m b/extras/graphics/mercury_cairo/cairo.pattern.m
index 700339e6c..0be8cdce2 100644
--- a/extras/graphics/mercury_cairo/cairo.pattern.m
+++ b/extras/graphics/mercury_cairo/cairo.pattern.m
@@ -267,7 +267,7 @@ add_color_stop_rgba(Pattern, Offset, R, G, B, A, !IO) :-
     cairo_pattern_t     *raw_pattern;
 
     raw_pattern = cairo_pattern_create_rgb(R, G, B);
-    Pattern = MR_GC_NEW(MCAIRO_pattern);
+    Pattern = MR_GC_NEW_ATTRIB(MCAIRO_pattern, MR_ALLOC_ID);
     Pattern->mcairo_raw_pattern = raw_pattern;
         MR_GC_register_finalizer(Pattern, MCAIRO_finalize_pattern, 0);
 ").
@@ -280,7 +280,7 @@ add_color_stop_rgba(Pattern, Offset, R, G, B, A, !IO) :-
     cairo_pattern_t     *raw_pattern;
 
     raw_pattern = cairo_pattern_create_rgba(R, G, B, A);
-    Pattern = MR_GC_NEW(MCAIRO_pattern);
+    Pattern = MR_GC_NEW_ATTRIB(MCAIRO_pattern, MR_ALLOC_ID);
     Pattern->mcairo_raw_pattern = raw_pattern;
         MR_GC_register_finalizer(Pattern, MCAIRO_finalize_pattern, 0);
 ").
@@ -292,7 +292,7 @@ add_color_stop_rgba(Pattern, Offset, R, G, B, A, !IO) :-
     cairo_pattern_t     *raw_pattern;
     raw_pattern = cairo_pattern_create_for_surface(
         ((MCAIRO_surface *)Surface)->mcairo_raw_surface);
-    Pattern = MR_GC_NEW(MCAIRO_pattern);
+    Pattern = MR_GC_NEW_ATTRIB(MCAIRO_pattern, MR_ALLOC_ID);
     Pattern->mcairo_raw_pattern = raw_pattern;
         MR_GC_register_finalizer(Pattern, MCAIRO_finalize_pattern, 0);
 ").
@@ -305,7 +305,7 @@ add_color_stop_rgba(Pattern, Offset, R, G, B, A, !IO) :-
     cairo_pattern_t     *raw_pattern;
 
     raw_pattern = cairo_pattern_create_linear(X0, Y0, X1, Y1);
-    Pattern = MR_GC_NEW(MCAIRO_pattern);
+    Pattern = MR_GC_NEW_ATTRIB(MCAIRO_pattern, MR_ALLOC_ID);
     Pattern->mcairo_raw_pattern = raw_pattern;
         MR_GC_register_finalizer(Pattern, MCAIRO_finalize_pattern, 0);
 ").
@@ -321,7 +321,7 @@ add_color_stop_rgba(Pattern, Offset, R, G, B, A, !IO) :-
     raw_pattern = cairo_pattern_create_radial(Cx0, Cy0, Radius0,
         Cx1, Cy1, Radius1);
 
-    Pattern = MR_GC_NEW(MCAIRO_pattern);
+    Pattern = MR_GC_NEW_ATTRIB(MCAIRO_pattern, MR_ALLOC_ID);
     Pattern->mcairo_raw_pattern = raw_pattern;
         MR_GC_register_finalizer(Pattern, MCAIRO_finalize_pattern, 0);
 ").
@@ -366,7 +366,7 @@ add_color_stop_rgba(Pattern, Offset, R, G, B, A, !IO) :-
     get_matrix(Pattern::in, Matrix::out, _IO0::di, _IO::uo),
     [promise_pure, will_not_call_mercury, tabled_for_io],
 "
-    Matrix = MR_GC_NEW(cairo_matrix_t);
+    Matrix = MR_GC_NEW_ATTRIB(cairo_matrix_t, MR_ALLOC_ID);
     cairo_pattern_get_matrix(Pattern->mcairo_raw_pattern, Matrix);
 ").
 
diff --git a/extras/graphics/mercury_cairo/cairo.pdf.m b/extras/graphics/mercury_cairo/cairo.pdf.m
index c166eccba..d537139bf 100644
--- a/extras/graphics/mercury_cairo/cairo.pdf.m
+++ b/extras/graphics/mercury_cairo/cairo.pdf.m
@@ -113,7 +113,7 @@ create_surface(FileName, Width, Height, Surface, !IO) :-
     Status = cairo_surface_status(raw_surface);
 
     if (Status == CAIRO_STATUS_SUCCESS) {
-        Surface = MR_GC_NEW(MCAIRO_surface);
+        Surface = MR_GC_NEW_ATTRIB(MCAIRO_surface, MR_ALLOC_ID);
         Surface->mcairo_raw_surface = raw_surface;
         MR_GC_register_finalizer(Surface, MCAIRO_finalize_surface, 0);
     } else {
diff --git a/extras/graphics/mercury_cairo/cairo.png.m b/extras/graphics/mercury_cairo/cairo.png.m
index 914296b08..3ac475856 100644
--- a/extras/graphics/mercury_cairo/cairo.png.m
+++ b/extras/graphics/mercury_cairo/cairo.png.m
@@ -79,7 +79,7 @@ image_surface_create_from_png(FileName, Surface, !IO) :-
     cairo_surface_t *raw_image;
 
     raw_image = cairo_image_surface_create_from_png(FileName);
-    Surface = MR_GC_NEW(MCAIRO_surface);
+    Surface = MR_GC_NEW_ATTRIB(MCAIRO_surface, MR_ALLOC_ID);
     Surface->mcairo_raw_surface = raw_image;
     MR_GC_register_finalizer(Surface, MCAIRO_finalize_surface, 0);
 ").
diff --git a/extras/graphics/mercury_cairo/cairo.ps.m b/extras/graphics/mercury_cairo/cairo.ps.m
index c394b5261..2269d20cd 100644
--- a/extras/graphics/mercury_cairo/cairo.ps.m
+++ b/extras/graphics/mercury_cairo/cairo.ps.m
@@ -165,7 +165,7 @@ create_surface(FileName, Width, Height, Surface, !IO) :-
     Status = cairo_surface_status(raw_surface);
 
     if (Status == CAIRO_STATUS_SUCCESS) {
-        Surface = MR_GC_NEW(MCAIRO_surface);
+        Surface = MR_GC_NEW_ATTRIB(MCAIRO_surface, MR_ALLOC_ID);
         Surface->mcairo_raw_surface = raw_surface;
         MR_GC_register_finalizer(Surface, MCAIRO_finalize_surface, 0);
     } else {
diff --git a/extras/graphics/mercury_cairo/cairo.recording.m b/extras/graphics/mercury_cairo/cairo.recording.m
index 0106bad20..7999ca997 100644
--- a/extras/graphics/mercury_cairo/cairo.recording.m
+++ b/extras/graphics/mercury_cairo/cairo.recording.m
@@ -130,7 +130,7 @@ create_surface(Content, MaybeExtents, Surface, !IO) :-
     Status = cairo_surface_status(raw_surface);
 
     if (Status == CAIRO_STATUS_SUCCESS) {
-        Surface = MR_GC_NEW(MCAIRO_surface);
+        Surface = MR_GC_NEW_ATTRIB(MCAIRO_surface, MR_ALLOC_ID);
         Surface->mcairo_raw_surface = raw_surface;
         MR_GC_register_finalizer(Surface, MCAIRO_finalize_surface, 0);
     } else {
diff --git a/extras/graphics/mercury_cairo/cairo.region.m b/extras/graphics/mercury_cairo/cairo.region.m
index 8ed163bf8..dea7dba58 100644
--- a/extras/graphics/mercury_cairo/cairo.region.m
+++ b/extras/graphics/mercury_cairo/cairo.region.m
@@ -157,7 +157,7 @@
     cairo_region_t  *raw_region;
 
     raw_region = cairo_region_create();
-    Region = MR_GC_NEW(MCAIRO_region);
+    Region = MR_GC_NEW_ATTRIB(MCAIRO_region, MR_ALLOC_ID);
     Region->mcairo_raw_region = raw_region;
     MR_GC_register_finalizer(Region, MCAIRO_finalize_region, 0);
 ").
@@ -183,7 +183,7 @@ create_rectangle(Rectangle, Region, !IO) :-
     rect.height = H;
 
     raw_region = cairo_region_create_rectangle(&rect);
-    Region = MR_GC_NEW(MCAIRO_region);
+    Region = MR_GC_NEW_ATTRIB(MCAIRO_region, MR_ALLOC_ID);
     Region->mcairo_raw_region = raw_region;
     MR_GC_register_finalizer(Region, MCAIRO_finalize_region, 0);
 ").
@@ -194,7 +194,7 @@ create_rectangle(Rectangle, Region, !IO) :-
 "
     cairo_region_t  *raw_copy;
     raw_copy = cairo_region_copy(Orig->mcairo_raw_region);
-    Copy = MR_GC_NEW(MCAIRO_region);
+    Copy = MR_GC_NEW_ATTRIB(MCAIRO_region, MR_ALLOC_ID);
     Copy->mcairo_raw_region = raw_copy;
     MR_GC_register_finalizer(Copy, MCAIRO_finalize_region, 0);
 ").
diff --git a/extras/graphics/mercury_cairo/cairo.surface.m b/extras/graphics/mercury_cairo/cairo.surface.m
index 14517ddd4..19b840b87 100644
--- a/extras/graphics/mercury_cairo/cairo.surface.m
+++ b/extras/graphics/mercury_cairo/cairo.surface.m
@@ -128,7 +128,7 @@
     cairo_surface_get_font_options(
         ((MCAIRO_surface *)Surface)->mcairo_raw_surface,
         raw_font_options);
-    FntOpts = MR_GC_NEW(MCAIRO_font_options);
+    FntOpts = MR_GC_NEW_ATTRIB(MCAIRO_font_options, MR_ALLOC_ID);
     FntOpts->mcairo_raw_font_options = raw_font_options;
     MR_GC_register_finalizer(FntOpts, MCAIRO_finalize_font_options, 0);
 ").
diff --git a/extras/graphics/mercury_cairo/cairo.svg.m b/extras/graphics/mercury_cairo/cairo.svg.m
index eeb9901d8..af106b795 100644
--- a/extras/graphics/mercury_cairo/cairo.svg.m
+++ b/extras/graphics/mercury_cairo/cairo.svg.m
@@ -127,7 +127,7 @@ create_surface(FileName, Width, Height, Surface, !IO) :-
     Status = cairo_surface_status(raw_surface);
 
     if (Status == CAIRO_STATUS_SUCCESS) {
-        Surface = MR_GC_NEW(MCAIRO_surface);
+        Surface = MR_GC_NEW_ATTRIB(MCAIRO_surface, MR_ALLOC_ID);
         Surface->mcairo_raw_surface = raw_surface;
         MR_GC_register_finalizer(Surface, MCAIRO_finalize_surface, 0);
     } else {
diff --git a/extras/graphics/mercury_cairo/cairo.text.m b/extras/graphics/mercury_cairo/cairo.text.m
index 2a8dcba82..2343f5aca 100644
--- a/extras/graphics/mercury_cairo/cairo.text.m
+++ b/extras/graphics/mercury_cairo/cairo.text.m
@@ -188,7 +188,7 @@ select_font_face(Context, Family, Slant, Weight, !IO) :-
 "
     cairo_matrix_t  *font_matrix;
 
-    font_matrix = MR_GC_NEW(cairo_matrix_t);
+    font_matrix = MR_GC_NEW_ATTRIB(cairo_matrix_t, MR_ALLOC_ID);
     cairo_get_font_matrix(Ctxt->mcairo_raw_context, font_matrix);
     Matrix = font_matrix;
 ").
@@ -229,7 +229,7 @@ show_glyphs(Ctxt, Glyphs, !IO) :-
     cairo_font_options_t    *raw_font_options;
     raw_font_options = cairo_font_options_create();
     cairo_get_font_options(Ctxt->mcairo_raw_context, raw_font_options);
-    FntOpts = MR_GC_NEW(MCAIRO_font_options);
+    FntOpts = MR_GC_NEW_ATTRIB(MCAIRO_font_options, MR_ALLOC_ID);
     FntOpts->mcairo_raw_font_options = raw_font_options;
     MR_GC_register_finalizer(FntOpts, MCAIRO_finalize_font_options, 0);
 ").
@@ -343,7 +343,7 @@ text_extents(Context, String, Extents, !IO) :-
     cairo_font_face_t   *raw_font_face;
 
     raw_font_face = cairo_toy_font_face_create(Family, Slant, Weight);
-    FontFace = MR_GC_NEW(MCAIRO_font_face);
+    FontFace = MR_GC_NEW_ATTRIB(MCAIRO_font_face, MR_ALLOC_ID);
     FontFace->mcairo_raw_font_face = raw_font_face;
     MR_GC_register_finalizer(FontFace, MCAIRO_finalize_font_face, 0);
 ").
diff --git a/extras/graphics/mercury_cairo/cairo.transformations.m b/extras/graphics/mercury_cairo/cairo.transformations.m
index b5eee6621..cc6403106 100644
--- a/extras/graphics/mercury_cairo/cairo.transformations.m
+++ b/extras/graphics/mercury_cairo/cairo.transformations.m
@@ -138,7 +138,7 @@
     get_matrix(Ctxt::in, Matrix::out, _IO0::di, _IO::uo),
     [promise_pure, will_not_call_mercury, tabled_for_io],
 "
-    Matrix = MR_GC_NEW(cairo_matrix_t);
+    Matrix = MR_GC_NEW_ATTRIB(cairo_matrix_t, MR_ALLOC_ID);
     cairo_get_matrix(Ctxt->mcairo_raw_context, Matrix);
 ").
 
-- 
2.35.1



More information about the reviews mailing list