Skip to content

Commit 7d57a19

Browse files
committed
checker: do not allow &u8(0), force nil like we do with &Type(0)
1 parent 3ab660b commit 7d57a19

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+184
-118
lines changed

doc/docs.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,11 +1599,11 @@ println('Your OS is ${current_os}.')
15991599
> This section is valid when .v files are not in the project's root directory.
16001600
16011601
Modules names in .v files, must match the name of their directory.
1602-
1603-
A .v file `./abc/source.v` must start with `module abc`. All .v files in this directory
1602+
1603+
A .v file `./abc/source.v` must start with `module abc`. All .v files in this directory
16041604
belong to the same module `abc`. They should also start with `module abc`.
16051605

1606-
If you have `abc/def/`, and .v files in both folders, you can `import abc`, but you will have
1606+
If you have `abc/def/`, and .v files in both folders, you can `import abc`, but you will have
16071607
to `import abc.def` too, to get to the symbols in the subfolder. It is independent.
16081608

16091609
In `module name` statement, name never repeats directory's hierarchy, but only its directory.
@@ -1637,7 +1637,7 @@ fn main() {
16371637

16381638
A function, located in `abc/def/source.v`, is called with `def.func()`, not `abc.def.func()`
16391639

1640-
This always implies a *single prefix*, whatever sub-module depth. This behavior flattens
1640+
This always implies a *single prefix*, whatever sub-module depth. This behavior flattens
16411641
modules/sub-modules hierarchy. Should you have two modules with the same name in different
16421642
directories, then you should use Module import aliasing (see below).
16431643

@@ -1963,7 +1963,7 @@ println(typ)
19631963
```
19641964

19651965
A match statement also can match the variant types of a `sumtype`. Note that
1966-
in that case, the match is exhaustive, since all variant types are mentioned
1966+
in that case, the match is exhaustive, since all variant types are mentioned
19671967
explicitly, so there is no need for an `else{}` branch.
19681968

19691969
```v nofmt
@@ -4730,12 +4730,12 @@ fn main() {
47304730

47314731
### Difference Between Channels and Shared Objects
47324732

4733-
**Purpose**:
4733+
**Purpose**:
47344734
- Channels: Used for message passing between threads, ensuring safe communication.
47354735
- Shared objects: Used for direct data sharing and modification between threads.
47364736

4737-
**Synchronization**:
4738-
- Channels: Implicit (via channel operations)
4737+
**Synchronization**:
4738+
- Channels: Implicit (via channel operations)
47394739
- Shared objects: Explicit (via `rlock`/`lock` blocks)
47404740

47414741
## JSON
@@ -5836,20 +5836,20 @@ pub mut:
58365836
58375837
Function/method deprecations:
58385838
5839-
Functions are deprecated before they are finally removed to give users time to migrate their code.
5840-
Adding a date is preferable in most cases. An immediate change, without a deprecation date, may be
5841-
used for functions that are found to be conceptually broken and obsoleted by much better
5842-
functionality. Other than that setting a date is advisable to grant users a grace period.
5839+
Functions are deprecated before they are finally removed to give users time to migrate their code.
5840+
Adding a date is preferable in most cases. An immediate change, without a deprecation date, may be
5841+
used for functions that are found to be conceptually broken and obsoleted by much better
5842+
functionality. Other than that setting a date is advisable to grant users a grace period.
58435843
5844-
Deprecated functions cause warnings, which cause errors if built with `-prod`. To avoid immediate
5845-
CI breakage, it is advisable to set a future date, ahead of the date when the code is merged. This
5846-
gives people who actively developed V projects, the chance to see the deprecation notice at least
5847-
once and fix the uses. Setting a date in the next 30 days, assumes they would have compiled their
5844+
Deprecated functions cause warnings, which cause errors if built with `-prod`. To avoid immediate
5845+
CI breakage, it is advisable to set a future date, ahead of the date when the code is merged. This
5846+
gives people who actively developed V projects, the chance to see the deprecation notice at least
5847+
once and fix the uses. Setting a date in the next 30 days, assumes they would have compiled their
58485848
projects manually at least once, within that time. For small changes, this should be plenty
5849-
of time. For complex changes, this time may need to be longer.
5849+
of time. For complex changes, this time may need to be longer.
58505850
5851-
Different V projects and maintainers may reasonably choose different deprecation policies.
5852-
Depending on the type and impact of the change, you may want to consult with them first, before
5851+
Different V projects and maintainers may reasonably choose different deprecation policies.
5852+
Depending on the type and impact of the change, you may want to consult with them first, before
58535853
deprecating a function.
58545854
58555855
@@ -7710,7 +7710,7 @@ fn main() {
77107710
C.sqlite3_finalize(stmt)
77117711
println('There are ${nr_users} users in the database.')
77127712
7713-
error_msg := &char(0)
7713+
error_msg := &char(unsafe { nil })
77147714
query_all_users := 'select * from users'
77157715
rc := C.sqlite3_exec(db, &char(query_all_users.str), my_callback, voidptr(7), &error_msg)
77167716
if rc != C.SQLITE_OK {
@@ -8193,7 +8193,7 @@ exists the file will be overridden. If you want to rebuild each time and not kee
81938193
instead use `#!/usr/bin/env -S v -raw-vsh-tmp-prefix tmp run`.
81948194
81958195
Note: there is a small shell script `cmd/tools/vrun`, that can be useful for systems, that have an
8196-
env program (`/usr/bin/env`), that still does not support an `-S` option (like BusyBox).
8196+
env program (`/usr/bin/env`), that still does not support an `-S` option (like BusyBox).
81978197
See https://github.com/vlang/v/blob/master/cmd/tools/vrun for more details.
81988198
81998199
# Appendices

examples/c_interop_wkhtmltopdf.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn main() {
7272
error_code := C.wkhtmltopdf_http_error_code(converter)
7373
println('wkhtmltopdf_http_error_code: ${error_code}')
7474
if result {
75-
pdata := &char(0)
75+
pdata := &char(unsafe { nil })
7676
ppdata := &pdata
7777
size := C.wkhtmltopdf_get_output(converter, voidptr(ppdata))
7878
println('wkhtmltopdf_get_output: ${size} bytes')

examples/sokol/01_cubes/cube.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
3737
height: h
3838
num_mipmaps: 0
3939
// usage: .dynamic
40-
label: &char(0)
40+
label: &char(unsafe { nil })
4141
d3d11_texture: 0
4242
}
4343
// comment, if .dynamic is enabled

examples/sokol/02_cubes_glsl/cube_glsl.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
6161
height: h
6262
num_mipmaps: 0
6363
// usage: .dynamic
64-
label: &char(0)
64+
label: &char(unsafe { nil })
6565
d3d11_texture: 0
6666
}
6767
// comment if .dynamic is enabled

examples/sokol/03_march_tracing_glsl/rt_glsl.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
6464
// usage: .dynamic
6565
// wrap_u: .clamp_to_edge
6666
// wrap_v: .clamp_to_edge
67-
label: &char(0)
67+
label: &char(unsafe { nil })
6868
d3d11_texture: 0
6969
}
7070
// comment if .dynamic is enabled

examples/sokol/05_instancing_glsl/rt_glsl.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn create_texture(w int, h int, buf byteptr) (gfx.Image, gfx.Sampler) {
7575
//usage: .dynamic
7676
// wrap_u: .clamp_to_edge
7777
// wrap_v: .clamp_to_edge
78-
label: &char(0)
78+
label: &char(unsafe { nil })
7979
d3d11_texture: 0
8080
}
8181
// vfmt on

examples/sokol/06_obj_viewer/modules/obj/rend.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
2929
// usage: .dynamic
3030
// wrap_u: .clamp_to_edge
3131
// wrap_v: .clamp_to_edge
32-
label: &char(0)
32+
label: &char(unsafe { nil })
3333
d3d11_texture: 0
3434
}
3535
// comment if .dynamic is enabled

examples/viewer/view.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
119119
height: h
120120
num_mipmaps: 0
121121
// usage: .dynamic
122-
label: &u8(0)
122+
label: &u8(unsafe { nil })
123123
d3d11_texture: 0
124124
}
125125
// comment if .dynamic is enabled

vlib/builtin/backtraces_windows.c.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn print_backtrace_skipping_top_frames_msvc(skipframes int) bool {
8787
si.f_max_name_len = sizeof(SymbolInfoContainer) - sizeof(SymbolInfo) - 1
8888
fname := &char(&si.f_name)
8989
mut sline64 := Line64{
90-
f_file_name: &u8(0)
90+
f_file_name: &u8(unsafe { nil })
9191
}
9292
sline64.f_size_of_struct = sizeof(Line64)
9393

vlib/builtin/builtin.c.v

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,9 @@ pub fn malloc(n isize) &u8 {
438438
if n < 0 {
439439
_memory_panic(@FN, n)
440440
} else if n == 0 {
441-
return &u8(0)
441+
return &u8(unsafe { nil })
442442
}
443-
mut res := &u8(0)
443+
mut res := &u8(unsafe { nil })
444444
$if prealloc {
445445
return unsafe { prealloc_malloc(n) }
446446
} $else $if gcboehm ? {
@@ -476,7 +476,7 @@ pub fn malloc_noscan(n isize) &u8 {
476476
if n < 0 {
477477
_memory_panic(@FN, n)
478478
}
479-
mut res := &u8(0)
479+
mut res := &u8(unsafe { nil })
480480
$if prealloc {
481481
return unsafe { prealloc_malloc(n) }
482482
} $else $if gcboehm ? {
@@ -529,7 +529,7 @@ pub fn malloc_uncollectable(n isize) &u8 {
529529
_memory_panic(@FN, n)
530530
}
531531

532-
mut res := &u8(0)
532+
mut res := &u8(unsafe { nil })
533533
$if prealloc {
534534
return unsafe { prealloc_malloc(n) }
535535
} $else $if gcboehm ? {
@@ -561,7 +561,7 @@ pub fn v_realloc(b &u8, n isize) &u8 {
561561
$if trace_realloc ? {
562562
C.fprintf(C.stderr, c'v_realloc %6d\n', n)
563563
}
564-
mut new_ptr := &u8(0)
564+
mut new_ptr := &u8(unsafe { nil })
565565
$if prealloc {
566566
unsafe {
567567
new_ptr = malloc(n)
@@ -613,7 +613,7 @@ pub fn realloc_data(old_data &u8, old_size int, new_size int) &u8 {
613613
return new_ptr
614614
}
615615
}
616-
mut nptr := &u8(0)
616+
mut nptr := &u8(unsafe { nil })
617617
$if gcboehm ? {
618618
nptr = unsafe { C.GC_REALLOC(old_data, new_size) }
619619
} $else {
@@ -636,7 +636,7 @@ pub fn vcalloc(n isize) &u8 {
636636
if n < 0 {
637637
_memory_panic(@FN, n)
638638
} else if n == 0 {
639-
return &u8(0)
639+
return &u8(unsafe { nil })
640640
}
641641
$if prealloc {
642642
return unsafe { prealloc_calloc(n) }
@@ -645,7 +645,7 @@ pub fn vcalloc(n isize) &u8 {
645645
} $else {
646646
return unsafe { C.calloc(1, n) }
647647
}
648-
return &u8(0) // not reached, TODO: remove when V's checker is improved
648+
return &u8(unsafe { nil }) // not reached, TODO: remove when V's checker is improved
649649
}
650650

651651
// special versions of the above that allocate memory which is not scanned
@@ -673,7 +673,7 @@ pub fn vcalloc_noscan(n isize) &u8 {
673673
} $else {
674674
return unsafe { vcalloc(n) }
675675
}
676-
return &u8(0) // not reached, TODO: remove when V's checker is improved
676+
return &u8(unsafe { nil }) // not reached, TODO: remove when V's checker is improved
677677
}
678678

679679
// free allows for manually freeing memory allocated at the address `ptr`.

0 commit comments

Comments
 (0)