Add context argument for callback functions.

Also fixes a couple bugs in sparse_end where the block was ignored and
the callback function might've been called when NULL.