develooper Front page | perl.perl5.porters | Postings from August 1999

Re: SV * and ANSI...

Hans Mulder
August 31, 1999 15:47
Re: SV * and ANSI...
Message ID:
Hoi <>,
> On Fri, 27 Aug 1999, Hans Mulder wrote:
> > In article <>, Chip Salzenberg <> wrote:
> >
> > >I think you actually might be able to get away with a creative
> > >interpretation of the rules WRT identically declared structure
> > >members.
> >
> > Nope, that cannot work.  At the time the ANSI standard was written
> > Data General manufactured machines where sizeof(void*) > sizeof(XPVHV*)
> > and the standard was written to allow this.  On such machines the
> > sv_refcnt and sv_flags fields in a SV have larger offsets than the
> > corresponding fields in a HV and consequently you can't access those
> > fields in a SV via a HV* or vice versa.
> Hmmm. Can you, then, in this case cast a void * to a XPVHV *? Or would
> that fail, since the pointers are of different sizes? (Even though we're
> using the larger in the declarations)

Yes, you can, at least in the three cases that matter:
1. You can cast the void*s you get from malloc() and friends to XPVHV*.
2. Casting a NULL void* produces a NULL XPVHV*
3. Casting a XPVHV* to void* and back to XPVHV* produces the XPVHV* you
   started with.

Keep in mind, though, that on the machine we're talking about, a cast to
void* was a run-time operation.  You don't want to pay that price every
time you access the struct pointed to by sv_any.

The ANSI standard implies that all struct pointers have the same
representation.   I get the impression that the sv_any field is
only used to hold pointers to various types of structs (and NULL).
If that is really the case, we could satisfy the requirement in
standard by declaring SV as:

struct sv {
    struct xxx*	sv_any;		/* pointer to something */
    U32		sv_refcnt;	/* how many references to us */
    U32		sv_flags;	/* what we are */

A definition of "struct xxx" is not required, provided we never
try to use the sv_any pointer to access such a beast.

-- HansM Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About