Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 35ddc2e

Browse files
committed
This patch reduces some unsightly #ifdefs, and fixes two typos in
comments in the psql code. This doesn't make any functional change, so feel free to save it for 7.5 Neil Conway
1 parent abd5d75 commit 35ddc2e

File tree

6 files changed

+31
-60
lines changed

6 files changed

+31
-60
lines changed

src/bin/psql/command.c

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.106 2003/11/29 19:52:06 pgsql Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.107 2003/12/01 22:14:40 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "command.h"
1010

1111
#include <errno.h>
12-
#include <assert.h>
1312
#include <ctype.h>
1413
#ifdef HAVE_PWD_H
1514
#include <pwd.h>
@@ -97,10 +96,7 @@ HandleSlashCmds(const char *line,
9796
const char *continue_parse = NULL; /* tell the mainloop where the
9897
* backslash command ended */
9998

100-
#ifdef USE_ASSERT_CHECKING
101-
assert(line);
102-
#endif
103-
99+
psql_assert(line);
104100
my_line = xstrdup(line);
105101

106102
/*
@@ -1234,9 +1230,7 @@ unescape(const unsigned char *source, size_t len)
12341230
*tmp;
12351231
size_t length;
12361232

1237-
#ifdef USE_ASSERT_CHECKING
1238-
assert(source);
1239-
#endif
1233+
psql_assert(source);
12401234

12411235
length = Min(len, strlen(source)) + 1;
12421236

@@ -1515,12 +1509,7 @@ editFile(const char *fname)
15151509
char *sys;
15161510
int result;
15171511

1518-
#ifdef USE_ASSERT_CHECKING
1519-
assert(fname);
1520-
#else
1521-
if (!fname)
1522-
return false;
1523-
#endif
1512+
psql_assert(fname);
15241513

15251514
/* Find an editor to use */
15261515
editorName = getenv("PSQL_EDITOR");
@@ -1755,12 +1744,7 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
17551744
{
17561745
size_t vallen = 0;
17571746

1758-
#ifdef USE_ASSERT_CHECKING
1759-
assert(param);
1760-
#else
1761-
if (!param)
1762-
return false;
1763-
#endif
1747+
psql_assert(param);
17641748

17651749
if (value)
17661750
vallen = strlen(value);

src/bin/psql/common.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.30 2003/11/29 19:52:06 pgsql Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.31 2003/12/01 22:14:40 momjian Exp $
77
*/
88
#ifndef COMMON_H
99
#define COMMON_H
@@ -13,6 +13,13 @@
1313
#include "pqsignal.h"
1414
#include "libpq-fe.h"
1515

16+
#ifdef USE_ASSERT_CHECKING
17+
#include <assert.h>
18+
#define psql_assert(p) assert(p)
19+
#else
20+
#define psql_assert(p)
21+
#endif
22+
1623
extern char *xstrdup(const char *string);
1724

1825
extern bool setQFout(const char *fname);

src/bin/psql/copy.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.34 2003/11/29 19:52:06 pgsql Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.35 2003/12/01 22:14:40 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "copy.h"
1010

1111
#include <errno.h>
12-
#include <assert.h>
1312
#include <signal.h>
1413
#include <sys/stat.h>
1514
#ifndef WIN32

src/bin/psql/stringutils.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/stringutils.c,v 1.35 2003/11/29 19:52:07 pgsql Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/stringutils.c,v 1.36 2003/12/01 22:14:40 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99

10-
#include <assert.h>
1110
#include <ctype.h>
1211

1312
#include "libpq-fe.h"
13+
#include "common.h"
1414
#include "settings.h"
1515
#include "stringutils.h"
1616

@@ -234,10 +234,8 @@ strip_quotes(char *source, char quote, char escape, int encoding)
234234
char *src;
235235
char *dst;
236236

237-
#ifdef USE_ASSERT_CHECKING
238-
assert(source);
239-
assert(quote);
240-
#endif
237+
psql_assert(source);
238+
psql_assert(quote);
241239

242240
src = dst = source;
243241

src/bin/psql/tab-complete.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.95 2003/12/01 22:08:01 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.96 2003/12/01 22:14:40 momjian Exp $
77
*/
88

99
/*----------------------------------------------------------------------
@@ -49,9 +49,6 @@
4949
#ifdef USE_READLINE
5050

5151
#include <ctype.h>
52-
#ifdef USE_ASSERT_CHECKING
53-
#include <assert.h>
54-
#endif
5552
#include "libpq-fe.h"
5653
#include "pqexpbuffer.h"
5754
#include "common.h"
@@ -1345,7 +1342,6 @@ psql_completion(char *text, int start, int end)
13451342
}
13461343
}
13471344

1348-
13491345
/*
13501346
* If we still don't have anything to match we have to fabricate some
13511347
* sort of default list. If we were to just return NULL, readline
@@ -1360,7 +1356,6 @@ psql_completion(char *text, int start, int end)
13601356
#endif
13611357
}
13621358

1363-
13641359
/* free storage */
13651360
free(prev_wd);
13661361
free(prev2_wd);
@@ -1382,7 +1377,7 @@ psql_completion(char *text, int start, int end)
13821377
directly but through the readline interface.
13831378
The return value is expected to be the full completion of the text, going
13841379
through a list each time, or NULL if there are no more matches. The string
1385-
will be free()'d be readline, so you must run it through strdup() or
1380+
will be free()'d by readline, so you must run it through strdup() or
13861381
something of that sort.
13871382
*/
13881383

@@ -1637,9 +1632,7 @@ complete_from_list(const char *text, int state)
16371632
const char *item;
16381633

16391634
/* need to have a list */
1640-
#ifdef USE_ASSERT_CHECKING
1641-
assert(completion_charpp);
1642-
#endif
1635+
psql_assert(completion_charpp);
16431636

16441637
/* Initialization */
16451638
if (state == 0)
@@ -1693,9 +1686,7 @@ complete_from_const(const char *text, int state)
16931686
(void) text; /* We don't care about what was entered
16941687
* already. */
16951688

1696-
#ifdef USE_ASSERT_CHECKING
1697-
assert(completion_charp);
1698-
#endif
1689+
psql_assert(completion_charp);
16991690
if (state == 0)
17001691
return xstrdup(completion_charp);
17011692
else
@@ -1809,7 +1800,7 @@ previous_word(int point, int skip)
18091800

18101801
/*
18111802
* Surround a string with single quotes. This works for both SQL and
1812-
* psql internal. Currently disable because it is reported not to
1803+
* psql internal. Currently disabled because it is reported not to
18131804
* cooperate with certain versions of readline.
18141805
*/
18151806
static char *

src/bin/psql/variables.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/variables.c,v 1.14 2003/11/29 19:52:07 pgsql Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/variables.c,v 1.15 2003/12/01 22:14:40 momjian Exp $
77
*/
88
#include "postgres_fe.h"
9+
#include "common.h"
910
#include "variables.h"
1011

11-
#include <assert.h>
12-
13-
1412
VariableSpace
1513
CreateVariableSpace(void)
1614
{
@@ -46,10 +44,8 @@ GetVariable(VariableSpace space, const char *name)
4644

4745
for (current = space; current; current = current->next)
4846
{
49-
#ifdef USE_ASSERT_CHECKING
50-
assert(current->name);
51-
assert(current->value);
52-
#endif
47+
psql_assert(current->name);
48+
psql_assert(current->value);
5349
if (strcmp(current->name, name) == 0)
5450
return current->value;
5551
}
@@ -161,10 +157,8 @@ SetVariable(VariableSpace space, const char *name, const char *value)
161157

162158
for (current = space, previous = NULL; current; previous = current, current = current->next)
163159
{
164-
#ifdef USE_ASSERT_CHECKING
165-
assert(current->name);
166-
assert(current->value);
167-
#endif
160+
psql_assert(current->name);
161+
psql_assert(current->value);
168162
if (strcmp(current->name, name) == 0)
169163
{
170164
free(current->value);
@@ -203,10 +197,8 @@ DeleteVariable(VariableSpace space, const char *name)
203197

204198
for (current = space, previous = NULL; current; previous = current, current = current->next)
205199
{
206-
#ifdef USE_ASSERT_CHECKING
207-
assert(current->name);
208-
assert(current->value);
209-
#endif
200+
psql_assert(current->name);
201+
psql_assert(current->value);
210202
if (strcmp(current->name, name) == 0)
211203
{
212204
free(current->name);

0 commit comments

Comments
 (0)