[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Uninitalized Face data
From: |
Antoine Leca |
Subject: |
Re: Uninitalized Face data |
Date: |
Thu, 24 Feb 2000 15:57:51 +0100 |
I wrote:
>
> Arnar Mar Hrafnkelsson wrote:
> >
> > If I have an array of instance handles say:
> >
> > int i;
> > TT_instance instance[10];
> >
> > for(i=0;i<10;i++) {
> > instance[i]=NULL; /* this is the part that
> > it doesn't like */
> > }
>
> Neither do I ;-)
>
> You are suposed to create the instances with something like:
>
> for(i=0;i<10;i++) {
> TT_New_Instance(some_face, instance[i]);
> }
to which Pavel responded:
> It is often useful to be able to initialize the handle with an invalid
> value and be able to detect that invalid value later. (In particular, this
> makes destruction of partially constructed data structures during error
> recovery much easier.)
>
> In fact, I had to cheat in a similar way Arnar did when I wrote
> ftstrpnm. I intended to point the problem out but, unfortunately,
> I slipped out of my memory. :P
>
> I think there should be a macro testing handle validity (xx_VALID(x)),
> and a macro setting a handle to the invalid value (either x = xx_NULL or
> xx_NULLIFY(x)). Moreover, it should be guaranteed that a zero-filled
> handle is invalid (making statically allocated handles invalid and making
> it possible to mass-initialize handles with memset()).
OK, I surrender ;-)
So if you want to initialize any kind of handle (opaque object) with an
invalid value, assuming that binary zero is really an invalid value (and
I agree with Pavel that the library should warrant that), then the following
C code should work with any ANSI-compliant compiler:
TT_Instance instance[10] = {0};
(even if instance is a local variable).
Similarly, assuming
int i;
TT_Instance instance[10];
the following code does the initialisation, even on existing objects:
static TT_Instance const null_instance = {0};
for(i=0;i<10;i++) {
instance[i] = null_instance;
}
(BTW: this kind of code generally does not work with pre-ANSI compilers,
which in the general case do not support structure operations.)
Now, about xx_VALID(xx), I believe (as I said before) that it is a bit more
difficult, because in the general case, the pointed-to object (I speak about
the internals here) can have been de-allocated, without every instance handle
being reset (that is why C pointers are dangerous, BTW).
Do I miss something here?
(a test of the kind xx_IS_NULL is trivial: that is just a call to memcmp())
Antoine
- Re: Uninitalized Face data, (continued)
- Re: Uninitalized Face data, Arnar Mar Hrafnkelsson, 2000/02/24
- Re: Uninitalized Face data, Bertrand Petit, 2000/02/24
- Re: Uninitalized Face data, Just van Rossum, 2000/02/24
- Re: Uninitalized Face data, Antoine Leca, 2000/02/24
- Re: Uninitalized Face data, Werner LEMBERG, 2000/02/24
- Re: Uninitalized Face data, Just van Rossum, 2000/02/24
- Re: Uninitalized Face data, Stefan Seefeld, 2000/02/24
- Re: Uninitalized Face data, Antoine Leca, 2000/02/25
- Re: Uninitalized Face data, David Turner, 2000/02/25
Re: Uninitalized Face data, Pavel Kankovsky, 2000/02/24
Re: Uninitalized Face data,
Antoine Leca <=
Re: Uninitalized Face data, David Turner, 2000/02/25