Skip to content

Commit a016ac3

Browse files
authored
examples: change byteptr to &byte in sokol examples and regex (#9606)
1 parent 07b1dc6 commit a016ac3

File tree

7 files changed

+24
-22
lines changed

7 files changed

+24
-22
lines changed

examples/sokol/01_cubes/cube.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ mut:
3939
* Texture functions
4040
*
4141
******************************************************************************/
42-
fn create_texture(w int, h int, buf byteptr) C.sg_image {
42+
fn create_texture(w int, h int, buf &byte) C.sg_image {
4343
sz := w * h * 4
4444
mut img_desc := C.sg_image_desc{
4545
width: w
@@ -68,7 +68,7 @@ fn destroy_texture(sg_img C.sg_image) {
6868
}
6969

7070
// Use only if usage: .dynamic is enabled
71-
fn update_text_texture(sg_img C.sg_image, w int, h int, buf byteptr) {
71+
fn update_text_texture(sg_img C.sg_image, w int, h int, buf &byte) {
7272
sz := w * h * 4
7373
mut tmp_sbc := C.sg_image_content{}
7474
tmp_sbc.subimage[0][0] = C.sg_subimage_content{

examples/sokol/02_cubes_glsl/cube_glsl.v

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ mut:
7272
* Texture functions
7373
*
7474
******************************************************************************/
75-
fn create_texture(w int, h int, buf byteptr) C.sg_image {
75+
fn create_texture(w int, h int, buf &byte) C.sg_image {
7676
sz := w * h * 4
7777
mut img_desc := C.sg_image_desc{
7878
width: w
@@ -101,7 +101,7 @@ fn destroy_texture(sg_img C.sg_image) {
101101
}
102102

103103
// Use only if usage: .dynamic is enabled
104-
fn update_text_texture(sg_img C.sg_image, w int, h int, buf byteptr) {
104+
fn update_text_texture(sg_img C.sg_image, w int, h int, buf &byte) {
105105
sz := w * h * 4
106106
mut tmp_sbc := C.sg_image_content{}
107107
tmp_sbc.subimage[0][0] = C.sg_subimage_content{
@@ -296,7 +296,7 @@ fn init_cube_glsl(mut app App) {
296296
mut vert_buffer_desc := C.sg_buffer_desc{}
297297
unsafe { C.memset(&vert_buffer_desc, 0, sizeof(vert_buffer_desc)) }
298298
vert_buffer_desc.size = vertices.len * int(sizeof(Vertex_t))
299-
vert_buffer_desc.content = byteptr(vertices.data)
299+
vert_buffer_desc.content = &byte(vertices.data)
300300
vert_buffer_desc.@type = .vertexbuffer
301301
// vert_buffer_desc.usage = .immutable
302302
vert_buffer_desc.label = 'cube-vertices'.str
@@ -315,7 +315,7 @@ fn init_cube_glsl(mut app App) {
315315
mut index_buffer_desc := C.sg_buffer_desc{}
316316
unsafe { C.memset(&index_buffer_desc, 0, sizeof(index_buffer_desc)) }
317317
index_buffer_desc.size = indices.len * int(sizeof(u16))
318-
index_buffer_desc.content = byteptr(indices.data)
318+
index_buffer_desc.content = &byte(indices.data)
319319
index_buffer_desc.@type = .indexbuffer
320320
index_buffer_desc.label = 'cube-indices'.str
321321
ibuf := gfx.make_buffer(&index_buffer_desc)

examples/sokol/03_march_tracing_glsl/rt_glsl.v

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ mut:
7171
/******************************************************************************
7272
* Texture functions
7373
******************************************************************************/
74-
fn create_texture(w int, h int, buf byteptr) C.sg_image {
74+
fn create_texture(w int, h int, buf &byte) C.sg_image {
7575
sz := w * h * 4
7676
mut img_desc := C.sg_image_desc{
7777
width: w
@@ -100,7 +100,7 @@ fn destroy_texture(sg_img C.sg_image) {
100100
}
101101

102102
// Use only if usage: .dynamic is enabled
103-
fn update_text_texture(sg_img C.sg_image, w int, h int, buf byteptr) {
103+
fn update_text_texture(sg_img C.sg_image, w int, h int, buf &byte) {
104104
sz := w * h * 4
105105
mut tmp_sbc := C.sg_image_content{}
106106
tmp_sbc.subimage[0][0] = C.sg_subimage_content{
@@ -175,7 +175,7 @@ fn init_cube_glsl(mut app App) {
175175
mut vert_buffer_desc := C.sg_buffer_desc{}
176176
unsafe { C.memset(&vert_buffer_desc, 0, sizeof(vert_buffer_desc)) }
177177
vert_buffer_desc.size = vertices.len * int(sizeof(Vertex_t))
178-
vert_buffer_desc.content = byteptr(vertices.data)
178+
vert_buffer_desc.content = &byte(vertices.data)
179179
vert_buffer_desc.@type = .vertexbuffer
180180
vert_buffer_desc.label = 'cube-vertices'.str
181181
vbuf := gfx.make_buffer(&vert_buffer_desc)
@@ -193,7 +193,7 @@ fn init_cube_glsl(mut app App) {
193193
mut index_buffer_desc := C.sg_buffer_desc{}
194194
unsafe {C.memset(&index_buffer_desc, 0, sizeof(index_buffer_desc))}
195195
index_buffer_desc.size = indices.len * int(sizeof(u16))
196-
index_buffer_desc.content = byteptr(indices.data)
196+
index_buffer_desc.content = &byte(indices.data)
197197
index_buffer_desc.@type = .indexbuffer
198198
index_buffer_desc.label = "cube-indices".str
199199
ibuf := gfx.make_buffer(&index_buffer_desc)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import stbi
1717
/******************************************************************************
1818
* Texture functions
1919
******************************************************************************/
20-
pub fn create_texture(w int, h int, buf byteptr) C.sg_image {
20+
pub fn create_texture(w int, h int, buf &byte) C.sg_image {
2121
sz := w * h * 4
2222
mut img_desc := C.sg_image_desc{
2323
width: w
@@ -70,7 +70,7 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader C.sg_shader,
7070
mut vert_buffer_desc := C.sg_buffer_desc{}
7171
unsafe { C.memset(&vert_buffer_desc, 0, sizeof(vert_buffer_desc)) }
7272
vert_buffer_desc.size = obj_buf.vbuf.len * int(sizeof(Vertex_pnct))
73-
vert_buffer_desc.content = byteptr(obj_buf.vbuf.data)
73+
vert_buffer_desc.content = &byte(obj_buf.vbuf.data)
7474
vert_buffer_desc.@type = .vertexbuffer
7575
vert_buffer_desc.label = 'vertbuf_part_${in_part:03}'.str
7676
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,
7979
mut index_buffer_desc := C.sg_buffer_desc{}
8080
unsafe {C.memset(&index_buffer_desc, 0, sizeof(index_buffer_desc))}
8181
index_buffer_desc.size = obj_buf.ibuf.len * int(sizeof(u32))
82-
index_buffer_desc.content = byteptr(obj_buf.ibuf.data)
82+
index_buffer_desc.content = &byte(obj_buf.ibuf.data)
8383
index_buffer_desc.@type = .indexbuffer
8484
index_buffer_desc.label = "indbuf_part_${in_part:03}".str
8585
ibuf := gfx.make_buffer(&index_buffer_desc)

examples/sokol/06_obj_viewer/show_obj.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ fn main() {
291291
obj_part: 0
292292
}
293293

294-
app.file_name = "v.obj" // default object is the v logo
294+
app.file_name = "v.obj_" // default object is the v logo
295295
app.single_material_flag = false
296296
$if !android {
297297
if os.args.len > 3 || (os.args.len >= 2 && os.args[1] in ['-h', '--help', '\\?', '-?']) {

examples/sokol/sounds/wav_player.v

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,13 @@ struct RIFFFormat {
117117
}
118118

119119
fn read_wav_file_samples(fpath string) ?[]f32 {
120+
120121
mut res := []f32{}
121122
// eprintln('> read_wav_file_samples: $fpath -------------------------------------------------')
122123
mut bytes := os.read_bytes(fpath) ?
123-
mut pbytes := byteptr(bytes.data)
124+
mut pbytes := &byte(bytes.data)
124125
mut offset := u32(0)
125-
rh := &RIFFHeader(pbytes)
126+
rh := unsafe{ &RIFFHeader(pbytes) }
126127
// eprintln('rh: $rh')
127128
if rh.riff != [byte(`R`), `I`, `F`, `F`]! {
128129
return error('WAV should start with `RIFF`')
@@ -140,7 +141,7 @@ fn read_wav_file_samples(fpath string) ?[]f32 {
140141
break
141142
}
142143
//
143-
ch := &RIFFChunkHeader(unsafe { pbytes + offset })
144+
ch := unsafe{ &RIFFChunkHeader(pbytes + offset) }
144145
offset += 8 + ch.chunk_size
145146
// eprintln('ch: $ch')
146147
// eprintln('p: $pbytes | offset: $offset | bytes.len: $bytes.len')
@@ -175,20 +176,20 @@ fn read_wav_file_samples(fpath string) ?[]f32 {
175176
}
176177
// eprintln('`fmt ` chunk: $rf\n`data` chunk: $ch')
177178
mut doffset := 0
178-
mut dp := byteptr(&ch.chunk_data)
179+
mut dp := unsafe{ &byte(&ch.chunk_data) }
179180
for doffset < ch.chunk_size {
180181
for c := 0; c < rf.nchannels; c++ {
181182
mut x := f32(0.0)
182183
mut step := 0
183184
ppos := unsafe { dp + doffset }
184185
if rf.bits_per_sample == 8 {
185-
d8 := byteptr(ppos)
186+
d8 := unsafe{ &byte(ppos) }
186187
x = (f32(*d8) - 128) / 128.0
187188
step = 1
188189
doffset++
189190
}
190191
if rf.bits_per_sample == 16 {
191-
d16 := &i16(ppos)
192+
d16 := unsafe{ &i16(ppos) }
192193
x = f32(*d16) / 32768.0
193194
step = 2
194195
}
@@ -206,4 +207,5 @@ fn read_wav_file_samples(fpath string) ?[]f32 {
206207
}
207208
}
208209
return res
210+
209211
}

vlib/regex/regex.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fn (re RE) get_char(in_txt string, i int) (u32,int) {
109109
// get_charb get a char from position i and return an u32 with the unicode code
110110
[inline]
111111
[direct_array_access]
112-
fn (re RE) get_charb(in_txt byteptr, i int) (u32,int) {
112+
fn (re RE) get_charb(in_txt &byte, i int) (u32,int) {
113113
// ascii 8 bit
114114
if (re.flag & f_bin) !=0 || unsafe {in_txt[i]} & 0x80 == 0 {
115115
return u32(unsafe {in_txt[i]}), 1
@@ -1567,7 +1567,7 @@ pub mut:
15671567
}
15681568

15691569
[direct_array_access]
1570-
pub fn (mut re RE) match_base(in_txt byteptr, in_txt_len int ) (int,int) {
1570+
pub fn (mut re RE) match_base(in_txt &byte, in_txt_len int ) (int,int) {
15711571
// result status
15721572
mut result := no_match_found // function return
15731573

0 commit comments

Comments
 (0)