This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


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

Re: guile bugs


Jim Blandy <jimb@red-bean.com> writes:

> > I think the idea of making SCM a struct or union makes more sense.
> > Sucks for performance, though.  Well, in the normal case.  Do you mind
> > having the type checking be dependent on gcc?
> > 
> >     #if __GNUC__ >= 2 && __GNUC_MINOR__ >= whatever...
> >     typedef union { long n; } __attribute__ ((transparent_union)) SCM;
> >     #define SCM_BITS(X) ((X).n)
> >     #else
> >     typedef long SCM;
> >     #define SCM_BITS(X) (X)
> >     #endif
> > 
> > A SCM object would get passed as a long, always.  Under gcc, using it
> > as a numeric value will not work.  This only works with recent enough
> > versions of gcc, of course, but transparent_union has been in there
> > for quite a while.  And for people with ancient versions of gcc, or
> > without gcc, they just don't get the type checking; they still get the
> > same calling convention, so even mixing gcc- and non-gcc-compiled code
> > works fine.
> 
> Unfortunately, transparent unions are still *returned* using the
> conventions for unions.  Which will definitely hurt performance.
> 
> Damn --- this would have been so great.  Perfect, no-overhead
> type-checking for anyone using GCC.
> 
> Ken, if I asked the EGCS folks about it, and they approved in
> principle, would you be able to write a patch for GCC to make it
> return, as well as pass, transparent unions as if they had the type of
> the union's first element?

I was thinking about a C language feature that I call "branded typdefs"
that seems to be more exactly what we want.  e.g.,

__branded__ typedef long SCM;

Means that SCM is a long, but is a new type, not just a type alias. This 
would then require casts when a SCM is intended to be used as a long,
and vice-versa.  (Of course, this, like all the other solutions, will
require inserting lots of casts into, e.g., numbers.c and the tags code).

My intuition is that this wouldn't be that hard to implement in GCC (for
someone more knowledgeable about GCC than am I), and would be useful
outside of just the Guile project.

Greg

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