Commit a364af8f by Siva Committed by Tianqi Chen

[GOLANG] Some fixes for golang latest version compiler. #3119 (#3182)

parent 6a4d71ff
......@@ -51,7 +51,7 @@ func (tbytearray ByteArray) nativeCPtr() (retVal uintptr) {
// `val` is the golang string object from which the ByteArray is initialized.
func (tbytearray ByteArray) setData(val string) {
bufPtr := ((*C.TVMByteArray)(unsafe.Pointer(tbytearray))).data
if bufPtr == (*_Ctype_char)(C.NULL) {
if bufPtr == (*C.char)(C.NULL) {
C.free(unsafe.Pointer(bufPtr))
}
......@@ -74,7 +74,7 @@ func (tbytearray ByteArray) getData() (retVal []byte) {
// returns newly created ByteArray.
func newByteArray(val []byte) (retVal ByteArray) {
handle := ByteArray(C.malloc(C.sizeof_TVMByteArray))
((*C.TVMByteArray)(unsafe.Pointer(handle))).data = (*_Ctype_char)(C.NULL)
((*C.TVMByteArray)(unsafe.Pointer(handle))).data = (*C.char)(C.NULL)
((*C.TVMByteArray)(unsafe.Pointer(handle))).size = 0
handle.setData(string(val))
retVal = handle
......
......@@ -123,7 +123,7 @@ func GetGlobalFunction(funcname string) (retVal *Function, err error) {
cfuncname := C.CString(funcname)
ret := (int32)(C.TVMFuncGetGlobal(cfuncname,
(*_Ctype_TVMFunctionHandle)(unsafe.Pointer(&funp))))
(*C.TVMFunctionHandle)(unsafe.Pointer(&funp))))
C.free(unsafe.Pointer(cfuncname))
if ret != 0 {
......@@ -229,12 +229,12 @@ func nativeTVMFuncCall(funp *Function, argValues []*Value, typeCodes []int32,
retValues []*Value, retTypeCode *int32) (err error) {
nargValues := nativeFromGoSlice(argValues)
nretValues := nativeFromGoSlice(retValues)
result := (int32)(C.TVMFuncCall(_Ctype_TVMFunctionHandle(*funp),
(*_Ctype_TVMValue)(unsafe.Pointer(nargValues)),
(*_Ctype_int)(unsafe.Pointer(&(typeCodes[0]))),
result := (int32)(C.TVMFuncCall(C.TVMFunctionHandle(*funp),
(*C.TVMValue)(unsafe.Pointer(nargValues)),
(*C.int)(unsafe.Pointer(&(typeCodes[0]))),
C.int(len(argValues)),
(*_Ctype_TVMValue)(unsafe.Pointer(nretValues)),
(*_Ctype_int)(unsafe.Pointer(retTypeCode))))
(*C.TVMValue)(unsafe.Pointer(nretValues)),
(*C.int)(unsafe.Pointer(retTypeCode))))
nativeToGoSlice(nargValues, argValues, typeCodes)
nativeToGoSlice(nretValues, retValues, (*[1<<31] int32)(unsafe.Pointer(retTypeCode))[:1:1])
C.free(unsafe.Pointer(nargValues))
......@@ -312,9 +312,9 @@ func goTVMCallback(args C.native_voidp, typeCodes C.native_voidp, numArgs int32,
// Handle KStr, KBytes: Local finalizers shouldn't try freeing them.
retValues[0].isLocal = false
apiRet := (int32) (C.TVMCFuncSetReturn(_Ctype_TVMRetValueHandle(retArg),
(*_Ctype_TVMValue)(unsafe.Pointer(nretValues)),
(*_Ctype_int)(unsafe.Pointer(&retTypeCode)), 1))
apiRet := (int32) (C.TVMCFuncSetReturn(C.TVMRetValueHandle(retArg),
(*C.TVMValue)(unsafe.Pointer(nretValues)),
(*C.int)(unsafe.Pointer(&retTypeCode)), 1))
C.free(unsafe.Pointer(nretValues))
if apiRet != 0 {
errStr := string("TVMCFuncSetReturn failed ")
......@@ -372,7 +372,7 @@ func RegisterFunction(args ...interface{}) (err error) {
cfuncname := C.CString(funcname)
result := (int32) (C.TVMFuncRegisterGlobal(cfuncname,
_Ctype_TVMFunctionHandle(*fhandle),
C.TVMFunctionHandle(*fhandle),
0)); // Override = False
C.free(unsafe.Pointer(cfuncname))
if result != 0 {
......
......@@ -64,7 +64,7 @@ func LoadModuleFromFile(modpath string, args ...interface{}) (retVal *Module, er
ret := (int32)(C.TVMModLoadFromFile(cmodpath,
cmodtype,
(*_Ctype_TVMModuleHandle)(unsafe.Pointer(&modp))))
(*C.TVMModuleHandle)(unsafe.Pointer(&modp))))
C.free(unsafe.Pointer(cmodpath))
C.free(unsafe.Pointer(cmodtype))
......@@ -117,10 +117,10 @@ func (tvmmodule *Module) GetFunction (
var funp uintptr
cfuncname := C.CString(funcname)
ret := (int32)(C.TVMModGetFunction((_Ctype_TVMModuleHandle)(*tvmmodule),
ret := (int32)(C.TVMModGetFunction((C.TVMModuleHandle)(*tvmmodule),
cfuncname,
C.int(queryImports),
(*_Ctype_TVMFunctionHandle)(unsafe.Pointer(&funp))))
(*C.TVMFunctionHandle)(unsafe.Pointer(&funp))))
C.free(unsafe.Pointer(cfuncname))
if ret != 0 {
......
......@@ -48,7 +48,7 @@ func (parray Array) nativeCPtr() (retVal uintptr) {
}
func (parray Array) nativeCopyFrom(data unsafe.Pointer, datalen int) (err error) {
ret := C.TVMArrayCopyFromBytes((*_Ctype_TVMArray)(unsafe.Pointer(parray.nativeCPtr())),
ret := C.TVMArrayCopyFromBytes((*C.TVMArray)(unsafe.Pointer(parray.nativeCPtr())),
data,
C.ulong(datalen))
if ret != 0 {
......@@ -66,7 +66,7 @@ func (parray Array) nativeCopyFrom(data unsafe.Pointer, datalen int) (err error)
func (parray Array) CopyFrom(val interface{}) (err error) {
var data unsafe.Pointer
var datalen int
dtype := ((*_Ctype_TVMArray)(unsafe.Pointer(parray))).dtype
dtype := ((*C.TVMArray)(unsafe.Pointer(parray))).dtype
switch val.(type) {
case []int8:
......@@ -127,7 +127,7 @@ func (parray Array) CopyFrom(val interface{}) (err error) {
}
func (parray Array) nativeCopyTo (data unsafe.Pointer, datalen int) (err error){
ret := C.TVMArrayCopyToBytes((*_Ctype_TVMArray)(unsafe.Pointer(parray.nativeCPtr())),
ret := C.TVMArrayCopyToBytes((*C.TVMArray)(unsafe.Pointer(parray.nativeCPtr())),
unsafe.Pointer(data),
C.ulong(datalen))
......@@ -150,7 +150,7 @@ func (parray Array) AsSlice() (retVal interface{}, err error) {
for ii := range shape {
size *= shape[ii]
}
dtype := ((*_Ctype_TVMArray)(unsafe.Pointer(parray))).dtype
dtype := ((*C.TVMArray)(unsafe.Pointer(parray))).dtype
switch parray.GetDType() {
case "int8":
......@@ -222,13 +222,13 @@ func (parray Array) AsSlice() (retVal interface{}, err error) {
// GetNdim returns the number of dimentions in Array
func (parray Array) GetNdim() (retVal int32) {
retVal = int32(((*_Ctype_TVMArray)(unsafe.Pointer(parray))).ndim)
retVal = int32(((*C.TVMArray)(unsafe.Pointer(parray))).ndim)
return
}
// GetShape returns the number of dimentions in Array
func (parray Array) GetShape() (retVal []int64) {
shapePtr := (*C.int64_t)(((*_Ctype_TVMArray)(unsafe.Pointer(parray))).shape)
shapePtr := (*C.int64_t)(((*C.TVMArray)(unsafe.Pointer(parray))).shape)
ndim := parray.GetNdim()
shapeSlice := (*[1<<31] int64)(unsafe.Pointer(shapePtr))[:ndim:ndim]
......@@ -239,14 +239,14 @@ func (parray Array) GetShape() (retVal []int64) {
// GetDType returns the number of dimentions in Array
func (parray Array) GetDType() (retVal string) {
ret := ((*_Ctype_TVMArray)(unsafe.Pointer(parray))).dtype
ret := ((*C.TVMArray)(unsafe.Pointer(parray))).dtype
retVal, _ = dtypeFromTVMType(*(*pTVMType)(unsafe.Pointer(&ret)))
return
}
// GetCtx returns the number of dimentions in Array
func (parray Array) GetCtx() (retVal Context) {
ret := ((*_Ctype_TVMArray)(unsafe.Pointer(parray))).ctx
ret := ((*C.TVMArray)(unsafe.Pointer(parray))).ctx
retVal = *(*Context)(unsafe.Pointer(&ret))
return
}
......@@ -267,14 +267,14 @@ func (parray Array) GetCtx() (retVal Context) {
func nativeTVMArrayAlloc(shape []int64, ndim int32,
dtypeCode int32, dtypeBits int32, dtypeLanes int32,
deviceType int32, deviceID int32) (retVal uintptr, err error) {
ret := (int32)(C.TVMArrayAlloc((*_Ctype_long)(&(shape[0])),
ret := (int32)(C.TVMArrayAlloc((*C.long)(&(shape[0])),
C.int(ndim),
C.int(dtypeCode),
C.int(dtypeBits),
C.int(dtypeLanes),
C.int(deviceType),
C.int(deviceID),
(*_Ctype_TVMArrayHandle)(unsafe.Pointer(&retVal))))
(*C.TVMArrayHandle)(unsafe.Pointer(&retVal))))
if ret != 0 {
err = errors.New(getTVMLastError())
return
......@@ -343,6 +343,6 @@ func Empty(shape []int64, args ...interface{}) (parray *Array, err error) {
//
// `ret` indicates the status of this api execution.
func nativeTVMArrayFree(parray Array) (retVal int32) {
retVal = (int32)(C.TVMArrayFree((*_Ctype_TVMArray)(unsafe.Pointer(parray.nativeCPtr()))))
retVal = (int32)(C.TVMArrayFree((*C.TVMArray)(unsafe.Pointer(parray.nativeCPtr()))))
return
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment