From f676daceb5b8ad04d88b45f1c0b2a54fab5ed296 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 30 Jul 2024 17:15:15 +0300 Subject: [PATCH] vlib: fix C warnings/errors for `v -show-c-output -cstrict -cc clang-18 run examples/gg/additive.v` --- vlib/builtin/cfns_wrapper.c.v | 2 +- vlib/builtin/string.v | 14 +++++++------- vlib/gg/gg.c.v | 2 +- vlib/gg/image.c.v | 4 ++-- vlib/sokol/sapp/sapp.c.v | 18 +++++++++--------- vlib/sokol/sapp/sapp_funcs.c.v | 6 +++--- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/vlib/builtin/cfns_wrapper.c.v b/vlib/builtin/cfns_wrapper.c.v index 35e468b00f..c56792b3ee 100644 --- a/vlib/builtin/cfns_wrapper.c.v +++ b/vlib/builtin/cfns_wrapper.c.v @@ -1,7 +1,7 @@ module builtin // vstrlen returns the V length of the C string `s` (0 terminator is not counted). -// The C string is expected to be a &byte pointer. +// The C string is expected to be a &u8 pointer. @[inline; unsafe] pub fn vstrlen(s &u8) int { return unsafe { C.strlen(&char(s)) } diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index e9db6ef27b..108ce0914a 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -82,17 +82,17 @@ pub fn (s string) runes() []rune { // -autofree and `@[manualfree]`. // It will panic, if the pointer `s` is 0. @[unsafe] -pub fn cstring_to_vstring(s &char) string { - return unsafe { tos2(&u8(s)) }.clone() +pub fn cstring_to_vstring(const_s &char) string { + return unsafe { tos2(&u8(const_s)) }.clone() } // tos_clone creates a new V string copy of the C style string, pointed by `s`. // See also cstring_to_vstring (it is the same as it, the only difference is, -// that tos_clone expects `&byte`, while cstring_to_vstring expects &char). +// that tos_clone expects `&u8`, while cstring_to_vstring expects &char). // It will panic, if the pointer `s` is 0. @[unsafe] -pub fn tos_clone(s &u8) string { - return unsafe { tos2(s) }.clone() +pub fn tos_clone(const_s &u8) string { + return unsafe { tos2(&u8(const_s)) }.clone() } // 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 { // Note: the memory block pointed by s is *reused, not copied*! // It will calculate the length first, thus it is more costly than `tos`. // It will panic, when the pointer `s` is 0. -// It is the same as `tos3`, but for &byte pointers, avoiding callsite casts. +// It is the same as `tos3`, but for &u8 pointers, avoiding callsite casts. // See also `tos_clone`. @[unsafe] pub fn tos2(s &u8) string { @@ -148,7 +148,7 @@ pub fn tos3(s &char) string { // Note: the memory block pointed by s is *reused, not copied*! // It will calculate the length first, so it is more costly than tos. // It returns '', when given a 0 pointer `s`, it does NOT panic. -// It is the same as `tos5`, but for &byte pointers, avoiding callsite casts. +// It is the same as `tos5`, but for &u8 pointers, avoiding callsite casts. // See also `tos_clone`. @[unsafe] pub fn tos4(s &u8) string { diff --git a/vlib/gg/gg.c.v b/vlib/gg/gg.c.v index 704e0dbb91..fa445f54c6 100644 --- a/vlib/gg/gg.c.v +++ b/vlib/gg/gg.c.v @@ -752,7 +752,7 @@ pub fn window_size() Size { // set_window_title sets main window's title pub fn set_window_title(title string) { - C.sapp_set_window_title(title.str) + C.sapp_set_window_title(&char(title.str)) } // window_size_real_pixels returns the `Size` of the active window without scale diff --git a/vlib/gg/image.c.v b/vlib/gg/image.c.v index d24a793f1b..2d0368baed 100644 --- a/vlib/gg/image.c.v +++ b/vlib/gg/image.c.v @@ -92,7 +92,7 @@ pub fn (mut img Image) init_sokol_image() &Image { num_mipmaps: 0 // wrap_u: .clamp_to_edge // XTODO SAMPLER // wrap_v: .clamp_to_edge - label: img.path.str + label: &char(img.path.str) d3d11_texture: 0 } @@ -156,7 +156,7 @@ pub fn (mut ctx Context) new_streaming_image(w int, h int, channels int, sicfg S num_slices: 1 num_mipmaps: 1 usage: .stream - label: img.path.str + label: &char(img.path.str) } // Sokol requires that streamed images have NO .ptr/.size initially: img_desc.data.subimage[0][0] = gfx.Range{ diff --git a/vlib/sokol/sapp/sapp.c.v b/vlib/sokol/sapp/sapp.c.v index a9b0166a89..4941c25ce1 100644 --- a/vlib/sokol/sapp/sapp.c.v +++ b/vlib/sokol/sapp/sapp.c.v @@ -211,7 +211,7 @@ pub fn frame_duration() f64 { // write string into clipboard @[inline] pub fn set_clipboard_string(str &u8) { - C.sapp_set_clipboard_string(str) + C.sapp_set_clipboard_string(&char(str)) } // read string from clipboard (usually during SAPP_EVENTTYPE_CLIPBOARD_PASTED) @@ -252,17 +252,17 @@ pub fn metal_get_device() voidptr { // Metal: get ARC-bridged pointer to current drawable pub fn metal_get_current_drawable() voidptr { - return C.sapp_metal_get_current_drawable() + return voidptr(C.sapp_metal_get_current_drawable()) } // Metal: get bridged pointer to MTKView's depth-stencil texture of type MTLTexture pub fn metal_get_depth_stencil_texture() voidptr { - return C.sapp_metal_get_depth_stencil_texture() + return voidptr(C.sapp_metal_get_depth_stencil_texture()) } // Metal: get bridged pointer to MTKView's msaa-color-texture of type MTLTexture (may be null) pub fn metal_get_msaa_color_texture() voidptr { - return C.sapp_metal_get_msaa_color_texture() + return voidptr(C.sapp_metal_get_msaa_color_texture()) } // macOS: get ARC-bridged pointer to macOS NSWindow @@ -298,7 +298,7 @@ pub fn d3d11_get_render_view() voidptr { // D3D11: get pointer ID3D11RenderTargetView object for msaa-resolve (may return null) @[inline] pub fn d3d11_get_resolve_view() voidptr { - return C.sapp_d3d11_get_resolve_view() + return voidptr(C.sapp_d3d11_get_resolve_view()) } // D3D11: get pointer to ID3D11DepthStencilView @@ -315,22 +315,22 @@ pub fn win32_get_hwnd() voidptr { // WebGPU: get WGPUDevice handle pub fn wgpu_get_device() voidptr { - return C.sapp_wgpu_get_device() + return voidptr(C.sapp_wgpu_get_device()) } // WebGPU: get swapchain's WGPUTextureView handle for rendering pub fn wgpu_get_render_view() voidptr { - return C.sapp_wgpu_get_render_view() + return voidptr(C.sapp_wgpu_get_render_view()) } // WebGPU: get swapchain's MSAA-resolve WGPUTextureView (may return null) pub fn wgpu_get_resolve_view() voidptr { - return C.sapp_wgpu_get_resolve_view() + return voidptr(C.sapp_wgpu_get_resolve_view()) } // WebGPU: get swapchain's WGPUTextureView for the depth-stencil surface pub fn wgpu_get_depth_stencil_view() voidptr { - return C.sapp_wgpu_get_depth_stencil_view() + return voidptr(C.sapp_wgpu_get_depth_stencil_view()) } // GL: get framebuffer object diff --git a/vlib/sokol/sapp/sapp_funcs.c.v b/vlib/sokol/sapp/sapp_funcs.c.v index 89c53026dd..2b6c06cb3b 100644 --- a/vlib/sokol/sapp/sapp_funcs.c.v +++ b/vlib/sokol/sapp/sapp_funcs.c.v @@ -78,10 +78,10 @@ fn C.sapp_frame_count() u64 fn C.sapp_frame_duration() f64 // write string into clipboard -fn C.sapp_set_clipboard_string(str &u8) +fn C.sapp_set_clipboard_string(const_str &char) // read string from clipboard (usually during SAPP_EVENTTYPE_CLIPBOARD_PASTED) -fn C.sapp_get_clipboard_string() &u8 +fn C.sapp_get_clipboard_string() &char // set the window title (only on desktop platforms) fn C.sapp_set_window_title(&char) @@ -93,7 +93,7 @@ fn C.sapp_set_window_title(&char) fn C.sapp_get_num_dropped_files() int // Get the file path of the dropped file -fn C.sapp_get_dropped_file_path(int) &u8 +fn C.sapp_get_dropped_file_path(int) &char // special run-function for SOKOL_NO_ENTRY (in standard mode this is an empty stub) fn C.sapp_run(desc &Desc) int