You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.7 KiB
60 lines
1.7 KiB
10 years ago
|
/*
|
||
|
* Mini Object Storage, (C) 2014 Minio, Inc.
|
||
|
*
|
||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
* you may not use this file except in compliance with the License.
|
||
|
* You may obtain a copy of the License at
|
||
|
*
|
||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||
|
*
|
||
|
* Unless required by applicable law or agreed to in writing, software
|
||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
* See the License for the specific language governing permissions and
|
||
|
* limitations under the License.
|
||
|
*/
|
||
|
|
||
|
package erasure
|
||
|
|
||
10 years ago
|
// #include <stdint.h>
|
||
10 years ago
|
import "C"
|
||
|
import (
|
||
|
"fmt"
|
||
|
"unsafe"
|
||
|
)
|
||
|
|
||
|
// Integer to Int conversion
|
||
10 years ago
|
func int2cInt(src_err_list []int) *C.int32_t {
|
||
10 years ago
|
var sizeErrInt = int(unsafe.Sizeof(src_err_list[0]))
|
||
|
switch sizeInt {
|
||
|
case sizeErrInt:
|
||
10 years ago
|
return (*C.int32_t)(unsafe.Pointer(&src_err_list[0]))
|
||
10 years ago
|
case sizeInt8:
|
||
|
int8Array := make([]int8, len(src_err_list))
|
||
10 years ago
|
for i, v := range src_err_list {
|
||
10 years ago
|
int8Array[i] = int8(v)
|
||
10 years ago
|
}
|
||
10 years ago
|
return (*C.int32_t)(unsafe.Pointer(&int8Array[0]))
|
||
10 years ago
|
case sizeInt16:
|
||
|
int16Array := make([]int16, len(src_err_list))
|
||
10 years ago
|
for i, v := range src_err_list {
|
||
10 years ago
|
int16Array[i] = int16(v)
|
||
10 years ago
|
}
|
||
10 years ago
|
return (*C.int32_t)(unsafe.Pointer(&int16Array[0]))
|
||
10 years ago
|
case sizeInt32:
|
||
|
int32Array := make([]int32, len(src_err_list))
|
||
10 years ago
|
for i, v := range src_err_list {
|
||
10 years ago
|
int32Array[i] = int32(v)
|
||
10 years ago
|
}
|
||
10 years ago
|
return (*C.int32_t)(unsafe.Pointer(&int32Array[0]))
|
||
10 years ago
|
case sizeInt64:
|
||
|
int64Array := make([]int64, len(src_err_list))
|
||
10 years ago
|
for i, v := range src_err_list {
|
||
10 years ago
|
int64Array[i] = int64(v)
|
||
10 years ago
|
}
|
||
10 years ago
|
return (*C.int32_t)(unsafe.Pointer(&int64Array[0]))
|
||
10 years ago
|
default:
|
||
10 years ago
|
panic(fmt.Sprintf("Unsupported: %d", sizeInt))
|
||
10 years ago
|
}
|
||
|
}
|