Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/bare.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ int
bare_setup(uv_loop_t *loop, js_platform_t *platform, js_env_t **env, int argc, const char *argv[], const bare_options_t *options, bare_t **result) {
int err;

bare_t *bare = malloc(sizeof(bare_t));
size_t len = sizeof(bare_t);

len += (size_t) argc * sizeof(char *);

for (int i = 0; i < argc; i++) {
len += strlen(argv[i]) + 1 /* NULL */;
}

bare_t *bare = malloc(len);

bare_process_t *process = &bare->process;

Expand All @@ -38,11 +46,23 @@ bare_setup(uv_loop_t *loop, js_platform_t *platform, js_env_t **env, int argc, c
process->options.memory_limit = bare__option(options, 0, memory_limit);

process->platform = platform;
process->argc = argc;
process->argv = argv;

memset(&process->callbacks, 0, sizeof(process->callbacks));

process->argc = argc;

char *storage = (char *) &process->argv[argc];

for (int i = 0; i < argc; i++) {
size_t len = strlen(argv[i]) + 1 /* NULL */;

memcpy(storage, argv[i], len);

process->argv[i] = storage;

storage += len;
}

bare_runtime_t *runtime = &process->runtime;

err = bare_runtime_setup(loop, process, runtime);
Expand Down
6 changes: 3 additions & 3 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ struct bare_process_s {

js_platform_t *platform;

int argc;
const char **argv;

struct {
bare_before_exit_cb before_exit;
void *before_exit_data;
Expand All @@ -84,6 +81,9 @@ struct bare_process_s {
bare_thread_cb thread;
void *thread_data;
} callbacks;

int argc;
char *argv[];
};

struct bare_s {
Expand Down