tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: The lamentation of proplib(3)



On Tue, 28 Jan 2014 21:36:48 +0000
Taylor R Campbell <campbell+netbsd-tech-kern%mumble.net@localhost> wrote:

> libnv may be more type-safe as an API itself than proplib, but if we
> are going to seriously adopt something for formal protocols, it ought
> to have schemas that support enforcement in the C type system so that
> the protocols can have type-safe APIs too.

I have thought for a long time that a limited form of reflection should
be added to C and C ++ precisely to support serialization of simple
data structures.  I know we can't fix C here and now, nor even in time
for what you propose.  I'd like to ask, though, if you agree that the
features I describe below would, were they available, be helpful to
what you propose.  

From XDR onward, serialization has been a persistent nuisance (so to
speak) because the compiler discards the information needed to provide
type-checked I/O.   

Every C struct can be described by a list of tuples, basically 

        offset, name, type, length

and it *should* be possible to iterate over that list to perform I/O.
All that is needed is for the compiler to capture that information in a
table, and for the language to provide access to it.  

It's already being done, just badly.  Some of the information, such as
offset, is weirdly available via macros.  The rest is provided to the
debugger in some horrible nonstandard way that is inaccessible to the
program.  

My question to you and the others participating in this thread is
simple: Do you think such a table would both reduce the effort of
writing I/O libraries and improve their correctness?  I for one can
imagine tying that information to writev/readv to programatically
generate iovec arrays and validate type information at read time.  

It's not an idle question.  It would be good to have a clear example
use-case.  

--jkl










Home | Main Index | Thread Index | Old Index