Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Don't use GPtrArray, review updates
  • Loading branch information
George Wright committed Oct 19, 2020
commit 0b3f9f49d0cb9338b88357c89153ff5d1e9e7eb3
18 changes: 7 additions & 11 deletions shell/platform/linux/fl_dart_project.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct _FlDartProject {
gchar* aot_library_path;
gchar* assets_path;
gchar* icu_data_path;
GPtrArray* dart_entrypoint_args;
gchar** dart_entrypoint_args;
};

G_DEFINE_TYPE(FlDartProject, fl_dart_project, G_TYPE_OBJECT)
Expand All @@ -43,7 +43,7 @@ static void fl_dart_project_dispose(GObject* object) {
g_clear_pointer(&self->aot_library_path, g_free);
g_clear_pointer(&self->assets_path, g_free);
g_clear_pointer(&self->icu_data_path, g_free);
g_ptr_array_unref(self->dart_entrypoint_args);
g_clear_pointer(&self->dart_entrypoint_args, g_strfreev);

G_OBJECT_CLASS(fl_dart_project_parent_class)->dispose(object);
}
Expand All @@ -66,8 +66,6 @@ G_MODULE_EXPORT FlDartProject* fl_dart_project_new() {
self->icu_data_path =
g_build_filename(executable_dir, "data", "icudtl.dat", nullptr);

self->dart_entrypoint_args = g_ptr_array_new_with_free_func(g_free);

return self;
}

Expand Down Expand Up @@ -102,19 +100,17 @@ G_MODULE_EXPORT const gchar* fl_dart_project_get_icu_data_path(
return self->icu_data_path;
}

G_MODULE_EXPORT GPtrArray* fl_dart_project_get_dart_entrypoint_arguments(
G_MODULE_EXPORT gchar** fl_dart_project_get_dart_entrypoint_arguments(
FlDartProject* self) {
g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
return g_ptr_array_ref(self->dart_entrypoint_args);
return self->dart_entrypoint_args;
}

G_MODULE_EXPORT void fl_dart_project_set_dart_entrypoint_arguments(
FlDartProject* self, int argc, const char** argv) {
FlDartProject* self, char** argv) {
g_return_if_fail(FL_IS_DART_PROJECT(self));
g_ptr_array_remove_range(self->dart_entrypoint_args, 0, self->dart_entrypoint_args->len);
for (int i = 0; i < argc; ++i) {
g_ptr_array_add(self->dart_entrypoint_args, g_strdup(argv[i]));
}
g_clear_pointer(&self->dart_entrypoint_args, g_strfreev);
self->dart_entrypoint_args = g_strdupv(argv);
}

GPtrArray* fl_dart_project_get_switches(FlDartProject* self) {
Expand Down
6 changes: 3 additions & 3 deletions shell/platform/linux/fl_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ gboolean fl_engine_start(FlEngine* self, GError** error) {
// so that all switches are used.
g_ptr_array_insert(command_line_args, 0, g_strdup("flutter"));

g_autoptr(GPtrArray) dart_entrypoint_args =
gchar** dart_entrypoint_args =
fl_dart_project_get_dart_entrypoint_arguments(self->project);

FlutterProjectArgs args = {};
Expand All @@ -394,8 +394,8 @@ gboolean fl_engine_start(FlEngine* self, GError** error) {
args.platform_message_callback = fl_engine_platform_message_cb;
args.custom_task_runners = &custom_task_runners;
args.shutdown_dart_vm_when_done = true;
args.dart_entrypoint_argc = dart_entrypoint_args->len;
args.dart_entrypoint_argv = reinterpret_cast<const char* const*>(dart_entrypoint_args->pdata);
args.dart_entrypoint_argc = g_strv_length(dart_entrypoint_args);
args.dart_entrypoint_argv = reinterpret_cast<const char* const*>(dart_entrypoint_args);

if (FlutterEngineRunsAOTCompiledDartCode()) {
FlutterEngineAOTDataSource source = {};
Expand Down
14 changes: 5 additions & 9 deletions shell/platform/linux/public/flutter_linux/fl_dart_project.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,23 @@ const gchar* fl_dart_project_get_icu_data_path(FlDartProject* project);
/**
* fl_dart_project_set_dart_entrypoint_arguments:
* @project: an #FlDartProject.
* @argc: the number of command line arguments in @argv
* @argv: a pointer to an array of C strings containing the command line arguments.
* @argv: a pointer to a NULL-terminated array of C strings containing the command line arguments.
*
* Sets the command line arguments to be passed through to the Dart
* entrypoint function.
*
* FlDartProject makes a deep copy of the arguments passed in here. The caller can
* safely deallocate their copy as soon as this call returns.
*/
void fl_dart_project_set_dart_entrypoint_arguments(FlDartProject* project, int argc, const char** argv);
void fl_dart_project_set_dart_entrypoint_arguments(FlDartProject* project, char** argv);

/**
* fl_dart_project_get_dart_entrypoint_arguments:
* @project: an #FlDartProject.
*
* Gets the command line arguments to be passed through to the Dart entrypoint function.
*
* Returns: a GPtrArray containing the command line arguments to be passed to the Dart
* entrypoint.
* Returns: a NULL-terminated array of strings containing the command line arguments
* to be passed to the Dart entrypoint.
*/
GPtrArray* fl_dart_project_get_dart_entrypoint_arguments(FlDartProject* project);
gchar** fl_dart_project_get_dart_entrypoint_arguments(FlDartProject* project);

G_END_DECLS

Expand Down