[gnome-builder/wip/gtk4-port] libide/foundry: simplify environ_to_argv
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port] libide/foundry: simplify environ_to_argv
- Date: Fri, 17 Jun 2022 08:26:15 +0000 (UTC)
commit cdbdba53129081190af09e978d22b9e1220e3019
Author: Christian Hergert <chergert redhat com>
Date: Fri Jun 17 01:25:44 2022 -0700
libide/foundry: simplify environ_to_argv
We can get away with a single allocation and then move all the elements
into place at once. Additionally, fix some thinko errors along the way.
src/libide/foundry/ide-run-context.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
---
diff --git a/src/libide/foundry/ide-run-context.c b/src/libide/foundry/ide-run-context.c
index 69f7a4674..e5a51a234 100644
--- a/src/libide/foundry/ide-run-context.c
+++ b/src/libide/foundry/ide-run-context.c
@@ -504,10 +504,8 @@ ide_run_context_unsetenv (IdeRunContext *self,
void
ide_run_context_environ_to_argv (IdeRunContext *self)
{
- static const char *envstr = "env";
IdeRunContextLayer *layer;
- char **args;
- gsize len;
+ const char **copy;
g_assert (IDE_IS_RUN_CONTEXT (self));
@@ -516,10 +514,14 @@ ide_run_context_environ_to_argv (IdeRunContext *self)
if (layer->env->len == 0)
return;
- args = g_array_steal (layer->env, &len);
- g_array_insert_vals (layer->argv, 0, args, len);
- g_array_insert_val (layer->argv, 0, envstr);
- g_free (args);
+ copy = (const char **)g_new0 (char *, layer->env->len + 2);
+ copy[0] = "env";
+ for (guint i = 0; i < layer->env->len; i++)
+ copy[1+i] = g_array_index (layer->env, const char *, i);
+ ide_run_context_prepend_args (self, (const char * const *)copy);
+ g_free (copy);
+
+ g_array_set_size (layer->env, 0);
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]