treewide: use ralloc_memdup

@@
expression memctx, dst, src, size;
@@

-dst = ralloc_size(memctx, size);
-memcpy(dst, src, size);
+dst = ralloc_memdup(memctx, src, size);

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27762>
This commit is contained in:
Alyssa Rosenzweig 2024-02-23 09:32:41 -04:00 committed by Marge Bot
parent 66b00e2966
commit 6825902bb6
6 changed files with 14 additions and 23 deletions

View file

@ -696,18 +696,13 @@ clone_printf_info(void *mem_ctx, const nir_shader *s)
const u_printf_info *src_info = &s->printf_info[i];
infos[i].num_args = src_info->num_args;
infos[i].arg_sizes = ralloc_size(mem_ctx,
sizeof(infos[i].arg_sizes[0]) *
src_info->num_args);
memcpy(infos[i].arg_sizes, src_info->arg_sizes,
sizeof(infos[i].arg_sizes[0]) * src_info->num_args);
infos[i].arg_sizes = ralloc_memdup(mem_ctx, src_info->arg_sizes,
sizeof(infos[i].arg_sizes[0]) * src_info->num_args);
infos[i].string_size = src_info->string_size;
infos[i].strings = ralloc_size(mem_ctx,
src_info->string_size);
memcpy(infos[i].strings, src_info->strings,
src_info->string_size);
infos[i].strings = ralloc_memdup(mem_ctx, src_info->strings,
src_info->string_size);
}
return infos;
@ -750,14 +745,13 @@ nir_shader_clone(void *mem_ctx, const nir_shader *s)
ns->constant_data_size = s->constant_data_size;
if (s->constant_data_size > 0) {
ns->constant_data = ralloc_size(ns, s->constant_data_size);
memcpy(ns->constant_data, s->constant_data, s->constant_data_size);
ns->constant_data = ralloc_memdup(ns, s->constant_data,
s->constant_data_size);
}
if (s->xfb_info) {
size_t size = nir_xfb_info_size(s->xfb_info->output_count);
ns->xfb_info = ralloc_size(ns, size);
memcpy(ns->xfb_info, s->xfb_info, size);
ns->xfb_info = ralloc_memdup(ns, s->xfb_info, size);
}
if (s->printf_info_count > 0) {

View file

@ -447,8 +447,8 @@ nir_link_shader_functions(nir_shader *shader,
sizeof(dst_info->arg_sizes[0]) * dst_info->num_args);
dst_info->string_size = src_info->string_size;
dst_info->strings = ralloc_size(shader, dst_info->string_size);
memcpy(dst_info->strings, src_info->strings, dst_info->string_size);
dst_info->strings = ralloc_memdup(shader, src_info->strings,
dst_info->string_size);
}
}

View file

@ -147,8 +147,7 @@ nir_create_passthrough_gs(const nir_shader_compiler_options *options,
memcpy(nir->info.xfb_stride, prev_stage->info.xfb_stride, sizeof(prev_stage->info.xfb_stride));
if (prev_stage->xfb_info) {
size_t size = nir_xfb_info_size(prev_stage->xfb_info->output_count);
nir->xfb_info = ralloc_size(nir, size);
memcpy(nir->xfb_info, prev_stage->xfb_info, size);
nir->xfb_info = ralloc_memdup(nir, prev_stage->xfb_info, size);
}
bool handle_flat = output_lines && nir->info.gs.output_primitive != gs_out_prim_for_topology(primitive_type);

View file

@ -516,8 +516,8 @@ v3d_get_compiled_shader(struct v3d_context *v3d,
if (ht) {
struct v3d_cache_key *dup_cache_key =
ralloc_size(shader, sizeof(struct v3d_cache_key));
dup_cache_key->key = ralloc_size(shader, key_size);
memcpy(dup_cache_key->key, cache_key.key, key_size);
dup_cache_key->key = ralloc_memdup(shader, cache_key.key,
key_size);
memcpy(dup_cache_key->sha1, cache_key.sha1 ,sizeof(dup_cache_key->sha1));
_mesa_hash_table_insert(ht, dup_cache_key, shader);
}

View file

@ -1074,8 +1074,7 @@ zink_create_quads_emulation_gs(const nir_shader_compiler_options *options,
memcpy(nir->info.xfb_stride, prev_stage->info.xfb_stride, sizeof(prev_stage->info.xfb_stride));
if (prev_stage->xfb_info) {
size_t size = nir_xfb_info_size(prev_stage->xfb_info->output_count);
nir->xfb_info = ralloc_size(nir, size);
memcpy(nir->xfb_info, prev_stage->xfb_info, size);
nir->xfb_info = ralloc_memdup(nir, prev_stage->xfb_info, size);
}
nir_variable *in_vars[VARYING_SLOT_MAX];

View file

@ -56,8 +56,7 @@ write_stream_out_to_cache(struct blob *blob,
static void
copy_blob_to_driver_cache_blob(struct blob *blob, struct gl_program *prog)
{
prog->driver_cache_blob = ralloc_size(NULL, blob->size);
memcpy(prog->driver_cache_blob, blob->data, blob->size);
prog->driver_cache_blob = ralloc_memdup(NULL, blob->data, blob->size);
prog->driver_cache_blob_size = blob->size;
}