@@ -243,34 +243,17 @@ assign_datestyle(const char *newval, void *extra)
243
243
* TIMEZONE
244
244
*/
245
245
246
- typedef struct
247
- {
248
- pg_tz * session_timezone ;
249
- int CTimeZone ;
250
- bool HasCTZSet ;
251
- } timezone_extra ;
252
-
253
246
/*
254
247
* check_timezone: GUC check_hook for timezone
255
248
*/
256
249
bool
257
250
check_timezone (char * * newval , void * * extra , GucSource source )
258
251
{
259
- timezone_extra myextra ;
252
+ pg_tz * new_tz ;
253
+ long gmtoffset ;
260
254
char * endptr ;
261
255
double hours ;
262
256
263
- /*
264
- * Initialize the "extra" struct that will be passed to assign_timezone.
265
- * We don't want to change any of the three global variables except as
266
- * specified by logic below. To avoid leaking memory during failure
267
- * returns, we set up the struct contents in a local variable, and only
268
- * copy it to *extra at the end.
269
- */
270
- myextra .session_timezone = session_timezone ;
271
- myextra .CTimeZone = CTimeZone ;
272
- myextra .HasCTZSet = HasCTZSet ;
273
-
274
257
if (pg_strncasecmp (* newval , "interval" , 8 ) == 0 )
275
258
{
276
259
/*
@@ -323,12 +306,11 @@ check_timezone(char **newval, void **extra, GucSource source)
323
306
324
307
/* Here we change from SQL to Unix sign convention */
325
308
#ifdef HAVE_INT64_TIMESTAMP
326
- myextra . CTimeZone = - (interval -> time / USECS_PER_SEC );
309
+ gmtoffset = - (interval -> time / USECS_PER_SEC );
327
310
#else
328
- myextra . CTimeZone = - interval -> time ;
311
+ gmtoffset = - interval -> time ;
329
312
#endif
330
- myextra .session_timezone = pg_tzset_offset (myextra .CTimeZone );
331
- myextra .HasCTZSet = true;
313
+ new_tz = pg_tzset_offset (gmtoffset );
332
314
333
315
pfree (interval );
334
316
}
@@ -341,17 +323,14 @@ check_timezone(char **newval, void **extra, GucSource source)
341
323
if (endptr != * newval && * endptr == '\0' )
342
324
{
343
325
/* Here we change from SQL to Unix sign convention */
344
- myextra .CTimeZone = - hours * SECS_PER_HOUR ;
345
- myextra .session_timezone = pg_tzset_offset (myextra .CTimeZone );
346
- myextra .HasCTZSet = true;
326
+ gmtoffset = - hours * SECS_PER_HOUR ;
327
+ new_tz = pg_tzset_offset (gmtoffset );
347
328
}
348
329
else
349
330
{
350
331
/*
351
332
* Otherwise assume it is a timezone name, and try to load it.
352
333
*/
353
- pg_tz * new_tz ;
354
-
355
334
new_tz = pg_tzset (* newval );
356
335
357
336
if (!new_tz )
@@ -367,40 +346,16 @@ check_timezone(char **newval, void **extra, GucSource source)
367
346
GUC_check_errdetail ("PostgreSQL does not support leap seconds." );
368
347
return false;
369
348
}
370
-
371
- myextra .session_timezone = new_tz ;
372
- myextra .HasCTZSet = false;
373
349
}
374
350
}
375
351
376
- /*
377
- * Prepare the canonical string to return. GUC wants it malloc'd.
378
- *
379
- * Note: the result string should be something that we'd accept as input.
380
- * We use the numeric format for interval cases, because it's simpler to
381
- * reload. In the named-timezone case, *newval is already OK and need not
382
- * be changed; it might not have the canonical casing, but that's taken
383
- * care of by show_timezone.
384
- */
385
- if (myextra .HasCTZSet )
386
- {
387
- char * result = (char * ) malloc (64 );
388
-
389
- if (!result )
390
- return false;
391
- snprintf (result , 64 , "%.5f" ,
392
- (double ) (- myextra .CTimeZone ) / (double ) SECS_PER_HOUR );
393
- free (* newval );
394
- * newval = result ;
395
- }
396
-
397
352
/*
398
353
* Pass back data for assign_timezone to use
399
354
*/
400
- * extra = malloc (sizeof (timezone_extra ));
355
+ * extra = malloc (sizeof (pg_tz * ));
401
356
if (!* extra )
402
357
return false;
403
- memcpy ( * extra , & myextra , sizeof ( timezone_extra )) ;
358
+ * (( pg_tz * * ) * extra ) = new_tz ;
404
359
405
360
return true;
406
361
}
@@ -411,43 +366,19 @@ check_timezone(char **newval, void **extra, GucSource source)
411
366
void
412
367
assign_timezone (const char * newval , void * extra )
413
368
{
414
- timezone_extra * myextra = (timezone_extra * ) extra ;
415
-
416
- session_timezone = myextra -> session_timezone ;
417
- CTimeZone = myextra -> CTimeZone ;
418
- HasCTZSet = myextra -> HasCTZSet ;
369
+ session_timezone = * ((pg_tz * * ) extra );
419
370
}
420
371
421
372
/*
422
373
* show_timezone: GUC show_hook for timezone
423
- *
424
- * We wouldn't need this, except that historically interval values have been
425
- * shown without an INTERVAL prefix, so the display format isn't what would
426
- * be accepted as input. Otherwise we could have check_timezone return the
427
- * preferred string to begin with.
428
374
*/
429
375
const char *
430
376
show_timezone (void )
431
377
{
432
378
const char * tzn ;
433
379
434
- if (HasCTZSet )
435
- {
436
- Interval interval ;
437
-
438
- interval .month = 0 ;
439
- interval .day = 0 ;
440
- #ifdef HAVE_INT64_TIMESTAMP
441
- interval .time = - (CTimeZone * USECS_PER_SEC );
442
- #else
443
- interval .time = - CTimeZone ;
444
- #endif
445
-
446
- tzn = DatumGetCString (DirectFunctionCall1 (interval_out ,
447
- IntervalPGetDatum (& interval )));
448
- }
449
- else
450
- tzn = pg_get_timezone_name (session_timezone );
380
+ /* Always show the zone's canonical name */
381
+ tzn = pg_get_timezone_name (session_timezone );
451
382
452
383
if (tzn != NULL )
453
384
return tzn ;
@@ -497,7 +428,7 @@ check_log_timezone(char **newval, void **extra, GucSource source)
497
428
* extra = malloc (sizeof (pg_tz * ));
498
429
if (!* extra )
499
430
return false;
500
- memcpy ( * extra , & new_tz , sizeof ( pg_tz * )) ;
431
+ * (( pg_tz * * ) * extra ) = new_tz ;
501
432
502
433
return true;
503
434
}
@@ -519,6 +450,7 @@ show_log_timezone(void)
519
450
{
520
451
const char * tzn ;
521
452
453
+ /* Always show the zone's canonical name */
522
454
tzn = pg_get_timezone_name (log_timezone );
523
455
524
456
if (tzn != NULL )
0 commit comments