[basic-improvements] try/finally support for c/c++ - more tests

Michael Matz matz@suse.de
Thu Nov 7 05:47:00 GMT 2002


Hi,

On Fri, 8 Nov 2002, Fergus Henderson wrote:

> Describing it as "completely inefficient" is going a bit too far, IMHO.
> Cleanups are most often used to protect code which acquires locks or
> makes system calls, aren't they?  Isn't acquiring a lock

No it isn't.  spinlocks e.g. can be implemented with inline asm, and have
no call in the fast path (which only takes some cycles) at all.

> or making a system call a fairly expensive operation anyway?
>
> The worst cause of inefficiency for this approach is probably the icache
> flush needed for the trampoline creation when you take the address of a
> GNU C nested function.
>
> (I would like to see a different extension to fix that: one that
> allowed you to take the address of a nested function in a way that
> gave you two pointers -- a code pointer and a data pointer -- rather
> than a single pointer to a trampoline.)

So instead of having an extension designed for doing what we want, you
want a) use another extension (which is neither designed, nor implemented
that well) to implement what we want, and b) add another not yet specified
extension to fix one problem with a) ?

> Now, all that said, I would like to see support for exception handling
> in GNU C

Although the extension only does cleanups not exceptions.


> (and for glibc to continue to be written in C rather than C++).
> But I would like the support for exception handling to include support
> for throwing and catching exceptions, not just try/finally.  The current
> proposal seems too limited to be useful for much else than glibc, IMHO.

Please?  A try/finally would be usefull nearly everywhere in C which deals
with resources.  E.g. for something like this:

char *buf;
char *name;
FILE *f;
name = (char *) malloc (size);
if (!name)
  return ERROR;
buf = (char *) malloc (size2);
if (!buf)
  {
    free (name);
    return ERROR;
  }
f = fopen (name, "r");
if (!f)
  {
    free (name);
    free (buf);
    return ERROR;
  }
if (fread (buf, size2, 1, f) < 0)
  {
    fclose (f);
    free (name);
    free (buf);
    return ERROR;
  }
...

Well, you get the idea.


Ciao,
Michael.



More information about the Gcc-patches mailing list