mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen,checker: support simple voidptr casts in consts, without delaying the initialisation to _vinit (#15996)
This commit is contained in:
@@ -4,6 +4,8 @@ pub const version = 1
|
||||
|
||||
pub const dl_ext = get_shared_library_extension()
|
||||
|
||||
pub const rtld_next = voidptr(-1)
|
||||
|
||||
// get_shared_library_extension returns the platform dependent shared library extension
|
||||
// i.e. .dll on windows, .so on most unixes, .dylib on macos.
|
||||
[inline]
|
||||
|
@@ -38,5 +38,9 @@ pub fn sym(handle voidptr, symbol string) voidptr {
|
||||
// that occurred from a call to one of the `dl` functions, since the last
|
||||
// call to dlerror()
|
||||
pub fn dlerror() string {
|
||||
return unsafe { cstring_to_vstring(C.dlerror()) }
|
||||
sptr := C.dlerror()
|
||||
if sptr == unsafe { nil } {
|
||||
return ''
|
||||
}
|
||||
return unsafe { cstring_to_vstring(sptr) }
|
||||
}
|
||||
|
14
vlib/dl/rtld_next_test.v
Normal file
14
vlib/dl/rtld_next_test.v
Normal file
@@ -0,0 +1,14 @@
|
||||
import dl
|
||||
|
||||
type RealOpen = fn (charptr, int, int) int
|
||||
|
||||
fn test_rtld_next() {
|
||||
$if windows {
|
||||
println('skipping test_rtld_next on windows')
|
||||
return
|
||||
}
|
||||
real_open := RealOpen((dl.sym(dl.rtld_next, 'open')))
|
||||
println(ptr_str(real_open))
|
||||
assert real_open != unsafe { nil }
|
||||
assert dl.dlerror() == ''
|
||||
}
|
Reference in New Issue
Block a user