[swift-users] Rebind tuple to its destructured base type

2018-01-12 Thread Kelvin Ma via swift-users
I have an array of matrices where the matrix type is defined as typealias Vec4 = (Float, Float, Float, Float) typealias Mat4 = (Vec4, Vec4, Vec4, Vec4) let matrices:[Mat4] I need to send them to an OpenGL API that accepts a buffer of Floats. How do I do this? withMemoryRebound(to:_:) requires th

Re: [swift-users] appending packed bytes to [UInt8]

2018-01-10 Thread Kelvin Ma via swift-users
ry layout of Swift-structs is not guaranteed to >> remain like this and is thus not future-proof, although I think that >> if/when things changes, there will be some way to tell the compiler that >> you want the memory to be this "expected" "C-like"

Re: [swift-users] appending packed bytes to [UInt8]

2018-01-10 Thread Kelvin Ma via swift-users
e memory layout of Swift-structs is not guaranteed to > remain like this and is thus not future-proof, although I think that > if/when things changes, there will be some way to tell the compiler that > you want the memory to be this "expected" "C-like" layout. > >

[swift-users] appending packed bytes to [UInt8]

2018-01-10 Thread Kelvin Ma via swift-users
I want to create a buffer with the layout 0 4 8 12 13 14 15 16 [ x:Float | y:Float | z:Float | r:UInt8 | g:UInt8 | b:UInt8 | _:UInt8 ] Normally, I’d use UnsafeRawBufferPointer for this, but I need the buffer to be a vector (i.e. with a

Re: [swift-users] Clarification about the Swift API Design Guide - Initializer and factory methods calls

2018-01-09 Thread Kelvin Ma via swift-users
I didn’t write the guidelines but i never really felt Array(repeating:count:) was weird, you have two arguments, they need to be distinguished, and repeating is actually shorter than repeatedValue. On Tue, Jan 9, 2018 at 12:09 PM, Gaétan Zanella via swift-users < swift-users@swift.org> wrote: > S

Re: [swift-users] Happy new year Swift community.

2018-01-01 Thread Kelvin Ma via swift-users
Happy new year from klossyland! On Mon, Jan 1, 2018 at 11:23 AM, Georgios Moschovitis via swift-users < swift-users@swift.org> wrote: > Happy new year! Greetings from Cyprus :) > > George. > > On 1 Jan 2018, at 1:42 AM, Adrian Zubarev via swift-users < > swift-users@swift.org> wrote: > > Well som

Re: [swift-users] abs() Bug?

2017-12-12 Thread Kelvin Ma via swift-users
this is correct behavior. −Int.min can’t be represented in signed 2’s complement because the range of Int is 2^(bitWidth - 1) ..< 2^(bitWidth - 1) so it correctly traps on SIGILL. what i’m more worried about is why abs(Int32.min) is returning a value for you,, but mine traps as it should. On Tue,

Re: [swift-users] status of SR-755

2017-11-23 Thread Kelvin Ma via swift-users
mywsherman.com/ > > On Nov 16, 2017, at 18:32, Kelvin Ma via swift-users < > swift-users@swift.org> wrote: > > It’s been like a year since SR-755 <https://bugs.swift.org/browse/SR-755> > was filed and linux crash logs still look like this. > > Cur

[swift-users] status of SR-755

2017-11-16 Thread Kelvin Ma via swift-users
It’s been like a year since SR-755 was filed and linux crash logs still look like this. Current stack trace: 0libswiftCore.so0x7f39facaf0f0 _swift_stdlib_reportFatalError + 171 1libswiftCore.so0x7f39fac5

Re: [swift-users] raw buffer pointer load alignment

2017-11-09 Thread Kelvin Ma via swift-users
On Thu, Nov 9, 2017 at 10:37 AM, Johannes Weiß wrote: > Hi Kelvin, > > > On 9 Nov 2017, at 12:30 am, Kelvin Ma wrote: > > > > For context, the problem I’m trying to solve is efficiently parsing JPEG > chunks. This means reading each chunk of the JPEG from a file into a raw > buffer pointer, and

Re: [swift-users] raw buffer pointer load alignment

2017-11-09 Thread Kelvin Ma via swift-users
On Thu, Nov 9, 2017 at 10:37 AM, Johannes Weiß wrote: > Hi Kelvin, > > > On 9 Nov 2017, at 12:30 am, Kelvin Ma wrote: > > > > For context, the problem I’m trying to solve is efficiently parsing JPEG > chunks. This means reading each chunk of the JPEG from a file into a raw > buffer pointer, and

Re: [swift-users] raw buffer pointer load alignment

2017-11-09 Thread Kelvin Ma via swift-users
For context, the problem I’m trying to solve is efficiently parsing JPEG chunks. This means reading each chunk of the JPEG from a file into a raw buffer pointer, and then parsing the chunk according to its expected layout. For example, a frame header chunk looks like this: 0 1

Re: [swift-users] raw buffer pointer load alignment

2017-11-08 Thread Kelvin Ma via swift-users
yikes there’s no less verbose way to do that? and if the type isn’t an integer there’s no way to avoid the default initialization? Can this be done with opaques or something? On Wed, Nov 8, 2017 at 7:04 PM, Johannes Weiß wrote: > Hi Kelvin, > > > On 8 Nov 2017, at 4:54 pm, Kelvin

[swift-users] raw buffer pointer load alignment

2017-11-08 Thread Kelvin Ma via swift-users
According to the docs , the load(fromByteOffset:as:) method requires the instance to be “properly aligned” Does that mean if I have raw data meant to be interpreted as 0 1 2 3 4 5 6 [

Re: [swift-users] Optimal String conversion to/from UTF-8 w/o null-termination?

2017-11-06 Thread Kelvin Ma via swift-users
doesn’t the compiler like to optimize the loop out of the benchmarking code? i’ve always had a hard time writing benchmarks in Swift On Fri, Nov 3, 2017 at 7:10 PM, Ryan Walklin via swift-users < swift-users@swift.org> wrote: > Why not just profile it? Set up a loop of 100,000 or so with each met

Re: [swift-users] Swift Documentation question

2017-07-01 Thread Kelvin Ma via swift-users
i agree. it would also be a lot better if the docs lived on the actual swift website instead of the apple website. > On Jul 1, 2017, at 4:36 PM, Jon Shier via swift-users > wrote: > > swiftdoc.org should be integrated into swift.org and be kept officially > up to date. Unfortunately it

[swift-users] A pure Swift XML parsing library

2017-06-23 Thread Kelvin Ma via swift-users
Hi all, seeing as (NS)XMLParser is still nonfunctional on Linux, and its API is horribly un-Swifty anyway, I’ve started the project SwiftXML which is a pure Swift XML parser library. Currently it can parse the most commonly used subset of XML features, though

[swift-users] A procedural noise library

2017-06-11 Thread Kelvin Ma via swift-users
Hi everyone, Thought you’d like to know that Swift now has a native procedural noise generation library, which I released today at https://github.com/kelvin13/noise . The Noise library supports several types of gradient noise (“Perlin noise”), cell noise (“Worley noise” or “Voronoi noise”), poisso

Re: [swift-users] Future(of: self.references)?

2017-05-22 Thread Kelvin Ma via swift-users
As someone who is very in favor of using `self` everywhere, I’ve come to the conclusion that the easiest way to use `self` everywhere is to write `self` everywhere. I write Swift as if `self` were mandatory, and as that email argues, that’s good enough for me. Personally I find self-less code harde

Re: [swift-users] X11/Xlib linker error

2017-05-22 Thread Kelvin Ma via swift-users
Tried that, doesn’t help On Mon, May 22, 2017 at 4:23 AM, Alex Blewitt wrote: > > On 21 May 2017, at 20:48, Kelvin Ma via swift-users > wrote: > > I’m trying to get Swift working with X11, and I keep getting this linker > error when I try to compile: > > ~/dev/cloudge

Re: [swift-users] passing command line arguments to `swift test`

2017-05-19 Thread Kelvin Ma via swift-users
i want to be able to run a single test case at a time instead of my whole test suite and i’m currently invoking the test binary directly after doing `swift test` On May 19, 2017, at 4:56 PM, Brent Royal-Gordon wrote: >> On May 18, 2017, at 8:16 AM, Kelvin Ma via swift-users >

[swift-users] passing command line arguments to `swift test`

2017-05-18 Thread Kelvin Ma via swift-users
Is there a way I can pass command line arguments along to the testing program with `swift test` so that they are visible in `CommandLine.arguments`? ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users

Re: [swift-users] Help! Slicing an array is very expensive

2017-05-08 Thread Kelvin Ma via swift-users
Depending on what you’re trying to do with the data, you might be better off using an UnsafeBufferPointer and allocating and reallocating that, C-style. On Mon, May 8, 2017 at 7:01 PM, Philippe Hausler via swift-users < swift-users@swift.org> wrote: > I wonder if Data might be a better tool for t

Re: [swift-users] Passing value types or members of value types?

2017-05-07 Thread Kelvin Ma via swift-users
i’m also curious as to whether this would be faster as a member function on the struct itself, since member functions get `self` as a pointer, right? > On May 7, 2017, at 11:21 AM, Kelvin Ma wrote: > > So if I am passing the large struct to a large function, or a function that > lives in a dif

Re: [swift-users] Passing value types or members of value types?

2017-05-07 Thread Kelvin Ma via swift-users
aoxin > > > > On Mon, May 8, 2017 at 12:21 AM, Kelvin Ma via swift-users < > swift-users@swift.org> wrote: > >> So if I am passing the large struct to a large function, or a function >> that lives in a different module (as my project is currently split into 8

Re: [swift-users] Passing value types or members of value types?

2017-05-07 Thread Kelvin Ma via swift-users
So if I am passing the large struct to a large function, or a function that lives in a different module (as my project is currently split into 8 or 9 modules — is that too many?), am I better off passing the members individually instead of passing the entire struct? It seems kind of tedious to have

Re: [swift-users] Passing value types or members of value types?

2017-05-06 Thread Kelvin Ma via swift-users
y, until it's *written* you will be working with a pointer. >> >> Sent from my iPhone, please excuse brevity and errors >> >>> On May 6, 2017, at 9:33 PM, Kelvin Ma via swift-users >>> wrote: >>> >>> If I have a “large” struct like >

[swift-users] Passing value types or members of value types?

2017-05-06 Thread Kelvin Ma via swift-users
If I have a “large” struct like struct Vertex { let x:Double, y:Double var r:Int, g:Int, b:Int let s:Double, t:Double var selected:Bool } and I want to pass it to a function without modifying it like func taxicab_distance(_ v1:Vertex, _ v2:Vertex) -> Double { return v2.x - v1

Re: [swift-users] Why does String.CharacterView have reserveCapacity(:)?

2017-05-06 Thread Kelvin Ma via swift-users
least be removed from `CharacterView` and `UnicodeScalarView` and only live in the parent `String` type. On Thu, May 4, 2017 at 6:33 AM, Brent Royal-Gordon wrote: > On May 2, 2017, at 12:35 PM, Kelvin Ma via swift-users < > swift-users@swift.org> wrote: > > I’m

[swift-users] Why does String.CharacterView have reserveCapacity(:)?

2017-05-02 Thread Kelvin Ma via swift-users
I’m wondering why the String.CharacterView structure has a reserveCapacity(:) member? And even more strangely, why String itself has the same method? It’s even weirder that String.UnicodeScalarView has this method, but it reserves `n` `UInt8`s of storage, instead of `n` `UInt32`s of storage. Also

Re: [swift-users] Swift can’t compile code with OpenGL function pointers

2017-03-30 Thread Kelvin Ma via swift-users
> On Thu, Mar 30, 2017 at 11:31 AM, Joe Groff wrote: > >> >> > On Mar 30, 2017, at 7:47 AM, Kelvin Ma via swift-users < >> swift-users@swift.org> wrote: >> > >> > OpenGL functions are loaded at runtime by a function loader (like >>

Re: [swift-users] Swift can’t compile code with OpenGL function pointers

2017-03-30 Thread Kelvin Ma via swift-users
There are hundreds of gl functions… I have to rewrite the signatures for all of them?? On Thu, Mar 30, 2017 at 11:31 AM, Joe Groff wrote: > > > On Mar 30, 2017, at 7:47 AM, Kelvin Ma via swift-users < > swift-users@swift.org> wrote: > > > > OpenGL functions are l

[swift-users] Swift can’t compile code with OpenGL function pointers

2017-03-30 Thread Kelvin Ma via swift-users
OpenGL functions are loaded at runtime by a function loader (like GLFW). They’re defined in a header but obviously they don’t have definitions at compile time so it causes a slew of linker errors when I try to build error: undefined reference to 'glEnable' error: undefined reference to 'gl

Re: [swift-users] [swift-build-dev] Importing C system libraries

2017-03-29 Thread Kelvin Ma via swift-users
’s possible. You could also bite the bullet and build your C >>>>>> libraries >>>>>> with SwiftPM as well. Hopefully someone on swift-build-dev can help you >>>>>> out. >>>>>> >>>>>> CC-ing Ankit >>>

Re: [swift-users] [swift-build-dev] Importing C system libraries

2017-03-29 Thread Kelvin Ma via swift-users
;>> On Tue, Mar 28, 2017 at 12:47 PM, Michael Ilseman >>>>> wrote: >>>>> >>>>>> Sure! In this example, I have built libgit2. I have a directory >>>>>> called Git, and inside that I have the following module map: &

Re: [swift-users] [swift-build-dev] Importing C system libraries

2017-03-28 Thread Kelvin Ma via swift-users
t;>>> foo.swift >>>> >>>> inside foo.swift I can: >>>> >>>> import Git >>>> // … use libGit2 >>>> >>>> >>>> Read more about how to write a more appropriate module.map file for >>>> your

Re: [swift-users] [swift-build-dev] Importing C system libraries

2017-03-28 Thread Kelvin Ma via swift-users
;>> >>> Read more about how to write a more appropriate module.map file for your >>> purposes at https://clang.llvm.org/docs/Modules.html. For example, you >>> might be able to define link flags inside the module.map, use umbrella >>> directories, submodules, etc.

Re: [swift-users] Importing C system libraries

2017-03-28 Thread Kelvin Ma via swift-users
>> >> >> On Mar 28, 2017, at 6:27 AM, Kelvin Ma wrote: >> >> Can you give an example? >> >> On Mon, Mar 27, 2017 at 3:59 PM, Michael Ilseman >> wrote: >> >>> Sure. At a low level, you can create a module.map file and use -L/-l >>&

Re: [swift-users] Importing C system libraries

2017-03-28 Thread Kelvin Ma via swift-users
u give an example? > > On Mon, Mar 27, 2017 at 3:59 PM, Michael Ilseman > wrote: > >> Sure. At a low level, you can create a module.map file and use -L/-l >> flags in your invocation of Swift. If you want to do so at a higher level, >> then perhaps SwiftPM can. CCing swi

Re: [swift-users] [swift-build-dev] Importing C system libraries

2017-03-28 Thread Kelvin Ma via swift-users
I can only fit one monitor in my dorm and it’s honestly tragic… On Tue, Mar 28, 2017 at 2:58 PM, David Sweeris wrote: > > On Mar 28, 2017, at 1:58 AM, Rien via swift-build-dev < > swift-build-...@swift.org> wrote: > > I feel your pain ;-) > > Just embrace the dark side, it takes a little time to

Re: [swift-users] Importing C system libraries

2017-03-28 Thread Kelvin Ma via swift-users
e SwiftPM part. > > > > On Mar 26, 2017, at 3:20 PM, Kelvin Ma via swift-users < > swift-users@swift.org> wrote: > > > > Idk if this has been asked before, but is there a way to import C > libraries into a Swift project without creating a local git repo? > Pref

Re: [swift-users] Importing C system libraries

2017-03-28 Thread Kelvin Ma via swift-users
ift-build-dev for the SwiftPM part. > >> > >> > >>> On Mar 26, 2017, at 3:20 PM, Kelvin Ma via swift-users < > swift-users@swift.org> wrote: > >>> > >>> Idk if this has been asked before, but is there a way to import C > libraries i

[swift-users] Importing C system libraries

2017-03-26 Thread Kelvin Ma via swift-users
Idk if this has been asked before, but is there a way to import C libraries into a Swift project without creating a local git repo? Preferably something similar to C where you can just `#include` headers and then specify the link flags (in Package.swift?) It’s getting very cumbersome to make a bun