Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C error from a name shadow that uses the same name as a C function in unsafe #17831

Open
csfore opened this issue Mar 30, 2023 · 0 comments
Open
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@csfore
Copy link
Contributor

csfore commented Mar 30, 2023

Describe the bug

Using a name that shadows a C function results in an error function pointer expected. Using C.stat(path, struct), with struct being called stat results in a function pointer expected error.

Expected Behavior

In my case of using C.stat(), a structure with the fields copied over.

Current Behavior

A function pointer expected error, likely due from variable name shadowing and V thinking it's a C function.

Reproduction Steps

module main
import os

fn stat_to_struct(path_s string) {
	mut stat := C.stat{}
	path := &char(path_s.str)
	unsafe {
		C.stat(path, &stat)
	}
}

Playground Link: https://play.vlang.io/?query=ad21bd2cc9

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.3.3 8c35ee0.cd6cc65

Environment details (OS name and version, etc.)

V full version: V 0.3.3 8c35ee0.cd6cc65
OS: linux, "Gentoo Linux"
Processor: 16 cpus, 64bit, little endian, AMD Ryzen 9 5900HX with Radeon Graphics

vexe: /home/csfore/v/v
vexe mtime: 2023-03-30 20:32:54

vroot: OK, value: /home/csfore/v
VMODULES: OK, value: /home/csfore/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.39.2
Git vroot status: weekly.2023.13-23-gcd6cc65e
.git/config present: true

CC version: cc (Gentoo 12.2.1_p20230121-r1 p10) 12.2.1 20230121
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

@csfore csfore added the Bug This tag is applied to issues which reports bugs. label Mar 30, 2023
@spytheman spytheman added Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Status: Confirmed This bug has been confirmed to be valid by a contributor. labels Apr 11, 2023
@spytheman spytheman self-assigned this Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects
None yet
Development

No branches or pull requests

2 participants