Skip to content

Commit

Permalink
fix ctypes bug for mac (#9)
Browse files Browse the repository at this point in the history
* fix c_api bug for mac

* update travis
  • Loading branch information
icemelon authored and tqchen committed Jan 11, 2017
1 parent 3931401 commit 7250005
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ language: cpp

os:
- linux
# - osx
- osx

env:
# code analysis
Expand Down
14 changes: 8 additions & 6 deletions python/tvm/_ctypes/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ class ArgVariant(ctypes.Union):
kStr = 3
kNodeHandle = 4

NODE_TYPE = {
}

def _type_key(handle):
def _return_node(x):
handle = x.v_handle
if not isinstance(handle, ctypes.c_void_p):
handle = ctypes.c_void_p(handle)
ret_val = ArgVariant()
ret_typeid = ctypes.c_int()
ret_success = ctypes.c_int()
Expand All @@ -35,17 +40,14 @@ def _type_key(handle):
ctypes.byref(ret_val),
ctypes.byref(ret_typeid),
ctypes.byref(ret_success)))
return py_str(ret_val.v_str)

NODE_TYPE = {
}
return NODE_TYPE.get(py_str(ret_val.v_str), NodeBase)(handle)

RET_SWITCH = {
kNull: lambda x: None,
kLong: lambda x: x.v_long,
kDouble: lambda x: x.v_double,
kStr: lambda x: py_str(x.v_str),
kNodeHandle: lambda x: NODE_TYPE.get(_type_key(x), NodeBase)(x.v_handle)
kNodeHandle: lambda x: _return_node(x)
}

class SliceBase(object):
Expand Down

0 comments on commit 7250005

Please sign in to comment.