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

call V from C not working when closure. #19446

Closed
herudi opened this issue Sep 26, 2023 · 0 comments · Fixed by #20630
Closed

call V from C not working when closure. #19446

herudi opened this issue Sep 26, 2023 · 0 comments · Fixed by #20630
Labels
Bug This tag is applied to issues which reports bugs. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@herudi
Copy link

herudi commented Sep 26, 2023

Describe the bug

i tried calling v from c via shared lib. but it doesn't work on closure of v. signal 11: segmentation fault. but if not closure is not a problem.

Reproduction Steps

V code

// foo.v
[export: 'foo']
fn show_foo(s &char) {
	my_fn := fn [s]() {
		println(unsafe { cstring_to_vstring(s) })
	}
	my_fn()
}

command: v -cc gcc -shared foo.v

C code

extern void foo(const char* s);

int main() {
	foo("bar");
}

compile: gcc foo.c foo.so -o foo -Wl,-rpath=.

next i call ./foo in terminal.

Expected Behavior

Expected output is bar in terminal.

Current Behavior

signal 11: segmentation fault
| 0x7fdf57847090 | /lib/x86_64-linux-gnu/libc.so.6(+0x43090) 

Possible Solution

No response

Additional Information/Context

No response

V version

Current V version: V 0.4.1 a8a3d3a, timestamp: 2023-09-26 07:02:39 +0300

Environment details (OS name and version, etc.)

V full version: V 0.4.1 20bce37.a8a3d3a
OS: linux, Pop!_OS 20.04 LTS
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-4030U CPU @ 1.90GHz

getwd: /home/herudi/deno/ffi-deno
vexe: /home/herudi/vlang/v
vexe mtime: 2023-09-26 04:11:20

vroot: OK, value: /home/herudi/vlang
VMODULES: OK, value: /home/herudi/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.25.1
Git vroot status: weekly.2023.28-458-ga8a3d3a6
.git/config present: true

CC version: cc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

Important

You can vote for this issue using the 👍 reaction. More votes increase the issue's priority
for developers.

Take into account that only the 👍 reaction counts as a vote.
Only reactions to the issue itself will be counted as votes, not comments.

@herudi herudi added the Bug This tag is applied to issues which reports bugs. label Sep 26, 2023
@ArtemkaKun ArtemkaKun added the Unit: cgen Bugs/feature requests, that are related to the default C generating backend. label Sep 26, 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. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants