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

Commit1c38265

Browse files
committed
Provide Assert() for frontend code.
Per discussion on-hackers. psql is converted to use the new code.Follows a suggestion from Heikki Linnakangas.
1 parent75758a6 commit1c38265

File tree

7 files changed

+30
-25
lines changed

7 files changed

+30
-25
lines changed

‎src/bin/psql/command.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ HandleSlashCmds(PsqlScanState scan_state,
9999
char*cmd;
100100
char*arg;
101101

102-
psql_assert(scan_state);
102+
Assert(scan_state!=NULL);
103103

104104
/* Parse off the command name */
105105
cmd=psql_scan_slash_command(scan_state);
@@ -1819,7 +1819,7 @@ editFile(const char *fname, int lineno)
18191819
char*sys;
18201820
intresult;
18211821

1822-
psql_assert(fname);
1822+
Assert(fname!=NULL);
18231823

18241824
/* Find an editor to use */
18251825
editorName=getenv("PSQL_EDITOR");
@@ -2177,7 +2177,7 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
21772177
{
21782178
size_tvallen=0;
21792179

2180-
psql_assert(param);
2180+
Assert(param!=NULL);
21812181

21822182
if (value)
21832183
vallen=strlen(value);

‎src/bin/psql/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
11601160
}
11611161

11621162
OK=AcceptResult(results);
1163-
psql_assert(!OK);
1163+
Assert(!OK);
11641164
PQclear(results);
11651165
break;
11661166
}

‎src/bin/psql/common.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@
1212
#include<setjmp.h>
1313
#include"libpq-fe.h"
1414

15-
#ifdefUSE_ASSERT_CHECKING
16-
#include<assert.h>
17-
#definepsql_assert(p) assert(p)
18-
#else
19-
#definepsql_assert(p)
20-
#endif
21-
2215
#defineatooid(x) ((Oid) strtoul((x), NULL, 10))
2316

2417
/*

‎src/bin/psql/psqlscan.l

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,8 +1184,8 @@ psql_scan_setup(PsqlScanState state,
11841184
const char *line, int line_len)
11851185
{
11861186
/* Mustn't be scanning already */
1187-
psql_assert(state->scanbufhandle == NULL);
1188-
psql_assert(state->buffer_stack == NULL);
1187+
Assert(state->scanbufhandle == NULL);
1188+
Assert(state->buffer_stack == NULL);
11891189
11901190
/* Do we need to hack the character set encoding? */
11911191
state->encoding = pset.encoding;
@@ -1245,7 +1245,7 @@ psql_scan(PsqlScanState state,
12451245
intlexresult;
12461246
12471247
/* Must be scanning already */
1248-
psql_assert(state->scanbufhandle);
1248+
Assert(state->scanbufhandle != NULL);
12491249
12501250
/* Set up static variables that will be used by yylex */
12511251
cur_state = state;
@@ -1424,7 +1424,7 @@ psql_scan_slash_command(PsqlScanState state)
14241424
PQExpBufferData mybuf;
14251425
14261426
/* Must be scanning already */
1427-
psql_assert(state->scanbufhandle);
1427+
Assert(state->scanbufhandle != NULL);
14281428
14291429
/* Build a local buffer that we'll return the data of */
14301430
initPQExpBuffer(&mybuf);
@@ -1478,7 +1478,7 @@ psql_scan_slash_option(PsqlScanState state,
14781478
charlocal_quote;
14791479
14801480
/* Must be scanning already */
1481-
psql_assert(state->scanbufhandle);
1481+
Assert(state->scanbufhandle != NULL);
14821482
14831483
if (quote == NULL)
14841484
quote = &local_quote;
@@ -1512,7 +1512,7 @@ psql_scan_slash_option(PsqlScanState state,
15121512
* or LEXRES_EOL (the latter indicating end of string). If we were inside
15131513
* a quoted string, as indicated by YY_START, EOL is an error.
15141514
*/
1515-
psql_assert(lexresult == LEXRES_EOL || lexresult == LEXRES_OK);
1515+
Assert(lexresult == LEXRES_EOL || lexresult == LEXRES_OK);
15161516
15171517
switch (YY_START)
15181518
{
@@ -1608,7 +1608,7 @@ void
16081608
psql_scan_slash_command_end(PsqlScanState state)
16091609
{
16101610
/* Must be scanning already */
1611-
psql_assert(state->scanbufhandle);
1611+
Assert(state->scanbufhandle != NULL);
16121612
16131613
/* Set up static variables that will be used by yylex */
16141614
cur_state = state;

‎src/bin/psql/stringutils.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ strip_quotes(char *source, char quote, char escape, int encoding)
245245
char*src;
246246
char*dst;
247247

248-
psql_assert(source);
249-
psql_assert(quote);
248+
Assert(source!=NULL);
249+
Assert(quote!='\0');
250250

251251
src=dst=source;
252252

@@ -299,8 +299,8 @@ quote_if_needed(const char *source, const char *entails_quote,
299299
char*dst;
300300
boolneed_quotes= false;
301301

302-
psql_assert(source);
303-
psql_assert(quote);
302+
Assert(source!=NULL);
303+
Assert(quote!='\0');
304304

305305
src=source;
306306
dst=ret=pg_malloc(2*strlen(src)+3);/* excess */

‎src/bin/psql/tab-complete.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3558,7 +3558,7 @@ complete_from_list(const char *text, int state)
35583558
constchar*item;
35593559

35603560
/* need to have a list */
3561-
psql_assert(completion_charpp);
3561+
Assert(completion_charpp!=NULL);
35623562

35633563
/* Initialization */
35643564
if (state==0)
@@ -3620,7 +3620,7 @@ complete_from_list(const char *text, int state)
36203620
staticchar*
36213621
complete_from_const(constchar*text,intstate)
36223622
{
3623-
psql_assert(completion_charp);
3623+
Assert(completion_charp!=NULL);
36243624
if (state==0)
36253625
{
36263626
if (completion_case_sensitive)
@@ -3708,7 +3708,7 @@ complete_from_files(const char *text, int state)
37083708
/* expect a NULL return for the empty string only */
37093709
if (!unquoted_text)
37103710
{
3711-
psql_assert(!*text);
3711+
Assert(*text=='\0');
37123712
unquoted_text=text;
37133713
}
37143714
}

‎src/include/postgres_fe.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,16 @@
2424

2525
#include"c.h"
2626

27+
/*
28+
* Assert() can be used in both frontend and backend code. In frontend code it
29+
* just calls the standard assert, if it's available. If use of assertions is
30+
* not configured, it does nothing.
31+
*/
32+
#ifdefUSE_ASSERT_CHECKING
33+
#include<assert.h>
34+
#defineAssert(p) assert(p)
35+
#else
36+
#defineAssert(p)
37+
#endif
38+
2739
#endif/* POSTGRES_FE_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp