Skip to content

Commit 4c81ec8

Browse files
committed
Merge branch 'PGPRO9_6' of gitlab.postgrespro.ru:pgpro-dev/postgrespro into PGPRO9_6
2 parents fd1be3a + 604b2b7 commit 4c81ec8

File tree

11 files changed

+169
-12
lines changed

11 files changed

+169
-12
lines changed

src/backend/access/heap/ptrack.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,16 @@ ptrack_get_and_clear(Oid tablespace_oid, Oid table_oid)
276276
{
277277
bytea *result = NULL;
278278
BlockNumber nblock;
279+
280+
Relation rel = RelationIdGetRelation(RelidByRelfilenode(tablespace_oid,
281+
table_oid));
282+
279283
if (table_oid == InvalidOid)
280284
{
281285
elog(WARNING, "InvalidOid");
282286
goto full_end;
283287
}
284288

285-
Relation rel = RelationIdGetRelation(RelidByRelfilenode(tablespace_oid,
286-
table_oid));
287-
288289
if (rel == InvalidRelation)
289290
{
290291
elog(WARNING, "InvalidRelation");

src/bin/psql/command.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1923,7 +1923,13 @@ do_connect(enum trivalue reuse_previous_specification,
19231923
keywords[++paramnum] = "fallback_application_name";
19241924
values[paramnum] = pset.progname;
19251925
keywords[++paramnum] = "client_encoding";
1926-
values[paramnum] = (pset.notty || getenv("PGCLIENTENCODING")) ? NULL : "auto";
1926+
values[paramnum] = (pset.notty || getenv("PGCLIENTENCODING")) ? NULL :
1927+
#ifdef HAVE_WIN32_LIBEDIT
1928+
"UTF8"
1929+
#else
1930+
"auto"
1931+
#endif
1932+
;
19271933

19281934
/* add array terminator */
19291935
keywords[++paramnum] = NULL;
@@ -2105,6 +2111,11 @@ printSSLInfo(void)
21052111
static void
21062112
checkWin32Codepage(void)
21072113
{
2114+
#ifdef HAVE_WIN32_LIBEDIT
2115+
if (isatty(fileno(stdout)))
2116+
printf(_("WARNING: Unicode mode enabled. "
2117+
"You need TTF font in your console window\n"));
2118+
#else
21082119
unsigned int wincp,
21092120
concp;
21102121

@@ -2117,6 +2128,7 @@ checkWin32Codepage(void)
21172128
" page \"Notes for Windows users\" for details.\n"),
21182129
concp, wincp);
21192130
}
2131+
#endif
21202132
}
21212133
#endif
21222134

src/bin/psql/input.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ gets_fromFile(FILE *source)
287287
for (VARNAME = current_history(); VARNAME != NULL; \
288288
VARNAME = use_prev_ ? previous_history() : next_history()) \
289289
{ \
290+
if (VARNAME -> line == NULL) \
291+
continue; \
290292
(void) 0
291293

292294
#define END_ITERATE_HISTORY() \
@@ -355,7 +357,9 @@ initializeInput(int flags)
355357

356358
/* these two things must be done in this order: */
357359
initialize_readline();
360+
#ifndef HAVE_WIN32_LIBEDIT
358361
rl_initialize();
362+
#endif
359363

360364
useHistory = true;
361365
using_history();
@@ -459,8 +463,10 @@ saveHistory(char *fname, int max_lines)
459463
#else /* don't have append support */
460464
{
461465
/* truncate what we have ... */
466+
#ifndef HAVE_WIN32_LIBEDIT
462467
if (max_lines >= 0)
463468
stifle_history(max_lines);
469+
#endif
464470
/* ... and overwrite file. Tough luck for concurrent sessions. */
465471
errnum = write_history(fname);
466472
if (errnum == 0)

src/bin/psql/startup.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "mainloop.h"
2929
#include "fe_utils/print.h"
3030
#include "settings.h"
31+
#include "mb/pg_wchar.h"
3132

3233

3334

@@ -158,7 +159,11 @@ main(int argc, char *argv[])
158159
pset.popt.topt.env_columns = getenv("COLUMNS") ? atoi(getenv("COLUMNS")) : 0;
159160

160161
pset.notty = (!isatty(fileno(stdin)) || !isatty(fileno(stdout)));
161-
162+
#ifdef HAVE_WIN32_LIBEDIT
163+
if (!pset.notty && pset.encoding == PG_SQL_ASCII) {
164+
pset.encoding = PG_UTF8;
165+
}
166+
#endif
162167
pset.getPassword = TRI_DEFAULT;
163168

164169
EstablishVariableSpace();
@@ -233,7 +238,13 @@ main(int argc, char *argv[])
233238
keywords[5] = "fallback_application_name";
234239
values[5] = pset.progname;
235240
keywords[6] = "client_encoding";
236-
values[6] = (pset.notty || getenv("PGCLIENTENCODING")) ? NULL : "auto";
241+
values[6] = (pset.notty || getenv("PGCLIENTENCODING")) ? NULL :
242+
#ifdef HAVE_WIN32_LIBEDIT
243+
"UTF8"
244+
#else
245+
"auto"
246+
#endif
247+
;
237248
keywords[7] = NULL;
238249
values[7] = NULL;
239250

@@ -992,3 +1003,4 @@ EstablishVariableSpace(void)
9921003
SetVariableAssignHook(pset.vars, "VERBOSITY", verbosity_hook);
9931004
SetVariableAssignHook(pset.vars, "SHOW_CONTEXT", show_context_hook);
9941005
}
1006+

src/bin/psql/tab-complete.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,9 +967,13 @@ initialize_readline(void)
967967
{
968968
rl_readline_name = (char *) pset.progname;
969969
rl_attempted_completion_function = psql_completion;
970-
970+
#ifndef HAVE_WIN32_LIBEDIT
971971
rl_basic_word_break_characters = WORD_BREAKS;
972972

973+
/* In WinLibEdit rl_basic_word_break_characters is constant */
974+
975+
#endif
976+
973977
completion_max_records = 1000;
974978

975979
/*

src/common/exec.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ pipe_read_line(char *cmd, char *line, int maxsize)
443443
break; /* Timeout, but perhaps we got a line already */
444444

445445
if (!ReadFile(childstdoutrddup, lineptr, maxsize - (lineptr - line),
446-
&bytesread, NULL))
446+
&bytesread, NULL))
447447
break; /* Error, but perhaps we got a line already */
448448

449449
lineptr += strlen(lineptr);
@@ -578,6 +578,11 @@ set_pglocale_pgservice(const char *argv0, const char *app)
578578
bindtextdomain(app, path);
579579
textdomain(app);
580580

581+
#if defined(HAVE_WIN32_LIBEDIT) && defined(ENABLE_NLS)
582+
bind_textdomain_codeset(app, "UTF-8");
583+
bind_textdomain_codeset(PG_TEXTDOMAIN("libpq"), "UTF-8");
584+
#endif
585+
581586
if (getenv("PGLOCALEDIR") == NULL)
582587
{
583588
/* set for libpq to use */

src/fe_utils/print.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,19 @@ format_numeric_locale(const char *my_str)
318318
static void
319319
fputnbytes(FILE *f, const char *str, size_t n)
320320
{
321+
322+
#ifdef HAVE_WIN32_LIBEDIT
323+
char buffer[1024];
324+
char *buf = buffer;
325+
if (n>1023) buf=malloc(n+1);
326+
strncpy(buf,str,n);
327+
buf[n]=0;
328+
fputs(buf,f);
329+
if (n>1023) free(buf);
330+
#else
321331
while (n-- > 0)
322332
fputc(*str++, f);
333+
#endif
323334
}
324335

325336

src/include/fe_utils/print.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717

1818

1919
/* This is not a particularly great place for this ... */
20+
/* Let build system to redefine default pager */
21+
#ifndef DEFAULT_PAGER
2022
#ifndef __CYGWIN__
2123
#define DEFAULT_PAGER "more"
2224
#else
2325
#define DEFAULT_PAGER "less"
2426
#endif
25-
27+
#endif
2628
enum printFormat
2729
{
2830
PRINT_NOTHING = 0, /* to make sure someone initializes this */

src/include/port.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ extern unsigned char pg_ascii_tolower(unsigned char ch);
152152
#ifdef printf
153153
#undef printf
154154
#endif
155+
#ifdef fputs
156+
#undef fputs
157+
#endif
155158

156159
extern int pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args);
157160
extern int pg_snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3, 4);
@@ -160,6 +163,10 @@ extern int pg_vfprintf(FILE *stream, const char *fmt, va_list args);
160163
extern int pg_fprintf(FILE *stream, const char *fmt,...) pg_attribute_printf(2, 3);
161164
extern int pg_printf(const char *fmt,...) pg_attribute_printf(1, 2);
162165

166+
#ifdef HAVE_WIN32_LIBEDIT
167+
extern int pg_fputs(const char *s, FILE *stream);
168+
extern int pg_puts(const char *s);
169+
#endif
163170
/*
164171
* The GCC-specific code below prevents the pg_attribute_printf above from
165172
* being replaced, and this is required because gcc doesn't know anything
@@ -180,6 +187,11 @@ extern int pg_printf(const char *fmt,...) pg_attribute_printf(1, 2);
180187
#define fprintf pg_fprintf
181188
#define printf pg_printf
182189
#endif
190+
#ifdef HAVE_WIN32_LIBEDIT
191+
/* Catch fputs as well so we can use WriteConsole for table output */
192+
#define fputs(s,f) pg_fputs(s,f)
193+
#define puts(s) pg_puts(s)
194+
#endif
183195
#endif /* USE_REPL_SNPRINTF */
184196

185197
#if defined(WIN32)

src/port/snprintf.c

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) 1983, 1995, 1996 Eric P. Allman
33
* Copyright (c) 1988, 1993
44
* The Regents of the University of California. All rights reserved.
@@ -103,7 +103,9 @@
103103
#undef vfprintf
104104
#undef fprintf
105105
#undef printf
106-
106+
#ifdef HAVE_WIN32_LIBEDIT
107+
#undef fputs
108+
#endif
107109
/* Info about where the formatted output is going */
108110
typedef struct
109111
{
@@ -262,13 +264,35 @@ flushbuffer(PrintfTarget *target)
262264
if (!target->failed && nc > 0)
263265
{
264266
size_t written;
265-
267+
#ifdef HAVE_WIN32_LIBEDIT
268+
/*With Win32 libedit we use WriteW API to write to
269+
* console instead of fwrite*/
270+
if (isatty(fileno(target->stream)))
271+
{
272+
/* Convert message from buffer (expected as utf8)
273+
to widechar */
274+
HANDLE consoleHandle = _get_osfhandle(_fileno(target->stream));
275+
DWORD actuallyWritten;
276+
wchar_t *widebuf= (wchar_t *)malloc(nc*sizeof(wchar_t));
277+
written = MultiByteToWideChar(CP_UTF8,0,target->bufstart,nc,widebuf,nc);
278+
WriteConsoleW(consoleHandle,widebuf,written,&actuallyWritten,NULL);
279+
if (actuallyWritten == written)
280+
target->nchars += nc;
281+
else
282+
target->failed = true;
283+
free(widebuf);
284+
} else {
285+
#endif
266286
written = fwrite(target->bufstart, 1, nc, target->stream);
267287
target->nchars += written;
268288
if (written != nc)
269289
target->failed = true;
290+
#ifdef HAVE_WIN32_LIBEDIT
291+
}
292+
#endif
270293
}
271294
target->bufptr = target->bufstart;
295+
fflush(target->stream);
272296
}
273297

274298

@@ -1139,3 +1163,43 @@ trailing_pad(int *padlen, PrintfTarget *target)
11391163
++(*padlen);
11401164
}
11411165
}
1166+
1167+
#ifdef HAVE_WIN32_LIBEDIT
1168+
/* replacement to fputs function which uses flushBuffer */
1169+
int pg_fputs(const char *s, FILE *stream)
1170+
{
1171+
PrintfTarget target;
1172+
1173+
if (stream == NULL)
1174+
{
1175+
errno = EINVAL;
1176+
return -1;
1177+
}
1178+
target.bufstart = s;
1179+
target.nchars = 0;
1180+
target.bufptr= s + strlen(s);
1181+
target.bufend=NULL;
1182+
target.failed=false;
1183+
target.stream = stream;
1184+
flushbuffer(&target);
1185+
return target.failed ? -1 : target.nchars;
1186+
}
1187+
1188+
/* replacement to puts function which uses flushBuffer */
1189+
int pg_puts(const char *tmps)
1190+
{
1191+
PrintfTarget target;
1192+
char *s = NULL;
1193+
1194+
s = (char *)malloc(strlen(tmps) + 1);
1195+
sprintf(s, "%s\n", tmps);
1196+
target.bufstart = s;
1197+
target.nchars = 0;
1198+
target.bufptr = s + strlen(s);
1199+
target.bufend = NULL;
1200+
target.failed = false;
1201+
target.stream = stdout;
1202+
flushbuffer(&target);
1203+
return target.failed ? -1 : target.nchars;
1204+
}
1205+
#endif

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy