Skip to content

Commit b81996b

Browse files
authored
Merge pull request #90 from dozn/main
Remove Instances of 'do', and Added `#no_nil` to `Body_Type`
2 parents 225079d + e25f971 commit b81996b

File tree

8 files changed

+31
-31
lines changed

8 files changed

+31
-31
lines changed

allocator.odin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ allocator_alloc_zerod :: proc(a: ^Allocator, size: int, alignment: int, loc := #
150150
}
151151

152152
allocator_alloc_non_zerod :: proc(a: ^Allocator, size: int, alignment: int, loc := #caller_location) -> (bytes: []byte, err: mem.Allocator_Error) {
153-
if size == 0 do return
153+
if size == 0 { return }
154154

155155
block := a.curr
156156
data := ([^]byte)(&block.data)

client/client.odin

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ request_destroy :: proc(r: ^Request) {
3939
}
4040

4141
with_json :: proc(r: ^Request, v: any, opt: json.Marshal_Options = {}) -> json.Marshal_Error {
42-
if r.method == .Get do r.method = .Post
42+
if r.method == .Get { r.method = .Post }
4343
http.headers_set_content_type(&r.headers, http.mime_to_content_type(.Json))
4444

4545
stream := bytes.buffer_to_stream(&r.body)
@@ -198,7 +198,7 @@ Body_Plain :: string
198198
// And should be deleted by you.
199199
Body_Url_Encoded :: map[string]string
200200

201-
Body_Type :: union {
201+
Body_Type :: union #no_nil {
202202
Body_Plain,
203203
Body_Url_Encoded,
204204
Body_Error, // TODO: why is this here if we also return an error?
@@ -209,7 +209,7 @@ Body_Type :: union {
209209
body_destroy :: proc(body: Body_Type, was_allocation: bool) {
210210
switch b in body {
211211
case Body_Plain:
212-
if was_allocation do delete(b)
212+
if was_allocation { delete(b) }
213213
case Body_Url_Encoded:
214214
for k, v in b {
215215
delete(k)
@@ -267,7 +267,7 @@ _parse_body :: proc(
267267
// Automatically decode url encoded bodies.
268268
if typ, ok := http.headers_get_unsafe(headers^, "content-type"); ok && typ == "application/x-www-form-urlencoded" {
269269
plain := body.(Body_Plain)
270-
defer if was_allocation do delete(plain)
270+
defer if was_allocation { delete(plain) }
271271

272272
keyvalues := strings.split(plain, "&", allocator)
273273
defer delete(keyvalues, allocator)
@@ -394,7 +394,7 @@ _response_body_chunked :: proc(
394394
body_buff: bytes.Buffer
395395

396396
bytes.buffer_init_allocator(&body_buff, 0, 0, allocator)
397-
defer if err != nil do bytes.buffer_destroy(&body_buff)
397+
defer if err != nil { bytes.buffer_destroy(&body_buff) }
398398

399399
for {
400400
if !bufio.scanner_scan(_body) {
@@ -414,7 +414,7 @@ _response_body_chunked :: proc(
414414
err = .Invalid_Chunk_Size
415415
return
416416
}
417-
if size == 0 do break
417+
if size == 0 { break }
418418

419419
if max_length > -1 && bytes.buffer_length(&body_buff) + size > max_length {
420420
return "", .Too_Long

client/communication.odin

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ format_request :: proc(target: http.URL, request: ^Request, allocator := context
8585
// Escape newlines in headers, if we don't, an attacker can find an endpoint
8686
// that returns a header with user input, and inject headers into the response.
8787
esc_value, was_allocation := strings.replace_all(value, "\n", "\\n", allocator)
88-
defer if was_allocation do delete(esc_value)
88+
defer if was_allocation { delete(esc_value) }
8989

9090
bytes.buffer_write_string(&buf, esc_value)
9191
bytes.buffer_write_string(&buf, "\r\n")
@@ -178,7 +178,7 @@ parse_response :: proc(socket: Communication, allocator := context.allocator) ->
178178

179179
line := bufio.scanner_text(&scanner)
180180
// Empty line means end of headers.
181-
if line == "" do break
181+
if line == "" { break }
182182

183183
key, hok := http.header_parse(&res.headers, line, allocator)
184184
if !hok {

nbio/_io_uring/os.odin

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ io_uring_init :: proc(ring: ^IO_Uring, entries: u32, params: ^io_uring_params) -
9696
assert((params.flags & IORING_SETUP_SQE128) == 0)
9797

9898
sq, ok := submission_queue_make(fd, params)
99-
if !ok do return .System_Resources
99+
if !ok { return .System_Resources }
100100

101101
ring.fd = fd
102102
ring.sq = sq
@@ -241,7 +241,7 @@ flush_sq :: proc(ring: ^IO_Uring) -> (n_pending: u32) {
241241
// Matches the implementation of sq_ring_needs_enter() in liburing.
242242
sq_ring_needs_enter :: proc(ring: ^IO_Uring, flags: ^u32) -> bool {
243243
assert(flags^ == 0)
244-
if ring.flags & IORING_SETUP_SQPOLL == 0 do return true
244+
if ring.flags & IORING_SETUP_SQPOLL == 0 { return true }
245245
if sync.atomic_load_explicit(ring.sq.flags, .Relaxed) & IORING_SQ_NEED_WAKEUP != 0 {
246246
flags^ |= IORING_ENTER_SQ_WAKEUP
247247
return true
@@ -267,7 +267,7 @@ cq_ready :: proc(ring: ^IO_Uring) -> (n_ready: u32) {
267267
// Provides all the wait/peek methods found in liburing, but with batching and a single method.
268268
copy_cqes :: proc(ring: ^IO_Uring, cqes: []io_uring_cqe, wait_nr: u32) -> (n_copied: u32, err: IO_Uring_Error) {
269269
n_copied = copy_cqes_ready(ring, cqes)
270-
if n_copied > 0 do return
270+
if n_copied > 0 { return }
271271
if wait_nr > 0 || cq_ring_needs_flush(ring) {
272272
_ = enter(ring, 0, wait_nr, IORING_ENTER_GETEVENTS) or_return
273273
n_copied = copy_cqes_ready(ring, cqes)
@@ -307,7 +307,7 @@ cqe_seen :: proc(ring: ^IO_Uring) {
307307
// For advanced use cases only that implement custom completion queue methods.
308308
// Matches the implementation of cq_advance() in liburing.
309309
cq_advance :: proc(ring: ^IO_Uring, count: u32) {
310-
if count == 0 do return
310+
if count == 0 { return }
311311
sync.atomic_store_explicit(ring.cq.head, ring.cq.head^ + count, .Release)
312312
}
313313

@@ -669,8 +669,8 @@ submission_queue_make :: proc(fd: os.Handle, params: ^io_uring_params) -> (sq: S
669669
int(fd),
670670
IORING_OFF_SQ_RING,
671671
)
672-
if mmap_result < 0 do return
673-
defer if !ok do unix.sys_munmap(rawptr(uintptr(mmap_result)), uint(size))
672+
if mmap_result < 0 { return }
673+
defer if !ok { unix.sys_munmap(rawptr(uintptr(mmap_result)), uint(size)) }
674674

675675
mmap := transmute([^]u8)uintptr(mmap_result)
676676

@@ -684,7 +684,7 @@ submission_queue_make :: proc(fd: os.Handle, params: ^io_uring_params) -> (sq: S
684684
int(fd),
685685
IORING_OFF_SQES,
686686
)
687-
if mmap_sqes_result < 0 do return
687+
if mmap_sqes_result < 0 { return }
688688

689689
array := cast([^]u32)&mmap[params.sq_off.array]
690690
sqes := cast([^]io_uring_sqe)uintptr(mmap_sqes_result)

nbio/nbio_internal_darwin.odin

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ flush :: proc(io: ^IO) -> os.Errno {
165165
flush_io :: proc(io: ^IO, events: []kqueue.KEvent) -> int {
166166
events := events
167167
events_loop: for &event, i in events {
168-
if len(io.io_pending) <= i do return i
168+
if len(io.io_pending) <= i { return i }
169169
completion := io.io_pending[i]
170170

171171
switch op in completion.operation {
@@ -230,13 +230,13 @@ flush_io :: proc(io: ^IO, events: []kqueue.KEvent) -> int {
230230
flush_timeouts :: proc(io: ^IO) -> (min_timeout: Maybe(i64)) {
231231
now: time.Time
232232
// PERF: is there a faster way to compare time? Or time since program start and compare that?
233-
if len(io.timeouts) > 0 do now = time.now()
233+
if len(io.timeouts) > 0 { now = time.now() }
234234

235235
for i := len(io.timeouts) - 1; i >= 0; i -= 1 {
236236
completion := io.timeouts[i]
237237

238238
timeout, ok := &completion.operation.(Op_Timeout)
239-
if !ok do panic("non-timeout operation found in the timeouts queue")
239+
if !ok { panic("non-timeout operation found in the timeouts queue") }
240240

241241
unow := time.to_unix_nanoseconds(now)
242242
expires := time.to_unix_nanoseconds(timeout.expires)

nbio/nbio_internal_linux.odin

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ Op_Poll_Remove :: struct {
112112

113113
flush :: proc(io: ^IO, wait_nr: u32, timeouts: ^uint, etime: ^bool) -> os.Errno {
114114
err := flush_submissions(io, wait_nr, timeouts, etime)
115-
if err != os.ERROR_NONE do return err
115+
if err != os.ERROR_NONE { return err }
116116

117117
err = flush_completions(io, 0, timeouts, etime)
118-
if err != os.ERROR_NONE do return err
118+
if err != os.ERROR_NONE { return err }
119119

120120
// Store length at this time, so we don't infinite loop if any of the enqueue
121121
// procs below then add to the queue again.
@@ -169,7 +169,7 @@ flush_completions :: proc(io: ^IO, wait_nr: u32, timeouts: ^uint, etime: ^bool)
169169
wait_remaining := wait_nr
170170
for {
171171
completed, err := io_uring.copy_cqes(&io.ring, cqes[:], wait_remaining)
172-
if err != .None do return ring_err_to_os_err(err)
172+
if err != .None { return ring_err_to_os_err(err) }
173173

174174
if wait_remaining < completed {
175175
wait_remaining = 0
@@ -198,7 +198,7 @@ flush_completions :: proc(io: ^IO, wait_nr: u32, timeouts: ^uint, etime: ^bool)
198198
}
199199
}
200200

201-
if completed < len(cqes) do break
201+
if completed < len(cqes) { break }
202202
}
203203

204204
return os.ERROR_NONE
@@ -214,7 +214,7 @@ flush_submissions :: proc(io: ^IO, wait_nr: u32, timeouts: ^uint, etime: ^bool)
214214
continue
215215
case .Completion_Queue_Overcommitted, .System_Resources:
216216
ferr := flush_completions(io, 1, timeouts, etime)
217-
if ferr != os.ERROR_NONE do return ferr
217+
if ferr != os.ERROR_NONE { return ferr }
218218
continue
219219
case:
220220
return ring_err_to_os_err(err)

nbio/nbio_linux.odin

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,18 @@ _tick :: proc(io: ^IO) -> os.Errno {
6464

6565
sqe, err = io_uring.timeout(&io.ring, 0, &t, 1, 0)
6666
}
67-
if err != nil do return ring_err_to_os_err(err)
67+
if err != nil { return ring_err_to_os_err(err) }
6868

6969
timeouts += 1
7070
io.ios_queued += 1
7171

7272
ferr := flush(io, 1, &timeouts, &etime)
73-
if ferr != os.ERROR_NONE do return ferr
73+
if ferr != os.ERROR_NONE { return ferr }
7474
}
7575

7676
for timeouts > 0 {
7777
fcerr := flush_completions(io, 0, &timeouts, &etime)
78-
if fcerr != os.ERROR_NONE do return fcerr
78+
if fcerr != os.ERROR_NONE { return fcerr }
7979
}
8080

8181
return os.ERROR_NONE

nbio/nbio_unix.odin

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import "core:os"
77

88
_open :: proc(_: ^IO, path: string, mode, perm: int) -> (handle: os.Handle, errno: os.Errno) {
99
handle, errno = os.open(path, mode, perm)
10-
if errno != os.ERROR_NONE do return
10+
if errno != os.ERROR_NONE { return }
1111

1212
errno = _prepare_handle(handle)
13-
if errno != os.ERROR_NONE do os.close(handle)
13+
if errno != os.ERROR_NONE { os.close(handle) }
1414
return
1515
}
1616

@@ -36,10 +36,10 @@ _open_socket :: proc(
3636
err: net.Network_Error,
3737
) {
3838
socket, err = net.create_socket(family, protocol)
39-
if err != nil do return
39+
if err != nil { return }
4040

4141
err = _prepare_socket(socket)
42-
if err != nil do net.close(socket)
42+
if err != nil { net.close(socket) }
4343
return
4444
}
4545

0 commit comments

Comments
 (0)