Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Pbckp 216 float locale#506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
daniel-95 merged 1 commit intoREL_2_5fromPBCKP-216-float_locale
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletionssrc/pg_probackup.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -311,6 +311,10 @@ main(int argc, char *argv[])
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_probackup"));
PROGRAM_FULL_PATH = palloc0(MAXPGPATH);

// Setting C locale for numeric values in order to impose dot-based floating-point representation
memorize_environment_locale();
setlocale(LC_NUMERIC, "C");

/* Get current time */
current_time = time(NULL);

Expand DownExpand Up@@ -1024,6 +1028,8 @@ main(int argc, char *argv[])
break;
}

free_environment_locale();

return 0;
}

Expand Down
2 changes: 2 additions & 0 deletionssrc/pg_probackup.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -905,6 +905,8 @@ extern InstanceConfig *readInstanceConfigFile(InstanceState *instanceState);
/* in show.c */
extern int do_show(CatalogState *catalogState, InstanceState *instanceState,
time_t requested_backup_id, bool show_archive);
extern void memorize_environment_locale(void);
extern void free_environment_locale(void);

/* in delete.c */
extern void do_delete(InstanceState *instanceState, time_t backup_id);
Expand Down
53 changes: 51 additions & 2 deletionssrc/show.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@
* show.c: show backup information.
*
* Portions Copyright (c) 2009-2011, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
* Portions Copyright (c) 2015-2019, Postgres Professional
* Portions Copyright (c) 2015-2022, Postgres Professional
*
*-------------------------------------------------------------------------
*/
Expand All@@ -12,6 +12,7 @@

#include <time.h>
#include <dirent.h>
#include <locale.h>
#include <sys/stat.h>

#include "utils/json.h"
Expand DownExpand Up@@ -71,6 +72,43 @@ static PQExpBufferData show_buf;
static bool first_instance = true;
static int32 json_level = 0;

static const char* lc_env_locale;
typedef enum {
LOCALE_C,// Used for formatting output to unify the dot-based floating point representation
LOCALE_ENV// Default environment locale
} output_numeric_locale;

#ifdef HAVE_USELOCALE
static locale_t env_locale, c_locale;
#endif
void memorize_environment_locale() {
lc_env_locale = (const char *)getenv("LC_NUMERIC");
lc_env_locale = lc_env_locale != NULL ? lc_env_locale : "C";
#ifdef HAVE_USELOCALE
env_locale = newlocale(LC_NUMERIC_MASK, lc_env_locale, (locale_t)0);
c_locale = newlocale(LC_NUMERIC_MASK, "C", (locale_t)0);
#else
#ifdef HAVE__CONFIGTHREADLOCALE
_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
#endif
#endif
}

void free_environment_locale() {
#ifdef HAVE_USELOCALE
freelocale(env_locale);
freelocale(c_locale);
#endif
}

static void set_output_numeric_locale(output_numeric_locale loc) {
#ifdef HAVE_USELOCALE
uselocale(loc == LOCALE_C ? c_locale : env_locale);
#else
setlocale(LC_NUMERIC, loc == LOCALE_C ? "C" : lc_env_locale);
#endif
}

/*
* Entry point of pg_probackup SHOW subcommand.
*/
Expand DownExpand Up@@ -513,6 +551,9 @@ show_instance_plain(const char *instance_name, parray *backup_list, bool show_na
ShowBackendRow *rows;
TimeLineID parent_tli = 0;

// Since we've been printing a table, set LC_NUMERIC to its default environment value
set_output_numeric_locale(LOCALE_ENV);

for (i = 0; i < SHOW_FIELDS_COUNT; i++)
widths[i] = strlen(names[i]);

Expand DownExpand Up@@ -726,6 +767,8 @@ show_instance_plain(const char *instance_name, parray *backup_list, bool show_na
}

pfree(rows);
// Restore the C locale
set_output_numeric_locale(LOCALE_C);
}

/*
Expand DownExpand Up@@ -806,6 +849,9 @@ show_archive_plain(const char *instance_name, uint32 xlog_seg_size,
uint32widths_sum = 0;
ShowArchiveRow *rows;

// Since we've been printing a table, set LC_NUMERIC to its default environment value
set_output_numeric_locale(LOCALE_ENV);

for (i = 0; i < SHOW_ARCHIVE_FIELDS_COUNT; i++)
widths[i] = strlen(names[i]);

Expand DownExpand Up@@ -973,6 +1019,8 @@ show_archive_plain(const char *instance_name, uint32 xlog_seg_size,
}

pfree(rows);
// Restore the C locale
set_output_numeric_locale(LOCALE_C);
//TODO: free timelines
}

Expand DownExpand Up@@ -1045,8 +1093,9 @@ show_archive_json(const char *instance_name, uint32 xlog_seg_size,
appendPQExpBuffer(buf, "%lu", tlinfo->size);

json_add_key(buf, "zratio", json_level);

if (tlinfo->size != 0)
zratio = ((float)xlog_seg_size*tlinfo->n_xlog_files) / tlinfo->size;
zratio = ((float)xlog_seg_size *tlinfo->n_xlog_files) / tlinfo->size;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Мне кажется, это к сути тикета не относится.

Copy link
MemberAuthor

@kulaginmkulaginmJul 15, 2022
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Этот кусочек вроде я приводил к единому стилю. Можно оставить, а можно выпилить.

appendPQExpBuffer(buf, "%.2f", zratio);

if (tlinfo->closest_backup != NULL)
Expand Down
3 changes: 3 additions & 0 deletionssrc/utils/configuration.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,6 +18,9 @@

#include"getopt_long.h"

#ifndefWIN32
#include<pwd.h>
#endif
#include<time.h>

#defineMAXPG_LSNCOMPONENT8
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp