This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v4][C][ADA] use function descriptors instead of trampolines in C

On Tue, Dec 18, 2018 at 10:23:46AM -0500, Paul Koning wrote:
> > On Dec 17, 2018, at 2:23 PM, Szabolcs Nagy <> wrote:
> > 
> > On 17/12/2018 18:22, Uecker, Martin wrote:
> >>> 
> >>> ...
> >> 
> >> So a thread_local static variable for storing the static
> >> chain?
> > 
> > something like that, but the more i think about it the
> > harder it seems: the call site of the nested function
> > may not be under control of the nested function writer,
> > in particular the nested function may be called on a
> > different thread, and extern library apis are unlikely
> > to provide guarantees about this, so in general if a
> > nested function escapes into an extern library then
> > this cannot be relied on, which limits my original
> > idea again to cases where there is no escape (which i
> > think is not that useful).
> I'm not sure I understand "escape" of a nested function pointer. 
> Your description makes it sound like you're talking about a function being called by someone who has been given the pointer, from outside the scope of the function.  That sounds like an illegal operation, exactly as it would be if you attempted to reference an automatic variable via a pointer from outside the scope of that variable.
> Did I misunderstand?

The most common case is when you pass a call to a nested function
to some function that has a function pointer argument, e.g. qsort.
This is well defined with GNU nested functions, but the function that calls
the callback (qsort in this case) doesn't know it is a call to a nested

#include <stdlib.h>
#include <stdbool.h>

main ()
  bool r = false;
  auto int cmp (const void *a, const void *b)
    const signed char *c = (const signed char *) a;
    const signed char *d = (const signed char *) b;
    return r ? *c - *d : *d - *c;

  signed char l[8] = { 10, 2, 11, 21, 0, 7, 18, 12 };
  qsort (l, 8, 1, cmp);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]