vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.69k stars 2.15k forks source link

C error: function pointer expected #22256

Open einar-hjortdal opened 1 week ago

einar-hjortdal commented 1 week ago

Describe the bug

C error: function pointer expected

Reproduction Steps

git clone git@github.com:einar-hjortdal/firebird.git \
&& cd firebird \
&& git checkout ecba31c3cb1a56e80f49599cdee14131547ded38 \
&& v run src/secure_remote_password_test.v

Expected Behavior

No C error

Current Behavior

C error

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.7 263ba23

Environment details (OS name and version, etc.)

V full version: V 0.4.7 ace4e93.263ba23 OS: linux, Linux version 5.14.0-427.33.1.el9_4.x86_64 (mockbuild@pp-el9) (gcc (GCC) 11.4.1 20231218 (Red Hat 11.4.1-3), GNU ld version 2.35.2-43.el9) #1 SMP PREEMPT_DYNAMIC Thu Aug 29 12:00:49 CEST 2024 Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz

getwd: /home/einar/Documents/projects/vlang/active/firebird vexe: /home/einar/.local/lib64/v/v vexe mtime: 2024-09-18 16:47:41

vroot: OK, value: /home/einar/.local/lib64/v VMODULES: OK, value: /home/einar/.vmodules VTMP: OK, value: /tmp/v_1001

Git version: git version 2.43.5 Git vroot status: weekly.2024.37-25-g263ba232 .git/config present: true

CC version: cc (GCC) 11.4.1 20231218 (Red Hat 11.4.1-3) thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

[!NOTE] You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote. Other reactions and those to comments will not be taken into account.

felipensp commented 1 week ago

The problem is the name clashing. See:

Array_u8 string_bytes = firebird__marshal_array_u8(string_bytes(s));

V s.bytes() turns into string_bytes(s) C code, which crashes.

felipensp commented 1 week ago

@spytheman @medvednikov what do you guys suggest for this cases?

einar-hjortdal commented 5 days ago

Is there a workaround I can use in the meantime? Development is stalled because of this error

Delta456 commented 5 days ago

Is there a workaround I can use in the meantime? Development is stalled because of this error

The error is here

fn (mut p WireProtocol) pack_string(s string) {
    string_bytes := marshal_array_u8(s.bytes())
    p.buf = arrays.append(p.buf, string_bytes)
}

Just change string_bytes to strings_bytes_ for now

Tungsten-180 commented 4 days ago

@felipensp would adding a default name mangling for user defined variables, functions, types, etc. and a different one for all internal auto generated types be a viable solution? ie. prefixing all user variables and functions with __VU_ and all internal library variables and std library functions with __VI_?

felipensp commented 4 days ago

@felipensp would adding a default name mangling for user defined variables, functions, types, etc. and a different one for all internal auto generated types be a viable solution? ie. prefixing all user variables and functions with __VU_ and all internal library variables and std library functions with __VI_?

Yeah, I already thought about this approach. What do you think @medvednikov ?

einar-hjortdal commented 3 days ago

Why not postfix userland function names with a hash?

Tungsten-180 commented 2 hours ago

Why not postfix userland function names with a hash?

is there a benefit to a hash over just an int counter like is used for anonymous... I believe structs?