Skip to content

Commit e656208

Browse files
committed
Pointers
1 parent 2fd2108 commit e656208

File tree

4 files changed

+73
-9
lines changed

4 files changed

+73
-9
lines changed

Source/Aliases.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,18 @@ public typealias CFloat = Float
7070
public typealias CInt = Int32
7171
public typealias CLong = Int
7272
public typealias CLongLong = Int64
73-
#if COCOA || ISLAND
74-
//UnsafeMutablePointer
75-
//UnsafePointer
73+
74+
#if !JAVA
75+
// UnsafeMutablePointer and UnsafePointer are defined by the compiler
7676
public typealias UnsafeMutableBufferPointer<T> = UnsafeMutablePointer<T>
7777
public typealias UnsafeBufferPointer<T> = UnsafePointer<T>
78-
public typealias UnsafeMutableRawPointer<T> = UnsafeMutablePointer<T>
79-
public typealias UnsafeRawPointer<T> = UnsafePointer<T>
80-
public typealias UnsafeMutableRawBufferPointer<T> = UnsafeMutablePointer<T>
81-
public typealias UnsafeRawBufferPointer<T> = UnsafePointer<T>
82-
78+
public typealias UnsafeMutableRawPointer = UnsafeMutablePointer<Void>
79+
public typealias UnsafeRawPointer = UnsafePointer<Void>
80+
public typealias UnsafeMutableRawBufferPointer = UnsafeMutablePointer<Void>
81+
public typealias UnsafeRawBufferPointer = UnsafePointer<Void>
8382
public typealias OpaquePointer = UnsafePointer<Void>
8483
#endif
84+
8585
public typealias CShort = Int16
8686
public typealias CSignedChar = Int8
8787
public typealias CUnsignedChar = UInt8

Source/MemoryLayout.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//public struct MemoryLayout<T> {
2+
3+
//var size: Byte { sizeOf<T> }
4+
//var alignment: Byte { sizeOf<T> }
5+
//var stride: Byte { sizeOf<T> }
6+
7+
//}

Source/Pointers.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#if !JAVA
2+
public extension OpaquePointer {
3+
4+
//init<T>(_ pointer: UnsafePointer<T>) {
5+
6+
//}
7+
//init<T>(_ pointer: UnsafeMutablePointer<T>) {
8+
9+
//}
10+
//init?<T>(_ pointer: UnsafePointer<T>?) {
11+
12+
//}
13+
//init?<T>(_ pointer: UnsafeMutablePointer<T>?) {
14+
15+
//}
16+
init(_ pointer: UnsafeRawPointer?) {
17+
return pointer
18+
}
19+
init?(bitPattern: Int) {
20+
return bitPattern as! OpaquePointer
21+
}
22+
init?(bitPattern: UInt) {
23+
return bitPattern as! OpaquePointer
24+
}
25+
26+
//@ToString // E201 Attributes of type "ToStringAspect!" are not allowed on this member
27+
var description: String {
28+
return "0x"+(self as! UInt).toHexString()
29+
}
30+
31+
var debugDescription: String {
32+
return "0x"+(self as! UInt).toHexString()
33+
}
34+
35+
//func hash(into: inout Hasher) {
36+
37+
//}
38+
//static func != (_ rhs: OpaquePointer, _lhs: OpaquePointer) -> Bool {
39+
// handled by compiler
40+
//}
41+
//static func == (OpaquePointer, OpaquePointer) -> Bool {
42+
// handled by compiler
43+
//}
44+
}
45+
46+
#endif

Source/Swift.Shared.projitems

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,15 @@
9494
<Compile Include="$(MSBuildThisFileDirectory)Dictionary.Java.swift" />
9595
<Compile Include="$(MSBuildThisFileDirectory)Operators.swift" />
9696
<Compile Include="$(MSBuildThisFileDirectory)Errors.swift" />
97-
<Compile Include="$(MSBuildThisFileDirectory)Unmanaged.swift" />
97+
<Compile Include="$(MSBuildThisFileDirectory)Unmanaged.swift">
98+
<VirtualFolder>Memory</VirtualFolder>
99+
</Compile>
100+
<Compile Include="$(MSBuildThisFileDirectory)MemoryLayout.swift">
101+
<VirtualFolder>Memory</VirtualFolder>
102+
</Compile>
103+
<Compile Include="$(MSBuildThisFileDirectory)Pointers.swift">
104+
<VirtualFolder>Memory</VirtualFolder>
105+
</Compile>
98106
</ItemGroup>
99107
<ItemGroup>
100108
<Folder Include="Sequences">
@@ -112,5 +120,8 @@
112120
<Folder Include="Cocoa">
113121
<Virtual>True</Virtual>
114122
</Folder>
123+
<Folder Include="Memory">
124+
<Virtual>True</Virtual>
125+
</Folder>
115126
</ItemGroup>
116127
</Project>

0 commit comments

Comments
 (0)