Skip to content

Commit 23f231e

Browse files
authored
builtin: tag array methods unsafe: *_many, grow_len, pointers (#8983)
1 parent 8874379 commit 23f231e

File tree

6 files changed

+14
-10
lines changed

6 files changed

+14
-10
lines changed

cmd/tools/modules/testing/common.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ pub fn (mut ts TestSession) test() {
213213
ts.nmessage_idx = 0
214214
go ts.print_messages()
215215
pool_of_test_runners.set_shared_context(ts)
216-
pool_of_test_runners.work_on_pointers(remaining_files.pointers())
216+
pool_of_test_runners.work_on_pointers(unsafe { remaining_files.pointers() })
217217
ts.benchmark.stop()
218218
ts.append_message(.sentinel, '') // send the sentinel
219219
_ := <-ts.nprint_ended // wait for the stop of the printing thread

vlib/builtin/array.v

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ pub fn (mut a array) insert(i int, val voidptr) {
156156
}
157157

158158
// insert_many inserts many values into the array from index `i`.
159+
[unsafe]
159160
pub fn (mut a array) insert_many(i int, val voidptr, size int) {
160161
$if !no_bounds_checking ? {
161162
if i < 0 || i > a.len {
@@ -178,8 +179,9 @@ pub fn (mut a array) prepend(val voidptr) {
178179
}
179180

180181
// prepend_many prepends another array to this array.
182+
[unsafe]
181183
pub fn (mut a array) prepend_many(val voidptr, size int) {
182-
a.insert_many(0, val, size)
184+
unsafe { a.insert_many(0, val, size) }
183185
}
184186

185187
// delete deletes array element at index `i`.
@@ -420,7 +422,7 @@ fn (mut a array) push(val voidptr) {
420422

421423
// push_many implements the functionality for pushing another array.
422424
// `val` is array.data and user facing usage is `a << [1,2,3]`
423-
// TODO make private, right now it's used by strings.Builder
425+
[unsafe]
424426
pub fn (mut a3 array) push_many(val voidptr, size int) {
425427
if a3.data == val && !isnil(a3.data) {
426428
// handle `arr << arr`
@@ -632,6 +634,7 @@ pub fn (mut a array) grow_cap(amount int) {
632634
}
633635

634636
// grow_len ensures that an array has a.len + amount of length
637+
[unsafe]
635638
pub fn (mut a array) grow_len(amount int) {
636639
a.ensure_cap(a.len + amount)
637640
a.len += amount
@@ -728,6 +731,7 @@ pub fn compare_f32(a &f32, b &f32) int {
728731

729732
// pointers returns a new array, where each element
730733
// is the address of the corresponding element in the array.
734+
[unsafe]
731735
pub fn (a array) pointers() []voidptr {
732736
mut res := []voidptr{}
733737
for i in 0 .. a.len {

vlib/io/reader.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub fn read_all(config ReadAllConfig) ?[]byte {
4646
break
4747
}
4848
if b.len == read {
49-
b.grow_len(read_all_grow_len)
49+
unsafe { b.grow_len(read_all_grow_len) }
5050
}
5151
}
5252
return b[..read]
@@ -66,7 +66,7 @@ pub fn read_any(r Reader) ?[]byte {
6666
break
6767
}
6868
if b.len == read {
69-
b.grow_len(read_all_grow_len)
69+
unsafe { b.grow_len(read_all_grow_len) }
7070
}
7171
}
7272
return b[..read]

vlib/strings/builder.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn new_builder(initial_size int) Builder {
2727
// write_bytes appends `bytes` to the accumulated buffer
2828
[unsafe]
2929
pub fn (mut b Builder) write_bytes(bytes byteptr, howmany int) {
30-
b.buf.push_many(bytes, howmany)
30+
unsafe { b.buf.push_many(bytes, howmany) }
3131
b.len += howmany
3232
}
3333

@@ -50,7 +50,7 @@ pub fn (mut b Builder) write_string(s string) {
5050
if s == '' {
5151
return
5252
}
53-
b.buf.push_many(s.str, s.len)
53+
unsafe { b.buf.push_many(s.str, s.len) }
5454
// for c in s {
5555
// b.buf << c
5656
// }
@@ -99,7 +99,7 @@ pub fn (mut b Builder) writeln(s string) {
9999
// for c in s {
100100
// b.buf << c
101101
// }
102-
b.buf.push_many(s.str, s.len)
102+
unsafe { b.buf.push_many(s.str, s.len) }
103103
// b.buf << []byte(s) // TODO
104104
b.buf << `\n`
105105
b.len += s.len + 1

vlib/sync/pool/pool.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn (mut pool PoolProcessor) set_max_jobs(njobs int) {
7474
// work_on_items returns *after* all threads finish.
7575
// You can optionally call get_results after that.
7676
pub fn (mut pool PoolProcessor) work_on_items<T>(items []T) {
77-
pool.work_on_pointers( items.pointers() )
77+
pool.work_on_pointers( unsafe { items.pointers() } )
7878
}
7979

8080
pub fn (mut pool PoolProcessor) work_on_pointers(items []voidptr) {

vlib/term/ui/ui.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn (mut ctx Context) write(s string) {
2929
if s == '' {
3030
return
3131
}
32-
ctx.print_buf.push_many(s.str, s.len)
32+
unsafe { ctx.print_buf.push_many(s.str, s.len) }
3333
}
3434

3535
[inline]

0 commit comments

Comments
 (0)