55 * command, configuration file, and command line options.
66 * See src/backend/utils/misc/README for more information.
77 *
8- * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.68 2002/05/1701:19:18 tgl Exp $
8+ * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.69 2002/05/1720:32:29 tgl Exp $
99 *
1010 * Copyright 2000 by PostgreSQL Global Development Group
1111 * Written by Peter Eisentraut <peter_e@gmx.net>.
@@ -936,43 +936,33 @@ guc_var_compare(const void *a, const void *b)
936936{
937937struct config_generic * confa = * (struct config_generic * * )a ;
938938struct config_generic * confb = * (struct config_generic * * )b ;
939- char namea [NAMEDATALEN ];
940- char nameb [NAMEDATALEN ];
941- int len ,
942- i ;
939+ const char * namea ;
940+ const char * nameb ;
943941
944942/*
945943 * The temptation to use strcasecmp() here must be resisted, because
946944 * the array ordering has to remain stable across setlocale() calls.
947- * So,apply an ASCII-only downcasing to both names and use strcmp() .
945+ * So,build our own with a simple ASCII-only downcasing .
948946 */
949- len = strlen (confa -> name );
950- if (len >=NAMEDATALEN )
951- len = NAMEDATALEN - 1 ;
952- for (i = 0 ;i < len ;i ++ )
953- {
954- char ch = confa -> name [i ];
955-
956- if (ch >='A' && ch <='Z' )
957- ch += 'a' - 'A' ;
958- namea [i ]= ch ;
959- }
960- namea [len ]= '\0' ;
961-
962- len = strlen (confb -> name );
963- if (len >=NAMEDATALEN )
964- len = NAMEDATALEN - 1 ;
965- for (i = 0 ;i < len ;i ++ )
966- {
967- char ch = confb -> name [i ];
968-
969- if (ch >='A' && ch <='Z' )
970- ch += 'a' - 'A' ;
971- nameb [i ]= ch ;
947+ namea = confa -> name ;
948+ nameb = confb -> name ;
949+ while (* namea && * nameb )
950+ {
951+ char cha = * namea ++ ;
952+ char chb = * nameb ++ ;
953+
954+ if (cha >='A' && cha <='Z' )
955+ cha += 'a' - 'A' ;
956+ if (chb >='A' && chb <='Z' )
957+ chb += 'a' - 'A' ;
958+ if (cha != chb )
959+ return cha - chb ;
972960}
973- nameb [len ]= '\0' ;
974-
975- return strcmp (namea ,nameb );
961+ if (* namea )
962+ return 1 ;/* a is longer */
963+ if (* nameb )
964+ return -1 ;/* b is longer */
965+ return 0 ;
976966}
977967
978968
@@ -1212,17 +1202,8 @@ ResetAllOptions(void)
12121202break ;
12131203}
12141204
1215- str = strdup (conf -> reset_val );
1216- if (str == NULL )
1217- elog (ERROR ,"out of memory" );
1218-
1219- /*
1220- * Remember string in workspace, so that we can free it
1221- * and avoid a permanent memory leak if hook elogs.
1222- */
1223- if (guc_string_workspace )
1224- free (guc_string_workspace );
1225- guc_string_workspace = str ;
1205+ /* We need not strdup here */
1206+ str = conf -> reset_val ;
12261207
12271208if (conf -> assign_hook )
12281209{
@@ -1233,14 +1214,11 @@ ResetAllOptions(void)
12331214elog (ERROR ,"Failed to reset %s" ,conf -> gen .name );
12341215else if (newstr != str )
12351216{
1236- free (str );
12371217/* See notes in set_config_option about casting */
12381218str = (char * )newstr ;
12391219}
12401220}
12411221
1242- guc_string_workspace = NULL ;
1243-
12441222SET_STRING_VARIABLE (conf ,str );
12451223SET_STRING_TENTATIVE_VAL (conf ,str );
12461224conf -> gen .source = conf -> gen .reset_source ;
@@ -1619,8 +1597,13 @@ set_config_option(const char *name, const char *value,
16191597break ;
16201598}
16211599
1600+ /* Should we report errors interactively? */
16221601interactive = (source >=PGC_S_SESSION );
1623- makeDefault = (source <=PGC_S_OVERRIDE )&& (value != NULL );
1602+ /*
1603+ * Should we set reset/session values? (If so, the behavior is not
1604+ * transactional.)
1605+ */
1606+ makeDefault = DoIt && (source <=PGC_S_OVERRIDE )&& (value != NULL );
16241607
16251608/*
16261609 * Ignore attempted set if overridden by previously processed setting.
@@ -1633,7 +1616,7 @@ set_config_option(const char *name, const char *value,
16331616{
16341617if (DoIt && !makeDefault )
16351618{
1636- elog (DEBUG2 ,"setting %s ignored because previous source is higher" ,
1619+ elog (DEBUG2 ,"%s: setting ignored because previous source is higher priority " ,
16371620name );
16381621return true;
16391622}
@@ -1867,6 +1850,11 @@ set_config_option(const char *name, const char *value,
18671850}
18681851else if (conf -> reset_val )
18691852{
1853+ /*
1854+ * We could possibly avoid strdup here, but easier to
1855+ * make this case work the same as the normal assignment
1856+ * case.
1857+ */
18701858newval = strdup (conf -> reset_val );
18711859if (newval == NULL )
18721860{
@@ -2429,10 +2417,12 @@ ProcessGUCArray(ArrayType *array, GucSource source)
24292417continue ;
24302418
24312419s = DatumGetCString (DirectFunctionCall1 (textout ,d ));
2420+
24322421ParseLongOption (s ,& name ,& value );
24332422if (!value )
24342423{
24352424elog (WARNING ,"cannot parse setting \"%s\"" ,name );
2425+ free (name );
24362426continue ;
24372427}
24382428
@@ -2442,6 +2432,10 @@ ProcessGUCArray(ArrayType *array, GucSource source)
24422432 * checked when it was inserted.
24432433 */
24442434SetConfigOption (name ,value ,PGC_SUSET ,source );
2435+
2436+ free (name );
2437+ if (value )
2438+ free (value );
24452439}
24462440}
24472441