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

2017-11-10 Thread Joe Groff via swift-users
> On Nov 8, 2017, at 5:41 PM, Kelvin Ma via swift-users > wrote: > > 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? It would be reasonable to put this all in e

Re: [swift-users] Communicating with dynamically loaded swift library

2017-10-04 Thread Joe Groff via swift-users
> On Oct 4, 2017, at 11:02 AM, Ján Kosa via swift-users > wrote: > > Hello folks, > > I have been toying with dynamic libraries, trying to implement plugin > functionality. I was able to get to the point where I can call simple > function in loaded library, but I am having troubles starting

Re: [swift-users] Threads and weak references

2017-09-25 Thread Joe Groff via swift-users
> On Sep 22, 2017, at 2:38 AM, Howard Lovatt via swift-users > wrote: > > Hi, > > I was using a weak reference in a concurrent application and and the main > thread wasn't seeing an update to a class's property made by another thread. > If I replaced the weak reference with a closure, the p

Re: [swift-users] Still can't derive from a generic class

2017-08-31 Thread Joe Groff via swift-users
> On Aug 30, 2017, at 11:17 AM, Joanna Carter via swift-users > wrote: > > Hi Kenny > >> Just curious, and because I have a distinct lack of imagination: can you >> share a concrete case of this pattern? This is likely due to the runtime not handling cycles properly in type metadata initial

Re: [swift-users] Using #function causes big memory leak

2017-08-28 Thread Joe Groff via swift-users
> On Aug 28, 2017, at 11:07 AM, Edward Connell wrote: > > I reported it 5/16 in bug reporter. Possibly that was the wrong DB? > > https://bugreport.apple.com/web/?problemID=26535526 > > No, that's correct. Thanks! -Joe __

Re: [swift-users] Using #function causes big memory leak

2017-08-28 Thread Joe Groff via swift-users
> On Aug 27, 2017, at 10:57 AM, Edward Connell via swift-users > wrote: > > import Foundation > > class A { > var counter = 0 { > //didSet { onSet("counter") } // no leak > didSet { onSet() } // huge leak > } > > var properties = ["counter" : 0] >

Re: [swift-users] Using #function causes big memory leak

2017-08-28 Thread Joe Groff via swift-users
> On Aug 27, 2017, at 10:57 AM, Edward Connell via swift-users > wrote: > > I reported this about a year ago, but it has never been fixed and it seems > like it should be fixed for the Swift 4.0 release. What was the SR or radar number? -Joe > > Here is a simple repro case. If you watch th

Re: [swift-users] Law of Exclusivity runtime false positive?

2017-07-28 Thread Joe Groff via swift-users
> On Jul 28, 2017, at 12:06 AM, David Hart via swift-users > wrote: > > Hello, > > Indeed, I had reduced the code too much. John McCall was kind enough to have > a look and here’s the offending code: > > func layoutHorizontally(leftRect: inout CGRect, rightRect: inout CGRect) { > let tot

Re: [swift-users] What is up with names not being Strings any more in Swift 4?

2017-07-17 Thread Joe Groff via swift-users
> On Jul 17, 2017, at 9:04 AM, Manfred Schubert wrote: > > >> Am 17.07.2017 um 17:47 schrieb Joe Groff : >> >> Yeah, this is the intended use pattern for these namespaced constant. You >> don't need the `rawValue:` label, though: >> >> extension NSImage.Name { >> static let myImage = Name("m

Re: [swift-users] What is up with names not being Strings any more in Swift 4?

2017-07-17 Thread Joe Groff via swift-users
> On Jul 17, 2017, at 8:26 AM, Jon Shier via swift-users > wrote: > > Like Notification.Name, I believe those types are supposed to help you > namespace your string constants when you access them. I’d recommend using a > code gen tool to generate them from your image assets, like: > >

Re: [swift-users] Is '_ = x' guaranteed to hold a reference to x?

2017-06-30 Thread Joe Groff via swift-users
> On Jun 30, 2017, at 12:25 PM, Mike Ferenduros > wrote: > > Ah, I think I was unclear - I want to extend the lifetime into an escaping > closure, not just within a scope, and I was wondering what the minimal way is > to do that. I see. Using `withExtendedLifetime` inside the closure still o

Re: [swift-users] Is '_ = x' guaranteed to hold a reference to x?

2017-06-30 Thread Joe Groff via swift-users
> On Jun 30, 2017, at 12:13 PM, Mike Ferenduros > wrote: > > With an empty body, you mean? I'd say it's probably more readable to nest the code that's dependent on the lifetime of the object in the block body, though you can just put `withExtendedLifetime(x) { }` at the end of the region (or

Re: [swift-users] Is '_ = x' guaranteed to hold a reference to x?

2017-06-30 Thread Joe Groff via swift-users
> On Jun 30, 2017, at 11:47 AM, Mike Ferenduros via swift-users > wrote: > > I'm doing a RAII sort of thing with an object, and would like to keep it > alive until an completion-block is called (asynchronously). > > Is it sufficient to say '_ = x' in the completion-block to keep a live > ref

Re: [swift-users] Swift alternative for heterogeneous collection of objects with "generic" contents.

2017-06-30 Thread Joe Groff via swift-users
> On Jun 29, 2017, at 10:59 PM, Mikhail Seriukov via swift-users > wrote: > > Hello everyone, > In objc there is quite common pattern when we use a base class with a type > property and concrete subclasses where type is uniquely identifying the > subclass. > We can then safely put subclasses

Re: [swift-users] Passing Data to a f(void *) function

2017-06-30 Thread Joe Groff via swift-users
> On Jun 30, 2017, at 7:40 AM, Martin R via swift-users > wrote: > > I have a C function > >void myfunc(const void *ptr); > > which is imported to Swift as > >func myfunc(_ ptr: UnsafeRawPointer!) > > This compiles and runs without problems: > >let data = Data(bytes: [1, 2, 3,

Re: [swift-users] intercept fatalError() or other termination messages from swift?

2017-06-28 Thread Joe Groff via swift-users
> On Jun 26, 2017, at 7:45 PM, David Baraff wrote: > > Ok, the data is for sure not there, or possibly i’m looking at the wrong > thing. Here is what I see: > > Incident Identifier: 15D12BCE-975B-47B6-BD03-DD8512D40DAF > CrashReporter Key: 8af1402ae87b0184acff113b3f7312743d94d074 > Hardware

Re: [swift-users] intercept fatalError() or other termination messages from swift?

2017-06-26 Thread Joe Groff via swift-users
> On Jun 26, 2017, at 12:22 PM, David Baraff wrote: > > To be very clear, i’m concerned about iOS not mac os x. I pulled up a crash > report using xcode tools, and saw no mention of the string output by fatal > error. If there is someway after the fact of, on an iPhone or iOS > interogating

Re: [swift-users] Extracting arbitrary types (e.g. UInt16) out of Data

2017-06-26 Thread Joe Groff via swift-users
> On Jun 26, 2017, at 10:05 AM, Philippe Hausler wrote: > > Data.copyBytes will do that under the hood > > var crc: UInt16 = 0 > let amountCopied = withUnsafeMutablePointer(to: &crc) { data.copyBytes(to: > UnsafeMutableBufferPointer(start: $0, count: 1)) } > if amountCopied == MemoryLayout.siz

Re: [swift-users] Extracting arbitrary types (e.g. UInt16) out of Data

2017-06-26 Thread Joe Groff via swift-users
> On Jun 26, 2017, at 10:20 AM, Charles Srstka via swift-users > wrote: > > Rats, I was hoping that one of the reasons about being so explicit what we’re > going to access and where with bindMemory() and friends would be to take care > of these sorts of issues. There are restrictions that un

Re: [swift-users] Swift 4 thread sanitizer more sensitive?

2017-06-26 Thread Joe Groff via swift-users
> On Jun 26, 2017, at 10:33 AM, Joe Groff via swift-users > wrote: > > >> On Jun 25, 2017, at 3:56 PM, Jon Shier via swift-users >> wrote: >> >> Running Alamofire through the thread sanitizer and the thread sanitizer >> finds issues in Swift

Re: [swift-users] Swift 4 thread sanitizer more sensitive?

2017-06-26 Thread Joe Groff via swift-users
> On Jun 25, 2017, at 3:56 PM, Jon Shier via swift-users > wrote: > > Running Alamofire through the thread sanitizer and the thread sanitizer > finds issues in Swift 4 mode but not Swift 3.2. Does Swift 4 add additional > threading instrumentation that you don’t get under other versions

Re: [swift-users] intercept fatalError() or other termination messages from swift?

2017-06-26 Thread Joe Groff via swift-users
> On Jun 23, 2017, at 9:13 PM, David Baraff via swift-users > wrote: > > I realize this is slightly centric to iOS, but it irks me that both Apple’s > crash report logs and popular platforms like PLCrashReporter can do the hard > stuff like give you a stack trace, but are *completely* unable

Re: [swift-users] Extracting arbitrary types (e.g. UInt16) out of Data

2017-06-26 Thread Joe Groff via swift-users
> On Jun 26, 2017, at 1:55 AM, Daniel Vollmer via swift-users > wrote: > > Hi Rick, > >> On 26. Jun 2017, at 02:37, Rick Mann via swift-users >> wrote: > > [snip] > >> I'd also like to avoid unnecessary copying of the data. All of it is >> immutable for the purposes of this problem. >> >

Re: [swift-users] Unimplemented types in Swift 4 KeyPaths

2017-06-21 Thread Joe Groff via swift-users
> On Jun 19, 2017, at 5:23 PM, Brett Walker via swift-users > wrote: > > Hi all, > > In the Swift 4 Keypaths proposal [0161] there seem to be several types that > are unimplemented (or not working as I expect them to), and I'm not sure > whether these are simply unfinished in Beta 1, or just

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

2017-05-10 Thread Joe Groff via swift-users
> On May 8, 2017, at 4:47 PM, Rick Mann via swift-users > wrote: > > I have this C library that interacts with some hardware over the network that > produces a ton of data. It tells me up front the maximum size the data might > be so I can allocate a buffer for it, then does a bunch of networ

Re: [swift-users] Atomics and Memory Fences in Swift

2017-05-01 Thread Joe Groff via swift-users
> On Apr 25, 2017, at 1:08 PM, Shawn Erickson wrote: > > > On Mon, Dec 5, 2016 at 9:28 AM Joe Groff via swift-users > wrote: > >> On Dec 4, 2016, at 4:53 PM, Andrew Trick via swift-users >> wrote: >> >> >>> On Nov 30, 2016, at 5:40 AM,

Re: [swift-users] Cannot subclass a class with objc_subclassing_restricted attribute

2017-04-18 Thread Joe Groff via swift-users
> On Apr 17, 2017, at 10:11 PM, Rick Mann wrote: > >> >> On Apr 17, 2017, at 08:54 , Joe Groff wrote: >> >> >>> On Apr 14, 2017, at 7:41 PM, Rick Mann via swift-users >>> wrote: >>> >>> I'm refactoring some Objective-C code to inherit from a new Swift super >>> class. This has been going

Re: [swift-users] Importing empty C structs

2017-04-18 Thread Joe Groff via swift-users
> On Apr 17, 2017, at 6:19 PM, Rick Mann via swift-users > wrote: > > I'm trying to make a module out of a C library and header file. It has at > least one empty struct: > > struct lgs_context_t {}; > > and a function: > > LGS_EXPORT struct lgs_context_t* lgs_init(const lgs_context_params_t

Re: [swift-users] Cannot subclass a class with objc_subclassing_restricted attribute

2017-04-17 Thread Joe Groff via swift-users
> On Apr 14, 2017, at 7:41 PM, Rick Mann via swift-users > wrote: > > I'm refactoring some Objective-C code to inherit from a new Swift super > class. This has been going okay, and I've been cleaning up build errors as I > spot them (some auxiliary enums caused enum name changes, etc.). > >

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

2017-03-30 Thread Joe Groff via swift-users
> On Mar 30, 2017, at 9:40 AM, Kelvin Ma wrote: > > There are hundreds of gl functions… I have to rewrite the signatures for all > of them?? Does GLFW expose any underlying loader mechanism or cached function pointer variables underneath the macros it defines? Possibly you could access those

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

2017-03-30 Thread Joe Groff via swift-users
> On Mar 30, 2017, at 7:47 AM, Kelvin Ma via swift-users > wrote: > > 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 >

Re: [swift-users] Set with element of NSObject subclasses didn't work as expected

2017-03-29 Thread Joe Groff via swift-users
> On Mar 28, 2017, at 12:50 PM, Zhao Xin via swift-users > wrote: > > Please see the code first. > > import Foundation > > class Foo:Hashable { > let value:Int > > public var hashValue: Int { return value } > public static func ==(lhs: Foo, rhs: Foo) -> Bool { > retur

Re: [swift-users] Memory Leak of Dictionary used in singleton

2017-03-24 Thread Joe Groff via swift-users
> On Mar 11, 2017, at 4:04 PM, Ekaterina Belinskaya via swift-users > wrote: > > Hi everyone! > > I have singleton. It contains a 2 dictionaries. > > struct Stat { > var statHash:String > var displayDescription:String > var displayName:String > var displayIcon:String > va

Re: [swift-users] Why does casting to Any make my forced downcast not crash?

2017-03-15 Thread Joe Groff via swift-users
> On Mar 15, 2017, at 4:47 AM, Kim Burgestrand wrote: > > On Tue, 14 Mar 2017 at 19:50 Joe Groff > wrote: > > It shouldn't. Please file a bug, if you haven't already. > > Will do! I'll file a bug that casting to `Any` first causes different > behavior. > > Follow-up

Re: [swift-users] Why does casting to Any make my forced downcast not crash?

2017-03-14 Thread Joe Groff via swift-users
> On Mar 13, 2017, at 5:13 AM, Kim Burgestrand via swift-users > wrote: > > Here are two implementations that I'd expect to be equivalent, but > something's different because the first example crashes, whereas the second > example does not crash. > > What's the difference between these two?

Re: [swift-users] Swift/Obj C interoperability: 'Obj C only' functions

2017-03-07 Thread Joe Groff via swift-users
> On Mar 6, 2017, at 2:20 AM, Andrew Hill2 via swift-users > wrote: > > Hi, > > I’ve been looking at making some changes to the ResearchKit library. This is > mainly written in Objective C, with small portions of Swift. > > The Pull request I’ve generated leveraged Swift generics to make han

Re: [swift-users] question about covariant subtyping

2017-02-23 Thread Joe Groff via swift-users
> On Feb 23, 2017, at 4:45 AM, Michael Roitzsch > wrote: > > So I understand that the first issue is a bug and the second may be a bug or > may be intentional. Would you advise that I file them both as bugs then? They're both bugs, ultimately. Slava was just pointing out that the second may

Re: [swift-users] question about covariant subtyping

2017-02-22 Thread Joe Groff via swift-users
> On Feb 22, 2017, at 8:50 AM, Michael Roitzsch via swift-users > wrote: > > Hi all, > > I am fairly new to Swift, so this may very well be a simple misunderstanding > on my part. > > I was exploring the subtyping rules of Swift, especially regarding > covariance. I came across two examples

Re: [swift-users] Non-objc protocol inheritance from objc protocol

2017-02-06 Thread Joe Groff via swift-users
> On Feb 6, 2017, at 3:22 PM, Jordan Rose via swift-users > wrote: > > Hi, Pavel. This is definitely supported, and it is indeed a bug that these > are not both producing 'true'. We're tracking this as rdar://problem/24453316 > . I also filed this as https://bugs.swift.org/browse/SR-3882

Re: [swift-users] Avoiding an extra copy withUnsafeBytes

2017-01-26 Thread Joe Groff via swift-users
> On Jan 26, 2017, at 7:03 AM, Ray Fix via swift-users > wrote: > > To compute a hash, I want to loop through bytes of a trivial type. To get > the bytes, I use withUnsafeBytes hands me a rawBufferPointer collection type. > Great! > > However this call also requires that the "of arg" be de

Re: [swift-users] isKnownUniquelyReferenced really a mutating function?

2017-01-25 Thread Joe Groff via swift-users
> On Jan 25, 2017, at 10:20 AM, Edward Connell via swift-users > wrote: > > I have a data structure that calls isKnownUniquelyReferenced on a member. It > forces everything to be marked as mutating because of the inout parameter, > however the parameter is never mutated, it is just read right

Re: [swift-users] Casting function pointers

2017-01-25 Thread Joe Groff via swift-users
> On Jan 25, 2017, at 1:23 AM, Rien via swift-users > wrote: > > I have a case where a callback has the following signature: > > @convention(c) (_ ssl: OpaquePointer?, _ num: UnsafeMutablePointer?, _ > arg: UnsafeMutableRawPointer?) -> Int32 > > But to install this callback I have to use a c

Re: [swift-users] Bool type and reading and writing operation atomicity

2017-01-17 Thread Joe Groff via swift-users
> On Jan 16, 2017, at 3:27 AM, Dale Myers via swift-users > wrote: > > Put simply, are reading and writing to Bools both atomic operations in Swift > (3)? > > Obviously, something reading and then assigning assuming the value doesn't > change between is not correct, but would something like

Re: [swift-users] Exclamation mark's in swift parameter listings?

2017-01-10 Thread Joe Groff via swift-users
> On Jan 9, 2017, at 11:19 PM, Rien via swift-users > wrote: > > It means that a call to that function with an optional will unwrap the > optional before it is used. > > That is quite neat when dealing with C-API’s because often you will receive a > pointer from a C-function which is optiona

Re: [swift-users] question about swift and c callbacks

2017-01-04 Thread Joe Groff via swift-users
> On Dec 30, 2016, at 11:17 AM, Yang Yang via swift-users > wrote: > > I try to wrap a c library in swift package named Test. > The code looks like this: > > Test1.h > > struct MyParams { > int (*func)(); > }; > > typedef struct MyParams MyParams; > > Test2.h > #include "Test1.h" > >

Re: [swift-users] are large values (not passed through a protocol) ever put on the heap?

2017-01-04 Thread Joe Groff via swift-users
> On Jan 3, 2017, at 10:04 PM, Ray Fix via swift-users > wrote: > > > There was a great talk at WWDC 2016 about internals and Swift performance. > https://developer.apple.com/videos/play/wwdc2016/416/ > > > At one point, Arnold Schwai

Re: [swift-users] Bls: Bls: module (de)-initialization

2016-12-22 Thread Joe Groff via swift-users
> On Dec 21, 2016, at 7:29 PM, Mr Bee wrote: > > Sorry for not being clear. My english isn't very good either. > > What I meant was static module linking (loading and unloading) for Swift > modules. Also with initialization and deinitialization for Swift modules. > > It's alright then. I just

Re: [swift-users] Swift 3 Whole Module Optimization Issue

2016-12-21 Thread Joe Groff via swift-users
> On Dec 21, 2016, at 7:08 PM, Jun Zhang via swift-users > wrote: > > Hi, everyone. >I think I found a swift 3 whole module optimization issue. The code below, > when building with release configuration and running on an iOS 10 real > device, will always causes a crash. > > import UIKit

Re: [swift-users] Bls: module (de)-initialization

2016-12-21 Thread Joe Groff via swift-users
> On Dec 21, 2016, at 7:11 PM, Mr Bee wrote: > > > Unloading Swift modules will likely never be supported, since this would > > impose a ton of complexity and performance cost on the runtime for little > > benefit. > > Hmmm… so Swift will only support static linking? I thought Swift is a mode

Re: [swift-users] module (de)-initialization

2016-12-21 Thread Joe Groff via swift-users
> On Dec 20, 2016, at 8:54 AM, Jens Alfke via swift-users > wrote: > > Also, AFAIK there is no mechanism in Swift (yet) to load or unload a module > at runtime, so a module load occurs when the program starts up, and an unload > occurs when the program exits. dlopen works fine, though the o

Re: [swift-users] Implicitly capture a mutating self

2016-12-16 Thread Joe Groff via swift-users
> On Dec 16, 2016, at 3:54 PM, Richard Wei wrote: > > Thanks. That’s true, but there are cases (like making BLAS calls) where I > have to nest more than 4 `withUnsafeMutable…` closures. It’s safe by really > clumsy. I just wish there were a cleaner way that looks like the do-notation > in Has

Re: [swift-users] Implicitly capture a mutating self

2016-12-16 Thread Joe Groff via swift-users
> On Dec 16, 2016, at 12:10 PM, Richard Wei wrote: > > `sync` is not escaping. Shadow copy causes the device memory to make a copy, > which can’t be a solution either. I’ll file a radar. > >> Note that, independently, this part looks fishy: >> >>> try! fill<<<(blockSize, blockCount)>>>[ >>>

Re: [swift-users] Implicitly capture a mutating self

2016-12-16 Thread Joe Groff via swift-users
> On Dec 15, 2016, at 11:46 PM, Richard Wei via swift-users > wrote: > > Hi, > > Swift 3.0.2 seems to have broken my code due to mutating self capture. But I > have to pass inout self to the closure. Any workaround? > > let blockSize = min(512, count) > let blockCount = (count+blockS

Re: [swift-users] Swift ported on FreeBSD platform

2016-12-08 Thread Joe Groff via swift-users
> On Dec 7, 2016, at 5:43 PM, Sid via swift-users wrote: > > Swift has been ported to FreeBSD. You can see that here > http://www.freshports.org/lang/swift . > > Can https://swift.org/about/#platform-support be updated to reflect this? > Thank you. It's great that people have contributed po

Re: [swift-users] ObjC vs Swift action selectors

2016-12-06 Thread Joe Groff via swift-users
> On Dec 6, 2016, at 12:53 PM, David Catmull wrote: > > I tried, writing that as @objc(action:) #selector(ClassName.action(_:)) but > that got an "expected declaration" error. > > I also tried adding @objc(action:) to the method itself (which seems > redundant anyway), but that didn't help ei

Re: [swift-users] ObjC vs Swift action selectors

2016-12-06 Thread Joe Groff via swift-users
> On Dec 6, 2016, at 8:54 AM, David Catmull via swift-users > wrote: > > I have a unit test in which I verify that a view controller is correctly > validating items in a context menu. I converted the view controller class to > Swift, keeping the selector names the same, while the test is stil

Re: [swift-users] Atomics and Memory Fences in Swift

2016-12-05 Thread Joe Groff via swift-users
> On Dec 4, 2016, at 4:53 PM, Andrew Trick via swift-users > wrote: > > >> On Nov 30, 2016, at 5:40 AM, Anders Ha via swift-users >> mailto:swift-users@swift.org>> wrote: >> >> Hi guys >> >> I have recently started adopting lock-free atomics with memory fences, but >> it seems Swift at thi

Re: [swift-users] Indirectly calling functions through assembly

2016-11-28 Thread Joe Groff via swift-users
> On Nov 26, 2016, at 5:20 PM, Krishna Mannem via swift-users > wrote: > > I’ve been messing around with swift and trying to figure out the internals > for fun. I’ve been running into a seg fault while running this gist > (https://gist.github.com/krishnamannem/032aa7b568f82297ba2f88041518085d

Re: [swift-users] Decimal to Double?

2016-11-28 Thread Joe Groff via swift-users
> On Nov 28, 2016, at 11:42 AM, Nevin Brackett-Rozinsky > wrote: > > On Mon, Nov 28, 2016 at 2:21 PM, Joe Groff via swift-users > wrote: > ExpressibleByFloatLiteral uses a binary float initial value and so doesn't > guarantee decimal accuracy >

Re: [swift-users] Decimal to Double?

2016-11-28 Thread Joe Groff via swift-users
> On Nov 28, 2016, at 11:29 AM, David Sweeris wrote: > > > > > Sent from my iPhone >> On Nov 28, 2016, at 13:21, Joe Groff wrote: >> >> It really shouldn't be, since ExpressibleByFloatLiteral uses a binary float >> initial value and so doesn't guarantee decimal accuracy. I'd recommend usin

Re: [swift-users] Decimal to Double?

2016-11-28 Thread Joe Groff via swift-users
> On Nov 28, 2016, at 9:22 AM, Alex Blewitt via swift-users > wrote: > > NSDecimal conforms to the ExpressibleBy(Float|Integer)Literal, but that just > means it can be created from a literal value, not the other way around: > > https://github.com/apple/swift-corelibs-foundation/blob/108a5b000

Re: [swift-users] Understanding pass-by-value

2016-11-04 Thread Joe Groff via swift-users
> On Nov 4, 2016, at 10:12 AM, Rien via swift-users > wrote: > > >> On 04 Nov 2016, at 17:48, Ryan Lovelett wrote: >> >>> I often end up “printing” the addresses or using GDB to take an inside >>> look. >> >> That is a really simple interrogation technique I wish I had thought of >> that! T

Re: [swift-users] Autoreleasepool for Ubuntu

2016-11-02 Thread Joe Groff via swift-users
> On Nov 2, 2016, at 1:16 PM, Bernardo Breder via swift-users > wrote: > > In my http server i want to manager the memory all the time that we close a > socket, like the example of manager in this link: > http://stackoverflow.com/questions/25860942/is-it-necessary-to-use-autoreleasepool-in-a-

Re: [swift-users] Autoreleasepool for Ubuntu

2016-11-02 Thread Joe Groff via swift-users
> On Nov 2, 2016, at 1:00 PM, Philippe Hausler wrote: > > See: > > https://github.com/apple/swift-corelibs-foundation/blob/d015466450b2675037c6f1ace8e17e73050ccfb9/Foundation/NSURL.swift#L561 > >

Re: [swift-users] Autoreleasepool for Ubuntu

2016-11-02 Thread Joe Groff via swift-users
> On Nov 2, 2016, at 10:17 AM, Jordan Rose wrote: > >> >> On Nov 2, 2016, at 09:42, Joe Groff via swift-users > <mailto:swift-users@swift.org>> wrote: >> >>> >>> On Nov 1, 2016, at 6:40 PM, Bernardo Breder via swift-users >>> m

Re: [swift-users] Autoreleasepool for Ubuntu

2016-11-02 Thread Joe Groff via swift-users
> On Nov 1, 2016, at 6:40 PM, Bernardo Breder via swift-users > wrote: > > Hello, > > I want to create a mini http server project and execute at Ubuntu 15. The > Xcode compile and access the function "autoreleasepool", but when i compile > the same code at Ubuntu, this function not found >

Re: [swift-users] IUO from C Library Interface

2016-10-24 Thread Joe Groff via swift-users
> On Oct 24, 2016, at 3:09 PM, Ryan Lovelett wrote: > >> Not being able to assign the function reference is a bug. As a >> workaround, you should be able to unsafeBitCast CC_SHA1_Update to the >> appropriate type. >> >> -Joe > > Two questions: > > 1. Is this an already reported bug? If so, wo

Re: [swift-users] IUO from C Library Interface

2016-10-24 Thread Joe Groff via swift-users
> On Oct 24, 2016, at 2:24 PM, Ryan Lovelett via swift-users > wrote: > > import CommonCrypto > > protocol Foo { > associatedtype Context > var context: Context { get set } > var bar: (UnsafeMutablePointer!, UnsafeRawPointer!, CC_LONG) > -> Int32 { get } > } > > struct SHA1: Foo { > var

Re: [swift-users] Segmentation fault: 11 after updating codebase to Swift 3.0

2016-10-21 Thread Joe Groff via swift-users
We discovered a problem recently where we would miscompile when imported ObjC lightweight generic classes are extended to conform to Swift protocols. This is being tracked by Apple as rdar://problem/28873860 , for reference, and should be release noted in upcoming Xcode seeds. If you happen to

Re: [swift-users] Coerce NSData to Data

2016-10-14 Thread Joe Groff via swift-users
> On Oct 14, 2016, at 11:15 AM, Ryan Lovelett via swift-users > wrote: > > I'm puzzeled by the behavior of the automatic coercion. Specifically > when something will work and when it will not. It at least has something > to do with the platform. That much I have tracked down. > > I've attached

Re: [swift-users] Overload by return type optionality?

2016-10-13 Thread Joe Groff via swift-users
> On Oct 13, 2016, at 3:27 PM, Rick Mann wrote: > >> >> On Oct 13, 2016, at 14:47 , Joe Groff wrote: >> >> >>> On Oct 13, 2016, at 2:36 PM, Rick Mann via swift-users >>> wrote: >>> >>> It seems I can write this: >>> >>> extension String >>> { >>> public func deleting(prefix inPrefix: Str

Re: [swift-users] Overload by return type optionality?

2016-10-13 Thread Joe Groff via swift-users
> On Oct 13, 2016, at 2:36 PM, Rick Mann via swift-users > wrote: > > It seems I can write this: > > extension String > { > public func deleting(prefix inPrefix: String) -> String > public func deleting(prefix inPrefix: String) -> String? > } > > But I was hoping it would do the right thing

Re: [swift-users] Data reflection metadata?

2016-10-13 Thread Joe Groff via swift-users
> On Oct 13, 2016, at 9:19 AM, Austin Zheng via swift-users > wrote: > > You probably want to check out this repo: https://github.com/Zewo/Reflection > > It's clever stuff. Really, really reliant on implementation details of the > runtime to function, so I'd be loathe to use it in any sort of

Re: [swift-users] Why are Swift Loops slow?

2016-10-12 Thread Joe Groff via swift-users
> On Oct 12, 2016, at 2:25 AM, Gerriet M. Denkmann via swift-users > wrote: > > uint64_t nbrBytes = 4e8; > uint64_t count = 0; > for( uint64_t byteIndex = 0; byteIndex < nbrBytes; byteIndex++ ) > { > count += byteIndex; > if ( ( byteIndex & 0x ) == 0 ) { count += 1.3; } (AA

Re: [swift-users] Casting tuples to protocols always fails (and the compiler should know)

2016-10-10 Thread Joe Groff via swift-users
> On Oct 10, 2016, at 10:53 AM, Sebastian Hagedorn > wrote: > > “Forever” is pretty long-term ;) > > Since it is currently *not* possible for tuples to conform to protocols, > isn’t it worth a warning (if my assumption that this would be easy to > implement is correct), even if it may be obs

Re: [swift-users] Compiler refuses non-escaping closure calls in nested function

2016-10-10 Thread Joe Groff via swift-users
> On Oct 9, 2016, at 5:07 PM, Jean-Denis Muys via swift-users > wrote: > > Here is a contrived reduction of my problem > > func mainFunction(closure:(Int) -> Int) -> Int { > > func closureDoubled(_ n: Int) -> Int { > let result = closure(n) > return 2*result > } > >

Re: [swift-users] Casting tuples to protocols always fails (and the compiler should know)

2016-10-10 Thread Joe Groff via swift-users
> On Oct 10, 2016, at 8:20 AM, Sebastian Hagedorn via swift-users > wrote: > > We encountered a very surprising behaviour in one of our apps, and believe > it’s a bug/missing warning in the Swift compilter, but it would be great if > someone could confirm we’re not missing a piece before I fi

Re: [swift-users] C interop: passing null pointers to unwrapped unsafe pointers

2016-10-07 Thread Joe Groff via swift-users
> On Oct 7, 2016, at 7:02 AM, Ingo Maier via swift-users > wrote: > > Is there a way in Swift 3 to pass a null pointer to a C function that > takes an implicitly unwrapped unsafe pointer? I understand that > pointer parameters in C that don't specify nullability are mapped to > implicitly unwra

Re: [swift-users] Different behaviour when casting Float and Double to NSNumber

2016-10-05 Thread Joe Groff via swift-users
> On Oct 5, 2016, at 2:30 AM, Lars-Jørgen Kristiansen via swift-users > wrote: > > I'm working with a third party API for some external hardware. One of the > functions takes a NSNumber, and it fails to interact correctly with the > hardware if I cast a Float too NSNumber, but works as expect

Re: [swift-users] Type inference when assigning the result of reduce to a dictionary

2016-10-04 Thread Joe Groff via swift-users
> On Oct 4, 2016, at 1:58 PM, Martin R wrote: > > >> On 4 Oct 2016, at 21:42, Joe Groff wrote: >> >> >>> On Oct 4, 2016, at 5:20 AM, Martin R via swift-users >>> wrote: >>> >>> I noticed the following when assigning the result of `reduce()` to a >>> dictionary: >>> >>> let array = [1,

Re: [swift-users] Type inference when assigning the result of reduce to a dictionary

2016-10-04 Thread Joe Groff via swift-users
> On Oct 4, 2016, at 5:20 AM, Martin R via swift-users > wrote: > > I noticed the following when assigning the result of `reduce()` to a > dictionary: > >let array = [1, 2, 3] >var dict: [Int: Int] = [:] >dict[0] = array.reduce(0, { $0 + $1 }) // (A) >// error: binary operator

Re: [swift-users] UnsafeMutablePointer on the stack?

2016-10-03 Thread Joe Groff via swift-users
> On Oct 3, 2016, at 10:20 AM, Jens Alfke via swift-users > wrote: > > >> On Oct 2, 2016, at 5:14 PM, Mike Ferenduros via swift-users >> mailto:swift-users@swift.org>> wrote: >> >> Personally I would be surprised if the malloc caused an actual measurable >> performance hit tbh. > > It won’

Re: [swift-users] How to malloc in Swift 3

2016-09-23 Thread Joe Groff via swift-users
> On Sep 23, 2016, at 2:20 PM, Jens Persson wrote: > > What is the difference between: > ptr.storeBytes(of: x, toByteOffset: offset, as: type(of: x)) > ptr.advanced(by: offset).assumingMemoryBound(to: type(of: x)).pointee = x > ? > I noticed that the former traps if storing to a misaligned offse

Re: [swift-users] How to malloc in Swift 3

2016-09-23 Thread Joe Groff via swift-users
> On Sep 23, 2016, at 1:55 AM, Gerriet M. Denkmann via swift-users > wrote: > > >> On 23 Sep 2016, at 15:47, Gerriet M. Denkmann via swift-users >> wrote: >> >> This used to work in Swift 2.2: >> >> var bitfield: UnsafeMutablePointer? >> bitfield = UnsafeMutablePointer( malloc( 888 ) ) >>

Re: [swift-users] Swift 3 likes to tease me

2016-09-23 Thread Joe Groff via swift-users
> On Sep 22, 2016, at 9:51 PM, Gerriet M. Denkmann via swift-users > wrote: > > This line (Swift 3): > if a.responds(to: Selector(“viewControllers") ) > creates this warning: Use '#selector' instead of explicitly constructing a > 'Selector' > > Ok. Following this advice I change it to:

Re: [swift-users] NSData vs Data write to string differently?

2016-09-22 Thread Joe Groff via swift-users
> On Sep 22, 2016, at 4:04 PM, Shawn Erickson via swift-users > wrote: > > In general you shouldn't depend on what description returns for classes, etc. > outside of your control unless it is documented (e.g. part of the API > contract). If you want a specific output you should code up someth

Re: [swift-users] Can anyone please explain this behavior?

2016-09-22 Thread Joe Groff via swift-users
> On Sep 22, 2016, at 11:28 AM, Jens Persson wrote: > > Yes, but should the compiler silently accept that? And is this issue really > related to the other issue? No, this is a separate issue. The compiler might be able to catch some obvious cases, but it'd be impossible to statically prevent

Re: [swift-users] Can anyone please explain this behavior?

2016-09-22 Thread Joe Groff via swift-users
> On Sep 22, 2016, at 11:23 AM, Jens Persson wrote: > > Oh, but how can the following (earlier mentioned) example have anything to do > with Script-mode top-level locals being treated as globals? > > Create "AnotherFile.swift" containing: > func f() -> Int { return a } > let a = f() In this c

Re: [swift-users] Can anyone please explain this behavior?

2016-09-22 Thread Joe Groff via swift-users
> On Sep 21, 2016, at 11:04 PM, Jens Persson wrote: > > Did you see the other code examples that came up in that twitter > conversations? These all look like the same problem. Whatever you're seeing is an accident of undefined behavior due to the hole in our semantic checking. -Joe > For ex

[swift-users] Fwd: How to bridge between CoreFoundation and SwiftFoundation on Linux?

2016-09-21 Thread Joe Groff via swift-users
> On Sep 21, 2016, at 1:03 PM, Bouke Haarsma via swift-users > wrote: > > The one that comes with SwiftFoundation > (https://github.com/apple/swift-corelibs-foundation/tree/master/CoreFoundation). > > I think it should be a bug that CFReadStream cannot be bridged to > (NS)InputStream, as oth

Re: [swift-users] Can anyone please explain this behavior?

2016-09-21 Thread Joe Groff via swift-users
> On Sep 21, 2016, at 2:22 PM, Jens Persson via swift-users > wrote: > > // This little Swift program compiles (and runs) fine: > > func foo() -> Int { return a } > let a = 1 > let b = 2 > print(foo()) > > But if `foo()` returns `b` instead of `a`, I get this compile time error: > "Use of unr

Re: [swift-users] Argument type 'Int' does not conform to expected type 'AnyObject'

2016-09-09 Thread Joe Groff via swift-users
> On Sep 9, 2016, at 2:02 PM, Kevin Nattinger via swift-users > wrote: > > You’ll need to explicitly add the “as NSNumber” now. > > https://github.com/apple/swift-evolution/blob/master/proposals/0072-eliminate-implicit-bridging-conversions.md Or even better, you should now be able to use `Any

Re: [swift-users] Defer with local variable's state

2016-08-11 Thread Joe Groff via swift-users
> On Aug 11, 2016, at 7:16 AM, Sebastian Hagedorn via swift-users > wrote: > > We often write code that returns early, but has to make sure a bit of code > (e.g., a completion handler) is always called whenever we return, which seems > like a great use case for defer. I started to write this:

Re: [swift-users] Set size of byte array

2016-08-09 Thread Joe Groff via swift-users
> On Aug 5, 2016, at 9:42 AM, KS Sreeram via swift-users > wrote: > > >> On 05-Aug-2016, at 1:19 PM, Daniel Vollmer wrote: >> >> I’m by no means a Swift expert (not even a user at the moment), but I don't >> see a way to do this either. The best that comes to mind is initializing a >> Contig

Re: [swift-users] Chaining struct-mutating funcs

2016-08-05 Thread Joe Groff via swift-users
Since your backing buffer is copy-on-write, you can do the in-place mutation optimization in your immutable implementations, something like this: class C { var value: Int init(value: Int) { self.value = value } } struct S { var c: C } func addInts(x: S, y: S) -> S { var tmp = x // Don't

Re: [swift-users] Why can't structs inherit from other structs?

2016-08-02 Thread Joe Groff via swift-users
> On Aug 1, 2016, at 5:28 PM, Rick Mann via swift-users > wrote: > > It sure seems natural. > > Is there some reason the language can't allow a sub-struct to add member > variables, such that the whole is treated like a contiguous set of members? Class-style inheritance is tied to identity.

Re: [swift-users] Draft guide for id-as-Any migration and known issues

2016-08-01 Thread Joe Groff via swift-users
I've also posted the document as a gist, to gather updates as I collect them: https://gist.github.com/jckarter/5ffa9ba75050b94cd2cf9092b332a866 -Joe > On Aug 1, 2016, at 11:46 AM, Joe Groff via swift-users > wrote: > > Hi everyone. SE-0116 should be landing in snapshots so

[swift-users] Draft guide for id-as-Any migration and known issues

2016-08-01 Thread Joe Groff via swift-users
Hi everyone. SE-0116 should be landing in snapshots soon, which changes how Objective-C APIs import into Swift. Instead of relying on special implicit conversions to AnyObject, we now import the ObjC APIs using `Any` to get the same effect without special language rules. I've written up a draft

Re: [swift-users] Cannot invoke 'stride' with an argument list of type '(from: Int, to: Int, by: Int)'

2016-07-05 Thread Joe Groff via swift-users
This is a known bug. The definition of 'stride' inside 'Int' for migration from Swift 2 causes the compiler to fail to find the global function. https://bugs.swift.org/browse/SR-1798 -Joe > On Jul 4, 2016, at 8:41 PM, Adriano Ferreira via swift-users > wrote: > > Hi everyone! > > I’m conver

Re: [swift-users] Checking whether an object is uniquely referenced, using a weak reference to it

2016-06-28 Thread Joe Groff via swift-users
> On Jun 28, 2016, at 9:32 AM, Jordan Rose via swift-users > wrote: > > >> On Jun 27, 2016, at 18:52, Tim Vermeulen wrote: >> >> Thanks for your reply. It didn’t clear up everything, though. The official >> documentation says "Weak references do not affect the result of this >> function.”,

  1   2   >