From 4d24cb015859df38dd1e5500b14700cfdc5dd620 Mon Sep 17 00:00:00 2001 From: Taegon Kim Date: Tue, 9 Mar 2021 00:18:26 +0900 Subject: [PATCH] darwin: fix the C. function declarations (#9194) --- vlib/darwin/darwin.v | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/vlib/darwin/darwin.v b/vlib/darwin/darwin.v index e5b5f97814..ef39b98f00 100644 --- a/vlib/darwin/darwin.v +++ b/vlib/darwin/darwin.v @@ -6,46 +6,46 @@ module darwin #flag -framework Cocoa #flag -framework Carbon -struct C.NSString { } +struct C.NSString {} #include "@VROOT/vlib/darwin/darwin.m" fn C.nsstring2(s string) voidptr // macOS and iOS helpers -//pub fn nsstring(s string) *C.NSString { +// pub fn nsstring(s string) *C.NSString { pub fn nsstring(s string) voidptr { return C.nsstring2(s) // println('ns $s len=$s.len') //# return [ [ NSString alloc ] initWithBytesNoCopy:s.str length:s.len //# encoding:NSUTF8StringEncoding freeWhenDone: false]; - //return 0 + // return 0 - //ns := C.alloc_NSString() - //return ns.initWithBytesNoCopy(s.str, length: s.len, - //encoding: NSUTF8StringEncoding, freeWhenDone: false) + // ns := C.alloc_NSString() + // return ns.initWithBytesNoCopy(s.str, length: s.len, + // encoding: NSUTF8StringEncoding, freeWhenDone: false) } // returns absolute path to folder where your resources should / will reside // for .app packages: .../my.app/Contents/Resources // for cli: .../parent_folder/Resources -fn C.CFBundleCopyResourcesDirectoryURL() byteptr +fn C.CFBundleCopyResourcesDirectoryURL(bundle voidptr) byteptr fn C.CFBundleGetMainBundle() voidptr -fn C.CFURLGetFileSystemRepresentation() int -fn C.CFRelease() +fn C.CFURLGetFileSystemRepresentation(url byteptr, resolve_against_base bool, buffer byteptr, buffer_size int) int +fn C.CFRelease(url byteptr) pub fn resource_path() string { - main_bundle := C.CFBundleGetMainBundle() resource_dir_url := C.CFBundleCopyResourcesDirectoryURL(main_bundle) if isnil(resource_dir_url) { panic('CFBundleCopyResourcesDirectoryURL failed') } buffer_size := 4096 - mut buffer := malloc(buffer_size) - buffer[0] = 0 - conv_result := C.CFURLGetFileSystemRepresentation(resource_dir_url, true, buffer, buffer_size) + mut buffer := unsafe{ malloc(buffer_size) } + unsafe{ buffer[0] = 0 } + conv_result := C.CFURLGetFileSystemRepresentation(resource_dir_url, true, buffer, + buffer_size) if conv_result == 0 { panic('CFURLGetFileSystemRepresentation failed') }