Skip to content

Commit 68220b0

Browse files
committed
Separate method for parsing args to avoid type piracy
1 parent fe9e166 commit 68220b0

File tree

11 files changed

+26
-26
lines changed

11 files changed

+26
-26
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "StaticTools"
22
uuid = "86c06d3c-3f03-46de-9781-57580aa96d0a"
33
authors = ["C. Brenhin Keller and contributors"]
4-
version = "0.7.5"
4+
version = "0.8.0"
55

66
[deps]
77
ManualMemory = "d125e4d3-2237-4719-b19c-fa641b8a4667"

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ The `MallocArray` type is one way to do that.
106106
using StaticTools
107107
function times_table(argc::Int, argv::Ptr{Ptr{UInt8}})
108108
argc == 3 || return printf(c"Incorrect number of command-line arguments\n")
109-
rows = parse(Int64, argv, 2) # First command-line argument
110-
cols = parse(Int64, argv, 3) # Second command-line argument
109+
rows = argparse(Int64, argv, 2) # First command-line argument
110+
cols = argparse(Int64, argv, 3) # Second command-line argument
111111

112112
M = MallocArray{Int64}(undef, rows, cols)
113113
@inbounds for i=1:rows
@@ -146,8 +146,8 @@ These `MallocArray`s can be `reshape`d and `reinterpret`ed without causing any
146146
```julia
147147
julia> function times_table(argc::Int, argv::Ptr{Ptr{UInt8}})
148148
argc == 3 || return printf(c"Incorrect number of command-line arguments\n")
149-
rows = parse(Int64, argv, 2) # First command-line argument
150-
cols = parse(Int64, argv, 3) # Second command-line argument
149+
rows = argparse(Int64, argv, 2) # First command-line argument
150+
cols = argparse(Int64, argv, 3) # Second command-line argument
151151

152152
M = MallocArray{Int64}(undef, rows, cols)
153153
@inbounds for i=1:rows
@@ -211,8 +211,8 @@ shell> ./stack_times_table
211211
```julia
212212
julia> function rand_matrix(argc::Int, argv::Ptr{Ptr{UInt8}})
213213
argc == 3 || return printf(stderrp(), c"Incorrect number of command-line arguments\n")
214-
rows = parse(Int64, argv, 2) # First command-line argument
215-
cols = parse(Int64, argv, 3) # Second command-line argument
214+
rows = argparse(Int64, argv, 2) # First command-line argument
215+
cols = argparse(Int64, argv, 3) # Second command-line argument
216216

217217
rng = static_rng()
218218

@@ -263,8 +263,8 @@ end
263263

264264
function loopvec_matrix(argc::Int, argv::Ptr{Ptr{UInt8}})
265265
argc == 3 || return printf(stderrp(), c"Incorrect number of command-line arguments\n")
266-
rows = parse(Int64, argv, 2) # First command-line argument
267-
cols = parse(Int64, argv, 3) # Second command-line argument
266+
rows = argparse(Int64, argv, 2) # First command-line argument
267+
cols = argparse(Int64, argv, 3) # Second command-line argument
268268

269269
# LHS
270270
A = MallocArray{Float64}(undef, rows, cols)

src/StaticTools.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ module StaticTools
5656
export newline, putchar, getchar, getc, puts, gets!, readline! # Char & String IO
5757
export fwrite, fread! # String and Binary IO
5858
export unsafe_mallocstring, strlen # String management
59-
export printf, printdlm, parsedlm # File parsing and formatting
59+
export printf, printdlm, parsedlm, argparse # File parsing and formatting
6060
export static_rng, splitmix64, xoshiro256✴︎✴︎, rand!, randn! # RNG functions
6161
end

src/llvmlibc.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,8 @@ end
586586
end
587587
@inline Base.parse(::Type{T}, s::Union{StaticString, MallocString, Ptr{UInt8}}) where {T <: Unsigned} = T(parse(UInt64, s))
588588

589-
# Convenient parsing for argv (slight type piracy)
590-
@inline Base.parse(::Type{T}, argv::Ptr{Ptr{UInt8}}, n::Integer) where {T} = parse(T, MallocString(argv, n))
589+
# Convenient parsing for argv
590+
@inline argparse(::Type{T}, argv::Ptr{Ptr{UInt8}}, n::Integer) where {T} = parse(T, MallocString(argv, n))
591591

592592
## --- dlopen
593593

test/scripts/loopvec_matrix.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ end
1515

1616
function loopvec_matrix(argc::Int, argv::Ptr{Ptr{UInt8}})
1717
argc == 3 || return printf(stderrp(), c"Incorrect number of command-line arguments\n")
18-
rows = parse(Int64, argv, 2) # First command-line argument
19-
cols = parse(Int64, argv, 3) # Second command-line argument
18+
rows = argparse(Int64, argv, 2) # First command-line argument
19+
cols = argparse(Int64, argv, 3) # Second command-line argument
2020

2121
# LHS
2222
A = MallocArray{Float64}(undef, rows, cols)

test/scripts/loopvec_product.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ using LoopVectorization
44

55
function loopvec_product(argc::Int, argv::Ptr{Ptr{UInt8}})
66
argc == 3 || return printf(stderrp(), c"Incorrect number of command-line arguments\n")
7-
rows = parse(Int64, argv, 2) # First command-line argument
8-
cols = parse(Int64, argv, 3) # Second command-line argument
7+
rows = argparse(Int64, argv, 2) # First command-line argument
8+
cols = argparse(Int64, argv, 3) # Second command-line argument
99

1010
s = 0
1111
@turbo for i=1:rows

test/scripts/rand_matrix.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ using StaticTools
33

44
function rand_matrix(argc::Int, argv::Ptr{Ptr{UInt8}})
55
argc == 3 || return printf(stderrp(), c"Incorrect number of command-line arguments\n")
6-
rows = parse(Int64, argv, 2) # First command-line argument
7-
cols = parse(Int64, argv, 3) # Second command-line argument
6+
rows = argparse(Int64, argv, 2) # First command-line argument
7+
cols = argparse(Int64, argv, 3) # Second command-line argument
88

99
# Manually fil matrix
1010
M = MallocArray{Float64}(undef, rows, cols)

test/scripts/randn_matrix.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ using StaticTools
33

44
function randn_matrix(argc::Int, argv::Ptr{Ptr{UInt8}})
55
argc == 3 || return printf(stderrp(), c"Incorrect number of command-line arguments\n")
6-
rows = parse(Int64, argv, 2) # First command-line argument
7-
cols = parse(Int64, argv, 3) # Second command-line argument
6+
rows = argparse(Int64, argv, 2) # First command-line argument
7+
cols = argparse(Int64, argv, 3) # Second command-line argument
88

99
M = MallocArray{Float64}(undef, rows, cols)
1010
rng = MarsagliaPolar(static_rng())

test/scripts/times_table.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ using StaticTools
33

44
function times_table(argc::Int, argv::Ptr{Ptr{UInt8}})
55
argc == 3 || return printf(stderrp(), c"Incorrect number of command-line arguments\n")
6-
rows = parse(Int64, argv, 2) # First command-line argument
7-
cols = parse(Int64, argv, 3) # Second command-line argument
6+
rows = argparse(Int64, argv, 2) # First command-line argument
7+
cols = argparse(Int64, argv, 3) # Second command-line argument
88

99
M = MallocArray{Int64}(undef, rows, cols)
1010
@inbounds for i=1:rows

test/scripts/withmallocarray.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ using StaticTools
33

44
function withmallocarray(argc::Int, argv::Ptr{Ptr{UInt8}})
55
argc == 3 || return printf(stderrp(), c"Incorrect number of command-line arguments\n")
6-
rows = parse(Int64, argv, 2) # First command-line argument
7-
cols = parse(Int64, argv, 3) # Second command-line argument
6+
rows = argparse(Int64, argv, 2) # First command-line argument
7+
cols = argparse(Int64, argv, 3) # Second command-line argument
88

99
mzeros(rows, cols) do A
1010
printf(A)

0 commit comments

Comments
 (0)