[7] in Pthreads mailing list archive
Re: netdb interfaces
daemon@ATHENA.MIT.EDU (Ken Raeburn)
Fri Jun 9 17:02:30 1995
From: Ken Raeburn <raeburn@cygnus.com>
Date: Fri, 9 Jun 1995 16:41:48 -0400
To: Greg Hudson <ghudson@MIT.EDU>
Cc: pthreads@MIT.EDU
In-Reply-To: Greg Hudson's message of Fri, 9 Jun 1995 13:25:37 -0400 <199506091725.NAA23698@glacier.MIT.EDU>
This time, I changed my mind when I disocvered that there's no way to
implement getservent_rf() in ANSI C (or getservent_r() in ANSI C plus
mutexes). Since struct servent has a list of aliases represented as a
NULL-terminated vector of character pointers, the "result structure,
buffer, and length" approach to netdb reentrancy means that the
internals of the library have to know what the alignment restrictions
are on character pointers, and how to take a possibly unaligned
pointer and round it up to the nearest acceptable aligned pointer for
storing a character pointer.
I don't think any object can ever require alignment greater than its
own size. Of course, doing the appropriate arithmetic on pointers
might be questionable under strict ANSI C.
How about implementing it as a structure with a variable-length tail?
struct x {
struct servent s;
char *ptr[1];
};
struct x *xp = malloc (sizeof (struct x)
+ sizeof (char *) * (n_pointers - 1)
+ buf_len);
Since ptr[0] must be properly aligned, so must ptr[1], ptr[2]
... ptr[n_pointers-1]. Does anyone know for sure if this is valid or
not? (I.e., can "(char **) (xp+1)" or "xp->ptr[1]" be valid storage,
in the example above?)
Of course, the current pthreads interfaces aren't perfect either.
They merely take the static data from the netdb routines and stuff it
into an _answer structure. So they suffer from the same arbitrary
limits as the old routines, and now your compiled binaries depend on
the size of the _answer structures, so those buffers can't change size
across versions of the implementation without breaking binary
compatibility.
I don't quite see that, but I haven't reviewed the interfaces in
question lately, so I'll take your word for it. Yuck.
I want garbage collection, dammit.
:-)