Memory pool interface design
Daniel Shahaf
d.s at daniel.shahaf.name
Mon May 18 02:37:31 IDT 2015
Elazar Leibovich wrote on Sun, May 17, 2015 at 00:04:49 +0300:
> A concrete example, a "regular" read_line function
>
> char *read_line(struct reader *r) { char *rv = malloc(len); read_to(rv);
> return rv; }
...
> Our read_line example would now look like
>
> struct error read_line(struct reader *r, char **line);
>
> And users would have to check error at each invocation.
>
> I think I can avoid that. What do I intend to do?
Another option is to signal error out-of-band — via some thread-global
variable or function — and require API users to check that out-of-band
channel after each call:
line = read_line()
if (line == NULL || read_line_error())
/* ... */ ;
For example:
https://docs.python.org/3/c-api/exceptions.html#c.PyErr_Occurred
Daniel
More information about the Linux-il
mailing list