Added convenience function gplugin_manager_add_paths_from_environment

Review Request #997 — Created Oct. 5, 2021 and submitted

Information

pjz
gplugin/gplugin
default

Reviewers

Added convenience functions gplugin_manager_append_paths_from_environment and gplugin_manager_prepend_paths_from_environment

Wrote a test that passes.

Summary ID
clang-format fixes
d0c8780cfb616fa43b09fb6382de531e881a5c21
back out inadverent convey hack attempt
5df1c1aaadf17dd1e384048670d9f3799a4519ea
Description From Last Updated

Needs a . at the end of the sentenance.

grimgrim

. again

grimgrim

You need to check if g_getenv actually returned something.

QuLogicQuLogic

we tend to avoid prefix incrementing because it confuses the crap out of people.

grimgrim

Always braces, and not multiple statements in one line.

QuLogicQuLogic

The docs should state that it prepends. Or maybe there should be both gplugin_manager_append_paths_from_environment / gplugin_manager_prepend_paths_from_environment?

QuLogicQuLogic

Only /* */ comments.

QuLogicQuLogic

gint

QuLogicQuLogic

No definitions in the middle of a function.

QuLogicQuLogic

The path names were changed from what this comment says.

QuLogicQuLogic

manager's

QuLogicQuLogic

The inner parentheses are redundant, and also you've not set paths to anything, so this should have failed.

QuLogicQuLogic

Should be static to be internal

QuLogicQuLogic

Extra blank lines.

QuLogicQuLogic

This doc line has changed to be 'The manager instance.' everywhere.

QuLogicQuLogic

Ditto.

QuLogicQuLogic

If this gets incremented for every path, then how can it be 4 at the end?

QuLogicQuLogic

Free post_paths.

QuLogicQuLogic

I think I'd rather see something like gboolean append instead of a function pointer getting passed around.

grimgrim

There should be a * Since: 0.36.0 at the end of the doc comment.

grimgrim

There should be a * Since: 0.36.0 at the end of the doc comment.

grimgrim

Add another line above this to be separate paragraph.

QuLogicQuLogic

Add another line above this to be separate paragraph.

QuLogicQuLogic
QuLogic
  1. 
      
  2. gplugin/gplugin-manager.c (Diff revision 1)
     
     

    You need to check if g_getenv actually returned something.

  3. gplugin/gplugin-manager.c (Diff revision 1)
     
     

    The docs should state that it prepends. Or maybe there should be both gplugin_manager_append_paths_from_environment / gplugin_manager_prepend_paths_from_environment?

    1. Can do either, or both... up to you guys - let me know.

    2. I hate to pollute the API, but lets do both.

    3. Alright. Since they only differ by one line, I refactored.

  4. Only /* */ comments.

  5. No definitions in the middle of a function.

  6. The inner parentheses are redundant, and also you've not set paths to anything, so this should have failed.

  7. 
      
grim
  1. 
      
  2. gplugin/gplugin-manager.c (Diff revision 1)
     
     

    Needs a . at the end of the sentenance.

  3. gplugin/gplugin-manager.c (Diff revision 1)
     
     

    . again

  4. gplugin/gplugin-manager.c (Diff revision 1)
     
     

    we tend to avoid prefix incrementing because it confuses the crap out of people.

  5. 
      
pjz
grim
QuLogic
  1. 
      
  2. gplugin/gplugin-manager.c (Diff revisions 1 - 2)
     
     

    Always braces, and not multiple statements in one line.

  3. gplugin/tests/test-plugin-manager-paths.c (Diff revisions 1 - 2)
     
     

    The path names were changed from what this comment says.

  4. gplugin/tests/test-plugin-manager-paths.c (Diff revisions 1 - 2)
     
     

    manager's

  5. 
      
pjz
QuLogic
  1. 
      
  2. gplugin/gplugin-manager.c (Diff revisions 2 - 3)
     
     

    Should be static to be internal

  3. gplugin/gplugin-manager.c (Diff revision 3)
     
     
     
     

    Extra blank lines.

  4. gplugin/gplugin-manager.c (Diff revision 3)
     
     

    This doc line has changed to be 'The manager instance.' everywhere.

  5. gplugin/gplugin-manager.c (Diff revision 3)
     
     
  6. If this gets incremented for every path, then how can it be 4 at the end?

    1. found_pos tracks the position as it goes through the loop, so is incremented every pass. found_paths tracks how many have been found, and is only incremented when a path is found. found_pos is used to check that the 'pre' paths are actually first and the 'post' paths are actaully last.

    2. Ah, the names are a bit too similar then. Maybe just call this one index? And then you should increment at the end of the loop for consistency with how indexing works in C. I'd also flip the order of the comparison in the asserts as well.

    3. renamed it to paths_pos

  7. Free post_paths.

  8. 
      
pjz
grim
  1. 
      
  2. gplugin/gplugin-manager.c (Diff revision 4)
     
     

    I think I'd rather see something like gboolean append instead of a function pointer getting passed around.

  3. gplugin/gplugin-manager.c (Diff revision 4)
     
     

    There should be a * Since: 0.36.0 at the end of the doc comment.

  4. gplugin/gplugin-manager.c (Diff revision 4)
     
     

    There should be a * Since: 0.36.0 at the end of the doc comment.

  5. 
      
pjz
QuLogic
  1. Ship It!
  2. gplugin/gplugin-manager.c (Diff revision 5)
     
     

    Add another line above this to be separate paragraph.

  3. gplugin/gplugin-manager.c (Diff revision 5)
     
     

    Add another line above this to be separate paragraph.

  4. 
      
grim
  1. 
      
  2. Also please make sure to run ninja clang-format from your build directory before your next update. That will automatically format all the things :)

    1. which build directory? I'm using 'convey' to run tests and such. convey clang-format seems to run, but writes no changes and doesn't seem to product any actionable output (eg. a list of fixes it wants). should it?

    2. Using convey is good too, but it only prints out the problems:

      diff -r 464e53233e3b gplugin/gplugin-manager.c
      --- a/gplugin/gplugin-manager.c Fri Oct 22 22:53:27 2021 -0400
      +++ b/gplugin/gplugin-manager.c Sat Oct 23 02:56:16 2021 +0000
      @@ -133,15 +133,15 @@
          gchar **paths;
          gint i;
          const gchar *from_env;
      -   void (*changer)(GPluginManager*, const gchar*);
      +   void (*changer)(GPluginManager *, const gchar *);
      
          from_env = g_getenv(name);
      -   if (from_env == NULL) {
      +   if(from_env == NULL) {
              return;
          }
      
          paths = g_strsplit(from_env, G_SEARCHPATH_SEPARATOR_S, 0);
      -   if (prepend) {
      +   if(prepend) {
              changer = &gplugin_manager_prepend_path;
          } else {
              changer = &gplugin_manager_append_path;
      @@ -727,10 +727,7 @@
          GPluginManager *manager,
          const gchar *name)
       {
      -   gplugin_manager_change_paths_from_environment(
      -           manager,
      -           name,
      -           FALSE);
      +   gplugin_manager_change_paths_from_environment(manager, name, FALSE);
       }
      
       /**
      @@ -746,10 +743,7 @@
          GPluginManager *manager,
          const gchar *name)
       {
      -   gplugin_manager_change_paths_from_environment(
      -           manager,
      -           name,
      -           TRUE);
      +   gplugin_manager_change_paths_from_environment(manager, name, TRUE);
       }
      
       /**
      diff -r 464e53233e3b gplugin/tests/test-plugin-manager-paths.c
      --- a/gplugin/tests/test-plugin-manager-paths.c Fri Oct 22 22:53:27 2021 -0400
      +++ b/gplugin/tests/test-plugin-manager-paths.c Sat Oct 23 02:56:16 2021 +0000
      @@ -221,7 +221,6 @@
          g_assert_cmpuint(0, ==, size);
       }
      
      -
       static void
       test_gplugin_manager_add_app_paths_via_environ(void)
       {
      @@ -240,26 +239,24 @@
          path_count = g_list_length(paths);
      
          /* build contents of environment vars */
      -   pre_paths = g_strdup_printf("%s%s%s",
      -           "/prefoo",
      -           G_SEARCHPATH_SEPARATOR_S,
      -           "/prebar/"
      -           );
      -   post_paths = g_strdup_printf("%s%s%s",
      -           "/postfoo",
      -           G_SEARCHPATH_SEPARATOR_S,
      -           "/postbar/"
      -           );
      +   pre_paths = g_strdup_printf(
      +       "%s%s%s",
      +       "/prefoo",
      +       G_SEARCHPATH_SEPARATOR_S,
      +       "/prebar/");
      +   post_paths = g_strdup_printf(
      +       "%s%s%s",
      +       "/postfoo",
      +       G_SEARCHPATH_SEPARATOR_S,
      +       "/postbar/");
      
          /* put /envfoo and /envbar as paths in an environment variable */
          g_setenv(pre_env_var_name, pre_paths, TRUE);
          g_setenv(post_env_var_name, post_paths, TRUE);
      
          /* have the manager add them */
      -   gplugin_manager_prepend_paths_from_environment(manager,
      -           pre_env_var_name);
      -   gplugin_manager_append_paths_from_environment(manager,
      -           post_env_var_name);
      +   gplugin_manager_prepend_paths_from_environment(manager, pre_env_var_name);
      +   gplugin_manager_append_paths_from_environment(manager, post_env_var_name);
      
          /* now get the manager's current paths */
          paths = gplugin_manager_get_paths(manager);
      @@ -271,16 +268,16 @@
          path_pos = 0;
          for(l = paths; l != NULL; l = l->next) {
              path_pos += 1;
      -       if (g_strcmp0(l->data, "/prefoo/") == 0) {
      +       if(g_strcmp0(l->data, "/prefoo/") == 0) {
                  g_assert_cmpint(2, >=, path_pos);
                  found_paths += 1;
      -       } else if (g_strcmp0(l->data, "/prebar/") == 0) {
      +       } else if(g_strcmp0(l->data, "/prebar/") == 0) {
                  g_assert_cmpint(2, >=, path_pos);
                  found_paths += 1;
      -       } else if (g_strcmp0(l->data, "/postfoo/") == 0) {
      +       } else if(g_strcmp0(l->data, "/postfoo/") == 0) {
                  g_assert_cmpint(2, <, path_pos);
                  found_paths += 1;
      -       } else if (g_strcmp0(l->data, "/postbar/") == 0) {
      +       } else if(g_strcmp0(l->data, "/postbar/") == 0) {
                  g_assert_cmpint(2, <, path_pos);
                  found_paths += 1;
              }
      
  3. 
      
pjz
grim
  1. Ship It!
  2. Thanks again for seeing this through to the end!!

  3. 
      
grim
Review request changed

Status: Closed (submitted)

Loading...