Skip to content

Commit ab6f3c1

Browse files
committed
libast & ksh: cleanup: remove unused errorctx() function
In version 93s+ 2007-03-25, AT&T added errorctx(), intending that it replace the errorpush() and errorpop() macros used in ksh to push and pop error contexts (this is the mechanism that shows a call stack of functions/commands in ksh error messages). Whereas errorpush()/errorpop() only pushes/pops a part of the Error_info_t struct (the part that is Error_context_t), errorctx() saves and restores the entire Error_info_t struct. This approach looks incompatible with existing ksh practice. After adding errorctx(), AT&T never used it. It just sat there until they abandoned ksh, never being changed or developed. If any attempt was made to transition to it, it must not have worked. Meanwhile, the existing mechanism works well and is time-tested, so it's time to delete yet another forgotten-about AT&T experiment. src/cmd/ksh93/Mamfile, src/lib/libast/include/error.h, src/lib/libcmd/cmd.h: - Remove ERROR_CONTEXT_T definition that determined the type of the error_info.context pointer (Error_context_t* in the old and now the only mechanism, Error_info_t* in the new experiment). - Remove ERROR_FREE, ERROR_POP, ERROR_PUSH and (unused) ERROR_SET definitions for errorctx(). - Transfer ERROR_CALLBACK (originally an alias for ERROR_SET) from cmd.h to error.h so we have related definitions in one place. src/lib/libast/misc/error.c: - context(): Remove use of ERROR_PUSH macro. - Remove the errorctx() function.
1 parent ecaf58b commit ab6f3c1

File tree

4 files changed

+8
-66
lines changed

4 files changed

+8
-66
lines changed

src/cmd/ksh93/Mamfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ make install virtual
10091009
note * Set common compiler invocation arguments
10101010
note *
10111011

1012-
setv compile %{CC} %{mam_cc_FLAGS} %{CCFLAGS} %{mam_cc_NOSTRICTALIASING} %{DEBUG+-DDEBUG=%{DEBUG}} -DSH_DICT=%{SH_DICT} %{SH_CMDLIB_DIR+-DSH_CMDLIB_DIR=%{SH_CMDLIB_DIR}} -I. -Iinclude -I%{INCLUDE_AST} -D_API_ast=20100309 -DERROR_CONTEXT_T=Error_context_t -c
1012+
setv compile %{CC} %{mam_cc_FLAGS} %{CCFLAGS} %{mam_cc_NOSTRICTALIASING} %{DEBUG+-DDEBUG=%{DEBUG}} -DSH_DICT=%{SH_DICT} %{SH_CMDLIB_DIR+-DSH_CMDLIB_DIR=%{SH_CMDLIB_DIR}} -I. -Iinclude -I%{INCLUDE_AST} -D_API_ast=20100309 -c
10131013

10141014
note *
10151015
note * Build *_dyn.o object files for dynamic library

src/lib/libast/include/error.h

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <option.h>
3232
#include <errno.h>
3333

34-
#define ERROR_VERSION 20230222L
34+
#define ERROR_VERSION 20251007L
3535

3636
#if !defined(errno) && defined(__DYNAMIC__)
3737
#define errno __DYNAMIC__(errno)
@@ -75,35 +75,25 @@
7575
#define ERROR_SILENT 0x0002 /* context is silent */
7676
#define ERROR_NOTIFY 0x0004 /* main(-sig,0,ctx) on signal */
7777

78-
#define ERROR_FREE 0x0010 /* free context on pop */
79-
#define ERROR_POP 0x0020 /* pop context */
80-
#define ERROR_PUSH 0x0040 /* push context */
81-
#define ERROR_SET 0x0080 /* set context */
78+
/* for libcmd */
79+
#define ERROR_CALLBACK 0x0080 /* ERROR_NOTIFY main() callback */
8280

8381
#ifdef ECONNRESET
8482
#define ERROR_PIPE(e) ((e)==EPIPE||(e)==ECONNRESET||(e)==EIO)
8583
#else
8684
#define ERROR_PIPE(e) ((e)==EPIPE||(e)==EIO)
8785
#endif
8886

89-
/*
90-
* errorpush()/errorpop() are obsolete -- use errorctx() instead
91-
*/
92-
93-
#ifndef ERROR_CONTEXT_T
94-
#define ERROR_CONTEXT_T Error_info_t
95-
#endif
96-
9787
#define ERROR_CONTEXT_BASE ((Error_context_t*)&error_info.context)
9888

99-
#define errorpush(p,f) (*(p)=*ERROR_CONTEXT_BASE,*ERROR_CONTEXT_BASE=error_info.empty,error_info.context=(Error_context_t*)(p),error_info.flags=(f))
89+
#define errorpush(p,f) (*(p)=*ERROR_CONTEXT_BASE,*ERROR_CONTEXT_BASE=error_info.empty,error_info.context=(p),error_info.flags=(f))
10090
#define errorpop(p) (*ERROR_CONTEXT_BASE=*(p))
10191

10292
typedef struct Error_info_s Error_info_t;
10393
typedef struct Error_context_s Error_context_t;
10494

10595
#define ERROR_CONTEXT \
106-
ERROR_CONTEXT_T* context; /* prev context stack element */ \
96+
Error_context_t* context; /* prev context stack element */ \
10797
int errors; /* >= ERROR_ERROR count */ \
10898
int flags; /* context flags */ \
10999
int line; /* input|output line number */ \
@@ -203,6 +193,5 @@ extern void errorv(const char*, int, va_list);
203193
#ifndef errorx
204194
extern char* errorx(const char*, const char*, const char*, const char*);
205195
#endif
206-
extern Error_info_t* errorctx(Error_info_t*, int, int);
207196

208197
#endif

src/lib/libast/misc/error.c

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,11 @@ print(Sfio_t* sp, char* name, char* delim)
281281
* print error context FIFO stack
282282
*/
283283

284-
#define CONTEXT(f,p) (((f)&ERROR_PUSH)?((Error_context_t*)&(p)->context->context):((Error_context_t*)(p)))
285-
286284
static void
287285
context(Sfio_t* sp, Error_context_t* cp)
288286
{
289287
if (cp->context)
290-
context(sp, CONTEXT(cp->flags, cp->context));
288+
context(sp, cp->context);
291289
if (!(cp->flags & ERROR_SILENT))
292290
{
293291
if (cp->id)
@@ -432,7 +430,7 @@ errorv(const char* id, int level, va_list ap)
432430
if (level && !(flags & ERROR_NOID))
433431
{
434432
if (error_info.context && level > 0)
435-
context(stkstd, CONTEXT(error_info.flags, error_info.context));
433+
context(stkstd, error_info.context);
436434
if (file)
437435
print(stkstd, file, (flags & ERROR_LIBRARY) ? " " : ": ");
438436
if (flags & (ERROR_CATALOG|ERROR_LIBRARY))
@@ -593,46 +591,3 @@ errorv(const char* id, int level, va_list ap)
593591
if (level >= ERROR_FATAL)
594592
(*error_info.exit)(level - ERROR_FATAL + 1);
595593
}
596-
597-
/*
598-
* error_info context control
599-
*/
600-
601-
static Error_info_t* freecontext;
602-
603-
Error_info_t*
604-
errorctx(Error_info_t* p, int op, int flags)
605-
{
606-
if (op & ERROR_POP)
607-
{
608-
if (!(_error_infop_ = p->context))
609-
_error_infop_ = &_error_info_;
610-
if (op & ERROR_FREE)
611-
{
612-
p->context = freecontext;
613-
freecontext = p;
614-
}
615-
p = _error_infop_;
616-
}
617-
else
618-
{
619-
if (!p)
620-
{
621-
if (p = freecontext)
622-
freecontext = freecontext->context;
623-
else if (!(p = newof(0, Error_info_t, 1, 0)))
624-
return NULL;
625-
*p = *_error_infop_;
626-
p->errors = p->flags = p->line = p->warnings = 0;
627-
p->catalog = p->file = 0;
628-
}
629-
if (op & ERROR_PUSH)
630-
{
631-
p->flags = flags;
632-
p->context = _error_infop_;
633-
_error_infop_ = p;
634-
}
635-
p->flags |= ERROR_PUSH;
636-
}
637-
return p;
638-
}

src/lib/libcmd/cmd.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131

3232
#define cmdinit _cmd_init
3333

34-
#define ERROR_CALLBACK ERROR_SET
35-
3634
#include <cmdext.h>
3735

3836
#if defined(CMD_BUILTIN) && !defined(CMD_STANDALONE)

0 commit comments

Comments
 (0)