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: Laurent Lyaudet
Subject: Re: Possible bug between trap, source, and FUNCNAME
Date: Wed, 25 Mar 2026 12:14:23 +0100

Le mar. 24 mars 2026 à 19:46, G. Branden Robinson
<g.branden.robinson@gmail.com> a écrit :
>
> 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.

Hello :),

I agree with your first remark about better naming than RETURN2.

Regarding kernel dev and functions naming,
usually 1 2 3 etc. are more or less the time of dev sequentiality index.
I did not check all your examples of function names.
But it may be that since usually later version have more arguments,
or are adapter to better hardware with larger bit widths,
the probability that time of dev sequentiality index
matches number of arguments or bit widths is higher than
uniform random probability.
Sometimes, it is clearly possible to give a better name to a function.
Sometimes, it is not so interesting because it is better to avoid
giving false hopes,
and a bad name is an incentive to read the code, to see what it does exactly.
However, maybe when the "Grand Master IA" will have a mono repo of all
code (kernel, shell, all the stack),
it will just be a mass search/replace to improve "everything" ;) XD.
(Crossing fingers there is no function name that is generated by code
somewhere ;) XD.)
I did this kind of mass search/replace on some projects,
I enjoyed it very much,
joy was not so shared by some members of the team ;) XD.

Thanks for your remarks.
And indeed better naming of sigspecs is part of a sane brainstorming :).

Best regards,
     Laurent Lyaudet



reply via email to

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