Skip to content

Commit

Permalink
[GOLANG] Some fixes for golang latest version compiler. apache#3119
Browse files Browse the repository at this point in the history
  • Loading branch information
srkreddy1238 committed May 13, 2019
1 parent 6a4d71f commit 0398b6e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions golang/src/bytearray.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand All @@ -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
Expand Down
20 changes: 10 additions & 10 deletions golang/src/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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 ")
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions golang/src/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down
22 changes: 11 additions & 11 deletions golang/src/ndarray.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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:
Expand Down Expand Up @@ -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))

Expand All @@ -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":
Expand Down Expand Up @@ -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]
Expand All @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit 0398b6e

Please sign in to comment.