Skip to content

Commit f676dac

Browse files
committed
vlib: fix C warnings/errors for v -show-c-output -cstrict -cc clang-18 run examples/gg/additive.v
1 parent 4b0a35a commit f676dac

File tree

6 files changed

+23
-23
lines changed

6 files changed

+23
-23
lines changed

vlib/builtin/cfns_wrapper.c.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module builtin
22

33
// vstrlen returns the V length of the C string `s` (0 terminator is not counted).
4-
// The C string is expected to be a &byte pointer.
4+
// The C string is expected to be a &u8 pointer.
55
@[inline; unsafe]
66
pub fn vstrlen(s &u8) int {
77
return unsafe { C.strlen(&char(s)) }

vlib/builtin/string.v

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@ pub fn (s string) runes() []rune {
8282
// -autofree and `@[manualfree]`.
8383
// It will panic, if the pointer `s` is 0.
8484
@[unsafe]
85-
pub fn cstring_to_vstring(s &char) string {
86-
return unsafe { tos2(&u8(s)) }.clone()
85+
pub fn cstring_to_vstring(const_s &char) string {
86+
return unsafe { tos2(&u8(const_s)) }.clone()
8787
}
8888

8989
// tos_clone creates a new V string copy of the C style string, pointed by `s`.
9090
// See also cstring_to_vstring (it is the same as it, the only difference is,
91-
// that tos_clone expects `&byte`, while cstring_to_vstring expects &char).
91+
// that tos_clone expects `&u8`, while cstring_to_vstring expects &char).
9292
// It will panic, if the pointer `s` is 0.
9393
@[unsafe]
94-
pub fn tos_clone(s &u8) string {
95-
return unsafe { tos2(s) }.clone()
94+
pub fn tos_clone(const_s &u8) string {
95+
return unsafe { tos2(&u8(const_s)) }.clone()
9696
}
9797

9898
// tos creates a V string, given a C style pointer to a 0 terminated block.
@@ -114,7 +114,7 @@ pub fn tos(s &u8, len int) string {
114114
// Note: the memory block pointed by s is *reused, not copied*!
115115
// It will calculate the length first, thus it is more costly than `tos`.
116116
// It will panic, when the pointer `s` is 0.
117-
// It is the same as `tos3`, but for &byte pointers, avoiding callsite casts.
117+
// It is the same as `tos3`, but for &u8 pointers, avoiding callsite casts.
118118
// See also `tos_clone`.
119119
@[unsafe]
120120
pub fn tos2(s &u8) string {
@@ -148,7 +148,7 @@ pub fn tos3(s &char) string {
148148
// Note: the memory block pointed by s is *reused, not copied*!
149149
// It will calculate the length first, so it is more costly than tos.
150150
// It returns '', when given a 0 pointer `s`, it does NOT panic.
151-
// It is the same as `tos5`, but for &byte pointers, avoiding callsite casts.
151+
// It is the same as `tos5`, but for &u8 pointers, avoiding callsite casts.
152152
// See also `tos_clone`.
153153
@[unsafe]
154154
pub fn tos4(s &u8) string {

vlib/gg/gg.c.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ pub fn window_size() Size {
752752

753753
// set_window_title sets main window's title
754754
pub fn set_window_title(title string) {
755-
C.sapp_set_window_title(title.str)
755+
C.sapp_set_window_title(&char(title.str))
756756
}
757757

758758
// window_size_real_pixels returns the `Size` of the active window without scale

vlib/gg/image.c.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub fn (mut img Image) init_sokol_image() &Image {
9292
num_mipmaps: 0
9393
// wrap_u: .clamp_to_edge // XTODO SAMPLER
9494
// wrap_v: .clamp_to_edge
95-
label: img.path.str
95+
label: &char(img.path.str)
9696
d3d11_texture: 0
9797
}
9898

@@ -156,7 +156,7 @@ pub fn (mut ctx Context) new_streaming_image(w int, h int, channels int, sicfg S
156156
num_slices: 1
157157
num_mipmaps: 1
158158
usage: .stream
159-
label: img.path.str
159+
label: &char(img.path.str)
160160
}
161161
// Sokol requires that streamed images have NO .ptr/.size initially:
162162
img_desc.data.subimage[0][0] = gfx.Range{

vlib/sokol/sapp/sapp.c.v

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ pub fn frame_duration() f64 {
211211
// write string into clipboard
212212
@[inline]
213213
pub fn set_clipboard_string(str &u8) {
214-
C.sapp_set_clipboard_string(str)
214+
C.sapp_set_clipboard_string(&char(str))
215215
}
216216

217217
// read string from clipboard (usually during SAPP_EVENTTYPE_CLIPBOARD_PASTED)
@@ -252,17 +252,17 @@ pub fn metal_get_device() voidptr {
252252

253253
// Metal: get ARC-bridged pointer to current drawable
254254
pub fn metal_get_current_drawable() voidptr {
255-
return C.sapp_metal_get_current_drawable()
255+
return voidptr(C.sapp_metal_get_current_drawable())
256256
}
257257

258258
// Metal: get bridged pointer to MTKView's depth-stencil texture of type MTLTexture
259259
pub fn metal_get_depth_stencil_texture() voidptr {
260-
return C.sapp_metal_get_depth_stencil_texture()
260+
return voidptr(C.sapp_metal_get_depth_stencil_texture())
261261
}
262262

263263
// Metal: get bridged pointer to MTKView's msaa-color-texture of type MTLTexture (may be null)
264264
pub fn metal_get_msaa_color_texture() voidptr {
265-
return C.sapp_metal_get_msaa_color_texture()
265+
return voidptr(C.sapp_metal_get_msaa_color_texture())
266266
}
267267

268268
// macOS: get ARC-bridged pointer to macOS NSWindow
@@ -298,7 +298,7 @@ pub fn d3d11_get_render_view() voidptr {
298298
// D3D11: get pointer ID3D11RenderTargetView object for msaa-resolve (may return null)
299299
@[inline]
300300
pub fn d3d11_get_resolve_view() voidptr {
301-
return C.sapp_d3d11_get_resolve_view()
301+
return voidptr(C.sapp_d3d11_get_resolve_view())
302302
}
303303

304304
// D3D11: get pointer to ID3D11DepthStencilView
@@ -315,22 +315,22 @@ pub fn win32_get_hwnd() voidptr {
315315

316316
// WebGPU: get WGPUDevice handle
317317
pub fn wgpu_get_device() voidptr {
318-
return C.sapp_wgpu_get_device()
318+
return voidptr(C.sapp_wgpu_get_device())
319319
}
320320

321321
// WebGPU: get swapchain's WGPUTextureView handle for rendering
322322
pub fn wgpu_get_render_view() voidptr {
323-
return C.sapp_wgpu_get_render_view()
323+
return voidptr(C.sapp_wgpu_get_render_view())
324324
}
325325

326326
// WebGPU: get swapchain's MSAA-resolve WGPUTextureView (may return null)
327327
pub fn wgpu_get_resolve_view() voidptr {
328-
return C.sapp_wgpu_get_resolve_view()
328+
return voidptr(C.sapp_wgpu_get_resolve_view())
329329
}
330330

331331
// WebGPU: get swapchain's WGPUTextureView for the depth-stencil surface
332332
pub fn wgpu_get_depth_stencil_view() voidptr {
333-
return C.sapp_wgpu_get_depth_stencil_view()
333+
return voidptr(C.sapp_wgpu_get_depth_stencil_view())
334334
}
335335

336336
// GL: get framebuffer object

vlib/sokol/sapp/sapp_funcs.c.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ fn C.sapp_frame_count() u64
7878
fn C.sapp_frame_duration() f64
7979

8080
// write string into clipboard
81-
fn C.sapp_set_clipboard_string(str &u8)
81+
fn C.sapp_set_clipboard_string(const_str &char)
8282

8383
// read string from clipboard (usually during SAPP_EVENTTYPE_CLIPBOARD_PASTED)
84-
fn C.sapp_get_clipboard_string() &u8
84+
fn C.sapp_get_clipboard_string() &char
8585

8686
// set the window title (only on desktop platforms)
8787
fn C.sapp_set_window_title(&char)
@@ -93,7 +93,7 @@ fn C.sapp_set_window_title(&char)
9393
fn C.sapp_get_num_dropped_files() int
9494

9595
// Get the file path of the dropped file
96-
fn C.sapp_get_dropped_file_path(int) &u8
96+
fn C.sapp_get_dropped_file_path(int) &char
9797

9898
// special run-function for SOKOL_NO_ENTRY (in standard mode this is an empty stub)
9999
fn C.sapp_run(desc &Desc) int

0 commit comments

Comments
 (0)