Zeuthen: Writing a C library, part 1
Zeuthen: Writing a C library, part 1
Posted Jun 28, 2011 13:32 UTC (Tue) by nix (subscriber, #2304)In reply to: Zeuthen: Writing a C library, part 1 by wahern
Parent article: Zeuthen: Writing a C library, part 1
The rule I follow is simply that libraries should never ever abort, period, except perhaps in a limited number of functions whose documented purpose is to terminate the process. Yes, it means you have to actually bother with a bit of error handling. That's the least you can expect from a half-competent C programmer, I'd say.
Posted Jun 30, 2011 14:08 UTC (Thu)
by stevem (subscriber, #1512)
[Link]
A library should *never* call abort in an attempt at error-handling. You throw away any chance for the calling code to do sensible stuff such as clean up properly.
Posted Jun 30, 2011 15:19 UTC (Thu)
by nix (subscriber, #2304)
[Link] (2 responses)
(Ironically, elsewhere in the same post David comments that libraries should not manipulate signal dispositions because these are process-wide state. I'd call the continued existence of a process process-wide state, as well, but apparently David disagrees. I think his attitude leads to appalling and unnecessary instability: he thinks mine leads to unfixed bugs in callers. We are probably both right, but ne'er the twain shall meet.)
Posted Jun 30, 2011 17:49 UTC (Thu)
by davidz2525 (guest, #58065)
[Link] (1 responses)
(Btw, another misconception is that libdbus-1 is meant for applications to use; it's really not, it's more intended for a base that you can build language/toolkit bindings on top + the implementation used to implement dbus-daemon(1) which MUST be able to handle OOM.)
Posted Jun 30, 2011 21:12 UTC (Thu)
by nix (subscriber, #2304)
[Link]
Damn good articles btw.
Posted Jul 1, 2011 5:28 UTC (Fri)
by whot (subscriber, #50317)
[Link] (1 responses)
The abort() was extremely annoying while programming but it also lead to the code being very stable. Every small error got punished badly so we had to make sure we fixed up the code properly.
Posted Jul 1, 2011 9:37 UTC (Fri)
by nix (subscriber, #2304)
[Link]
Zeuthen: Writing a C library, part 1
Zeuthen: Writing a C library, part 1
Zeuthen: Writing a C library, part 1
Zeuthen: Writing a C library, part 1
Zeuthen: Writing a C library, part 1
Zeuthen: Writing a C library, part 1