Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: segfaults with some compiler and flag combinations #22

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,30 @@ concurrency:
cancel-in-progress: true

jobs:
debounce:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
outputs:
abort: ${{ steps.debounce.outputs.abort }}
steps:
- run: printenv
- name: Debounce
if: github.ref_name != 'main' && github.event_name == 'push'
id: debounce
run: |
pr_branches=$(gh pr list --json headRefName --repo $GITHUB_REPOSITORY)
if [[ "$pr_branches" != '[]' && $(echo "$pr_branches" | jq -r --arg GITHUB_REF_NAME '.[].headRefName | select(. == $GITHUB_REF_NAME)') ]]; then
echo "This push is associated with a pull request. Skipping the job."
echo "abort=true" >> "$GITHUB_OUTPUT"
fi

linux:
needs: debounce
if: needs.debounce.outputs.abort != 'true'
uses: ./.github/workflows/linux.yml

macos:
needs: debounce
if: needs.debounce.outputs.abort != 'true'
uses: ./.github/workflows/macos.yml
21 changes: 0 additions & 21 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,7 @@ env:
MOD_PATH: ~/.vmodules/vibe

jobs:
debounce:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
outputs:
abort: ${{ steps.debounce.outputs.abort }}
steps:
- name: Debounce
if: github.ref_name != 'main' && github.event_name == 'push'
id: debounce
run: |
pr_branches=$(gh pr list --json headRefName --repo $GITHUB_REPOSITORY)
if [[ $(echo "$pr_branches" | jq -r --arg GITHUB_REF '.[].headRefName | select(. == $GITHUB_REF)') ]]; then
echo "This push is associated with a pull request. Skipping the job."
echo "abort=true" >> "$GITHUB_OUTPUT"
fi

setup:
needs: debounce
if: needs.debounce.outputs.abort != 'true'
strategy:
matrix:
os: [ubuntu-20.04, ubuntu-latest]
Expand Down Expand Up @@ -94,8 +75,6 @@ jobs:
- name: Build
run: v -shared ${{ env.MOD_PATH }}
- name: Run tests
# TODO: investigate segfaults when running tests in copmiler + optimization combinations
if: matrix.cc != 'gcc' && matrix.optimization != '-prod'
uses: nick-fields/retry@v2
with:
timeout_minutes: 3
Expand Down
20 changes: 0 additions & 20 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,7 @@ env:
MOD_PATH: ~/.vmodules/vibe

jobs:
debounce:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
outputs:
abort: ${{ steps.debounce.outputs.abort }}
steps:
- name: Debounce
if: github.ref_name != 'main' && github.event_name == 'push'
id: debounce
run: |
pr_branches=$(gh pr list --json headRefName --repo $GITHUB_REPOSITORY)
if [[ $(echo "$pr_branches" | jq -r --arg GITHUB_REF '.[].headRefName | select(. == $GITHUB_REF)') ]]; then
echo "This push is associated with a pull request. Skipping the job."
echo "abort=true" >> "$GITHUB_OUTPUT"
fi

setup:
needs: debounce
if: needs.debounce.outputs.abort != 'true'
strategy:
matrix:
os: [macos-11, macos-latest]
Expand Down Expand Up @@ -80,7 +61,6 @@ jobs:
- name: Build
run: v -shared ${{ env.MOD_PATH }}
- name: Run tests
if: matrix.optimization != '-prod'
uses: nick-fields/retry@v2
with:
timeout_minutes: 3
Expand Down
2 changes: 1 addition & 1 deletion curl/instructions/easy.v
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ pub fn easy_perform(handle &C.CURL) state.Ecode {
return ecode(C.curl_easy_perform(handle))
}

pub fn easy_getinfo[T](handle &C.CURL, info state.Info, typ T) state.Ecode {
pub fn easy_getinfo(handle &C.CURL, info state.Info, typ voidptr) state.Ecode {
return ecode(C.curl_easy_getinfo(handle, int(info), typ))
}
2 changes: 1 addition & 1 deletion curl/lib.v
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn easy_perform(handle &Handle) Ecode {
return instructions.easy_perform(handle)
}

pub fn easy_getinfo[T](handle &Handle, info Info, typ T) Ecode {
pub fn easy_getinfo(handle &Handle, info Info, typ voidptr) Ecode {
return instructions.easy_getinfo(handle, info, typ)
}

Expand Down
16 changes: 7 additions & 9 deletions src/_instruction_download.v
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ fn (req Request) download_file_(url string, file_path string) !Response {
curl.easy_setopt(h, .writedata, &fw)
send_request(h)!

mut status_code := 0
curl.easy_getinfo(h, .response_code, &status_code)
resp.status = Status(status_code)
curl.easy_getinfo(h, .response_code, &resp.status_code)
resp.status = Status(resp.status_code)
resp.get_http_version()!

return resp.Response
Expand Down Expand Up @@ -59,9 +58,8 @@ fn (req Request) download_file_with_progress_(url string, file_path string, mut
send_request(h)!
dl.finish()

mut status_code := 0
curl.easy_getinfo(h, .response_code, &status_code)
resp.status = Status(status_code)
curl.easy_getinfo(h, .response_code, &resp.status_code)
resp.status = Status(resp.status_code)
resp.get_http_version()!

return resp.Response
Expand All @@ -80,10 +78,10 @@ fn (req Request) follow_download_head(h &curl.Handle, url string) !VibeResponse
req.set_head_opts(h, url, &resp)
send_request(h)!

mut status_code := 0
curl.easy_getinfo(h, .response_code, &status_code)
if status_code / 100 == 3 {
curl.easy_getinfo(h, .response_code, &resp.status_code)
if resp.status_code / 100 == 3 {
resp.handle_redirect(h, req.max_redirects)!
curl.easy_getinfo(h, .response_code, &resp.status_code)
}

return resp
Expand Down
5 changes: 2 additions & 3 deletions src/_instructions_common.v
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,15 @@ fn send_request(handle &curl.Handle) ! {
}

fn (mut resp VibeResponse) handle_redirect(h &curl.Handle, max_redirects u16) ! {
mut status_code := 0
mut redir_url := ''.str

for _ in 0 .. max_redirects {
resp = VibeResponse{}
curl.easy_getinfo(h, .redirect_url, &redir_url)
curl.easy_setopt(h, .url, redir_url)
send_request(h)!
curl.easy_getinfo(h, .response_code, &status_code)
if status_code / 100 != 3 {
curl.easy_getinfo(h, .response_code, &resp.status_code)
if resp.status_code / 100 != 3 {
return
}
}
Expand Down
18 changes: 8 additions & 10 deletions src/_instructions_get.v
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ fn (req Request) get_(url string) !Response {
curl.easy_setopt(h, .writefunction, write_resp)
send_request(h)!

mut status_code := 0
curl.easy_getinfo(h, .response_code, &status_code)
if status_code / 100 == 3 {
curl.easy_getinfo(h, .response_code, &resp.status_code)
if resp.status_code / 100 == 3 {
resp.handle_redirect(h, req.max_redirects)!
curl.easy_getinfo(h, .response_code, &status_code)
curl.easy_getinfo(h, .response_code, &resp.status_code)
}

resp.get_http_version()!
resp.status = Status(status_code)
resp.status = Status(resp.status_code)
resp.body = resp.body[resp.header.len..]

return resp.Response
Expand Down Expand Up @@ -52,11 +51,10 @@ fn (req Request) get_slice_(url string, start usize, max_size_ ?usize) !Response
return curl.curl_error(res)
}

mut status_code := 0
curl.easy_getinfo(h, .response_code, &status_code)
if status_code / 100 == 3 {
curl.easy_getinfo(h, .response_code, &resp.status_code)
if resp.status_code / 100 == 3 {
resp.handle_redirect(h, req.max_redirects)!
curl.easy_getinfo(h, .response_code, &status_code)
curl.easy_getinfo(h, .response_code, &resp.status_code)
}

if resp.body.len == 0 {
Expand All @@ -65,7 +63,7 @@ fn (req Request) get_slice_(url string, start usize, max_size_ ?usize) !Response
}

resp.get_http_version()!
resp.status = Status(status_code)
resp.status = Status(resp.status_code)
if start < usize(resp.header.len) {
resp.body = resp.body[resp.header.len - int(start)..]
}
Expand Down
9 changes: 4 additions & 5 deletions src/_instructions_head.v
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ fn (req Request) head_(url string) !Response {
req.set_head_opts(h, url, &resp)
send_request(h)!

mut status_code := 0
curl.easy_getinfo(h, .response_code, &status_code)
if status_code / 100 == 3 {
curl.easy_getinfo(h, .response_code, &resp.status_code)
if resp.status_code / 100 == 3 {
resp.handle_redirect(h, req.max_redirects)!
curl.easy_getinfo(h, .response_code, &status_code)
curl.easy_getinfo(h, .response_code, &resp.status_code)
}
resp.get_http_version()!
resp.status = Status(status_code)
resp.status = Status(resp.status_code)

return resp.Response
}
Expand Down
9 changes: 4 additions & 5 deletions src/_instructions_post.v
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ fn (req Request) post_(url string, data string) !Response {
req.set_common_opts(h, url, resp)
send_request(h)!

mut status_code := 0
curl.easy_getinfo(h, .response_code, &status_code)
if status_code / 100 == 3 {
curl.easy_getinfo(h, .response_code, &resp.status_code)
if resp.status_code / 100 == 3 {
resp.handle_redirect(h, req.max_redirects)!
curl.easy_getinfo(h, .response_code, &status_code)
curl.easy_getinfo(h, .response_code, &resp.status_code)
}

resp.get_http_version()!
resp.status = Status(status_code)
resp.status = Status(resp.status_code)
resp.body = resp.body[resp.header.len..]

return resp.Response
Expand Down
5 changes: 3 additions & 2 deletions src/_state_response.v
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ pub mut:
struct VibeResponse {
Response
mut:
pos usize
slice struct {
pos usize
status_code int
slice struct {
start usize
end usize
mut:
Expand Down
Loading