Skip to content

Commit

Permalink
zuo: fix some compiler warnings
Browse files Browse the repository at this point in the history
Change parts of `zuo.c` to avoid warnings that show up with flags like

-Wall -Wextra -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Wshadow -Wpointer-arith -Wcast-qual -pedantic -O2 -std=c11

Repair a bug in Windows for `fd-poll` that better testing exposed, but
also update test and docs to clarify that `fd-poll` is not so useful on
Windows.
  • Loading branch information
benknoble authored and mflatt committed Apr 26, 2024
1 parent 2644aff commit a04dffe
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 150 deletions.
42 changes: 42 additions & 0 deletions racket/src/zuo/.github/scripts/msvcprep.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

REM Find Visual Studio [Express] in one of the usual places.
REM Expects something like "x86", "amd64", or "x86_amd64" as an argument.

set VCMODE=%1

REM For 2022 and later, look in "Program Files"
set Applications=%ProgramFiles%

set VCVARBAT=%Applications%\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat

if not exist "%VCVARBAT%" set VCVARBAT=%Applications%\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat
if not exist "%VCVARBAT%" set VCVARBAT=%Applications%\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build\vcvarsall.bat
if not exist "%VCVARBAT%" set VCVARBAT=%Applications%\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat

REM For 2019 and earlier, look in "Program Files (x86)"
set Applications=%ProgramFiles(x86)%
if "%Applications%" == "" set Applications=%ProgramFiles%

if not exist "%VCVARBAT%" set VCVARBAT=%Applications%\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat
if not exist "%VCVARBAT%" set VCVARBAT=%Applications%\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvarsall.bat
if not exist "%VCVARBAT%" set VCVARBAT=%Applications%\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat
if not exist "%VCVARBAT%" set VCVARBAT=%Applications%\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat

if not exist "%VCVARBAT%" set VCVARBAT=%Applications%\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat
if not exist "%VCVARBAT%" set VCVARBAT=%Applications%\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvarsall.bat
if not exist "%VCVARBAT%" set VCVARBAT=%Applications%\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat
if not exist "%VCVARBAT%" set VCVARBAT=%Applications%\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat

if not exist "%VCVARBAT%" set VCVARBAT=%Applications%\Microsoft Visual Studio 14.0\vc\vcvarsall.bat

if not exist "%VCVARBAT%" set VCVARBAT=%Applications%\Microsoft Visual Studio 13.0\vc\vcvarsall.bat

if not exist "%VCVARBAT%" set VCVARBAT=%Applications%\Microsoft Visual Studio 12.0\vc\vcvarsall.bat

if not exist "%VCVARBAT%" set VCVARBAT=%Applications%\Microsoft Visual Studio 11.0\vc\vcvarsall.bat

if not exist "%VCVARBAT%" set VCVARBAT=%Applications%\Microsoft Visual Studio 10.0\vc\vcvarsall.bat

if not exist "%VCVARBAT%" set VCVARBAT=%Applications%\Microsoft Visual Studio 9.0\vc\vcvarsall.bat

"%VCVARBAT%" %VCMODE%
45 changes: 45 additions & 0 deletions racket/src/zuo/.github/workflows/zuo-cflags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
name: Zuo with Strict Compiler Flags

# yamllint disable-line rule:truthy
on: [push, pull_request]

jobs:
build-gcc:
runs-on: ubuntu-22.04

env:
CFLAGS: "-Werror -Wall -Wextra -Wstrict-prototypes -Wold-style-definition -Wshadow -Wpointer-arith -Wcast-qual -pedantic -O2 -std=c11 -D_POSIX_C_SOURCE=200809L"

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 100
- name: Compile
run: |
gcc -c $CFLAGS -DZUO_EMBEDDED zuo.c -o zuo_embed.o
gcc $CFLAGS zuo.c -o zuo
- name: Check
run: ./zuo build.zuo check

build-msvc:
runs-on: windows-2022

env:
CFLAGS: "/W1 /WX"

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 100
- name: Compile
shell: cmd
run: |
call .github\scripts\msvcprep.bat x86_amd64
cl /c %CFLAGS% /DZUO_EMBEDDED /Fo:zuo_embed.obj zuo.c
cl %CFLAGS% zuo.c -o zuo
- name: Check
shell: cmd
run: |
call .github\scripts\msvcprep.bat x86_amd64
zuo build.zuo check
2 changes: 1 addition & 1 deletion racket/src/zuo/build.zuo
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
(lambda ()
(unless (= 0 (process-status
(thread-process-wait
(hash-ref (process "to-run/zuo"
(hash-ref (process (.exe "to-run/zuo")
(at-source "tests/main.zuo"))
'process))))
(error "check failed")))))))
Expand Down
7 changes: 4 additions & 3 deletions racket/src/zuo/tests/file-handle.zuo
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@
'stdout 'pipe))])
(define in (hash-ref ht 'stdout))
(define out (hash-ref ht 'stdin))
(check (fd-poll (list in) 0) #f)
(check (fd-poll (list in out) 0) out)
(check (fd-poll (list in out)) out)
(unless (eq? 'windows (system-type)) ;; polling doesn't work on Windows pipes
(check (fd-poll (list in) 0) #f)
(check (fd-poll (list in out) 0) out)
(check (fd-poll (list in out)) out))
(fd-write out "x")
(check (fd-poll (list in)) in)
(check (fd-poll (list in) 0) in)
Expand Down
6 changes: 3 additions & 3 deletions racket/src/zuo/tests/path.zuo
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
".")
(check (find-relative-path "home/zuo/src" "tmp/cache")
(build-path ".." ".." ".." "tmp" "cache"))
(check (find-relative-path "." "tmp/cache")
(check (find-relative-path "." (build-path "tmp" "cache"))
(build-path "tmp" "cache"))
(check (find-relative-path "tmp/cache" ".")
(build-path ".." ".."))
Expand Down Expand Up @@ -148,7 +148,7 @@
(check-arg-fail (file-name-from-path 10) not-path)

(check (path-replace-extension "a.c" ".o") "a.o")
(check (path-replace-extension "p/a.c" ".o") (build-path "p" "a.o"))
(check (path-replace-extension "p/.rc" ".o") (build-path "p" ".rc.o"))
(check (path-replace-extension "p/a.c" ".o") (build-path "p/a.o"))
(check (path-replace-extension "p/.rc" ".o") (build-path "p/.rc.o"))
(check-arg-fail (path-replace-extension 10 "x") not-path)
(check-arg-fail (path-replace-extension "x" 10) not-string)
4 changes: 3 additions & 1 deletion racket/src/zuo/zuo-doc/lang-zuo.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,9 @@ until at least one is ready, and then it returns the first element of
@racket[handles] that is ready. If @racket[timeout-msecs] is a number,
then it specifies a number of milliseconds to wait; the result is
@racket[#f] if no handle in @racket[handles] is ready before
@racket[timeout-msecs] milliseconds pass.
@racket[timeout-msecs] milliseconds pass. Polling typically does not
work on Windows, because pipe handles claim to be ready for reading even
when no data is available.

@history[#:added "1.1"]}

Expand Down

0 comments on commit a04dffe

Please sign in to comment.