Skip to content

Commit 72eb213

Browse files
authored
BREAKING: Fix memory safety bug by only supporting strided arrays of isbits (#8)
* Fix memory safety bug by only supporting strided arrays of isbits * update ci * update ci arch * ci * throw the FieldError * Bump version to 0.4
1 parent 77000d1 commit 72eb213

9 files changed

Lines changed: 141 additions & 397 deletions

File tree

.github/workflows/CI.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,30 @@ jobs:
1717
matrix:
1818
version:
1919
- '1.7'
20-
- '1.9'
2120
- '1.10'
21+
- '1.12'
22+
- 'pre'
2223
- 'nightly'
2324
os:
2425
- ubuntu-latest
2526
- windows-latest
2627
- macos-latest
2728
arch:
28-
- x64
29+
- 'default'
30+
- 'x86'
31+
exclude:
32+
- os: macos-latest
33+
version: '1.7'
34+
- os: macos-latest
35+
arch: 'x86'
2936
steps:
30-
- uses: actions/checkout@v4
31-
- uses: julia-actions/setup-julia@v1
37+
- uses: actions/checkout@v6
38+
- uses: julia-actions/setup-julia@v2
3239
with:
3340
version: ${{ matrix.version }}
3441
arch: ${{ matrix.arch }}
3542
show-versioninfo: true
36-
- uses: julia-actions/cache@v1
43+
- uses: julia-actions/cache@v2
3744
- uses: julia-actions/julia-buildpkg@v1
3845
- uses: julia-actions/julia-runtest@v1
3946
with:

Project.toml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
name = "MutatePlainDataArray"
22
uuid = "3b0f367b-da20-4531-811a-c13cc92422b5"
33
authors = ["Haoran Ni <haoranni@terpmail.umd.edu> and contributors"]
4-
version = "0.3.0"
4+
version = "0.4.0"
55

66
[compat]
77
julia = "1.7"
88

9-
[extras]
10-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
11-
12-
[targets]
13-
test = ["Test"]
9+
[workspace]
10+
projects = ["test"]

README.md

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
Enable mutating immutable plain data fields using `aref` wrapper, allowing mutating immutable plain data fields using the following syntax:
66
```julia
7-
aref(v)[i].a.b._i._j[] = val
7+
aref(v)[i].a.b[] = val
88
```
99

10-
The nested fields can be accessed using either the field name, or the field index prefixed with `_`.
11-
Except for the wrapped vector, every field in the chain must be immutable. The final type to be mutated must be bits type.
10+
The nested fields can be accessed using either the field name, or the field index with `getproperty`.
11+
The wrapped vector must implement the strided arrays interface and must have `isbitstype` element type.
1212

1313
Examples:
14-
```julia
14+
```julia-repl
1515
julia> using MutatePlainDataArray
1616
1717
julia> a = [1, 2, 3];
@@ -25,28 +25,23 @@ julia> a
2525
2
2626
3
2727
28-
julia> b = [(tup=(1, 2.5), s="a"), (tup=(2, 4.5), s="b")];
28+
julia> b = [(;tup=(1, 2.5), s=4), (;tup=(2, 4.5), s=5)];
2929
30-
julia> aref(b)[1].tup._2[] = Inf
30+
julia> aref(b)[1].tup.:2[] = Inf
3131
Inf
3232
3333
julia> b
34-
2-element Vector{NamedTuple{(:tup, :s), Tuple{Tuple{Int64, Float64}, String}}}:
35-
(tup = (1, Inf), s = "a")
36-
(tup = (2, 4.5), s = "b")
34+
2-element Vector{@NamedTuple{tup::Tuple{Int64, Float64}, s::Int64}}:
35+
(tup = (1, Inf), s = 4)
36+
(tup = (2, 4.5), s = 5)
3737
38-
julia> aref(b)[2]._1._1[] *= 100
38+
julia> (aref(b)[2].:1).:1[] *= 100
3939
200
4040
4141
julia> b
42-
2-element Vector{NamedTuple{(:tup, :s), Tuple{Tuple{Int64, Float64}, String}}}:
43-
(tup = (1, Inf), s = "a")
44-
(tup = (200, 4.5), s = "b")
45-
46-
julia> aref(b)[1].s[] = "invalid"
47-
ERROR: The field type String (field s in NamedTuple{(:tup, :s), Tuple{Tuple{Int64, Float64}, String}}) is not immutable.
48-
Stacktrace:
49-
...
42+
2-element Vector{@NamedTuple{tup::Tuple{Int64, Float64}, s::Int64}}:
43+
(tup = (1, Inf), s = 4)
44+
(tup = (200, 4.5), s = 5)
5045
```
5146

5247
The mutation provided by this package is

benchmark/Manifest.toml

Lines changed: 0 additions & 267 deletions
This file was deleted.

benchmark/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ BangBang = "198e06fe-97b7-11e9-32a5-e1d131e6ad66"
33
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
44
MutatePlainDataArray = "3b0f367b-da20-4531-811a-c13cc92422b5"
55
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
6+
7+
[sources]
8+
MutatePlainDataArray = {path = ".."}

benchmark/runbenchmarks.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ struct BAI1
1717
c::Int
1818
d::Int
1919
bab::BAB
20-
m::Matrix{Float64}
20+
m::Float64
2121
end
22-
BAI1() = BAI1(0, 0, 0, 0, BAB(), zeros(100, 100))
22+
BAI1() = BAI1(0, 0, 0, 0, BAB(), 100)
2323

2424

2525
function inbounds_setinner!_mutate(v, i)

0 commit comments

Comments
 (0)