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

2016-05-21 Thread Michal Kalinowski via swift-users
Some good info in Package Manager docs:

https://github.com/apple/swift-package-manager/blob/master/Documentation/SystemModules.md

Hope that helps,
Michał

> On 21 May 2016, at 17:42, Ken Burgett via swift-users  
> wrote:
> 
> 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 Ubuntu Linux 14.04 
> version of the Swift 3.0 toolchain.
> 
> Thanks in advance for your help.
> 
> -- 
> Ken Burgett
> Principal Software Engineer
> Email: k...@iotone.io
> Office: 530.693.4449
> Mobile: 831.332.6846
> URL: www.iotone.co
> ___
> 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] 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 Ubuntu Linux 14.04 version of the Swift 3.0 toolchain.


Thanks in advance for your help.

--
Ken Burgett
Principal Software Engineer
Email: k...@iotone.io
Office: 530.693.4449
Mobile: 831.332.6846
URL: www.iotone.co
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] UnsafeMutablePointer vs. UnsafeMutablePointer

2016-05-21 Thread Dmitri Gribenko via swift-users
On Sat, May 21, 2016 at 2:15 AM, Adrian Zubarev via swift-users
 wrote:
> So basically if I do something like this I should be on the safe side:

Yes, this code is safe.  If you just want to store a contiguous buffer
of elements of the same type, you should consider using Array.  It has
methods that will allow you to operate on the unsafe pointer to the
memory if you need that for speed, but it will do the memory
management for you.

> Does the UnsafeMutablePointer reserves me a safe portion of memory (by safe
> I mean which isn’t used by anyone at the time I will start using it)?

Yes, you will become a unique owner of the newly allocated chunk of
memory.  (Same as malloc() in C.)

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j*/
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] UnsafeMutablePointer vs. UnsafeMutablePointer

2016-05-21 Thread Adrian Zubarev via swift-users
So basically if I do something like this I should be on the safe side:

public class Characters {
 
private let reference: UnsafeMutablePointer

var characters: [Character] {
 
var characters = [Character]()
 
for index in 0...alloc(self.count)
self.reference.initializeFrom(characters)
}
 
deinit {
 
self.reference.destroy(self.count)
self.reference.dealloc(self.count)
}
}
Or do I have to fix something?

Here I don’t walk out of the boundary I allocate.

Does the UnsafeMutablePointer reserves me a safe portion of memory (by safe I 
mean which isn’t used by anyone at the time I will start using it)?

Sure another pointer could be created and hack into my memory but that wasn’t 
the question. :)

Thanks.



-- 
Adrian Zubarev
Sent with Airmail

Am 21. Mai 2016 bei 11:04:10, Dmitri Gribenko (griboz...@gmail.com) schrieb:

Hi Adrian,  

On Sat, May 21, 2016 at 1:48 AM, Adrian Zubarev via swift-users  
 wrote:  
> I played around with UnsafeMutablePointer and realized one behavior:  
>  
> let pString = UnsafeMutablePointer.alloc(1)  
> pString.initialize("test")  
> pString.predecessor().memory // will crash ax expected  
> pString.predecessor() == pString.advancedBy(-1) // true  
> pString.destroy()  
> pString.dealloc(1)  
>  
> where  
>  
> let iInt = UnsafeMutablePointer.alloc(1)  
> iInt.initialize("test")  
> iInt.predecessor().memory // will not crash  
> iInt.predecessor() == iInt.advancedBy(-1) // true  
> iInt.predecessor().memory = 42 // did I just modified some memory I don't  
> own?  

Yes, you did.  

In the String case the crash is not guaranteed (it is a segmentation  
fault, not a controlled trap). Someone else's valid String can happen  
to be located immediately before your memory chunk, and then the code  
would "just work", loading that other string.  

Dereferencing (reading or writing into) an out-of-bounds pointer is  
undefined behavior in Swift.  

Dmitri  

--  
main(i,j){for(i=2;;i++){for(j=2;j*/  
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users