Skip to content

Commit

Permalink
Fix issues in 32-bit architectures
Browse files Browse the repository at this point in the history
Fix #18
  • Loading branch information
Alejandro Isaza committed Feb 18, 2016
1 parent 9ecb61c commit 6b93d77
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 123 deletions.
6 changes: 0 additions & 6 deletions HDF5Kit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
616B83B41BDD5B9700B28545 /* Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 616B83B21BDD5B9700B28545 /* Helpers.swift */; };
617187841BFCF64200FB5D5F /* DataspaceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 617187831BFCF64200FB5D5F /* DataspaceTests.swift */; };
617187851BFCF64200FB5D5F /* DataspaceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 617187831BFCF64200FB5D5F /* DataspaceTests.swift */; };
617187871BFCF9CB00FB5D5F /* PointerUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 617187861BFCF9CB00FB5D5F /* PointerUtilities.swift */; };
617187881BFCF9CB00FB5D5F /* PointerUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 617187861BFCF9CB00FB5D5F /* PointerUtilities.swift */; };
6185A7B51BD3395200CD5FC5 /* HDF5Kit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6185A7AB1BD3395200CD5FC5 /* HDF5Kit.framework */; };
6185A8B31BD339FD00CD5FC5 /* H5.c in Sources */ = {isa = PBXBuildFile; fileRef = 61B314BA1BBDBA8D00F63C45 /* H5.c */; };
6185A8B41BD339FD00CD5FC5 /* H5A.c in Sources */ = {isa = PBXBuildFile; fileRef = 61B314BB1BBDBA8D00F63C45 /* H5A.c */; };
Expand Down Expand Up @@ -744,7 +742,6 @@
616B83AF1BDD5A8500B28545 /* GroupTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GroupTests.swift; sourceTree = "<group>"; };
616B83B21BDD5B9700B28545 /* Helpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Helpers.swift; sourceTree = "<group>"; };
617187831BFCF64200FB5D5F /* DataspaceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataspaceTests.swift; sourceTree = "<group>"; };
617187861BFCF9CB00FB5D5F /* PointerUtilities.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PointerUtilities.swift; sourceTree = "<group>"; };
6185A7AB1BD3395200CD5FC5 /* HDF5Kit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = HDF5Kit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6185A7B41BD3395200CD5FC5 /* HDF5KitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = HDF5KitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
6185A9F01BD33B2D00CD5FC5 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk/usr/lib/libz.tbd; sourceTree = DEVELOPER_DIR; };
Expand Down Expand Up @@ -1205,7 +1202,6 @@
61EE30691C191C4200324344 /* IntDataset.swift */,
61B3179C1BBE21CE00F63C45 /* NativeType.swift */,
616B83AC1BDD493200B28545 /* Object.swift */,
617187861BFCF9CB00FB5D5F /* PointerUtilities.swift */,
61EE306C1C191C4E00324344 /* StringDataset.swift */,
);
path = Source;
Expand Down Expand Up @@ -2139,7 +2135,6 @@
6185A9951BD339FD00CD5FC5 /* H5trace.c in Sources */,
6185A90A1BD339FD00CD5FC5 /* H5Gloc.c in Sources */,
6185A9001BD339FD00CD5FC5 /* H5Ftest.c in Sources */,
617187881BFCF9CB00FB5D5F /* PointerUtilities.swift in Sources */,
6185A9281BD339FD00CD5FC5 /* H5HLcache.c in Sources */,
6185A8E71BD339FD00CD5FC5 /* H5FDmpi.c in Sources */,
6185A8D41BD339FD00CD5FC5 /* H5Dlayout.c in Sources */,
Expand Down Expand Up @@ -2414,7 +2409,6 @@
61B3176C1BBDBA8E00F63C45 /* H5trace.c in Sources */,
61B3173F1BBDBA8E00F63C45 /* H5Shyper.c in Sources */,
61B3168B1BBDBA8E00F63C45 /* H5Fio.c in Sources */,
617187871BFCF9CB00FB5D5F /* PointerUtilities.swift in Sources */,
61B3166A1BBDBA8E00F63C45 /* H5F.c in Sources */,
61B3163B1BBDBA8E00F63C45 /* H5B2test.c in Sources */,
61B317571BBDBA8E00F63C45 /* H5Tcommit.c in Sources */,
Expand Down
20 changes: 14 additions & 6 deletions Source/Dataset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public 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(-1, UInt64.self) else {
guard offset != unsafeBitCast(Int64(-1), UInt64.self) else {
return nil
}
return Int(offset)
Expand All @@ -31,7 +31,10 @@ public class Dataset: Object {
return space.dims
}
set {
H5Dset_extent(id, ptr(newValue))
let array = newValue.map({ hsize_t($0) })
array.withUnsafeBufferPointer { pointer in
H5Dset_extent(id, pointer.baseAddress)
}
}
}

Expand All @@ -43,9 +46,11 @@ public class Dataset: Object {
}

let rank = space.dims.count
var chunkSize = [Int](count: rank, repeatedValue: 0)
H5Pget_chunk(plistId, Int32(rank), ptr(&chunkSize))
return chunkSize
var chunkSize = [hsize_t](count: rank, repeatedValue: 0)
chunkSize.withUnsafeMutableBufferPointer { (inout pointer: UnsafeMutableBufferPointer<hsize_t>) in
H5Pget_chunk(plistId, Int32(rank), pointer.baseAddress)
}
return chunkSize.map({ Int($0) })
}

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

let plist = H5Pcreate(H5P_CLS_DATASET_CREATE_ID_g)
H5Pset_chunk(plist, Int32(chunkDimensions.count), ptr(chunkDimensions))
let chunkDimensions64 = chunkDimensions.map({ hsize_t($0) })
chunkDimensions64.withUnsafeBufferPointer { pointer in
H5Pset_chunk(plist, Int32(chunkDimensions.count), pointer.baseAddress)
}
defer {
H5Pclose(plist)
}
Expand Down
51 changes: 39 additions & 12 deletions Source/Dataspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public class Dataspace {

/// Create a Dataspace
public init(dims: [Int]) {
id = H5Screate_simple(Int32(dims.count), ptr(dims), nil)
let dims64 = dims.map({ hsize_t($0) })
id = dims64.withUnsafeBufferPointer { pointer in
return H5Screate_simple(Int32(dims.count), pointer.baseAddress, nil)
}
guard id >= 0 else {
fatalError("Failed to create Dataspace")
}
Expand All @@ -34,7 +37,11 @@ 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]) {
id = H5Screate_simple(Int32(dims.count), ptr(dims), ptr(maxDims))
let dims64 = dims.map({ hsize_t($0) })
let maxDims64 = maxDims.map({ hsize_t($0) })
id = withExtendedLifetime((dims64, maxDims64)) {
return H5Screate_simple(Int32(dims.count), dims64, maxDims64)
}
guard id >= 0 else {
fatalError("Failed to create Dataspace")
}
Expand All @@ -57,21 +64,25 @@ public class Dataspace {
/// The size of each dimension in the Dataspace
public var dims: [Int] {
let rank = Int(H5Sget_simple_extent_ndims(id))
var dims = [Int](count: rank, repeatedValue: 0)
guard H5Sget_simple_extent_dims(id, ptr(&dims), nil) >= 0 else {
fatalError("Coulnd't get the dimensons of the Dataspace")
var dims = [hsize_t](count: rank, repeatedValue: 0)
dims.withUnsafeMutableBufferPointer { pointer in
guard H5Sget_simple_extent_dims(id, pointer.baseAddress, nil) >= 0 else {
fatalError("Coulnd't get the dimensons of the Dataspace")
}
}
return dims
return dims.map({ Int($0) })
}

/// The maximum size of each dimension in the Dataspace
public var maxDims: [Int] {
let rank = Int(H5Sget_simple_extent_ndims(id))
var maxDims = [Int](count: rank, repeatedValue: 0)
guard H5Sget_simple_extent_dims(id, nil, ptr(&maxDims)) >= 0 else {
fatalError("Coulnd't get the dimensons of the Dataspace")
var maxDims = [hsize_t](count: rank, repeatedValue: 0)
maxDims.withUnsafeMutableBufferPointer { pointer in
guard H5Sget_simple_extent_dims(id, nil, pointer.baseAddress) >= 0 else {
fatalError("Coulnd't get the dimensons of the Dataspace")
}
}
return maxDims
return maxDims.map({ Int($0) })
}

// MARK: - Selection
Expand Down Expand Up @@ -105,7 +116,13 @@ 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 start: [Int], stride: [Int]?, count: [Int]?, block: [Int]?) {
H5Sselect_hyperslab(id, H5S_SELECT_SET, ptr(start), ptr(stride), ptr(count), ptr(block))
let start64 = start.map({ hsize_t($0) })
let stride64 = stride?.map({ hsize_t($0) })
let count64 = count?.map({ hsize_t($0) })
let block64 = block?.map({ hsize_t($0) })
withExtendedLifetime((start64, stride64, count64, block64)) {
H5Sselect_hyperslab(id, H5S_SELECT_SET, start64, pointerOrNil(stride64), pointerOrNil(count64), pointerOrNil(block64))
}
selectionDims = count ?? dims
}

Expand Down Expand Up @@ -139,6 +156,16 @@ public class Dataspace {

/// This function allows the same shaped selection to be moved to different locations within a dataspace without requiring it to be redefined.
public func offset(offset: [Int]) {
H5Soffset_simple(id, ptr(offset))
let offset64 = offset.map({ hssize_t($0) })
offset64.withUnsafeBufferPointer { pointer in
H5Soffset_simple(id, pointer.baseAddress)
}
}
}

func pointerOrNil(array: [hsize_t]?) -> UnsafePointer<hsize_t> {
if let array = array {
return UnsafePointer(array)
}
return nil
}
5 changes: 4 additions & 1 deletion Source/DoubleDataset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ extension GroupType {
precondition(dataspace.dims.count == chunkDimensions.count)

let plist = H5Pcreate(H5P_CLS_DATASET_CREATE_ID_g)
H5Pset_chunk(plist, Int32(chunkDimensions.count), ptr(chunkDimensions))
let chunkDimensions64 = chunkDimensions.map({ hsize_t($0) })
chunkDimensions64.withUnsafeBufferPointer { pointer in
H5Pset_chunk(plist, Int32(chunkDimensions.count), pointer.baseAddress)
}
defer {
H5Pclose(plist)
}
Expand Down
5 changes: 4 additions & 1 deletion Source/FloatDataset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ extension GroupType {
precondition(dataspace.dims.count == chunkDimensions.count)

let plist = H5Pcreate(H5P_CLS_DATASET_CREATE_ID_g)
H5Pset_chunk(plist, Int32(chunkDimensions.count), ptr(chunkDimensions))
let chunkDimensions64 = chunkDimensions.map({ hsize_t($0) })
chunkDimensions64.withUnsafeBufferPointer { pointer in
H5Pset_chunk(plist, Int32(chunkDimensions.count), pointer.baseAddress)
}
defer {
H5Pclose(plist)
}
Expand Down
5 changes: 4 additions & 1 deletion Source/IntDataset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ extension GroupType {
precondition(dataspace.dims.count == chunkDimensions.count)

let plist = H5Pcreate(H5P_CLS_DATASET_CREATE_ID_g)
H5Pset_chunk(plist, Int32(chunkDimensions.count), ptr(chunkDimensions))
let chunkDimensions64 = chunkDimensions.map({ hsize_t($0) })
chunkDimensions64.withUnsafeBufferPointer { pointer in
H5Pset_chunk(plist, Int32(chunkDimensions.count), pointer.baseAddress)
}
defer {
H5Pclose(plist)
}
Expand Down
95 changes: 0 additions & 95 deletions Source/PointerUtilities.swift

This file was deleted.

5 changes: 4 additions & 1 deletion Source/StringDataset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ extension GroupType {
precondition(dataspace.dims.count == chunkDimensions.count)

let plist = H5Pcreate(H5P_CLS_DATASET_CREATE_ID_g)
H5Pset_chunk(plist, Int32(chunkDimensions.count), ptr(chunkDimensions))
let chunkDimensions64 = chunkDimensions.map({ hsize_t($0) })
chunkDimensions64.withUnsafeBufferPointer { pointer in
H5Pset_chunk(plist, Int32(chunkDimensions.count), pointer.baseAddress)
}
defer {
H5Pclose(plist)
}
Expand Down

0 comments on commit 6b93d77

Please sign in to comment.