From 27fb6baa20a3427bebb45cbe3325b6e45cee6e81 Mon Sep 17 00:00:00 2001 From: Anna Petrasova Date: Thu, 26 May 2022 16:17:58 -0400 Subject: [PATCH] r.patch: fix race condition for CELL rasters --- raster/r.patch/do_patch.c | 6 +++--- raster/r.patch/local_proto.h | 2 +- raster/r.patch/main.c | 8 ++++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/raster/r.patch/do_patch.c b/raster/r.patch/do_patch.c index fc468970121..4ace596d4c9 100644 --- a/raster/r.patch/do_patch.c +++ b/raster/r.patch/do_patch.c @@ -21,7 +21,7 @@ int is_zero_value(void *rast, RASTER_MAP_TYPE data_type) } int do_patch(void *result, void *patch, struct Cell_stats *statf, int ncols, - RASTER_MAP_TYPE out_type, size_t out_cell_size, int use_zero) + RASTER_MAP_TYPE out_type, size_t out_cell_size, int use_zero, int no_support) { int more; @@ -38,7 +38,7 @@ int do_patch(void *result, void *patch, struct Cell_stats *statf, int ncols, if (is_zero_value(patch, out_type)) more = 1; Rast_raster_cpy(result, patch, 1, out_type); - if (out_type == CELL_TYPE) + if (out_type == CELL_TYPE && !no_support) Rast_update_cell_stats((CELL *) result, 1, statf); } } /* ZERO support */ @@ -49,7 +49,7 @@ int do_patch(void *result, void *patch, struct Cell_stats *statf, int ncols, more = 1; else { Rast_raster_cpy(result, patch, 1, out_type); - if (out_type == CELL_TYPE) + if (out_type == CELL_TYPE && !no_support) Rast_update_cell_stats((CELL *) result, 1, statf); } } /* NULL support */ diff --git a/raster/r.patch/local_proto.h b/raster/r.patch/local_proto.h index fad71830e38..73b10de1b2c 100644 --- a/raster/r.patch/local_proto.h +++ b/raster/r.patch/local_proto.h @@ -1,6 +1,6 @@ /* do_patch.c */ int do_patch(void *result, void *, struct Cell_stats *, int, RASTER_MAP_TYPE, - size_t, int); + size_t, int, int); /* support.c */ int support(char **, struct Cell_stats *, int, struct Categories *, int *, struct Colors *, int *, RASTER_MAP_TYPE); diff --git a/raster/r.patch/main.c b/raster/r.patch/main.c index 06a46707ecd..1e5fe52875c 100644 --- a/raster/r.patch/main.c +++ b/raster/r.patch/main.c @@ -152,6 +152,10 @@ int main(int argc, char *argv[]) Rast_get_cellhd(name, "", &cellhd[i]); } + if (!no_support && nprocs > 1 && out_type == CELL_TYPE) { + no_support = true; + G_warning(_("Creating support files (labels, color table) disabled for nprocs > 1")); + } out_cell_size = Rast_cell_size(out_type); @@ -214,7 +218,7 @@ int main(int argc, char *argv[]) north_edge = Rast_row_to_northing(row, &window); south_edge = north_edge - window.ns_res; - if (out_type == CELL_TYPE) + if (out_type == CELL_TYPE && !no_support) Rast_update_cell_stats((CELL *) local_presult, ncols, &statf[0]); for (i = 1; i < nfiles; i++) { @@ -227,7 +231,7 @@ int main(int argc, char *argv[]) Rast_get_row(local_infd[i], local_patch, row, out_type); if (!do_patch(local_presult, local_patch, &statf[i], ncols, - out_type, out_cell_size, use_zero)) + out_type, out_cell_size, use_zero, no_support)) break; } void *p = G_incr_void_ptr(outbuf, out_cell_size *