[swift-users] Mapping C semantics to Swift

2016-05-19 Thread Ken Burgett via swift-users
I would like to know if a struct in Swift has any guarantee of contiguity, like a struct in C. I am attempting to port a C program that makes many assumptions about the underlying semantics of C structs, and does things like overlaying an array over the struct using a cast, and then performs a

Re: [swift-users] Mapping C semantics to Swift

2016-05-20 Thread Ken Burgett via swift-users
I have been told that the in-memory layout of a Swift struct is 'undefined', so the C style of aliasing an array over a struct and iterating across the struct is a definite no-no. Not surprising, since aliasing violates all type-safe rules. So, if you have this situation, you must address it

Re: [swift-users] Mapping C semantics to Swift

2016-05-20 Thread Ken Burgett via swift-users
On 2016-05-20 08:55, Jens Alfke wrote: On May 20, 2016, at 7:33 AM, Ken Burgett via swift-users wrote: the required C struct morphs into a Swift class, with a member function 'as_C_byte_array' which answers an array of the required form. Internally, this function will shift and

[swift-users] Need documentation on how to import C header into Swift 3.0

2016-05-21 Thread Ken Burgett via swift-users
Hi Joe, Can you point me to a good example of how to build a Swift 3.0 module that wraps some C code? I have searched, but keep finding Swift 2.2 documentation and it all seems to involve connecting to Objective-C, while my interests are accessing C code on a Linux platform, using the latest

[swift-users] Proper syntax for 2D table with initial values

2016-05-23 Thread Ken Burgett via swift-users
I have a large 2D table defined within a C .h file, as follows: static const uint8_t blake2b_kat[256][64] = { { 0x78, 0x6A, 0x02, 0xF7, 0x42, 0x01, 0x59, 0x03, 0xC6, 0xC6, 0xFD, 0x85, 0x25, 0x52, 0xD2, 0x72, 0x91, 0x2F, 0x47, 0x40, 0xE1, 0x58, 0x47, 0x61, 0x8A, 0x86, 0xE2, 0x17,

[swift-users] error: NoSources("/home/kenb/.../Cpp_Swift/Sources/cwrapper")

2016-05-24 Thread Ken Burgett via swift-users
I tried build a system module, following the cpp and swift variant mentioned here (http://ankit.im/swift/2016/05/21/creating-objc-cpp-packages-with-swift-package-manager/). I hope the author will answer in detail, but I would like to know what produces the 'error: NoSources(..)' error message?

[swift-users] Printing large hexadecimal values

2016-05-25 Thread Ken Burgett via swift-users
I really shouldn't have to ask this question for a variety of other languages, but print format conversion in Swift a black box to me. I wish to print a 64-bit unsigned integer as 8 hexadecimal digits, and I can't find any documentation on this. Please advise. -- Ken Burgett Principal Softwa

Re: [swift-users] Printing large hexadecimal values

2016-05-25 Thread Ken Burgett via swift-users
On 2016-05-25 12:00, Jens Alfke wrote: On May 25, 2016, at 11:11 AM, Ken Burgett wrote: the "%llx" field is not getting interpreted... You have to import Foundation to bring in the String.init(format:…) method, which is bridged from Foundation's NSString class. (This is a temporary inconvenie

[swift-users] Simple text file I/O with Swift 3

2016-05-28 Thread Ken Burgett via swift-users
Hi all, I am trying to understand how Swift 3 File I/O works in a linux environment. I put together a trivial test program using what I can glean from the few examples I can find. See below. === import Glibc import Foundation let filename = Process.arguments[1] l

Re: [swift-users] Simple text file I/O with Swift 3

2016-05-30 Thread Ken Burgett via swift-users
t Glibc let path = "./sample.txt" let BUFSIZE = 1024 let fp = fopen(path, "r") if fp != nil { var buf = [CChar](count:BUFSIZE, repeatedValue:CChar(0)) while fgets(&buf, Int32(BUFSIZE), fp) != nil { print(String.fromCString(buf)!, terminator:"") } } K

Re: [swift-users] swift-users Digest, Vol 6, Issue 28

2016-05-30 Thread Ken Burgett via swift-users
le text file I/O with Swift 3 Message-ID: Content-Type: text/plain; charset=us-ascii On 28 May 2016, at 19:05, Ken Burgett via swift-users wrote: print(buf) The trick here is to replace the above line with: print(String(validatingUTF8: buf)) `fgets` sets up `buf` to hold a C string, s

Re: [swift-users] Simple text file I/O with Swift 3 (Quinn "The Eskimo!")

2016-05-30 Thread Ken Burgett via swift-users
le text file I/O with Swift 3 Message-ID: Content-Type: text/plain; charset=us-ascii On 28 May 2016, at 19:05, Ken Burgett via swift-users wrote: print(buf) The trick here is to replace the above line with: print(String(validatingUTF8: buf)) `fgets` sets up `buf` to hold a C string, s

[swift-users] Looking for a Swift3 JSON parser

2016-06-08 Thread Ken Burgett via swift-users
I am looking for a parser for JSON is compatible with Swift 3 on Linux. SwiftyJSON looks interesting, but it is Swift 2.2 compatible, AFAIK. Any URL will be appreciated, and a Swift3 package would bring joy. -- Ken Burgett Principal Software Engineer Email: k...@iotone.io Office: 530.693.4449

[swift-users] proper syntax for inout array handling?

2016-06-09 Thread Ken Burgett via swift-users
I am converting a very dirty C program to Swift3, and their is plenty of pointer arithmetic to be dealt with. As part of the effort, I have created a 'memcpy clone to help with some of the transformation. Here is the output from the REPL: 1. var source = [UInt

Re: [swift-users] proper syntax for inout array handling?

2016-06-10 Thread Ken Burgett via swift-users
On 2016-06-09 21:37, Joe Groff wrote: On Jun 9, 2016, at 8:39 PM, Saagar Jha via swift-users wrote: Nevermind, I lied. Swift does allow direct pointer arithmetic: import Foundation var source = [UInt8](repeating: 0x1f, count: 32) var destination = [UInt8](repeating: 0, count: 64) memcpy(&de