Thread: minor code cleanup

minor code cleanup

From
Neil Conway
Date:
The attached patch makes the following cosmetic improvements:

- replace some function signatures of the form "some_type foo()" with
"some_type foo(void)"
- replace a few instances of a literal 0 being used as a NULL pointer;
there are more instances of this in the code, but I just fixed a few
- in src/backend/utils/mb/wstrncmp.c, replace K&R style function
declarations with ANSI style, remove use of 'register' keyword
- remove an "extern" modifier that was applied to a function definition
(rather than a declaration)

(These changes were made initially to satisfy "sparse", but IMHO they
are all good style anyway.)

Barring any objections, I intend to apply this patch on Sunday or Monday.

-Neil
Index: src/backend/bootstrap/bootparse.y
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/backend/bootstrap/bootparse.y,v
retrieving revision 1.73
diff -c -r1.73 bootparse.y
*** src/backend/bootstrap/bootparse.y    31 Aug 2004 17:10:36 -0000    1.73
--- src/backend/bootstrap/bootparse.y    9 Oct 2004 10:10:11 -0000
***************
*** 52,58 ****


  static void
! do_start()
  {
      StartTransactionCommand();
      elog(DEBUG4, "start transaction");
--- 52,58 ----


  static void
! do_start(void)
  {
      StartTransactionCommand();
      elog(DEBUG4, "start transaction");
***************
*** 60,66 ****


  static void
! do_end()
  {
      CommitTransactionCommand();
      elog(DEBUG4, "commit transaction");
--- 60,66 ----


  static void
! do_end(void)
  {
      CommitTransactionCommand();
      elog(DEBUG4, "commit transaction");
Index: src/backend/bootstrap/bootstrap.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/backend/bootstrap/bootstrap.c,v
retrieving revision 1.194
diff -c -r1.194 bootstrap.c
*** src/backend/bootstrap/bootstrap.c    8 Oct 2004 01:36:33 -0000    1.194
--- src/backend/bootstrap/bootstrap.c    9 Oct 2004 10:14:26 -0000
***************
*** 1012,1018 ****

      len = strlen(str);

!     node = FindStr(str, len, 0);
      if (node)
          return node->strnum;
      else
--- 1012,1018 ----

      len = strlen(str);

!     node = FindStr(str, len, NULL);
      if (node)
          return node->strnum;
      else
Index: src/backend/utils/mb/wstrncmp.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/backend/utils/mb/wstrncmp.c,v
retrieving revision 1.6
diff -c -r1.6 wstrncmp.c
*** src/backend/utils/mb/wstrncmp.c    25 Mar 2001 23:23:59 -0000    1.6
--- src/backend/utils/mb/wstrncmp.c    9 Oct 2004 10:47:52 -0000
***************
*** 38,47 ****
  #include "mb/pg_wchar.h"

  int
! pg_wchar_strncmp(s1, s2, n)
! register const pg_wchar *s1,
!            *s2;
! register size_t n;
  {
      if (n == 0)
          return 0;
--- 38,44 ----
  #include "mb/pg_wchar.h"

  int
! pg_wchar_strncmp(const pg_wchar *s1, const pg_wchar *s2, size_t n)
  {
      if (n == 0)
          return 0;
***************
*** 56,65 ****
  }

  int
! pg_char_and_wchar_strncmp(s1, s2, n)
! register const char *s1;
! register const pg_wchar *s2;
! register size_t n;
  {
      if (n == 0)
          return 0;
--- 53,59 ----
  }

  int
! pg_char_and_wchar_strncmp(const char *s1, const pg_wchar *s2, size_t n)
  {
      if (n == 0)
          return 0;
***************
*** 74,83 ****
  }

  size_t
! pg_wchar_strlen(str)
! const pg_wchar *str;
  {
!     register const pg_wchar *s;

      for (s = str; *s; ++s)
          ;
--- 68,76 ----
  }

  size_t
! pg_wchar_strlen(const pg_wchar *str)
  {
!     const pg_wchar *s;

      for (s = str; *s; ++s)
          ;
Index: src/backend/utils/misc/guc.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/backend/utils/misc/guc.c,v
retrieving revision 1.240
diff -c -r1.240 guc.c
*** src/backend/utils/misc/guc.c    8 Oct 2004 01:36:35 -0000    1.240
--- src/backend/utils/misc/guc.c    9 Oct 2004 10:49:53 -0000
***************
*** 4318,4324 ****
      define_custom_variable(&var->gen);
  }

! extern void
  EmitWarningsOnPlaceholders(const char *className)
  {
      struct config_generic **vars = guc_variables;
--- 4318,4324 ----
      define_custom_variable(&var->gen);
  }

! void
  EmitWarningsOnPlaceholders(const char *className)
  {
      struct config_generic **vars = guc_variables;
Index: src/bin/initdb/initdb.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/bin/initdb/initdb.c,v
retrieving revision 1.59
diff -c -r1.59 initdb.c
*** src/bin/initdb/initdb.c    7 Oct 2004 18:57:26 -0000    1.59
--- src/bin/initdb/initdb.c    9 Oct 2004 10:56:04 -0000
***************
*** 1881,1887 ****
   * call exit_nicely() if we got a signal, or else output "ok".
   */
  static void
! check_ok()
  {
      if (caught_signal)
      {
--- 1881,1887 ----
   * call exit_nicely() if we got a signal, or else output "ok".
   */
  static void
! check_ok(void)
  {
      if (caught_signal)
      {
***************
*** 2066,2072 ****
          {"debug", no_argument, NULL, 'd'},
          {"show", no_argument, NULL, 's'},
          {"noclean", no_argument, NULL, 'n'},
!         {0, 0, 0, 0}
      };

      int            c,
--- 2066,2072 ----
          {"debug", no_argument, NULL, 'd'},
          {"show", no_argument, NULL, 's'},
          {"noclean", no_argument, NULL, 'n'},
!         {NULL, 0, NULL, 0}
      };

      int            c,
Index: src/bin/pg_config/pg_config.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/bin/pg_config/pg_config.c,v
retrieving revision 1.7
diff -c -r1.7 pg_config.c
*** src/bin/pg_config/pg_config.c    6 Oct 2004 17:21:45 -0000    1.7
--- src/bin/pg_config/pg_config.c    9 Oct 2004 10:58:30 -0000
***************
*** 31,37 ****
  static char *progname;

  static void
! help()
  {
      printf(_("\n%s provides information about the installed version of PostgreSQL.\n\n"), progname);
      printf(_("Usage:\n"));
--- 31,37 ----
  static char *progname;

  static void
! help(void)
  {
      printf(_("\n%s provides information about the installed version of PostgreSQL.\n\n"), progname);
      printf(_("Usage:\n"));
***************
*** 52,58 ****
  }

  static void
! advice()
  {
      fprintf(stderr, _("\nTry \"%s --help\" for more information\n"), progname);
  }
--- 52,58 ----
  }

  static void
! advice(void)
  {
      fprintf(stderr, _("\nTry \"%s --help\" for more information\n"), progname);
  }
Index: src/bin/pg_ctl/pg_ctl.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/bin/pg_ctl/pg_ctl.c,v
retrieving revision 1.32
diff -c -r1.32 pg_ctl.c
*** src/bin/pg_ctl/pg_ctl.c    7 Oct 2004 15:21:55 -0000    1.32
--- src/bin/pg_ctl/pg_ctl.c    9 Oct 2004 10:56:29 -0000
***************
*** 1190,1196 ****
          {"mode", required_argument, NULL, 'm'},
          {"pgdata", required_argument, NULL, 'D'},
          {"silent", no_argument, NULL, 's'},
!         {0, 0, 0, 0}
      };

      int            option_index;
--- 1190,1196 ----
          {"mode", required_argument, NULL, 'm'},
          {"pgdata", required_argument, NULL, 'D'},
          {"silent", no_argument, NULL, 's'},
!         {NULL, 0, NULL, 0}
      };

      int            option_index;
Index: src/bin/psql/common.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/bin/psql/common.c,v
retrieving revision 1.91
diff -c -r1.91 common.c
*** src/bin/psql/common.c    20 Sep 2004 18:51:19 -0000    1.91
--- src/bin/psql/common.c    9 Oct 2004 10:57:31 -0000
***************
*** 268,274 ****
   * Returns whether our backend connection is still there.
   */
  static bool
! ConnectionUp()
  {
      return PQstatus(pset.db) != CONNECTION_BAD;
  }
--- 268,274 ----
   * Returns whether our backend connection is still there.
   */
  static bool
! ConnectionUp(void)
  {
      return PQstatus(pset.db) != CONNECTION_BAD;
  }
Index: src/interfaces/ecpg/preproc/descriptor.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/interfaces/ecpg/preproc/descriptor.c,v
retrieving revision 1.22
diff -c -r1.22 descriptor.c
*** src/interfaces/ecpg/preproc/descriptor.c    29 Aug 2004 05:07:00 -0000    1.22
--- src/interfaces/ecpg/preproc/descriptor.c    9 Oct 2004 10:53:59 -0000
***************
*** 315,321 ****
  descriptor_variable(const char *name, int input)
  {
      static char descriptor_names[2][MAX_DESCRIPTOR_NAMELEN];
!     static const struct ECPGtype descriptor_type = {ECPGt_descriptor, 0};
      static const struct variable varspace[2] = {
          {descriptor_names[0], (struct ECPGtype *) & descriptor_type, 0, NULL},
          {descriptor_names[1], (struct ECPGtype *) & descriptor_type, 0, NULL}
--- 315,321 ----
  descriptor_variable(const char *name, int input)
  {
      static char descriptor_names[2][MAX_DESCRIPTOR_NAMELEN];
!     static const struct ECPGtype descriptor_type = {ECPGt_descriptor, NULL};
      static const struct variable varspace[2] = {
          {descriptor_names[0], (struct ECPGtype *) & descriptor_type, 0, NULL},
          {descriptor_names[1], (struct ECPGtype *) & descriptor_type, 0, NULL}
Index: src/interfaces/ecpg/preproc/type.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/interfaces/ecpg/preproc/type.c,v
retrieving revision 1.64
diff -c -r1.64 type.c
*** src/interfaces/ecpg/preproc/type.c    29 Aug 2004 05:07:00 -0000    1.64
--- src/interfaces/ecpg/preproc/type.c    9 Oct 2004 10:53:17 -0000
***************
*** 97,103 ****

      ne->type = type;
      ne->size = size;
!     ne->u.element = 0;
      ne->struct_sizeof = NULL;

      return ne;
--- 97,103 ----

      ne->type = type;
      ne->size = size;
!     ne->u.element = NULL;
      ne->struct_sizeof = NULL;

      return ne;
***************
*** 291,297 ****
              if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
                  mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n");

!             ECPGdump_a_simple(o, name, type->type, 0, make_str("-1"), NULL, prefix);
              ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, make_str("-1"), NULL, ind_prefix);
              break;
          default:
--- 291,297 ----
              if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
                  mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n");

!             ECPGdump_a_simple(o, name, type->type, NULL, make_str("-1"), NULL, prefix);
              ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, make_str("-1"), NULL, ind_prefix);
              break;
          default:
Index: src/pl/plpgsql/src/pl_funcs.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/pl/plpgsql/src/pl_funcs.c,v
retrieving revision 1.37
diff -c -r1.37 pl_funcs.c
*** src/pl/plpgsql/src/pl_funcs.c    14 Sep 2004 23:46:46 -0000    1.37
--- src/pl/plpgsql/src/pl_funcs.c    9 Oct 2004 10:59:36 -0000
***************
*** 166,172 ****
   * ----------
   */
  void
! plpgsql_ns_pop()
  {
      int            i;
      PLpgSQL_ns *old;
--- 166,172 ----
   * ----------
   */
  void
! plpgsql_ns_pop(void)
  {
      int            i;
      PLpgSQL_ns *old;
***************
*** 503,509 ****


  static void
! dump_ind()
  {
      int            i;

--- 503,509 ----


  static void
! dump_ind(void)
  {
      int            i;


Re: minor code cleanup

From
Neil Conway
Date:
On Sat, 2004-10-09 at 22:08, Neil Conway wrote:
> The attached patch makes the following cosmetic improvements [...]

Patch applied.

-Neil