mirror of
https://github.com/postgres/postgres.git
synced 2025-04-25 21:42:33 +03:00
Provide Assert() for frontend code.
Per discussion on-hackers. psql is converted to use the new code. Follows a suggestion from Heikki Linnakangas.
This commit is contained in:
parent
75758a6ff0
commit
1c382655ad
@ -99,7 +99,7 @@ HandleSlashCmds(PsqlScanState scan_state,
|
|||||||
char *cmd;
|
char *cmd;
|
||||||
char *arg;
|
char *arg;
|
||||||
|
|
||||||
psql_assert(scan_state);
|
Assert(scan_state != NULL);
|
||||||
|
|
||||||
/* Parse off the command name */
|
/* Parse off the command name */
|
||||||
cmd = psql_scan_slash_command(scan_state);
|
cmd = psql_scan_slash_command(scan_state);
|
||||||
@ -1819,7 +1819,7 @@ editFile(const char *fname, int lineno)
|
|||||||
char *sys;
|
char *sys;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
psql_assert(fname);
|
Assert(fname != NULL);
|
||||||
|
|
||||||
/* Find an editor to use */
|
/* Find an editor to use */
|
||||||
editorName = getenv("PSQL_EDITOR");
|
editorName = getenv("PSQL_EDITOR");
|
||||||
@ -2177,7 +2177,7 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
|
|||||||
{
|
{
|
||||||
size_t vallen = 0;
|
size_t vallen = 0;
|
||||||
|
|
||||||
psql_assert(param);
|
Assert(param != NULL);
|
||||||
|
|
||||||
if (value)
|
if (value)
|
||||||
vallen = strlen(value);
|
vallen = strlen(value);
|
||||||
|
@ -1160,7 +1160,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
|
|||||||
}
|
}
|
||||||
|
|
||||||
OK = AcceptResult(results);
|
OK = AcceptResult(results);
|
||||||
psql_assert(!OK);
|
Assert(!OK);
|
||||||
PQclear(results);
|
PQclear(results);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -12,13 +12,6 @@
|
|||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include "libpq-fe.h"
|
#include "libpq-fe.h"
|
||||||
|
|
||||||
#ifdef USE_ASSERT_CHECKING
|
|
||||||
#include <assert.h>
|
|
||||||
#define psql_assert(p) assert(p)
|
|
||||||
#else
|
|
||||||
#define psql_assert(p)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
|
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1184,8 +1184,8 @@ psql_scan_setup(PsqlScanState state,
|
|||||||
const char *line, int line_len)
|
const char *line, int line_len)
|
||||||
{
|
{
|
||||||
/* Mustn't be scanning already */
|
/* Mustn't be scanning already */
|
||||||
psql_assert(state->scanbufhandle == NULL);
|
Assert(state->scanbufhandle == NULL);
|
||||||
psql_assert(state->buffer_stack == NULL);
|
Assert(state->buffer_stack == NULL);
|
||||||
|
|
||||||
/* Do we need to hack the character set encoding? */
|
/* Do we need to hack the character set encoding? */
|
||||||
state->encoding = pset.encoding;
|
state->encoding = pset.encoding;
|
||||||
@ -1245,7 +1245,7 @@ psql_scan(PsqlScanState state,
|
|||||||
int lexresult;
|
int lexresult;
|
||||||
|
|
||||||
/* Must be scanning already */
|
/* Must be scanning already */
|
||||||
psql_assert(state->scanbufhandle);
|
Assert(state->scanbufhandle != NULL);
|
||||||
|
|
||||||
/* Set up static variables that will be used by yylex */
|
/* Set up static variables that will be used by yylex */
|
||||||
cur_state = state;
|
cur_state = state;
|
||||||
@ -1424,7 +1424,7 @@ psql_scan_slash_command(PsqlScanState state)
|
|||||||
PQExpBufferData mybuf;
|
PQExpBufferData mybuf;
|
||||||
|
|
||||||
/* Must be scanning already */
|
/* Must be scanning already */
|
||||||
psql_assert(state->scanbufhandle);
|
Assert(state->scanbufhandle != NULL);
|
||||||
|
|
||||||
/* Build a local buffer that we'll return the data of */
|
/* Build a local buffer that we'll return the data of */
|
||||||
initPQExpBuffer(&mybuf);
|
initPQExpBuffer(&mybuf);
|
||||||
@ -1478,7 +1478,7 @@ psql_scan_slash_option(PsqlScanState state,
|
|||||||
char local_quote;
|
char local_quote;
|
||||||
|
|
||||||
/* Must be scanning already */
|
/* Must be scanning already */
|
||||||
psql_assert(state->scanbufhandle);
|
Assert(state->scanbufhandle != NULL);
|
||||||
|
|
||||||
if (quote == NULL)
|
if (quote == NULL)
|
||||||
quote = &local_quote;
|
quote = &local_quote;
|
||||||
@ -1512,7 +1512,7 @@ psql_scan_slash_option(PsqlScanState state,
|
|||||||
* or LEXRES_EOL (the latter indicating end of string). If we were inside
|
* or LEXRES_EOL (the latter indicating end of string). If we were inside
|
||||||
* a quoted string, as indicated by YY_START, EOL is an error.
|
* a quoted string, as indicated by YY_START, EOL is an error.
|
||||||
*/
|
*/
|
||||||
psql_assert(lexresult == LEXRES_EOL || lexresult == LEXRES_OK);
|
Assert(lexresult == LEXRES_EOL || lexresult == LEXRES_OK);
|
||||||
|
|
||||||
switch (YY_START)
|
switch (YY_START)
|
||||||
{
|
{
|
||||||
@ -1608,7 +1608,7 @@ void
|
|||||||
psql_scan_slash_command_end(PsqlScanState state)
|
psql_scan_slash_command_end(PsqlScanState state)
|
||||||
{
|
{
|
||||||
/* Must be scanning already */
|
/* Must be scanning already */
|
||||||
psql_assert(state->scanbufhandle);
|
Assert(state->scanbufhandle != NULL);
|
||||||
|
|
||||||
/* Set up static variables that will be used by yylex */
|
/* Set up static variables that will be used by yylex */
|
||||||
cur_state = state;
|
cur_state = state;
|
||||||
|
@ -245,8 +245,8 @@ strip_quotes(char *source, char quote, char escape, int encoding)
|
|||||||
char *src;
|
char *src;
|
||||||
char *dst;
|
char *dst;
|
||||||
|
|
||||||
psql_assert(source);
|
Assert(source != NULL);
|
||||||
psql_assert(quote);
|
Assert(quote != '\0');
|
||||||
|
|
||||||
src = dst = source;
|
src = dst = source;
|
||||||
|
|
||||||
@ -299,8 +299,8 @@ quote_if_needed(const char *source, const char *entails_quote,
|
|||||||
char *dst;
|
char *dst;
|
||||||
bool need_quotes = false;
|
bool need_quotes = false;
|
||||||
|
|
||||||
psql_assert(source);
|
Assert(source != NULL);
|
||||||
psql_assert(quote);
|
Assert(quote != '\0');
|
||||||
|
|
||||||
src = source;
|
src = source;
|
||||||
dst = ret = pg_malloc(2 * strlen(src) + 3); /* excess */
|
dst = ret = pg_malloc(2 * strlen(src) + 3); /* excess */
|
||||||
|
@ -3558,7 +3558,7 @@ complete_from_list(const char *text, int state)
|
|||||||
const char *item;
|
const char *item;
|
||||||
|
|
||||||
/* need to have a list */
|
/* need to have a list */
|
||||||
psql_assert(completion_charpp);
|
Assert(completion_charpp != NULL);
|
||||||
|
|
||||||
/* Initialization */
|
/* Initialization */
|
||||||
if (state == 0)
|
if (state == 0)
|
||||||
@ -3620,7 +3620,7 @@ complete_from_list(const char *text, int state)
|
|||||||
static char *
|
static char *
|
||||||
complete_from_const(const char *text, int state)
|
complete_from_const(const char *text, int state)
|
||||||
{
|
{
|
||||||
psql_assert(completion_charp);
|
Assert(completion_charp != NULL);
|
||||||
if (state == 0)
|
if (state == 0)
|
||||||
{
|
{
|
||||||
if (completion_case_sensitive)
|
if (completion_case_sensitive)
|
||||||
@ -3708,7 +3708,7 @@ complete_from_files(const char *text, int state)
|
|||||||
/* expect a NULL return for the empty string only */
|
/* expect a NULL return for the empty string only */
|
||||||
if (!unquoted_text)
|
if (!unquoted_text)
|
||||||
{
|
{
|
||||||
psql_assert(!*text);
|
Assert(*text == '\0');
|
||||||
unquoted_text = text;
|
unquoted_text = text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,4 +24,16 @@
|
|||||||
|
|
||||||
#include "c.h"
|
#include "c.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Assert() can be used in both frontend and backend code. In frontend code it
|
||||||
|
* just calls the standard assert, if it's available. If use of assertions is
|
||||||
|
* not configured, it does nothing.
|
||||||
|
*/
|
||||||
|
#ifdef USE_ASSERT_CHECKING
|
||||||
|
#include <assert.h>
|
||||||
|
#define Assert(p) assert(p)
|
||||||
|
#else
|
||||||
|
#define Assert(p)
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* POSTGRES_FE_H */
|
#endif /* POSTGRES_FE_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user