From ac163ddfe54ee0f6b4b11f0f785414941190e097 Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Mon, 23 Oct 2023 05:45:57 +0200 Subject: [PATCH 1/2] fix: segfault with some compiler and flag combinations --- curl/instructions/easy.v | 2 +- curl/lib.v | 2 +- src/_instruction_download.v | 16 +++++++--------- src/_instructions_common.v | 5 ++--- src/_instructions_get.v | 18 ++++++++---------- src/_instructions_head.v | 9 ++++----- src/_instructions_post.v | 9 ++++----- src/_state_response.v | 5 +++-- 8 files changed, 30 insertions(+), 36 deletions(-) diff --git a/curl/instructions/easy.v b/curl/instructions/easy.v index 31b9369..aa291d9 100644 --- a/curl/instructions/easy.v +++ b/curl/instructions/easy.v @@ -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)) } diff --git a/curl/lib.v b/curl/lib.v index edcc93d..7ad957d 100644 --- a/curl/lib.v +++ b/curl/lib.v @@ -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) } diff --git a/src/_instruction_download.v b/src/_instruction_download.v index fe54f70..2dda5ba 100644 --- a/src/_instruction_download.v +++ b/src/_instruction_download.v @@ -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 @@ -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 @@ -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 diff --git a/src/_instructions_common.v b/src/_instructions_common.v index 524c05c..d37881c 100644 --- a/src/_instructions_common.v +++ b/src/_instructions_common.v @@ -58,7 +58,6 @@ 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 { @@ -66,8 +65,8 @@ fn (mut resp VibeResponse) handle_redirect(h &curl.Handle, max_redirects u16) ! 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 } } diff --git a/src/_instructions_get.v b/src/_instructions_get.v index eb2dde5..d4c9750 100644 --- a/src/_instructions_get.v +++ b/src/_instructions_get.v @@ -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 @@ -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 { @@ -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)..] } diff --git a/src/_instructions_head.v b/src/_instructions_head.v index dc58411..5f1851d 100644 --- a/src/_instructions_head.v +++ b/src/_instructions_head.v @@ -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 } diff --git a/src/_instructions_post.v b/src/_instructions_post.v index 33a0da2..46229ae 100644 --- a/src/_instructions_post.v +++ b/src/_instructions_post.v @@ -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 diff --git a/src/_state_response.v b/src/_state_response.v index b390b38..30a9c9a 100644 --- a/src/_state_response.v +++ b/src/_state_response.v @@ -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: From 9c2700025d4ad243b1956788d9e4f3d7e61f7f4f Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Sat, 21 Oct 2023 19:53:28 +0200 Subject: [PATCH 2/2] ci: re-enable related CI --- .github/workflows/ci.yml | 22 ++++++++++++++++++++++ .github/workflows/linux.yml | 21 --------------------- .github/workflows/macos.yml | 20 -------------------- 3 files changed, 22 insertions(+), 41 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 779548d..e1eed7f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 2fa9d48..8965b0e 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -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] @@ -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 diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 7ade94d..e7215dd 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -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] @@ -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