Improve and harden handling of edge cases in C-API

Addresses https://github.com/sass/libsass/issues/776