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

Commit1a5fb65

Browse files
committed
From: Massimo Dal Zotto <dz@cs.unitn.it>assert.patch adds a switch to turn on/off the assert checking if enabled at compile time. You can now compile postgres with assert checking and disable it at runtime in a production environment.
1 parent1682c36 commit1a5fb65

File tree

4 files changed

+89
-18
lines changed

4 files changed

+89
-18
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.93 1998/07/09 03:28:47 scrappy Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.94 1998/08/25 21:04:36 scrappy Exp $
1414
*
1515
* NOTES
1616
*
@@ -238,6 +238,9 @@ void GetCharSetByHost(char *, int, char *);
238238

239239
#endif
240240

241+
#ifdefUSE_ASSERT_CHECKING
242+
intassert_enabled=1;
243+
#endif
241244

242245
staticvoid
243246
checkDataDir(constchar*DataDir,bool*DataDirOK)
@@ -295,8 +298,6 @@ checkDataDir(const char *DataDir, bool *DataDirOK)
295298
}
296299
}
297300

298-
299-
300301
int
301302
PostmasterMain(intargc,char*argv[])
302303
{
@@ -365,10 +366,22 @@ PostmasterMain(int argc, char *argv[])
365366
DataDir=getenv("PGDATA");/* default value */
366367

367368
opterr=0;
368-
while ((opt=getopt(nonblank_argc,argv,"a:B:b:D:dim:Mno:p:Ss"))!=EOF)
369+
while ((opt=getopt(nonblank_argc,argv,"A:a:B:b:D:dim:Mno:p:Ss"))!=EOF)
369370
{
370371
switch (opt)
371372
{
373+
case'A':
374+
#ifndefUSE_ASSERT_CHECKING
375+
fprintf(stderr,"Assert checking is not enabled\n");
376+
#else
377+
/*
378+
* Pass this option also to each backend.
379+
*/
380+
assert_enabled=atoi(optarg);
381+
strcat(ExtraOptions," -A ");
382+
strcat(ExtraOptions,optarg);
383+
#endif
384+
break;
372385
case'a':
373386
/* Can no longer set authentication method. */
374387
break;
@@ -566,6 +579,9 @@ static void
566579
usage(constchar*progname)
567580
{
568581
fprintf(stderr,"usage: %s [options]\n",progname);
582+
#ifdefUSE_ASSERT_CHECKING
583+
fprintf(stderr,"\t-A [1|0]\tenable/disable runtime assert checking\n");
584+
#endif
569585
fprintf(stderr,"\t-B nbufs\tset number of shared buffers\n");
570586
fprintf(stderr,"\t-D datadir\tset data directory\n");
571587
fprintf(stderr,"\t-S \t\tsilent mode (disassociate from tty)\n");

‎src/backend/tcop/postgres.c

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.84 1998/08/2515:00:17 thomas Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.85 1998/08/2521:04:38 scrappy Exp $
1111
*
1212
* NOTES
1313
* this is the "main" module of the postgres backend and
@@ -850,6 +850,9 @@ usage(char *progname)
850850
{
851851
fprintf(stderr,
852852
"Usage: %s [options] [dbname]\n",progname);
853+
#ifdefUSE_ASSERT_CHECKING
854+
fprintf(stderr," A: enable/disable assert checking\n");
855+
#endif
853856
fprintf(stderr,"\t-B buffers\tset number of buffers in buffer pool\n");
854857
fprintf(stderr,"\t-C \t\tsupress version info\n");
855858
fprintf(stderr,"\t-D dir\t\tdata directory\n");
@@ -866,6 +869,7 @@ usage(char *progname)
866869
fprintf(stderr,"\t-o file\t\tsend stdout and stderr to given filename \n");
867870
fprintf(stderr,"\t-s \t\tshow stats after each query\n");
868871
fprintf(stderr,"\t-v version\tset protocol version being used by frontend\n");
872+
fprintf(stderr,"\t-W \t\twait N seconds to allow attach from a debugger\n");
869873
}
870874

871875
/* ----------------------------------------------------------------
@@ -943,10 +947,22 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
943947

944948
optind=1;/* reset after postmaster usage */
945949

946-
while ((flag=getopt(argc,argv,"B:bCD:d:Eef:iK:Lm:MNo:P:pQS:st:v:x:F"))
950+
while ((flag=getopt(argc,argv,
951+
"A:B:bCD:d:Eef:iK:Lm:MNo:P:pQS:st:v:x:FW:"))
947952
!=EOF)
948953
switch (flag)
949954
{
955+
case'A':
956+
/* ----------------
957+
* enable/disable assert checking.
958+
* ----------------
959+
*/
960+
#ifdefUSE_ASSERT_CHECKING
961+
assert_enabled=atoi(optarg);
962+
#else
963+
fprintf(stderr,"Assert checking is not enabled\n");
964+
#endif
965+
break;
950966

951967
case'b':
952968
/* ----------------
@@ -955,6 +971,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
955971
*/
956972
BushyPlanFlag=1;
957973
break;
974+
958975
case'B':
959976
/* ----------------
960977
*specify the size of buffer pool
@@ -1165,6 +1182,14 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
11651182
FrontendProtocol= (ProtocolVersion)atoi(optarg);
11661183
break;
11671184

1185+
case'W':
1186+
/* ----------------
1187+
* wait N seconds to allow attach from a debugger
1188+
* ----------------
1189+
*/
1190+
sleep(atoi(optarg));
1191+
break;
1192+
11681193
case'x':
11691194
#if0/* planner/xfunc.h */
11701195

@@ -1390,7 +1415,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
13901415
if (!IsUnderPostmaster)
13911416
{
13921417
puts("\nPOSTGRES backend interactive interface");
1393-
puts("$Revision: 1.84 $ $Date: 1998/08/2515:00:17 $");
1418+
puts("$Revision: 1.85 $ $Date: 1998/08/2521:04:38 $");
13941419
}
13951420

13961421
/* ----------------
@@ -1631,3 +1656,29 @@ ShowUsage(void)
16311656
PrintBufferUsage(StatFp);
16321657
/* DisplayTupleCount(StatFp); */
16331658
}
1659+
1660+
#ifdefUSE_ASSERT_CHECKING
1661+
int
1662+
assertEnable(intval)
1663+
{
1664+
assert_enabled=val;
1665+
returnval;
1666+
}
1667+
1668+
#ifdefASSERT_CHECKING_TEST
1669+
int
1670+
assertTest(intval)
1671+
{
1672+
Assert(val==0);
1673+
1674+
if (assert_enabled) {
1675+
/* val != 0 should be trapped by previous Assert */
1676+
elog(NOTICE,"Assert test successfull (val = %d)",val);
1677+
}else {
1678+
elog(NOTICE,"Assert checking is disabled (val = %d)",val);
1679+
}
1680+
1681+
returnval;
1682+
}
1683+
#endif
1684+
#endif

‎src/backend/utils/init/enbl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/enbl.c,v 1.2 1997/09/0704:53:42 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/enbl.c,v 1.3 1998/08/25 21:04:40 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
14-
#include"c.h"
14+
#include"postgres.h"
1515
#include"utils/module.h"/* where the declarations go */
1616

1717
/*

‎src/include/c.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: c.h,v 1.42 1998/06/23 15:35:46 momjian Exp $
10+
* $Id: c.h,v 1.43 1998/08/25 21:04:41 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -583,12 +583,10 @@ typedef struct Exception
583583
}Exception;
584584

585585
/*
586-
* USE_ASSERT_CHECKING, if defined, turnsoff all the assertions.
586+
* USE_ASSERT_CHECKING, if defined, turnson all the assertions.
587587
* - plai 9/5/90
588588
*
589-
* It should _NOT_ be undef'ed in releases or in benchmark copies
590-
*
591-
* #undef USE_ASSERT_CHECKING
589+
* It should _NOT_ be defined in releases or in benchmark copies
592590
*/
593591

594592
/*
@@ -597,7 +595,7 @@ typedef struct Exception
597595
*
598596
*/
599597
#defineTrap(condition,exception) \
600-
{ if (condition) \
598+
{ if ((assert_enabled) && (condition)) \
601599
ExceptionalCondition(CppAsString(condition), &(exception), \
602600
(char*)NULL, __FILE__, __LINE__); }
603601

@@ -609,7 +607,7 @@ typedef struct Exception
609607
*Isn't CPP fun?
610608
*/
611609
#defineTrapMacro(condition,exception) \
612-
((bool) ((! condition) || \
610+
((bool) ((!assert_enabled) || (!condition) || \
613611
(ExceptionalCondition(CppAsString(condition), \
614612
&(exception), \
615613
(char*) NULL, __FILE__, __LINE__))))
@@ -619,6 +617,7 @@ typedef struct Exception
619617
#defineAssertMacro(condition)(void)true
620618
#defineAssertArg(condition)
621619
#defineAssertState(condition)
620+
#defineassert_enabled 0
622621
#else
623622
#defineAssert(condition) \
624623
Trap(!(condition), FailedAssertion)
@@ -632,6 +631,7 @@ typedef struct Exception
632631
#defineAssertState(condition) \
633632
Trap(!(condition), BadState)
634633

634+
externintassert_enabled;
635635
#endif/* USE_ASSERT_CHECKING */
636636

637637
/*
@@ -640,7 +640,7 @@ typedef struct Exception
640640
*
641641
*/
642642
#defineLogTrap(condition,exception,printArgs) \
643-
{ if (condition) \
643+
{ if ((assert_enabled) && (condition)) \
644644
ExceptionalCondition(CppAsString(condition), &(exception), \
645645
form printArgs, __FILE__, __LINE__); }
646646

@@ -650,7 +650,7 @@ typedef struct Exception
650650
*#define foo(x) (LogAssertMacro(x != 0, "yow!") && bar(x))
651651
*/
652652
#defineLogTrapMacro(condition,exception,printArgs) \
653-
((bool) ((! condition) || \
653+
((bool) ((!assert_enabled) || (!condition) || \
654654
(ExceptionalCondition(CppAsString(condition), \
655655
&(exception), \
656656
form printArgs, __FILE__, __LINE__))))
@@ -673,6 +673,10 @@ typedef struct Exception
673673
#defineLogAssertState(condition,printArgs) \
674674
LogTrap(!(condition), BadState, printArgs)
675675

676+
externintassertEnable(intval);
677+
#ifdefASSERT_CHECKING_TEST
678+
externintassertTest(intval);
679+
#endif
676680
#endif/* USE_ASSERT_CHECKING */
677681

678682
/* ----------------------------------------------------------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp