예제 #1
0
파일: Err.c 프로젝트: theory/lucy
void
Err_throw_mess(VTable *vtable, CharBuf *message) {
    Err_Make_t make
        = METHOD_PTR(CERTIFY(vtable, VTABLE), Cfish_Err_Make);
    Err *err = (Err*)CERTIFY(make(NULL), ERR);
    Err_Cat_Mess(err, message);
    DECREF(message);
    Err_do_throw(err);
}
예제 #2
0
static void
S_fill(InStream *self, int64_t amount) {
    InStreamIVARS *const ivars     = InStream_IVARS(self);
    FileWindow *const window       = ivars->window;
    const int64_t virtual_file_pos = SI_tell(self);
    const int64_t real_file_pos    = virtual_file_pos + ivars->offset;
    const int64_t remaining        = ivars->len - virtual_file_pos;

    // Throw an error if the requested amount would take us beyond EOF.
    if (amount > remaining) {
        THROW(ERR,  "Read past EOF of %o (pos: %u64 len: %u64 request: %u64)",
              ivars->filename, virtual_file_pos, ivars->len, amount);
    }

    // Make the request.
    if (FH_Window(ivars->file_handle, window, real_file_pos, amount)) {
        char    *fw_buf    = FileWindow_Get_Buf(window);
        int64_t  fw_offset = FileWindow_Get_Offset(window);
        int64_t  fw_len    = FileWindow_Get_Len(window);
        char *const window_limit = fw_buf + fw_len;
        ivars->buf = fw_buf
                     - fw_offset          // theoretical start of real file
                     + ivars->offset      // top of virtual file
                     + virtual_file_pos;  // position within virtual file
        ivars->limit = window_limit - ivars->buf > remaining
                       ? ivars->buf + remaining
                       : window_limit;
    }
    else {
        Err *error = Err_get_error();
        String *str = Str_newf(" (%o)", ivars->filename);
        Err_Cat_Mess(error, str);
        DECREF(str);
        RETHROW(INCREF(error));
    }
}