Skip to content

Commit

Permalink
refactor: update unsafe syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed May 19, 2024
1 parent 261ebf1 commit b9c0441
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
10 changes: 3 additions & 7 deletions curl/instructions/easy.v
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@ fn ecode(i int) state.Ecode {

pub fn easy_init() !&C.CURL {
handle := C.curl_easy_init()
unsafe {
if handle == nil {
error('Failed performing curl.easy_init()')
}
if handle == unsafe { nil } {
error('Failed performing curl.easy_init()')
}
return handle
}

pub fn easy_strerror(err_code state.Ecode) string {
str_err := &char(C.curl_easy_strerror(int(err_code)))
unsafe {
return str_err.vstring()
}
return unsafe { str_err.vstring() }
}

pub fn easy_setopt[T](handle &C.CURL, option state.Opt, parameter T) state.Ecode {
Expand Down
20 changes: 5 additions & 15 deletions src/_instructions_write_fns.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,22 @@ module vibe
fn write_resp(data &char, size usize, nmemb usize, mut resp VibeResponse) usize {
n := size * nmemb
resp.pos += n
unsafe {
resp.body += data.vstring_with_len(int(n))
}
resp.body += unsafe { data.vstring_with_len(int(n)) }
return n
}

fn write_resp_header(data &char, size usize, nmemb usize, mut resp VibeResponse) usize {
n := size * nmemb
resp.pos += n
unsafe {
resp.header += data.vstring_with_len(int(n))
}
resp.header += unsafe { data.vstring_with_len(int(n)) }
return n
}

fn write_resp_slice(data &char, size usize, nmemb usize, mut resp VibeResponse) usize {
n := size * nmemb
resp.pos += n
if resp.pos > resp.slice.start {
unsafe {
resp.body += data.vstring_with_len(int(n))
}
resp.body += unsafe { data.vstring_with_len(int(n)) }
if resp.slice.end != resp.slice.start && resp.pos > resp.slice.end {
resp.slice.finished = true
return 0
Expand All @@ -36,19 +30,15 @@ fn write_resp_slice(data &char, size usize, nmemb usize, mut resp VibeResponse)
fn write_download(data &char, size usize, nmemb usize, mut fw FileWriter) usize {
n := size * nmemb
if fw.file.is_opened {
fw.pos += u64(unsafe {
fw.file.write_ptr_at(data, int(n), fw.pos)
})
fw.pos += u64(unsafe { fw.file.write_ptr_at(data, int(n), fw.pos) })
}
return n
}

fn write_download_with_progress(data &char, size u64, nmemb u64, mut w ProgressWriter) u64 {
n := size * nmemb
if w.file.is_opened {
w.pos += u64(unsafe {
w.file.write_ptr_at(data, int(n), w.pos)
})
w.pos += u64(unsafe { w.file.write_ptr_at(data, int(n), w.pos) })
w.download.progress(w.pos, w.size)
}
return n
Expand Down

0 comments on commit b9c0441

Please sign in to comment.