help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Possible bug between trap, source, and FUNCNAME


From: G. Branden Robinson
Subject: Re: Possible bug between trap, source, and FUNCNAME
Date: Tue, 24 Mar 2026 13:45:59 -0500

At 2026-03-24T12:08:20+0100, Laurent Lyaudet wrote:
> Le lun. 23 mars 2026 à 15:26, Chet Ramey <chet.ramey@case.edu> a écrit
> :
> > The difference is that the when executing a function, the RETURN
> > trap is executed in the function context, whereas when sourcing a
> > script, the trap is executed in the calling context.
> >
> > It's inconsistent, but it's been this way since the RETURN trap came
> > in to support the bash debugger.
> 
> Ok, thanks for confirming it's inconsistent, but not modifiable.  I
> was thinking if or not it would be a good idea to add other
> "sigspecs", like RETURN2, RETURN3 with consistent behavior and not
> altered by Bash option like extdebug, functrace, or the trace
> attribute.

I don't have an opinion on the wisdom or worth of adding additional
return traps to Bash.  But if any _are_ added, I urge Chet to give them
meaningful names.  `RETURN2` and `RETURN3` communicate little more than
`RETURN` does.  For example,

FUNCTION_RETURN
CONTEXT_RETURN
RETURN_FUNCTION
RETURN_CONTEXT

...would all be better.  I generally dislike abbreviations as well, but
they're pretty well established in Bash and even

FUNCRETURN
CTXTRETURN
RETURNFUNC
RETURNCTXT

would be better than `RETURN2` and `RETURN3`.

I concede that the naming convention you propose has precedent.

Unix and Linux kernel programmers observe a storied tradition when
finding that the set of existing system calls is inadequate to service
application demands.  When this occurs, and a new kernel subsystem is
not necessary, they coin a new system call name that is the same as an
existing one and tack on an integer at the end, which represents either
a count of expected arguments[1] or the width of the system's native
integer type in bits.[2]  Neither imparts any additional _semantic_
information, nor offers any clue as to the type of data manipulated or
the aspect of implementation behavior that motivated the introduction of
a new system call in the first place.

You can see why kernel hackers get paid the big bucks...

Regards,
Branden

[1] Unix got the ball rolling with dup() and dup2().  Linux added a
    dup3().  Similarly we have clone(), clone2(), and clone(3); accept()
    and accept4(); eventfd() and eventfd2().  Also check out
    epoll_create() and epoll_create1(), both of which take only one
    argument--I hope the promulgator of the latter won a kernel API
    design award for militant consistency.  For fun, contrast
    inotify_init() and inotify_init1().

[2] Suffixing a system call with an integer width in bits is less
    exasperating than doing so with an argument count, but exposes yet
    another failure of foresight by Unix kernel developers.  There's a
    strong tendency in kernel hacking to praise one's programming
    specialization as being "close to the metal", and a commitment to
    awareness of the eventual assembly language representation of one's
    code enjoys great rhetorical emphasis even if it is not always
    honored in the breach.  But this problem, too, could have been
    escaped even in the Bell Labs Unix kernel had its authors overcome
    their antipathy to strong typing.

    Awareness of the desirability of having real (that is, stronger)
    data types in the system call API was evident even by 1979 when
    Seventh Edition Unix was released.

    https://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/include/sys/types.h

    Predictably enough, the opportunity that arose here was squandered
    immediately, because the types were "defined" with C's `typedef`,
    which is not a type _definition_ but rather a type _aliasing_
    facility.  That means that you don't get any type checking
    assistance from the compiler.  This is not the case merely with old-
    school C but with ISO C up to the present day.

    See attached C programs for an illustration.

Attachment: typedef1.c
Description: Text Data

Attachment: typedef2.c
Description: Text Data

Attachment: typedef3.c
Description: Text Data

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]