Skip to content

Commit

Permalink
Update to Swift 4
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandro-isaza committed Nov 26, 2017
1 parent 0a15376 commit 7dd3a15
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 32 deletions.
30 changes: 19 additions & 11 deletions HDF5Kit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2210,16 +2210,16 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0910;
ORGANIZATIONNAME = "Venture Media Labs";
TargetAttributes = {
6185A7AA1BD3395200CD5FC5 = {
CreatedOnToolsVersion = 7.0.1;
LastSwiftMigration = 0800;
LastSwiftMigration = 0910;
};
6185A7B31BD3395200CD5FC5 = {
CreatedOnToolsVersion = 7.0.1;
LastSwiftMigration = 0800;
LastSwiftMigration = 0910;
};
61B3149C1BBDBA3100F63C45 = {
CreatedOnToolsVersion = 7.0.1;
Expand Down Expand Up @@ -2963,7 +2963,6 @@
PRODUCT_NAME = HDF5Kit;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -2989,7 +2988,6 @@
PRODUCT_NAME = HDF5Kit;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand All @@ -3010,7 +3008,6 @@
PRODUCT_BUNDLE_IDENTIFIER = com.venturemedia.HDF5KitTests;
PRODUCT_NAME = HDF5KitTests;
SDKROOT = iphoneos;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -3029,7 +3026,6 @@
PRODUCT_BUNDLE_IDENTIFIER = com.venturemedia.HDF5KitTests;
PRODUCT_NAME = HDF5KitTests;
SDKROOT = iphoneos;
SWIFT_VERSION = 3.0;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -3042,14 +3038,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = NO;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = NO;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -3078,6 +3080,8 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand All @@ -3091,14 +3095,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = NO;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = NO;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand All @@ -3120,6 +3130,8 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand All @@ -3143,7 +3155,6 @@
PRODUCT_NAME = HDF5Kit;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -3164,7 +3175,6 @@
PRODUCT_BUNDLE_IDENTIFIER = com.venturemedia.HDF5Kit;
PRODUCT_NAME = HDF5Kit;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -3177,7 +3187,6 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.venturemedia.HDF5KitTests;
PRODUCT_NAME = HDF5KitTests;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -3190,7 +3199,6 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.venturemedia.HDF5KitTests;
PRODUCT_NAME = HDF5KitTests;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0910"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -40,6 +40,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -84,6 +85,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0910"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -55,6 +56,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
16 changes: 16 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"object": {
"pins": [
{
"package": "CHDF5",
"repositoryURL": "https://github.com/aleph7/CHDF5.git",
"state": {
"branch": null,
"revision": "7cc74342b0bbaa784e310ddf4248c841c78e8354",
"version": "1.0.1"
}
}
]
},
"version": 1
}
18 changes: 17 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
// swift-tools-version:4.0

import PackageDescription

let package = Package(
name: "HDF5Kit",
products: [
.library(
name: "HDF5Kit",
targets: ["HDF5Kit"]),
],
dependencies: [
.Package(url: "https://github.com/aleph7/CHDF5.git", majorVersion: 1)
.package(url: "https://github.com/aleph7/CHDF5.git", from: "1.0.0")
],
targets: [
.target(
name: "HDF5Kit",
dependencies: [],
path: "Source"),
.testTarget(
name: "HDF5KitTests",
dependencies: ["HDF5Kit"]),
]
)
8 changes: 4 additions & 4 deletions Source/Dataset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ open class Dataset: Object {
/// The address in the file of the dataset or `nil` if the offset is undefined. That address is expressed as the offset in bytes from the beginning of the file.
public var offset: Int? {
let offset = H5Dget_offset(id)
guard offset != unsafeBitCast(Int64(-1), to: UInt64.self) else {
guard offset != UInt64(bitPattern: Int64(-1)) else {
return nil
}
return Int(offset)
Expand All @@ -31,7 +31,7 @@ open class Dataset: Object {
return space.dims
}
set {
let array = newValue.map({ unsafeBitCast(hssize_t($0), to: hsize_t.self) })
let array = newValue.map({ hsize_t(bitPattern: hssize_t($0)) })
array.withUnsafeBufferPointer { (pointer) -> Void in
H5Dset_extent(id, pointer.baseAddress)
}
Expand All @@ -50,7 +50,7 @@ open class Dataset: Object {
chunkSize.withUnsafeMutableBufferPointer { (pointer: inout UnsafeMutableBufferPointer<hsize_t>) -> Void in
H5Pget_chunk(plistId, Int32(rank), pointer.baseAddress)
}
return chunkSize.map({ Int(unsafeBitCast($0, to: hssize_t.self)) })
return chunkSize.map({ Int(hssize_t(bitPattern: $0)) })
}

/// Read data using an optional memory Dataspace and an optional file Dataspace
Expand Down Expand Up @@ -91,7 +91,7 @@ extension GroupType {
precondition(dataspace.dims.count == chunkDimensions.count)

let plist = H5Pcreate(H5P_CLS_DATASET_CREATE_ID_g)
let chunkDimensions64 = chunkDimensions.map({ unsafeBitCast(hssize_t($0), to: hsize_t.self) })
let chunkDimensions64 = chunkDimensions.map({ hsize_t(bitPattern: hssize_t($0)) })
chunkDimensions64.withUnsafeBufferPointer { (pointer) -> Void in
H5Pset_chunk(plist, Int32(chunkDimensions.count), pointer.baseAddress)
}
Expand Down
18 changes: 9 additions & 9 deletions Source/Dataspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Dataspace {

/// Create a Dataspace
public init(dims: [Int]) {
let dims64 = dims.map({ unsafeBitCast(hssize_t($0), to: hsize_t.self) })
let dims64 = dims.map({ hsize_t(bitPattern: hssize_t($0)) })
id = dims64.withUnsafeBufferPointer { pointer in
return H5Screate_simple(Int32(dims.count), pointer.baseAddress, nil)
}
Expand All @@ -41,8 +41,8 @@ public class Dataspace {

/// Create a Dataspace for use in a chunked Dataset. No component of `maxDims` should be less than the corresponding element of `dims`. Elements of `maxDims` can have a value of -1, those dimension will have an unlimited size.
public init(dims: [Int], maxDims: [Int]) {
let dims64 = dims.map({ unsafeBitCast(hssize_t($0), to: hsize_t.self) })
let maxDims64 = maxDims.map({ unsafeBitCast(hssize_t($0), to: hsize_t.self) })
let dims64 = dims.map({ hsize_t(bitPattern: hssize_t($0)) })
let maxDims64 = maxDims.map({ hsize_t(bitPattern: hssize_t($0)) })
id = withExtendedLifetime((dims64, maxDims64)) {
return H5Screate_simple(Int32(dims.count), dims64, maxDims64)
}
Expand Down Expand Up @@ -74,7 +74,7 @@ public class Dataspace {
fatalError("Coulnd't get the dimensons of the Dataspace")
}
}
return dims.map({ Int(unsafeBitCast($0, to: hssize_t.self)) })
return dims.map({ Int(hssize_t(bitPattern: $0)) })
}

/// The maximum size of each dimension in the Dataspace
Expand All @@ -86,7 +86,7 @@ public class Dataspace {
fatalError("Coulnd't get the dimensons of the Dataspace")
}
}
return maxDims.map({ Int(unsafeBitCast($0, to: hssize_t.self)) })
return maxDims.map({ Int(hssize_t(bitPattern: $0)) })
}

// MARK: - Selection
Expand Down Expand Up @@ -120,10 +120,10 @@ public class Dataspace {
/// - parameter count: Determines how many blocks to select from the dataspace, in each dimension.
/// - parameter block: Determines the size of the element block selected from the dataspace. If the block parameter is set to `nil`, the block size defaults to a single element in each dimension (as if each value in the block array were set to 1).
public func select(start: [Int], stride: [Int]?, count: [Int]?, block: [Int]?) {
let start64 = start.map({ unsafeBitCast(hssize_t($0), to: hsize_t.self) })
let stride64 = stride?.map({ unsafeBitCast(hssize_t($0), to: hsize_t.self) })
let count64 = count?.map({ unsafeBitCast(hssize_t($0), to: hsize_t.self) })
let block64 = block?.map({ unsafeBitCast(hssize_t($0), to: hsize_t.self) })
let start64 = start.map({ hsize_t(bitPattern: hssize_t($0)) })
let stride64 = stride?.map({ hsize_t(bitPattern: hssize_t($0)) })
let count64 = count?.map({ hsize_t(bitPattern: hssize_t($0)) })
let block64 = block?.map({ hsize_t(bitPattern: hssize_t($0)) })
withExtendedLifetime((start64, stride64, count64, block64)) { () -> Void in
H5Sselect_hyperslab(id, H5S_SELECT_SET, start64, pointerOrNil(stride64), pointerOrNil(count64), pointerOrNil(block64))
}
Expand Down
2 changes: 1 addition & 1 deletion Source/DoubleDataset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ extension GroupType {
precondition(dataspace.dims.count == chunkDimensions.count)

let plist = H5Pcreate(H5P_CLS_DATASET_CREATE_ID_g)
let chunkDimensions64 = chunkDimensions.map({ unsafeBitCast(hssize_t($0), to: hsize_t.self) })
let chunkDimensions64 = chunkDimensions.map({ hsize_t(bitPattern: hssize_t($0)) })
chunkDimensions64.withUnsafeBufferPointer { (pointer) -> Void in
H5Pset_chunk(plist, Int32(chunkDimensions.count), pointer.baseAddress)
}
Expand Down
2 changes: 1 addition & 1 deletion Source/FloatDataset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ extension GroupType {
precondition(dataspace.dims.count == chunkDimensions.count)

let plist = H5Pcreate(H5P_CLS_DATASET_CREATE_ID_g)
let chunkDimensions64 = chunkDimensions.map({ unsafeBitCast(hssize_t($0), to: hsize_t.self) })
let chunkDimensions64 = chunkDimensions.map({ hsize_t(bitPattern: hssize_t($0)) })
chunkDimensions64.withUnsafeBufferPointer { (pointer) -> Void in
H5Pset_chunk(plist, Int32(chunkDimensions.count), pointer.baseAddress)
}
Expand Down
2 changes: 1 addition & 1 deletion Source/IntDataset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ extension GroupType {
precondition(dataspace.dims.count == chunkDimensions.count)

let plist = H5Pcreate(H5P_CLS_DATASET_CREATE_ID_g)
let chunkDimensions64 = chunkDimensions.map({ unsafeBitCast(hssize_t($0), to: hsize_t.self) })
let chunkDimensions64 = chunkDimensions.map({ hsize_t(bitPattern: hssize_t($0)) })
chunkDimensions64.withUnsafeBufferPointer { (pointer) -> Void in
H5Pset_chunk(plist, Int32(chunkDimensions.count), pointer.baseAddress)
}
Expand Down
2 changes: 1 addition & 1 deletion Source/StringDataset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ extension GroupType {
precondition(dataspace.dims.count == chunkDimensions.count)

let plist = H5Pcreate(H5P_CLS_DATASET_CREATE_ID_g)
let chunkDimensions64 = chunkDimensions.map({ unsafeBitCast(hssize_t($0), to: hsize_t.self) })
let chunkDimensions64 = chunkDimensions.map({ hsize_t(bitPattern: hssize_t($0)) })
chunkDimensions64.withUnsafeBufferPointer { (pointer) -> Void in
H5Pset_chunk(plist, Int32(chunkDimensions.count), pointer.baseAddress)
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/HDF5KitTests/FileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FileTests: XCTestCase {
let dims = [width, height]
let dataspace = Dataspace(dims: dims)
XCTAssertEqual(Int(dataspace.size), width * height)
XCTAssertEqual(dataspace.dims.map{ Int(unsafeBitCast($0, to: hssize_t.self)) }, dims)
XCTAssertEqual(dataspace.dims.map{ Int(hssize_t($0)) }, dims)

let dataset = file.createDoubleDataset(datasetName, dataspace: dataspace)!
XCTAssertNil(dataset.offset)
Expand Down

0 comments on commit 7dd3a15

Please sign in to comment.