2 ms·
That's not really the best example of using goto's, as that code is generated from this file: https://github.com/zedshaw/mongrel2/blob/master/src/http11/http11
by MarkSweep 11y ago
That's not really the best example of using goto's, as that code is generated from this file:
https://github.com/zedshaw/mongrel2/blob/master/src/http11/http11_parser.rl https://github.com/zedshaw/mongrel2/blob/master/src/http11/h...
A nicer example of the use of goto's in Mongrel2 is the check macro:
https://github.com/zedshaw/mongrel2/blob/a884aef0f4a460e130dc35a689ffad2c6f051bf6/src/dbg.h#L72 https://github.com/zedshaw/mongrel2/blob/a884aef0f4a460e130d...
The convention of the project is that every function that has to deal with an error condition has an "error" label. These macro a used to jump to that label to clean up the function before returning. Here's an example:
https://github.com/zedshaw/mongrel2/blob/a884aef0f4a460e130dc35a689ffad2c6f051bf6/src/superpoll.c#L281-L288 https://github.com/zedshaw/mongrel2/blob/a884aef0f4a460e130d...
I think that this use of gotos is more clear than the alternative of a lot of nested if statements checking for success or having the clean up logic duplicated in a lot of places.