fix build on travis-ci.org

Some early returns were missing after the removal of longjmp in #22.
This has led to segfaults on Linux (confirmed locally).
document.h: avoid casting away const

Another instance of casting away constness via C-style cast
has been missed (introduced by #20).
Merge pull request #26 from pah/fixes/errorreturn-castqual

Fix segfault and build error on Linux