From a016ac39c0e3dab7b2bdc2f7b4f7dfbd9ff8a07f Mon Sep 17 00:00:00 2001 From: penguindark <57967770+penguindark@users.noreply.github.com> Date: Mon, 5 Apr 2021 17:17:45 +0200 Subject: [PATCH] examples: change byteptr to &byte in sokol examples and regex (#9606) --- examples/sokol/01_cubes/cube.v | 4 ++-- examples/sokol/02_cubes_glsl/cube_glsl.v | 8 ++++---- examples/sokol/03_march_tracing_glsl/rt_glsl.v | 8 ++++---- examples/sokol/06_obj_viewer/obj/rend.v | 6 +++--- examples/sokol/06_obj_viewer/show_obj.v | 2 +- examples/sokol/sounds/wav_player.v | 14 ++++++++------ vlib/regex/regex.v | 4 ++-- 7 files changed, 24 insertions(+), 22 deletions(-) diff --git a/examples/sokol/01_cubes/cube.v b/examples/sokol/01_cubes/cube.v index 41e3e7fd9a..66034cabce 100644 --- a/examples/sokol/01_cubes/cube.v +++ b/examples/sokol/01_cubes/cube.v @@ -39,7 +39,7 @@ mut: * Texture functions * ******************************************************************************/ -fn create_texture(w int, h int, buf byteptr) C.sg_image { +fn create_texture(w int, h int, buf &byte) C.sg_image { sz := w * h * 4 mut img_desc := C.sg_image_desc{ width: w @@ -68,7 +68,7 @@ fn destroy_texture(sg_img C.sg_image) { } // Use only if usage: .dynamic is enabled -fn update_text_texture(sg_img C.sg_image, w int, h int, buf byteptr) { +fn update_text_texture(sg_img C.sg_image, w int, h int, buf &byte) { sz := w * h * 4 mut tmp_sbc := C.sg_image_content{} tmp_sbc.subimage[0][0] = C.sg_subimage_content{ diff --git a/examples/sokol/02_cubes_glsl/cube_glsl.v b/examples/sokol/02_cubes_glsl/cube_glsl.v index 4c233b872d..b60f864ae4 100644 --- a/examples/sokol/02_cubes_glsl/cube_glsl.v +++ b/examples/sokol/02_cubes_glsl/cube_glsl.v @@ -72,7 +72,7 @@ mut: * Texture functions * ******************************************************************************/ -fn create_texture(w int, h int, buf byteptr) C.sg_image { +fn create_texture(w int, h int, buf &byte) C.sg_image { sz := w * h * 4 mut img_desc := C.sg_image_desc{ width: w @@ -101,7 +101,7 @@ fn destroy_texture(sg_img C.sg_image) { } // Use only if usage: .dynamic is enabled -fn update_text_texture(sg_img C.sg_image, w int, h int, buf byteptr) { +fn update_text_texture(sg_img C.sg_image, w int, h int, buf &byte) { sz := w * h * 4 mut tmp_sbc := C.sg_image_content{} tmp_sbc.subimage[0][0] = C.sg_subimage_content{ @@ -296,7 +296,7 @@ fn init_cube_glsl(mut app App) { mut vert_buffer_desc := C.sg_buffer_desc{} unsafe { C.memset(&vert_buffer_desc, 0, sizeof(vert_buffer_desc)) } vert_buffer_desc.size = vertices.len * int(sizeof(Vertex_t)) - vert_buffer_desc.content = byteptr(vertices.data) + vert_buffer_desc.content = &byte(vertices.data) vert_buffer_desc.@type = .vertexbuffer // vert_buffer_desc.usage = .immutable vert_buffer_desc.label = 'cube-vertices'.str @@ -315,7 +315,7 @@ fn init_cube_glsl(mut app App) { mut index_buffer_desc := C.sg_buffer_desc{} unsafe { C.memset(&index_buffer_desc, 0, sizeof(index_buffer_desc)) } index_buffer_desc.size = indices.len * int(sizeof(u16)) - index_buffer_desc.content = byteptr(indices.data) + index_buffer_desc.content = &byte(indices.data) index_buffer_desc.@type = .indexbuffer index_buffer_desc.label = 'cube-indices'.str ibuf := gfx.make_buffer(&index_buffer_desc) diff --git a/examples/sokol/03_march_tracing_glsl/rt_glsl.v b/examples/sokol/03_march_tracing_glsl/rt_glsl.v index c747c72061..9306a6c2d7 100644 --- a/examples/sokol/03_march_tracing_glsl/rt_glsl.v +++ b/examples/sokol/03_march_tracing_glsl/rt_glsl.v @@ -71,7 +71,7 @@ mut: /****************************************************************************** * Texture functions ******************************************************************************/ -fn create_texture(w int, h int, buf byteptr) C.sg_image { +fn create_texture(w int, h int, buf &byte) C.sg_image { sz := w * h * 4 mut img_desc := C.sg_image_desc{ width: w @@ -100,7 +100,7 @@ fn destroy_texture(sg_img C.sg_image) { } // Use only if usage: .dynamic is enabled -fn update_text_texture(sg_img C.sg_image, w int, h int, buf byteptr) { +fn update_text_texture(sg_img C.sg_image, w int, h int, buf &byte) { sz := w * h * 4 mut tmp_sbc := C.sg_image_content{} tmp_sbc.subimage[0][0] = C.sg_subimage_content{ @@ -175,7 +175,7 @@ fn init_cube_glsl(mut app App) { mut vert_buffer_desc := C.sg_buffer_desc{} unsafe { C.memset(&vert_buffer_desc, 0, sizeof(vert_buffer_desc)) } vert_buffer_desc.size = vertices.len * int(sizeof(Vertex_t)) - vert_buffer_desc.content = byteptr(vertices.data) + vert_buffer_desc.content = &byte(vertices.data) vert_buffer_desc.@type = .vertexbuffer vert_buffer_desc.label = 'cube-vertices'.str vbuf := gfx.make_buffer(&vert_buffer_desc) @@ -193,7 +193,7 @@ fn init_cube_glsl(mut app App) { mut index_buffer_desc := C.sg_buffer_desc{} unsafe {C.memset(&index_buffer_desc, 0, sizeof(index_buffer_desc))} index_buffer_desc.size = indices.len * int(sizeof(u16)) - index_buffer_desc.content = byteptr(indices.data) + index_buffer_desc.content = &byte(indices.data) index_buffer_desc.@type = .indexbuffer index_buffer_desc.label = "cube-indices".str ibuf := gfx.make_buffer(&index_buffer_desc) diff --git a/examples/sokol/06_obj_viewer/obj/rend.v b/examples/sokol/06_obj_viewer/obj/rend.v index 695200ba7d..87a445304c 100644 --- a/examples/sokol/06_obj_viewer/obj/rend.v +++ b/examples/sokol/06_obj_viewer/obj/rend.v @@ -17,7 +17,7 @@ import stbi /****************************************************************************** * Texture functions ******************************************************************************/ -pub fn create_texture(w int, h int, buf byteptr) C.sg_image { +pub fn create_texture(w int, h int, buf &byte) C.sg_image { sz := w * h * 4 mut img_desc := C.sg_image_desc{ width: w @@ -70,7 +70,7 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader C.sg_shader, mut vert_buffer_desc := C.sg_buffer_desc{} unsafe { C.memset(&vert_buffer_desc, 0, sizeof(vert_buffer_desc)) } vert_buffer_desc.size = obj_buf.vbuf.len * int(sizeof(Vertex_pnct)) - vert_buffer_desc.content = byteptr(obj_buf.vbuf.data) + vert_buffer_desc.content = &byte(obj_buf.vbuf.data) vert_buffer_desc.@type = .vertexbuffer vert_buffer_desc.label = 'vertbuf_part_${in_part:03}'.str vbuf := gfx.make_buffer(&vert_buffer_desc) @@ -79,7 +79,7 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader C.sg_shader, mut index_buffer_desc := C.sg_buffer_desc{} unsafe {C.memset(&index_buffer_desc, 0, sizeof(index_buffer_desc))} index_buffer_desc.size = obj_buf.ibuf.len * int(sizeof(u32)) - index_buffer_desc.content = byteptr(obj_buf.ibuf.data) + index_buffer_desc.content = &byte(obj_buf.ibuf.data) index_buffer_desc.@type = .indexbuffer index_buffer_desc.label = "indbuf_part_${in_part:03}".str ibuf := gfx.make_buffer(&index_buffer_desc) diff --git a/examples/sokol/06_obj_viewer/show_obj.v b/examples/sokol/06_obj_viewer/show_obj.v index 0f80b9d7c7..ec9a55908e 100644 --- a/examples/sokol/06_obj_viewer/show_obj.v +++ b/examples/sokol/06_obj_viewer/show_obj.v @@ -291,7 +291,7 @@ fn main() { obj_part: 0 } - app.file_name = "v.obj" // default object is the v logo + app.file_name = "v.obj_" // default object is the v logo app.single_material_flag = false $if !android { if os.args.len > 3 || (os.args.len >= 2 && os.args[1] in ['-h', '--help', '\\?', '-?']) { diff --git a/examples/sokol/sounds/wav_player.v b/examples/sokol/sounds/wav_player.v index 5ea90aec78..688dcc7e64 100644 --- a/examples/sokol/sounds/wav_player.v +++ b/examples/sokol/sounds/wav_player.v @@ -117,12 +117,13 @@ struct RIFFFormat { } fn read_wav_file_samples(fpath string) ?[]f32 { + mut res := []f32{} // eprintln('> read_wav_file_samples: $fpath -------------------------------------------------') mut bytes := os.read_bytes(fpath) ? - mut pbytes := byteptr(bytes.data) + mut pbytes := &byte(bytes.data) mut offset := u32(0) - rh := &RIFFHeader(pbytes) + rh := unsafe{ &RIFFHeader(pbytes) } // eprintln('rh: $rh') if rh.riff != [byte(`R`), `I`, `F`, `F`]! { return error('WAV should start with `RIFF`') @@ -140,7 +141,7 @@ fn read_wav_file_samples(fpath string) ?[]f32 { break } // - ch := &RIFFChunkHeader(unsafe { pbytes + offset }) + ch := unsafe{ &RIFFChunkHeader(pbytes + offset) } offset += 8 + ch.chunk_size // eprintln('ch: $ch') // eprintln('p: $pbytes | offset: $offset | bytes.len: $bytes.len') @@ -175,20 +176,20 @@ fn read_wav_file_samples(fpath string) ?[]f32 { } // eprintln('`fmt ` chunk: $rf\n`data` chunk: $ch') mut doffset := 0 - mut dp := byteptr(&ch.chunk_data) + mut dp := unsafe{ &byte(&ch.chunk_data) } for doffset < ch.chunk_size { for c := 0; c < rf.nchannels; c++ { mut x := f32(0.0) mut step := 0 ppos := unsafe { dp + doffset } if rf.bits_per_sample == 8 { - d8 := byteptr(ppos) + d8 := unsafe{ &byte(ppos) } x = (f32(*d8) - 128) / 128.0 step = 1 doffset++ } if rf.bits_per_sample == 16 { - d16 := &i16(ppos) + d16 := unsafe{ &i16(ppos) } x = f32(*d16) / 32768.0 step = 2 } @@ -206,4 +207,5 @@ fn read_wav_file_samples(fpath string) ?[]f32 { } } return res + } diff --git a/vlib/regex/regex.v b/vlib/regex/regex.v index d5aa48056a..6dcd6d6232 100644 --- a/vlib/regex/regex.v +++ b/vlib/regex/regex.v @@ -109,7 +109,7 @@ fn (re RE) get_char(in_txt string, i int) (u32,int) { // get_charb get a char from position i and return an u32 with the unicode code [inline] [direct_array_access] -fn (re RE) get_charb(in_txt byteptr, i int) (u32,int) { +fn (re RE) get_charb(in_txt &byte, i int) (u32,int) { // ascii 8 bit if (re.flag & f_bin) !=0 || unsafe {in_txt[i]} & 0x80 == 0 { return u32(unsafe {in_txt[i]}), 1 @@ -1567,7 +1567,7 @@ pub mut: } [direct_array_access] -pub fn (mut re RE) match_base(in_txt byteptr, in_txt_len int ) (int,int) { +pub fn (mut re RE) match_base(in_txt &byte, in_txt_len int ) (int,int) { // result status mut result := no_match_found // function return