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

Commit023a48b

Browse files
committed
Deal with C++ incompatibility of sys_nerr declaration by taking it out
of c.h altogether, and putting it into the only places that use it(elog.c and exc.c), instead. Modify these routines to check for aNULL or empty-string return from strerror, too, since some platformsdefine strerror to return empty string for unknown errors (what a uselessdefinition that is ...). Clean up some cruft in ExcPrint while at it.
1 parent37fd198 commit023a48b

File tree

3 files changed

+51
-43
lines changed

3 files changed

+51
-43
lines changed

‎src/backend/utils/error/elog.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.77 2001/01/19 22:08:47 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.78 2001/01/21 00:59:26 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
15-
1615
#include"postgres.h"
1716

1817
#include<time.h>
@@ -44,6 +43,10 @@
4443

4544
externinterrno;
4645

46+
#ifdefHAVE_SYS_NERR
47+
externintsys_nerr;
48+
#endif
49+
4750
externCommandDestwhereToSendOutput;
4851

4952
#ifdefENABLE_SYSLOG
@@ -120,10 +123,8 @@ elog(int lev, const char *fmt, ...)
120123
char*msg_buf=msg_fixedbuf;
121124
/* this buffer is only used for strange values of lev: */
122125
charprefix_buf[32];
123-
#ifdefHAVE_SYS_NERR
124126
/* this buffer is only used if errno has a bogus value: */
125127
charerrorstr_buf[32];
126-
#endif
127128
constchar*errorstr;
128129
constchar*prefix;
129130
constchar*cp;
@@ -137,19 +138,24 @@ elog(int lev, const char *fmt, ...)
137138
if (lev <=DEBUG&&Debugfile<0)
138139
return;/* ignore debug msgs if noplace to send */
139140

141+
/* Save error str before calling any function that might change errno */
142+
if (errno >=0
140143
#ifdefHAVE_SYS_NERR
141-
/* save errno string for %m */
142-
if (errno<sys_nerr&&errno >=0)
144+
&&errno <=sys_nerr
145+
#endif
146+
)
143147
errorstr=strerror(errno);
144148
else
149+
errorstr=NULL;
150+
/*
151+
* Some strerror()s return an empty string for out-of-range errno.
152+
* This is ANSI C spec compliant, but not exactly useful.
153+
*/
154+
if (errorstr==NULL||*errorstr=='\0')
145155
{
146156
sprintf(errorstr_buf,"error %d",errno);
147157
errorstr=errorstr_buf;
148158
}
149-
#else
150-
/* assume strerror() will cope gracefully with bogus errno values */
151-
errorstr=strerror(errno);
152-
#endif
153159

154160
if (lev==ERROR||lev==FATAL)
155161
{

‎src/backend/utils/error/exc.c

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/error/Attic/exc.c,v 1.33 2001/01/09 18:40:14 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/error/Attic/exc.c,v 1.34 2001/01/21 00:59:26 tgl Exp $
1212
*
1313
* NOTE
1414
* XXX this code needs improvement--check for state violations and
1515
* XXX reset after handling an exception.
16+
* XXX Probably should be merged with elog.c.
1617
*
1718
*-------------------------------------------------------------------------
1819
*/
@@ -23,6 +24,13 @@
2324
#include"storage/ipc.h"
2425
#include"utils/exc.h"
2526

27+
externinterrno;
28+
29+
#ifdefHAVE_SYS_NERR
30+
externintsys_nerr;
31+
#endif
32+
33+
2634
staticvoidExcUnCaught(Exception*excP,ExcDetaildetail,ExcDatadata,
2735
ExcMessagemessage);
2836
staticvoidExcPrint(Exception*excP,ExcDetaildetail,ExcDatadata,
@@ -40,8 +48,6 @@ ExcFrame *ExcCurFrameP = NULL;
4048

4149
staticExcProc*ExcUnCaughtP=NULL;
4250

43-
externchar*ProgramName;
44-
4551
/*
4652
* Exported Functions
4753
*/
@@ -94,49 +100,49 @@ EnableExceptionHandling(bool on)
94100
ExceptionHandlingEnabled=on;
95101
}
96102

97-
98-
externinterrno;
99-
100103
staticvoid
101104
ExcPrint(Exception*excP,
102105
ExcDetaildetail,
103106
ExcDatadata,
104107
ExcMessagemessage)
105108
{
109+
/* this buffer is only used if errno has a bogus value: */
110+
charerrorstr_buf[32];
111+
constchar*errorstr;
112+
106113
#ifdeflint
107114
data=data;
108115
#endif
109116

110-
fflush(stdout);/* In case stderr is buffered */
111-
112-
#if0
113-
if (ProgramName!=NULL&&*ProgramName!='\0')
114-
fprintf(stderr,"%s: ",ProgramName);
117+
/* Save error str before calling any function that might change errno */
118+
if (errno >=0
119+
#ifdefHAVE_SYS_NERR
120+
&&errno <=sys_nerr
115121
#endif
122+
)
123+
errorstr=strerror(errno);
124+
else
125+
errorstr=NULL;
126+
/*
127+
* Some strerror()s return an empty string for out-of-range errno.
128+
* This is ANSI C spec compliant, but not exactly useful.
129+
*/
130+
if (errorstr==NULL||*errorstr=='\0')
131+
{
132+
sprintf(errorstr_buf,"error %d",errno);
133+
errorstr=errorstr_buf;
134+
}
135+
136+
fflush(stdout);/* In case stderr is buffered */
116137

117138
if (message!=NULL)
118139
fprintf(stderr,"%s",message);
119140
elseif (excP->message!=NULL)
120141
fprintf(stderr,"%s",excP->message);
121142
else
122-
#ifdeflint
123-
fprintf(stderr,"UNNAMED EXCEPTION 0x%lx",excP);
124-
#else
125-
fprintf(stderr,"UNNAMED EXCEPTION 0x%lx", (long)excP);
126-
#endif
127-
128-
fprintf(stderr," (%ld)",detail);
129-
130-
#ifdefHAVE_SYS_NERR
131-
if (errno>0&&errno<sys_nerr)
132-
#else
133-
if (errno>0)
134-
#endif
135-
fprintf(stderr," [%s]",strerror(errno));
136-
elseif (errno!=0)
137-
fprintf(stderr," [Error %d]",errno);
143+
fprintf(stderr,"UNNAMED EXCEPTION %p",excP);
138144

139-
fprintf(stderr,"\n");
145+
fprintf(stderr," (%ld) [%s]\n",detail,errorstr);
140146

141147
fflush(stderr);
142148
}

‎src/include/c.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $Id: c.h,v 1.87 2001/01/09 18:40:15 petere Exp $
11+
* $Id: c.h,v 1.88 2001/01/21 00:59:24 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -993,10 +993,6 @@ extern intvsnprintf(char *str, size_t count, const char *fmt, va_list args);
993993
#include<regex/utils.h>
994994
#endif
995995

996-
#ifdefHAVE_SYS_NERR
997-
externintsys_nerr;
998-
#endif
999-
1000996
/* ----------------
1001997
*end of c.h
1002998
* ----------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp