Re: [swift-users] Unsafe(Mutable)Pointer (suc)predecessor and advancedBy functions

2016-05-26 Thread Andrew Trick via swift-users
> On May 26, 2016, at 9:59 AM, Adrian Zubarev via swift-users > wrote: > > I’ve got one more questions about Unsafe(Mutable)Pointer. I know that I’m > able to access memory that might not belong to me. > > My question is: > > Can I trust these functions that they will return a pointer to so

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

2016-06-28 Thread Andrew Trick 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.”,

Re: [swift-users] NSData and UnsafePointer

2016-07-16 Thread Andrew Trick via swift-users
> On Jul 16, 2016, at 5:28 AM, J.E. Schotsman via swift-users > wrote: > > A mysterious bug has got me thinking about using UnsafePointer with > NSData (Swift 2). > > Is this safe: > > let data:NSData = … > let dataStart = UnsafePointer(data:NSDAta.bytes) > > myProcessdata1(dataStart,data.l

Re: [swift-users] Pointer conversions between different sockaddr types

2016-08-19 Thread Andrew Trick via swift-users
> On Aug 18, 2016, at 12:28 AM, Quinn The Eskimo! via swift-users > wrote: > > > On 17 Aug 2016, at 18:55, Martin R via swift-users > wrote: > >> - Are both solutions correct, should one be preferred, or are both wrong? > > Your `withMemoryRebound` solution is correct. Absolutely, withMem

Re: [swift-users] Pointer conversions between different sockaddr types

2016-08-19 Thread Andrew Trick via swift-users
> On Aug 19, 2016, at 4:49 PM, Michael Ferenduros via swift-users > wrote: > > >>> On Aug 18, 2016, at 12:28 AM, Quinn The Eskimo! via swift-users >>> wrote: >>> >>> >>> On 17 Aug 2016, at 18:55, Martin R via swift-users >> swift.org> wrote: >>> - Are both solutions correct, should

Re: [swift-users] changes to pointer data types in Xcode 8 beta 6

2016-08-20 Thread Andrew Trick via swift-users
> On Aug 15, 2016, at 3:05 PM, Dave Reed via swift-users > wrote: > > I'm trying to convert the following code (from the Big Nerd Ranch's Freddy > JSON parser) that works in Xcode 8 beta 5 and convert it to work with beta 6. > Essentially it appears it needs to take a Data object and convert

Re: [swift-users] Pointer conversions between different sockaddr types

2016-08-20 Thread Andrew Trick via swift-users
> On Aug 20, 2016, at 4:02 AM, Michael Ferenduros via swift-users > wrote: > >> >> On 20 Aug 2016, at 07:25, Andrew Trick > > wrote: >> >>> >>> On Aug 19, 2016, at 4:49 PM, Michael Ferenduros via swift-users >>> mailto:swift-users@swift.org>> wrote: >>> >>> >

Re: [swift-users] Data(bytesNoCopy:count:deallocator)

2016-08-23 Thread Andrew Trick via swift-users
> On Aug 23, 2016, at 8:40 AM, Stéphane Lizeray via swift-users > wrote: > > Hello, > > I create an UsafeMutableRawPointer using the allocate method. > > Later on I want to create a Data struct from this pointer using the > bytesNoCopy initializer. Which deallocator should I pass? > > It lo

Re: [swift-users] Function to unsafe pointer and back

2016-09-01 Thread Andrew Trick via swift-users
> On Sep 1, 2016, at 12:37 PM, Lou Zell via swift-users > wrote: > > As to your real question, what’s your high-level goal? Swift doesn’t really > do pointers to functions [1] but it does provide lots of other excellent > ‘treat code as data’ features. If you can explain more about your goa

Re: [swift-users] Function to unsafe pointer and back

2016-09-02 Thread Andrew Trick via swift-users
> On Sep 2, 2016, at 9:49 AM, Jordan Rose wrote: > > (One place we are still weak is in converting between C function references > and UnsafeRawPointer—there’s no dedicated API to do this. I’m not sure we > have a recommendation in the rare cases when this is necessary. Andy?) Good question.

Re: [swift-users] UnsafeMutablePointer Swift 3 conversion

2016-09-07 Thread Andrew Trick via swift-users
> On Sep 3, 2016, at 6:03 PM, Gerard Iglesias via swift-users > wrote: > > This is my funny version… I succeeded and I didn’t come back to find an other > way… > > // Grab a pointer to the constant buffer's data store > // Since we are using Swift, it is easier to cast the pointer to the > S

Re: [swift-users] UnsafeMutablePointer Swift 3 conversion

2016-09-08 Thread Andrew Trick via swift-users
> On Sep 8, 2016, at 4:04 AM, Gerard Iglesias wrote: > > Andrew, > > Thank you for the compliment ;) > > And thank you for the 2 advices > > And the question about use of size or stride ? I understand that the > underlaying float data are aligned in this specific case, but I wonder in > fac

Re: [swift-users] Canonical way to cast C structs

2016-09-13 Thread Andrew Trick via swift-users
> On Sep 12, 2016, at 12:39 PM, Bouke Haarsma via swift-users > wrote: > > Sorry for all the pings, but it appears that the code below doesn’t work > after all; > >> fatal error: can't unsafeBitCast between types of different sizes > > So the question remains on how to perform the casts usin

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

2016-09-23 Thread Andrew Trick via swift-users
> On Sep 23, 2016, at 2:23 PM, Joe Groff wrote: > > >> 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

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

2016-10-12 Thread Andrew Trick via swift-users
> On Oct 12, 2016, at 9:05 AM, Joe Groff via swift-users > wrote: > > It looks like LLVM does not recognize the overflow traps Swift emits on > arithmetic operations as dead code, so that prevents it from completely > eliminating the Swift loop. That's a bug worth fixing in Swift, but unlike

Re: [swift-users] What is "binding" memory?

2016-11-01 Thread Andrew Trick via swift-users
> On Nov 1, 2016, at 11:55 AM, Manfred Schubert via swift-users > wrote: > > The "UnsafeRawPointer Migration" guide talks about "binding memory to a type“ > as if that was a well known term. I have never heard of it yet though, and > googling it returns no relevant results. I do not understan

Re: [swift-users] What is "binding" memory?

2016-11-02 Thread Andrew Trick via swift-users
> On Nov 2, 2016, at 12:58 PM, Dave Abrahams via swift-users > wrote: > >> At the top of the migration guide is a link to the memory model explanation: >> https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md#memory-model-explanation >> >> "A memory location's

Re: [swift-users] What is "binding" memory?

2016-11-02 Thread Andrew Trick via swift-users
> On Nov 2, 2016, at 3:50 PM, Dave Abrahams wrote: > >> The original poster seemed to have the impression that the operation >> of binding memory itself might affect program state, > > Formally speaking, it does! Oh boy. I keep failing at this. How does one formally distinguish between seman

Re: [swift-users] What is "binding" memory?

2016-11-03 Thread Andrew Trick via swift-users
> On Nov 2, 2016, at 10:07 AM, Manfred Schubert via swift-users > wrote: > > Am 01.11.2016 um 21:40 schrieb Andrew Trick : >> >> I’m not sure I like the “prepares the memory” language myself. Binding >> memory communicates to the compiler that the memory locations are safe for >> typed acces

Re: [swift-users] What is "binding" memory?

2016-11-03 Thread Andrew Trick via swift-users
> On Nov 2, 2016, at 10:32 AM, Manfred Schubert via swift-users > wrote: > > Am 01.11.2016 um 21:43 schrieb Michael Ilseman : >> >> This is more so a semantic distinction rather than some kind of physical >> operation. The memory is not altered, but all reads and writes to that >> memory loc

Re: [swift-users] What is "binding" memory?

2016-11-03 Thread Andrew Trick via swift-users
> On Nov 2, 2016, at 10:37 AM, Rien via swift-users > wrote: > >>> var rawPtr = UnsafeMutableRawPointer.allocate(bytes: 2, alignedTo: 0) >>> >>> var widePtr = rawPtr.bindMemory(to: Int16.self, capacity: 1) >>> >>> widePtr.pointee = 32 >>> >>> var narrowPtr = rawPtr.bindMemory(to: UInt8.self,

Re: [swift-users] What is "binding" memory?

2016-11-03 Thread Andrew Trick via swift-users
> On Nov 3, 2016, at 7:16 AM, Manfred Schubert via swift-users > wrote: > > >> Am 02.11.2016 um 18:37 schrieb Rien : >> var rawPtr = UnsafeMutableRawPointer.allocate(bytes: 2, alignedTo: 0) var widePtr = rawPtr.bindMemory(to: Int16.self, capacity: 1) widePtr.p

Re: [swift-users] What is "binding" memory?

2016-11-03 Thread Andrew Trick via swift-users
> On Nov 3, 2016, at 7:41 AM, Rien via swift-users > wrote: > >> On 03 Nov 2016, at 15:16, Manfred Schubert via swift-users >> mailto:swift-users@swift.org>> wrote: >> >> >>> Am 02.11.2016 um 18:37 schrieb Rien >> >: >>> > > var rawPtr = UnsafeMutableR

Re: [swift-users] What is "binding" memory?

2016-11-04 Thread Andrew Trick via swift-users
> On Nov 4, 2016, at 12:16 AM, Rien wrote: > > Thanks Any, most informative. > > So the pointer “gateway’s” are in fact ephemeral. That is good for > performance. > > As to the low level interfaces, are you aware of any effort that addresses > the POSIX socket functions? > (Things like ‘addr

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

2016-12-04 Thread Andrew Trick via swift-users
> On Nov 30, 2016, at 5:40 AM, Anders Ha via swift-users > wrote: > > Hi guys > > I have recently started adopting lock-free atomics with memory fences, but it > seems Swift at this moment does not have any native instruments. > > Then I read a thread in the Apple Developer Forum > (https:/

Re: [swift-users] unsafe memory model questions

2016-12-12 Thread Andrew Trick via swift-users
> On Dec 11, 2016, at 2:51 PM, Ray Fix via swift-users > wrote: > > Hello, > > So bindMemory is part of the memory model and memory can only bind to one > type at a time to avoid aliasing. But what does binding actually do? Is it > somehow communicating with the optimizer? Binding memory to

Re: [swift-users] How much memory does withMemoryRebound bind

2017-01-04 Thread Andrew Trick via swift-users
> On Dec 29, 2016, at 2:03 PM, Guillaume Lessard via swift-users > wrote: > > Hi Etan, > > `withMemoryRebound` does not copy memory. > The proposal for UnsafeRawPointer contains information about the memory model > (as related to pointers): > https://github.com/apple/swift-evolution/blob/mast

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

2017-01-25 Thread Andrew Trick 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] isKnownUniquelyReferenced really a mutating function?

2017-01-25 Thread Andrew Trick via swift-users
> On Jan 25, 2017, at 10:53 AM, Edward Connell via swift-users > wrote: > > I am implementing a custom Array type for a distributed memory system. > > I have a DataView struct which represents the array to the user as a value > type, and a backing store class object referenced by the DataView

Re: [swift-users] unsafeBitCast to Unimplemented Class

2017-02-06 Thread Andrew Trick via swift-users
> On Feb 5, 2017, at 9:01 AM, Dave Abrahams via swift-users > wrote: > > > on Sat Feb 04 2017, Saagar Jha > wrote: > >> Thanks–your not only did you method work, it had the side effect of >> obviating the need for a Bridging Header. > > Uh, wait: this doesn

Re: [swift-users] unsafeBitCast to Unimplemented Class

2017-02-06 Thread Andrew Trick via swift-users
> On Feb 6, 2017, at 8:51 PM, Dave Abrahams wrote: > > > on Mon Feb 06 2017, Andrew Trick wrote: > >> Is a missing declaration a use case that needs to be supported? > > I couldn't say. > >> Wouldn’t it be more proper to use selector based dispatch in those >> cases? > > Example, please?

Re: [swift-users] unsafeBitCast to Unimplemented Class

2017-02-08 Thread Andrew Trick via swift-users
> On Feb 7, 2017, at 3:44 PM, Dave Abrahams via swift-users > wrote: > >> >> I phrased that as a question because I'm the last person who should be >> giving advice here... What I had in mind is this: >> >> if ([self isKindOfClass:NSClassFromString(@“Bar”)]) { >> self.perform(@selector(FakeB

Re: [swift-users] Ugliness bridging Swift String to char *

2017-03-06 Thread Andrew Trick via swift-users
> On Mar 1, 2017, at 7:08 PM, Kenny Leung via swift-users > wrote: > > Hi Jordan. > > Thanks for the lengthy answer. > >> On Mar 1, 2017, at 6:21 PM, Jordan Rose > > wrote: >> >> Hey, Kenny. The const vs non-const part is important, since both the >> implicit c

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

2017-07-03 Thread Andrew Trick via swift-users
> On Jun 30, 2017, at 9:14 AM, Joe Groff via swift-users > wrote: > > >> 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!) >>

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

2017-07-30 Thread Andrew Trick via swift-users
> On Jul 30, 2017, at 5:11 AM, David Hart via swift-users > wrote: > >> >> On 28 Jul 2017, at 18:55, Joe Groff > > wrote: >> >>> >>> On Jul 28, 2017, at 12:06 AM, David Hart via swift-users >>> mailto:swift-users@swift.org>> wrote: >>> >>> Hello, >>> >>> Indeed, I

Re: [swift-users] Memory Address of value types and reference types

2017-09-12 Thread Andrew Trick via swift-users
> On Sep 12, 2017, at 9:55 AM, somu subscribe via swift-users > wrote: > > Hi Quinn, > > Thanks for the reply, > > It is an iOS Swift project (uses Foundation, UIKit, CloudKit and other native > frameworks) in which I would like to check the memory address for debugging > (and out of enthus

Re: [swift-users] Why does the withUnsafeMutableBufferPointer closure take an inout parameter?

2017-10-13 Thread Andrew Trick via swift-users
> On Oct 12, 2017, at 3:52 AM, Geordie Jay via swift-users > wrote: > > > Guillaume Lessard via swift-users > schrieb am Mi. 11. Okt. 2017 um 23:49: > A lot of the MutableCollection implementation is in protocol extensions > (swapAt, for example.) > > Should a

Re: [swift-users] Tuple of two or more instances to withExtendedLifetime

2017-12-13 Thread Andrew Trick via swift-users
Yes, withExtendedLifetime is a generic API that guarantees the lifetime of any non-trivial value. i.e. if the tuple contains a reference, the lifetime of that reference will be extended. That said, there is a theoretical bug in the optimizer that you will be much more likely to hit in practice

Re: [swift-users] Need some help understanding test behavior.

2017-12-14 Thread Andrew Trick via swift-users
This sounds like a question for the swift-dev list, directed toward whomever has been working on linux/powerpc support... > On Dec 14, 2017, at 3:25 AM, Atul Sowani via swift-users > wrote: > > Hi, > > I am trying to understand behavior of Swift test case Sanitizers/tsan.swift. > When I run