@@ -5140,6 +5140,7 @@ static bool report_needed; /* true if any GUC_REPORT reports are needed */
51405140static int GUCNestLevel = 0 ; /* 1 when in main transaction */
51415141
51425142
5143+ static int guc_var_name_compare (const void * key , const void * generic );
51435144static int guc_var_compare (const void * a , const void * b );
51445145static void InitializeGUCOptionsFromEnvironment (void );
51455146static void InitializeOneGUCOption (struct config_generic * gconf );
@@ -5715,7 +5716,6 @@ struct config_generic *
57155716find_option (const char * name , bool create_placeholders , bool skip_errors ,
57165717 int elevel )
57175718{
5718- const char * * key = & name ;
57195719 struct config_generic * * res ;
57205720 int i ;
57215721
@@ -5725,11 +5725,11 @@ find_option(const char *name, bool create_placeholders, bool skip_errors,
57255725 * By equating const char ** with struct config_generic *, we are assuming
57265726 * the name field is first in config_generic.
57275727 */
5728- res = (struct config_generic * * ) bsearch ((void * ) & key ,
5728+ res = (struct config_generic * * ) bsearch ((void * ) & name ,
57295729 (void * ) guc_variables ,
57305730 num_guc_variables ,
57315731 sizeof (struct config_generic * ),
5732- guc_var_compare );
5732+ guc_var_name_compare );
57335733 if (res )
57345734 return * res ;
57355735
@@ -5776,6 +5776,23 @@ find_option(const char *name, bool create_placeholders, bool skip_errors,
57765776 return NULL ;
57775777}
57785778
5779+ /*
5780+ * comparator for bsearch guc_variables array
5781+ * qsort requires that two arguments are the type of element,
5782+ * but bsearch requires the first argument to be the key,
5783+ * the second argument is type of the array element.
5784+ *
5785+ * In pg upstream, bsearch is not used in this file, so
5786+ * the function should be removed later.
5787+ */
5788+ static int
5789+ guc_var_name_compare (const void * key , const void * generic )
5790+ {
5791+ const char * name = * (char * const * )key ;
5792+ const struct config_generic * conf = * (struct config_generic * const * ) generic ;
5793+
5794+ return guc_name_compare (name , conf -> name );
5795+ }
57795796
57805797/*
57815798 * comparator for qsorting and bsearching guc_variables array
@@ -9435,18 +9452,17 @@ static void
94359452define_custom_variable (struct config_generic * variable )
94369453{
94379454 const char * name = variable -> name ;
9438- const char * * nameAddr = & name ;
94399455 struct config_string * pHolder ;
94409456 struct config_generic * * res ;
94419457
94429458 /*
94439459 * See if there's a placeholder by the same name.
94449460 */
9445- res = (struct config_generic * * ) bsearch ((void * ) & nameAddr ,
9461+ res = (struct config_generic * * ) bsearch ((void * ) & name ,
94469462 (void * ) guc_variables ,
94479463 num_guc_variables ,
94489464 sizeof (struct config_generic * ),
9449- guc_var_compare );
9465+ guc_var_name_compare );
94509466 if (res == NULL )
94519467 {
94529468 /*
0 commit comments