[swift-users] Making a copy of an UnsafePointer
My code gets some data from an OpenCV cv::Mat object, and passes it to some Swift code that takes it via an UnsafePointer parameter. This works fine until I want to make the call asynchronous (using a DispatchQueue), I think because the underlying cv::Mat gets deallocated by the caller before the async method completes. So I want to make a copy of it to hold onto during the async operation. I tried this: let copy = UnsafeMutablePointer.allocate(capacity: inSourceBufferLength) copy.initialize(from: inSourceBuffer, count: inSourceBufferLength) self.queue.async { self.foo(data: copy, length: inSourceBufferLength) } But that doesn't seem to be working. Is UnsafeMutablePointer<> not memory managed? I'd also like to keep immutable semantics throughout, but I can forego that if it makes things really messy. -- Rick Mann rm...@latencyzero.com ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users
Re: [swift-users] Passing variadic C args through?
Here you go: https://bugs.swift.org/browse/SR-6386 > On Nov 14, 2017, at 18:01 , Jordan Rosewrote: > > Sure. I'm not sure we have a good idea for how to catch the bug—what if you > really meant to pass the array as an NSArray?—but it's worth recording > somewhere. Thanks, Rick. > > Jordan > > >> On Nov 14, 2017, at 18:00, Rick Mann wrote: >> >> I tried to find an alternative init() to use, but couldn't (despite dozens >> of releases, Xcode's code completion still fails much of the time). Thanks >> for pointing me to the right one! >> >> Should I file a bug? >> >>> On Nov 14, 2017, at 17:47 , Jordan Rose wrote: >>> >>> Heh, it would be nice to catch this. You're collecting a bunch of arguments >>> in an Array, and then passing that array straight on as a single argument >>> itself, which means it gets passed as either an NSArray or a pointer (not >>> sure which). Use 'init(format:arguments:)' instead. >>> >>> Jordan >>> >>> On Nov 14, 2017, at 17:19, Rick Mann via swift-users wrote: I've had a long-working `debugLog()` method that looks like this: ``` func debugLog(_ inMsg: T, file inFile : String = #file, line inLine : Int = #line) { let file = (inFile as NSString).lastPathComponent let s = "\(file):\(inLine)\(inMsg)" print(s) } ``` I wanted to add a version that works like `String(format:)`: ``` func debugLog(format inFormat: String, file inFile : String = #file, line inLine : Int = #line, _ inArgs: CVarArg...) { let s = String(format: inFormat, inArgs) debugLog(s, file: inFile, line: inLine) } ``` While this compiles and executes, all of the values are zero for this example: ``` let xc = CGFloat(1.0) let yc = CGFloat(0.0) let len = CGFloat(282.1364917907643) debugLog(format: "Pixel %f, %f length too far %f", xc, yc, len) ``` Output: ``` FisheyeImageRenderer.swift:108Pixel 0.00, 0.00 length too far 0.00 ``` Something is being misinterpreted in the passing of `inArgs: CVarArg...` TIA, -- Rick Mann rm...@latencyzero.com ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users >>> >> >> >> -- >> Rick Mann >> rm...@latencyzero.com >> >> > -- Rick Mann rm...@latencyzero.com ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users
Re: [swift-users] Passing variadic C args through?
Sure. I'm not sure we have a good idea for how to catch the bug—what if you really meant to pass the array as an NSArray?—but it's worth recording somewhere. Thanks, Rick. Jordan > On Nov 14, 2017, at 18:00, Rick Mannwrote: > > I tried to find an alternative init() to use, but couldn't (despite dozens of > releases, Xcode's code completion still fails much of the time). Thanks for > pointing me to the right one! > > Should I file a bug? > >> On Nov 14, 2017, at 17:47 , Jordan Rose wrote: >> >> Heh, it would be nice to catch this. You're collecting a bunch of arguments >> in an Array, and then passing that array straight on as a single argument >> itself, which means it gets passed as either an NSArray or a pointer (not >> sure which). Use 'init(format:arguments:)' instead. >> >> Jordan >> >> >>> On Nov 14, 2017, at 17:19, Rick Mann via swift-users >>> wrote: >>> >>> I've had a long-working `debugLog()` method that looks like this: >>> >>> ``` >>> func >>> debugLog(_ inMsg: T, file inFile : String = #file, line inLine : Int = >>> #line) >>> { >>> let file = (inFile as NSString).lastPathComponent >>> let s = "\(file):\(inLine)\(inMsg)" >>> print(s) >>> } >>> ``` >>> >>> I wanted to add a version that works like `String(format:)`: >>> >>> ``` >>> func >>> debugLog(format inFormat: String, file inFile : String = #file, line inLine >>> : Int = #line, _ inArgs: CVarArg...) >>> { >>> let s = String(format: inFormat, inArgs) >>> debugLog(s, file: inFile, line: inLine) >>> } >>> >>> ``` >>> >>> While this compiles and executes, all of the values are zero for this >>> example: >>> >>> ``` >>> let xc = CGFloat(1.0) >>> let yc = CGFloat(0.0) >>> let len = CGFloat(282.1364917907643) >>> >>> debugLog(format: "Pixel %f, %f length too far %f", xc, yc, len) >>> ``` >>> >>> Output: >>> >>> ``` >>> FisheyeImageRenderer.swift:108Pixel 0.00, 0.00 length too far >>> 0.00 >>> ``` >>> >>> Something is being misinterpreted in the passing of `inArgs: CVarArg...` >>> >>> TIA, >>> >>> -- >>> Rick Mann >>> rm...@latencyzero.com >>> >>> >>> >>> ___ >>> swift-users mailing list >>> swift-users@swift.org >>> https://lists.swift.org/mailman/listinfo/swift-users >> > > > -- > Rick Mann > rm...@latencyzero.com > > ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users
Re: [swift-users] Passing variadic C args through?
I tried to find an alternative init() to use, but couldn't (despite dozens of releases, Xcode's code completion still fails much of the time). Thanks for pointing me to the right one! Should I file a bug? > On Nov 14, 2017, at 17:47 , Jordan Rosewrote: > > Heh, it would be nice to catch this. You're collecting a bunch of arguments > in an Array, and then passing that array straight on as a single argument > itself, which means it gets passed as either an NSArray or a pointer (not > sure which). Use 'init(format:arguments:)' instead. > > Jordan > > >> On Nov 14, 2017, at 17:19, Rick Mann via swift-users >> wrote: >> >> I've had a long-working `debugLog()` method that looks like this: >> >> ``` >> func >> debugLog(_ inMsg: T, file inFile : String = #file, line inLine : Int = >> #line) >> { >> let file = (inFile as NSString).lastPathComponent >> let s = "\(file):\(inLine)\(inMsg)" >> print(s) >> } >> ``` >> >> I wanted to add a version that works like `String(format:)`: >> >> ``` >> func >> debugLog(format inFormat: String, file inFile : String = #file, line inLine >> : Int = #line, _ inArgs: CVarArg...) >> { >> let s = String(format: inFormat, inArgs) >> debugLog(s, file: inFile, line: inLine) >> } >> >> ``` >> >> While this compiles and executes, all of the values are zero for this >> example: >> >> ``` >> let xc = CGFloat(1.0) >> let yc = CGFloat(0.0) >> let len = CGFloat(282.1364917907643) >> >> debugLog(format: "Pixel %f, %f length too far %f", xc, yc, len) >> ``` >> >> Output: >> >> ``` >> FisheyeImageRenderer.swift:108Pixel 0.00, 0.00 length too far >> 0.00 >> ``` >> >> Something is being misinterpreted in the passing of `inArgs: CVarArg...` >> >> TIA, >> >> -- >> Rick Mann >> rm...@latencyzero.com >> >> >> >> ___ >> swift-users mailing list >> swift-users@swift.org >> https://lists.swift.org/mailman/listinfo/swift-users > -- Rick Mann rm...@latencyzero.com ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users
Re: [swift-users] Passing variadic C args through?
Heh, it would be nice to catch this. You're collecting a bunch of arguments in an Array, and then passing that array straight on as a single argument itself, which means it gets passed as either an NSArray or a pointer (not sure which). Use 'init(format:arguments:)' instead. Jordan > On Nov 14, 2017, at 17:19, Rick Mann via swift-users> wrote: > > I've had a long-working `debugLog()` method that looks like this: > > ``` > func > debugLog(_ inMsg: T, file inFile : String = #file, line inLine : Int = > #line) > { > let file = (inFile as NSString).lastPathComponent > let s = "\(file):\(inLine)\(inMsg)" > print(s) > } > ``` > > I wanted to add a version that works like `String(format:)`: > > ``` > func > debugLog(format inFormat: String, file inFile : String = #file, line inLine : > Int = #line, _ inArgs: CVarArg...) > { > let s = String(format: inFormat, inArgs) > debugLog(s, file: inFile, line: inLine) > } > > ``` > > While this compiles and executes, all of the values are zero for this example: > > ``` > let xc = CGFloat(1.0) > let yc = CGFloat(0.0) > let len = CGFloat(282.1364917907643) > > debugLog(format: "Pixel %f, %f length too far %f", xc, yc, len) > ``` > > Output: > > ``` > FisheyeImageRenderer.swift:108Pixel 0.00, 0.00 length too far > 0.00 > ``` > > Something is being misinterpreted in the passing of `inArgs: CVarArg...` > > TIA, > > -- > Rick Mann > rm...@latencyzero.com > > > > ___ > swift-users mailing list > swift-users@swift.org > https://lists.swift.org/mailman/listinfo/swift-users ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users
[swift-users] Passing variadic C args through?
I've had a long-working `debugLog()` method that looks like this: ``` func debugLog(_ inMsg: T, file inFile : String = #file, line inLine : Int = #line) { let file = (inFile as NSString).lastPathComponent let s = "\(file):\(inLine)\(inMsg)" print(s) } ``` I wanted to add a version that works like `String(format:)`: ``` func debugLog(format inFormat: String, file inFile : String = #file, line inLine : Int = #line, _ inArgs: CVarArg...) { let s = String(format: inFormat, inArgs) debugLog(s, file: inFile, line: inLine) } ``` While this compiles and executes, all of the values are zero for this example: ``` let xc = CGFloat(1.0) let yc = CGFloat(0.0) let len = CGFloat(282.1364917907643) debugLog(format: "Pixel %f, %f length too far %f", xc, yc, len) ``` Output: ``` FisheyeImageRenderer.swift:108Pixel 0.00, 0.00 length too far 0.00 ``` Something is being misinterpreted in the passing of `inArgs: CVarArg...` TIA, -- Rick Mann rm...@latencyzero.com ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users
Re: [swift-users] Compile error trying to follow Swift for Windows MSVC instructions
I’ve not used the MSVC build mode very much. I suspect that this is a name lookup failure and needs a namespace qualification. I’ll look into tweaking that when I’m near a computer. In the mean time, I recommend using the cross-compile or possibly trying with clang-cl. On Tue, Nov 14, 2017 at 1:05 PM Michael Gottesmanwrote: > +CC Compnerd > > > On Nov 9, 2017, at 10:36 AM, Eric Wing via swift-users < > swift-users@swift.org> wrote: > > > > I'm trying to build Swift for Windows with Visual Studio using the > > directions found here: > > https://github.com/apple/swift/blob/master/docs/Windows.md > > > > I'm following the MSVC section for directions. I am stuck in step 6. > > LLVM/Clang/Compiler-RT > > > > I seem to be hitting a C++ error in the code in IndexDataStore.h. Any > > ideas on how to get around this? > > > > > > > C:\PROGRA~2\MICROS~1\2017\COMMUN~1\VC\Tools\MSVC\1411~1.255\bin\Hostx64\x64\cl.exe > > /nologo /TP -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE > > -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE > > -D_CRT_SECURE_NO_WARNINGS -D_GNU_SOURCE -D_HAS_EXCEPTIONS=0 > > -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE > > -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS > > -Itools\clang\lib\Index -IC:\Source\SWIFT\llvm\tools\clang\lib\Index > > -IC:\Source\SWIFT\llvm\tools\clang\include -Itools\clang\include > > -Iinclude -IC:\Source\SWIFT\llvm\include /DWIN32 /D_WINDOWS > > /Zc:inline /Zc:strictStrings /Oi /Zc:rvalueCast /W4 -wd4141 -wd4146 > > -wd4180 -wd4244 -wd4258 -wd4267 -wd4291 -wd4345 -wd4351 -wd4355 > > -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4800 > > -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 > > -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 > > -wd4577 -wd4091 -wd4592 -wd4319 -wd4324 -w14062 -we4238 /MD /O1 /Ob1 > > -UNDEBUG /EHs-c- /GR- /showIncludes > > /Fotools\clang\lib\Index\CMakeFiles\clangIndex.dir\IndexDataStore.cpp.obj > > /Fdtools\clang\lib\Index\CMakeFiles\clangIndex.dir\clangIndex.pdb /FS > > -c C:\Source\SWIFT\llvm\tools\clang\lib\Index\IndexDataStore.cpp > > > C:\Source\SWIFT\llvm\tools\clang\include\clang/Index/IndexDataStore.h(41): > > error C3646: 'ModTime': unknown override specifier > > > C:\Source\SWIFT\llvm\tools\clang\include\clang/Index/IndexDataStore.h(41): > > error C4430: missing type specifier - int assumed. Note: C++ does not > > support default-int > > > C:\Source\SWIFT\llvm\tools\clang\include\clang/Index/IndexDataStore.h(74): > > error C3646: 'ModTime': unknown override specifier > > > C:\Source\SWIFT\llvm\tools\clang\include\clang/Index/IndexDataStore.h(74): > > error C4430: missing type specifier - int assumed. Note: C++ does not > > support default-int > > C:\Source\SWIFT\llvm\tools\clang\lib\Index\IndexDataStore.cpp(164): > > error C2039: 'ModTime': is not a member of > > 'clang::index::AbstractDirectoryWatcher::Event' > > > C:\Source\SWIFT\llvm\tools\clang\include\clang/Index/IndexDataStore.h(38): > > note: see declaration of > > 'clang::index::AbstractDirectoryWatcher::Event' > > C:\Source\SWIFT\llvm\tools\clang\lib\Index\IndexDataStore.cpp(164): > > error C2039: '__this': is not a member of > > 'clang::index::AbstractDirectoryWatcher::Event' > > > C:\Source\SWIFT\llvm\tools\clang\include\clang/Index/IndexDataStore.h(38): > > note: see declaration of > > 'clang::index::AbstractDirectoryWatcher::Event' > > [2723/3603] Building CXX object > > tools\clang\lib\Index\CMakeFiles\clangIndex.dir\IndexingContext.cpp.obj > > ninja: build stopped: subcommand failed. > > > > > > Note: I'm using VS2017 instead of VS2015 because it's supposed to have > > better C++ conformance. > > > > I also want to note, building Debug hits a different fatal error where > > MSVC aborts saying you must compile with /bigobj because the files are > > too large. I changed my build and then hit the above compile error > > with IndexDataStore.h. I then tried building a release version without > > /bigobj, but I hit the same compile error with IndexDataStore.h. > > > > > > > > > > > > Also, can somebody clarify what the differences are between the > > different build approaches in the document (clang vs. MSVC vs. > > clang-cl). Will these all produce binaries that are interoperable with > > each other and allow me to link against regular MSVC built C > > libraries? And do one of these clang options need MSVC's clang-C2? > > > > And also, what is Compiler-RT and since it is optional, what do I lose > > if I skip it? > > > > And finally, why is the Win10 SDK needed? Doesn't that mean it won't > > work on Win7 or Win8? What could Swift need that requires Win10 APIs? > > > > Thanks, > > Eric > > ___ > > swift-users mailing list > > swift-users@swift.org > > https://lists.swift.org/mailman/listinfo/swift-users > > -- Saleem Abdulrasool compnerd (at) compnerd (dot) org
Re: [swift-users] Compile error trying to follow Swift for Windows MSVC instructions
+CC Compnerd > On Nov 9, 2017, at 10:36 AM, Eric Wing via swift-users >wrote: > > I'm trying to build Swift for Windows with Visual Studio using the > directions found here: > https://github.com/apple/swift/blob/master/docs/Windows.md > > I'm following the MSVC section for directions. I am stuck in step 6. > LLVM/Clang/Compiler-RT > > I seem to be hitting a C++ error in the code in IndexDataStore.h. Any > ideas on how to get around this? > > > C:\PROGRA~2\MICROS~1\2017\COMMUN~1\VC\Tools\MSVC\1411~1.255\bin\Hostx64\x64\cl.exe > /nologo /TP -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE > -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE > -D_CRT_SECURE_NO_WARNINGS -D_GNU_SOURCE -D_HAS_EXCEPTIONS=0 > -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE > -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS > -Itools\clang\lib\Index -IC:\Source\SWIFT\llvm\tools\clang\lib\Index > -IC:\Source\SWIFT\llvm\tools\clang\include -Itools\clang\include > -Iinclude -IC:\Source\SWIFT\llvm\include /DWIN32 /D_WINDOWS > /Zc:inline /Zc:strictStrings /Oi /Zc:rvalueCast /W4 -wd4141 -wd4146 > -wd4180 -wd4244 -wd4258 -wd4267 -wd4291 -wd4345 -wd4351 -wd4355 > -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4800 > -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 > -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 > -wd4577 -wd4091 -wd4592 -wd4319 -wd4324 -w14062 -we4238 /MD /O1 /Ob1 > -UNDEBUG /EHs-c- /GR- /showIncludes > /Fotools\clang\lib\Index\CMakeFiles\clangIndex.dir\IndexDataStore.cpp.obj > /Fdtools\clang\lib\Index\CMakeFiles\clangIndex.dir\clangIndex.pdb /FS > -c C:\Source\SWIFT\llvm\tools\clang\lib\Index\IndexDataStore.cpp > C:\Source\SWIFT\llvm\tools\clang\include\clang/Index/IndexDataStore.h(41): > error C3646: 'ModTime': unknown override specifier > C:\Source\SWIFT\llvm\tools\clang\include\clang/Index/IndexDataStore.h(41): > error C4430: missing type specifier - int assumed. Note: C++ does not > support default-int > C:\Source\SWIFT\llvm\tools\clang\include\clang/Index/IndexDataStore.h(74): > error C3646: 'ModTime': unknown override specifier > C:\Source\SWIFT\llvm\tools\clang\include\clang/Index/IndexDataStore.h(74): > error C4430: missing type specifier - int assumed. Note: C++ does not > support default-int > C:\Source\SWIFT\llvm\tools\clang\lib\Index\IndexDataStore.cpp(164): > error C2039: 'ModTime': is not a member of > 'clang::index::AbstractDirectoryWatcher::Event' > C:\Source\SWIFT\llvm\tools\clang\include\clang/Index/IndexDataStore.h(38): > note: see declaration of > 'clang::index::AbstractDirectoryWatcher::Event' > C:\Source\SWIFT\llvm\tools\clang\lib\Index\IndexDataStore.cpp(164): > error C2039: '__this': is not a member of > 'clang::index::AbstractDirectoryWatcher::Event' > C:\Source\SWIFT\llvm\tools\clang\include\clang/Index/IndexDataStore.h(38): > note: see declaration of > 'clang::index::AbstractDirectoryWatcher::Event' > [2723/3603] Building CXX object > tools\clang\lib\Index\CMakeFiles\clangIndex.dir\IndexingContext.cpp.obj > ninja: build stopped: subcommand failed. > > > Note: I'm using VS2017 instead of VS2015 because it's supposed to have > better C++ conformance. > > I also want to note, building Debug hits a different fatal error where > MSVC aborts saying you must compile with /bigobj because the files are > too large. I changed my build and then hit the above compile error > with IndexDataStore.h. I then tried building a release version without > /bigobj, but I hit the same compile error with IndexDataStore.h. > > > > > > Also, can somebody clarify what the differences are between the > different build approaches in the document (clang vs. MSVC vs. > clang-cl). Will these all produce binaries that are interoperable with > each other and allow me to link against regular MSVC built C > libraries? And do one of these clang options need MSVC's clang-C2? > > And also, what is Compiler-RT and since it is optional, what do I lose > if I skip it? > > And finally, why is the Win10 SDK needed? Doesn't that mean it won't > work on Win7 or Win8? What could Swift need that requires Win10 APIs? > > Thanks, > Eric > ___ > swift-users mailing list > swift-users@swift.org > https://lists.swift.org/mailman/listinfo/swift-users ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users