GSoC proposal: Quirinus C library (qc)

Julio Merino jmmv at freebsd.org
Sun Mar 2 19:51:21 UTC 2014


Hello Dmitry,

As others have mentioned, having such a BSD-licensed library would be
a nice thing, but it's also a huge undertake. I guess that if you
scope the project properly, you'd come out of GSoC with just a tiny
piece of it working.

But that has already been discussed. The reason I'm replying is
because of the one comment below:

On Tue, Feb 25, 2014 at 3:24 AM, Dmitry Selyutin <ghostman.sd at gmail.com> wrote:
>
> 2. Common and universal error type, qc_error. Such errors can be generated
> from errno values as well as from Windows API errors.
> Almost all functions from qc library except for the three common functions
> (constructor, destructor, replicator) return qc_error code and set specific
> qc_errno variable to this code.
> It is now possible to write such constructions:
>   if (qc_bytes_import_str(bytes_instance, "Hello, world!"))
>     qc_errormsg(qc_errno, "error check");
> Global variable qc_errno is implemented in terms of multithreading
> applications, it is unique for every running thread.

For error handling, I'm quite happy with what I did in ATF/Kyua.
Basically, indicating "no error" brings no more overhead than
returning and checking a NULL pointer, whereas indicating "error" can
provide arbitrary amounts of information in dynamically-allocated
structures. There is no global state (i.e. no "errno" style
variables).

The base library has support to pass around "libc" errors, usage
errors, generic errors and OOM errors. The latter are interesting
because no memory allocation should take place when reporting an OOM
condition. Lastly, client code can define its own error objects if so
wishes to pass around other structured data.

The code, BSD-licensed, is here:

https://github.com/jmmv/kyua/blob/master/kyua-testers/error_fwd.h
https://github.com/jmmv/kyua/blob/master/kyua-testers/error.h
https://github.com/jmmv/kyua/blob/master/kyua-testers/error.c


More information about the freebsd-hackers mailing list